Initial public release
Luxe 0.1.0: a coding agent harness for the terminal. See README.md to get started and CHANGELOG.md for releases.
This commit is contained in:
13
web/demo/AGENTS.md
Normal file
13
web/demo/AGENTS.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# todo
|
||||
|
||||
A task list. No dependencies, no build step — plain ES modules on Node.
|
||||
|
||||
```bash
|
||||
npm test # node --test
|
||||
node src/cli.js # the CLI, on ./tasks.json
|
||||
TODO_FILE=/tmp/try.json node src/cli.js add 'x' --due 2026-03-04 # try it without touching that
|
||||
```
|
||||
|
||||
- Dates are ISO day strings (`2026-03-14`) and compare as text. Never parse them into `Date`.
|
||||
- Every filter in `src/filter.js` is pure and takes the task list first.
|
||||
- A behavior change needs a test in `test/` that fails without it.
|
||||
11
web/demo/package.json
Normal file
11
web/demo/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "todo",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "A task list small enough to read in one sitting.",
|
||||
"bin": { "todo": "src/cli.js" },
|
||||
"scripts": {
|
||||
"test": "node --test"
|
||||
}
|
||||
}
|
||||
61
web/demo/src/cli.js
Normal file
61
web/demo/src/cli.js
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env node
|
||||
/** todo — a task list small enough to read in one sitting. */
|
||||
|
||||
import { dueBy, open, tagged } from "./filter.js";
|
||||
import { load, make, save } from "./store.js";
|
||||
|
||||
const USAGE = `todo add <title> [--due DATE] [--tag TAG]
|
||||
todo list [--tag TAG]
|
||||
todo due <DATE>
|
||||
todo done <title>`;
|
||||
|
||||
function show(tasks) {
|
||||
if (tasks.length === 0) {
|
||||
console.log("nothing here");
|
||||
return;
|
||||
}
|
||||
for (const task of tasks) {
|
||||
const mark = task.done ? "x" : " ";
|
||||
const due = task.due ? ` due ${task.due}` : "";
|
||||
console.log(`[${mark}] ${task.title}${due}`);
|
||||
}
|
||||
}
|
||||
|
||||
const [command, ...rest] = process.argv.slice(2);
|
||||
const flag = (name) => {
|
||||
const at = rest.indexOf(`--${name}`);
|
||||
return at === -1 ? null : rest[at + 1];
|
||||
};
|
||||
const words = rest.filter((word, i) => !word.startsWith("--") && !rest[i - 1]?.startsWith("--"));
|
||||
const tasks = await load();
|
||||
|
||||
switch (command) {
|
||||
case "add": {
|
||||
const tag = flag("tag");
|
||||
tasks.push(make(words.join(" "), { due: flag("due"), tags: tag ? [tag] : [] }));
|
||||
await save(tasks);
|
||||
show(tasks.slice(-1));
|
||||
break;
|
||||
}
|
||||
case "list": {
|
||||
const tag = flag("tag");
|
||||
show(tag ? tagged(open(tasks), [tag]) : open(tasks));
|
||||
break;
|
||||
}
|
||||
case "due":
|
||||
show(dueBy(open(tasks), words[0]));
|
||||
break;
|
||||
case "done": {
|
||||
const match = tasks.find((task) => task.title === words.join(" "));
|
||||
if (!match) {
|
||||
console.error(`no task called ${words.join(" ")}`);
|
||||
process.exit(1);
|
||||
}
|
||||
match.done = true;
|
||||
await save(tasks);
|
||||
show([match]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.log(USAGE);
|
||||
}
|
||||
20
web/demo/src/filter.js
Normal file
20
web/demo/src/filter.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/** Selecting tasks out of a list. */
|
||||
|
||||
/**
|
||||
* Tasks due on or before `date`.
|
||||
*
|
||||
* Dates are ISO day strings (`2026-03-14`), so they compare correctly as text.
|
||||
*/
|
||||
export function dueBy(tasks, date) {
|
||||
return tasks.filter((task) => task.due && task.due <= date);
|
||||
}
|
||||
|
||||
/** Tasks that are still open, newest first. */
|
||||
export function open(tasks) {
|
||||
return tasks.filter((task) => !task.done).sort((a, b) => b.added.localeCompare(a.added));
|
||||
}
|
||||
|
||||
/** Tasks carrying every one of `tags`. */
|
||||
export function tagged(tasks, tags) {
|
||||
return tasks.filter((task) => tags.every((tag) => task.tags.includes(tag)));
|
||||
}
|
||||
26
web/demo/src/store.js
Normal file
26
web/demo/src/store.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/** Reading and writing the task file. */
|
||||
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
|
||||
// `TODO_FILE` points it elsewhere, so trying the CLI never touches the real list
|
||||
const FILE = process.env.TODO_FILE ?? "tasks.json";
|
||||
|
||||
/** Every task on disk, or an empty list the first time. */
|
||||
export async function load() {
|
||||
try {
|
||||
return JSON.parse(await readFile(FILE, "utf8"));
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT") return [];
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/** Replaces the file. Callers own the whole list, so there is nothing to merge. */
|
||||
export async function save(tasks) {
|
||||
await writeFile(FILE, `${JSON.stringify(tasks, null, 2)}\n`);
|
||||
}
|
||||
|
||||
/** A new task, with today's date and no tags unless asked for. */
|
||||
export function make(title, { due = null, tags = [] } = {}) {
|
||||
return { title, due, done: false, added: new Date().toISOString().slice(0, 10), tags };
|
||||
}
|
||||
29
web/demo/test/filter.test.js
Normal file
29
web/demo/test/filter.test.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { dueBy, open, tagged } from "../src/filter.js";
|
||||
|
||||
const tasks = [
|
||||
{ title: "Ship the docs", due: "2026-03-10", done: false, added: "2026-03-01", tags: ["docs"] },
|
||||
{ title: "Fix the parser", due: "2026-03-14", done: false, added: "2026-03-04", tags: ["bug"] },
|
||||
{ title: "Answer Priya", due: "2026-03-20", done: true, added: "2026-03-02", tags: ["inbox"] },
|
||||
];
|
||||
|
||||
test("dueBy keeps everything up to the cutoff", () => {
|
||||
assert.deepEqual(
|
||||
dueBy(tasks, "2026-03-10").map((t) => t.title),
|
||||
["Ship the docs"],
|
||||
);
|
||||
});
|
||||
|
||||
test("open sorts newest first and drops what is done", () => {
|
||||
assert.deepEqual(
|
||||
open(tasks).map((t) => t.title),
|
||||
["Fix the parser", "Ship the docs"],
|
||||
);
|
||||
});
|
||||
|
||||
test("tagged wants all of them, not any", () => {
|
||||
assert.deepEqual(tagged(tasks, ["bug"]).length, 1);
|
||||
assert.deepEqual(tagged(tasks, ["bug", "docs"]).length, 0);
|
||||
});
|
||||
Reference in New Issue
Block a user