@llm4ts/shell 2.52.0 → 2.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,163 @@
1
+ // Run a meeting of personas on a topic toward a goal: they discuss item by item, a Scribe writes the solution outline and the plan, you steer from the meeting file.
2
+ //
3
+ // llm4ts run roundtable --repo ~/work/portal "Architecture outline for the payments hub" \
4
+ // -- --goal "An outline and a plan the committee can approve, within our standards" \
5
+ // --agents "PO,PM,Sr SW Eng,Cloud Architect,DevOps,SRE" --context docs/standards
6
+ // llm4ts run roundtable --repo ~/work/portal -- --meeting payments-hub # continue, or fold in your answers
7
+ // llm4ts run roundtable --repo ~/work/portal -- --eject-personas # the bundled cards, to edit
8
+ // llm4ts run roundtable --repo ~/work/portal -- --list # meetings and personas
9
+ //
10
+ // Code chairs the meeting (ADR 0046). The first attendee proposes the agenda;
11
+ // the run stops for you to edit it unless --no-pause. Then every attendee is
12
+ // asked once per round, in persona order, on each item: a position, a
13
+ // proposal, an objection (blocking or not), a question (for the room, or
14
+ // parked for you), an agreement, or a pass. An item settles after a complete
15
+ // round with no open blocking objection and no open question; silence is
16
+ // consent. Three rounds per item (--rounds), forty turns in all (--max-turns);
17
+ // what is still open is written down, never forced. Then the Scribe writes
18
+ // outline.md and plan.md, code renders decisions.md (with the dissent) and
19
+ // open-questions.md, every attendee reviews once, the Scribe fixes what
20
+ // blocks, and the meeting is done.
21
+ //
22
+ // The FILE is the state: <repo>/.llm4ts/meetings/<id>/meeting.md. Answer a
23
+ // parked question under `## Answers`, or write under `## Feedback`, and
24
+ // rerun: your words become turns, the item reopens for one more round and the
25
+ // drafts are rewritten. Personas are cards: bundled ones, replaced by
26
+ // .llm4ts/personas/<name>.md of the same name. Every persona borrows one
27
+ // read-only, toolless seat: LLM4TS_REASONER (default claude). --context
28
+ // gives every attendee the same documents, under LLM4TS_CONTEXT_BUDGET.
29
+ // Nothing in the repository's git is touched.
30
+ import { readdir } from "node:fs/promises";
31
+ import { join, resolve } from "node:path";
32
+ import * as Console from "effect/Console";
33
+ import * as Effect from "effect/Effect";
34
+ import { budget } from "@llm4ts/flow/Context";
35
+ import { judgmentOf } from "@llm4ts/flow/Judgment";
36
+ import { parseMeeting } from "@llm4ts/flow/Roundtable";
37
+ import { ScriptUsage, asToolless, nodePlainFileStore, resolveFlowInput, runFlowMain, runNode, stage } from "@llm4ts/runner";
38
+ import { reasonerFromEnvironment } from "./lib/epic-stories.js";
39
+ import { describePersonas, ejectPersonas, meetingDir, meetingSlug, meetingsDir, parseRoundtableArgs, personasDir, resolvePersonas, runRoundtable } from "./lib/roundtable.js";
40
+ import { defaultAttendees } from "./lib/roundtable-personas.js";
41
+ const files = nodePlainFileStore;
42
+ const namesIn = (dir, suffix) => Effect.tryPromise(() => readdir(dir, { withFileTypes: true })).pipe(Effect.map((entries) => entries
43
+ .filter((entry) => entry.isFile() && entry.name.endsWith(suffix))
44
+ .map((entry) => entry.name.slice(0, -suffix.length))
45
+ .sort()), Effect.catch(() => Effect.succeed([])));
46
+ const foldersIn = (dir) => Effect.tryPromise(() => readdir(dir, { withFileTypes: true })).pipe(Effect.map((entries) => entries
47
+ .filter((entry) => entry.isDirectory())
48
+ .map((entry) => entry.name)
49
+ .sort()), Effect.catch(() => Effect.succeed([])));
50
+ /** `.llm4ts/personas/<name>.md`, keyed by name. */
51
+ const customCards = Effect.fn("roundtable.customCards")(function* (workDir) {
52
+ const dir = personasDir(workDir);
53
+ const names = yield* namesIn(dir, ".md");
54
+ const cards = {};
55
+ for (const name of names) {
56
+ const text = yield* files.read(join(dir, `${name}.md`));
57
+ if (text !== undefined)
58
+ cards[name] = text;
59
+ }
60
+ return cards;
61
+ });
62
+ const textLike = /\.(md|markdown|txt|adoc|rst)$/i;
63
+ /** Every text document under `--context`, recursively, in path order. */
64
+ const contextDocs = Effect.fn("roundtable.contextDocs")(function* (dir) {
65
+ if (dir === undefined)
66
+ return [];
67
+ const entries = yield* Effect.tryPromise(() => readdir(dir, { withFileTypes: true, recursive: true })).pipe(Effect.catch(() => ScriptUsage.make({ message: `--context ${dir} is not a readable directory` })));
68
+ const paths = entries
69
+ .filter((entry) => entry.isFile() && textLike.test(entry.name))
70
+ .map((entry) => join(entry.parentPath, entry.name))
71
+ .sort();
72
+ const docs = [];
73
+ for (const path of paths) {
74
+ const text = yield* files.read(path);
75
+ if (text !== undefined)
76
+ docs.push({ path: path.slice(dir.length + 1), text });
77
+ }
78
+ return docs;
79
+ });
80
+ const program = Effect.gen(function* () {
81
+ const flags = yield* parseRoundtableArgs(process.argv.slice(2));
82
+ const given = yield* resolveFlowInput("", flags.rest);
83
+ const workDir = given.workDir;
84
+ if (flags.ejectPersonas) {
85
+ const written = yield* ejectPersonas(files, workDir);
86
+ yield* Console.log(written.length === 0
87
+ ? `every bundled card is already under ${personasDir(workDir)}`
88
+ : `wrote ${written.length} card(s):\n${written.map((path) => ` ${path}`).join("\n")}`);
89
+ return;
90
+ }
91
+ const custom = yield* customCards(workDir);
92
+ if (flags.list) {
93
+ const ids = yield* foldersIn(meetingsDir(workDir));
94
+ const lines = [];
95
+ for (const id of ids) {
96
+ const text = yield* files.read(join(meetingDir(workDir, id), "meeting.md"));
97
+ const meeting = text === undefined ? undefined : yield* parseMeeting(text).pipe(Effect.option);
98
+ lines.push(meeting === undefined || meeting._tag === "None"
99
+ ? ` ${id} (no readable meeting.md)`
100
+ : ` ${id} ${meeting.value.status} ${meeting.value.topic}`);
101
+ }
102
+ const personas = yield* resolvePersonas(custom, defaultAttendees);
103
+ yield* Console.log([
104
+ lines.length === 0 ? `no meetings under ${meetingsDir(workDir)}` : "meetings:",
105
+ ...lines,
106
+ "",
107
+ `personas (bundled${Object.keys(custom).length === 0 ? "" : `, ${Object.keys(custom).length} custom`}):`,
108
+ describePersonas([...personas.attendees, personas.scribe])
109
+ ].join("\n"));
110
+ return;
111
+ }
112
+ const topic = given.prompt.trim();
113
+ const meetingId = flags.meeting ?? (topic.length === 0 ? undefined : meetingSlug(topic));
114
+ if (meetingId === undefined) {
115
+ return yield* ScriptUsage.make({
116
+ message: `give the topic to start a meeting, or --meeting <id> to continue one`
117
+ });
118
+ }
119
+ // An existing meeting's attendees are the file's; --agents only seats a new one.
120
+ const existing = yield* files.read(join(meetingDir(workDir, meetingId), "meeting.md"));
121
+ const attendeeNames = existing === undefined
122
+ ? (flags.agents ?? defaultAttendees)
123
+ : (yield* parseMeeting(existing, join(meetingDir(workDir, meetingId), "meeting.md")))
124
+ .attendees;
125
+ const personas = yield* resolvePersonas(custom, attendeeNames);
126
+ // Relative to the repository: the standards usually live beside the code.
127
+ const docs = yield* contextDocs(flags.context === undefined ? undefined : resolve(workDir, flags.context));
128
+ const reasoning = asToolless(yield* reasonerFromEnvironment(process.env));
129
+ const outcome = yield* runNode({
130
+ workDir,
131
+ workspace: given.workspace,
132
+ userPrompt: topic.length === 0 ? `roundtable ${meetingId}` : topic,
133
+ // No coder turn is ever taken: the toolless reasoning seat fills both.
134
+ coder: reasoning,
135
+ reasoning,
136
+ environment: process.env
137
+ }, (context) => stage(context.events, "roundtable", runRoundtable({
138
+ files,
139
+ events: context.events,
140
+ seat: context.reasoning,
141
+ judgment: judgmentOf(context),
142
+ workDir,
143
+ meetingId,
144
+ topic,
145
+ goal: flags.goal,
146
+ attendees: personas.attendees,
147
+ scribe: personas.scribe,
148
+ context: docs,
149
+ caps: {
150
+ roundsPerItem: flags.rounds ?? 3,
151
+ maxTurns: flags.maxTurns ?? 40
152
+ },
153
+ noPause: flags.noPause,
154
+ budget: budget(process.env)
155
+ })));
156
+ if (outcome._tag === "NothingToDo") {
157
+ yield* Console.log(outcome.message);
158
+ }
159
+ else {
160
+ yield* Console.log(outcome.summary.join("\n"));
161
+ }
162
+ });
163
+ runFlowMain(program);
@@ -0,0 +1,202 @@
1
+ // Run a taskforce on a goal: a Chief of Staff plans the briefs, specialists work them in waves, a Reviewer interrogates, the Doc Writer delivers; you steer from the plan file.
2
+ //
3
+ // llm4ts run taskforce --repo ~/work/portal "Can the auth module move behind the new gateway? Outline and plan." \
4
+ // -- --context docs/standards
5
+ // llm4ts run taskforce --repo ~/work/portal -- --run can-the-auth-module-move-behind-the-new-gateway # continue
6
+ // llm4ts run taskforce --repo ~/work/portal -- --eject-personas # the bundled cards, to edit
7
+ // llm4ts run taskforce --repo ~/work/portal -- --list # runs and specialists
8
+ //
9
+ // Code runs the loop (ADR 0047). The Chief of Staff proposes the plan: the
10
+ // deliverables and two to twelve briefs (GOAL, SCOPE, CONTEXT, ACCEPTANCE,
11
+ // VERIFY, TIMEBOX, FORBIDDEN, REPORT) with owners and dependencies; the run
12
+ // stops for you to edit it unless --no-pause. Independent briefs run
13
+ // together (--parallel). Each specialist has hands by card: the Researcher
14
+ // and the Reviewer read the repository, the Operator's commands are run by
15
+ // code, the Engineer gets a throwaway worktree, the rest are toolless. A
16
+ // brief reports PASS, ISSUES or BLOCKED with evidence; BLOCKED is retried
17
+ // once. After the wave the Chief of Staff checks the goal and may plan one
18
+ // more wave. The Doc Writer writes the deliverables (result.md always), the
19
+ // review lenses find what is wrong, the Judgment service says what blocks
20
+ // the goal, one fix wave runs, the Doc Writer redrafts, the Memory Manager
21
+ // writes the run note. Three waves (--waves), twelve briefs (--briefs).
22
+ //
23
+ // The FILE is the state: <repo>/.llm4ts/taskforce/<id>/plan.md. Answer a
24
+ // question under `## Answers`, or write under `## Feedback`, and rerun.
25
+ // decisions.tsv is the trail. Cards are bundled, replaced by
26
+ // .llm4ts/personas/<name>.md of the same name; lenses by
27
+ // .llm4ts/lenses/<name>.md. Seats: LLM4TS_REASONER (default claude) for
28
+ // every card, LLM4TS_CODER (default claude) for the Engineer, or the
29
+ // roster's seat per role. Nothing in the repository's git is touched;
30
+ // worktrees live beside it (LLM4TS_WORKTREE_ROOT).
31
+ import { readdir } from "node:fs/promises";
32
+ import { join, resolve } from "node:path";
33
+ import * as Console from "effect/Console";
34
+ import * as Effect from "effect/Effect";
35
+ import { budget } from "@llm4ts/flow/Context";
36
+ import { judgmentOf } from "@llm4ts/flow/Judgment";
37
+ import { parseNote } from "@llm4ts/flow/Memory";
38
+ import { parseReviewer, Reviewer } from "@llm4ts/flow/Reviewer";
39
+ import { parsePlan } from "@llm4ts/flow/Taskforce";
40
+ import { ScriptUsage, asReadOnly, asToolless, nodePlainFileStore, nodeProcessExecutor, resolveFlowInput, runFlowMain, runNode, stage, withTurnLimit } from "@llm4ts/runner";
41
+ import { coderFromEnvironment } from "@llm4ts/runner/Connectors";
42
+ import { reasonerFromEnvironment, worktreeRootFor } from "./lib/epic-stories.js";
43
+ import { bundledLenses, commandsPath, declaredCommands, defaultAgents, describeCast, ejectPersonas, lensesDir, parseTaskforceArgs, personasDir, resolveCast, runDir, runSlug, runsDir, runTaskforce } from "./lib/taskforce.js";
44
+ const files = nodePlainFileStore;
45
+ const namesIn = (dir, suffix) => Effect.tryPromise(() => readdir(dir, { withFileTypes: true })).pipe(Effect.map((entries) => entries
46
+ .filter((entry) => entry.isFile() && entry.name.endsWith(suffix))
47
+ .map((entry) => entry.name.slice(0, -suffix.length))
48
+ .sort()), Effect.catch(() => Effect.succeed([])));
49
+ const foldersIn = (dir) => Effect.tryPromise(() => readdir(dir, { withFileTypes: true })).pipe(Effect.map((entries) => entries
50
+ .filter((entry) => entry.isDirectory())
51
+ .map((entry) => entry.name)
52
+ .sort()), Effect.catch(() => Effect.succeed([])));
53
+ /** `<dir>/<name>.md`, keyed by name. */
54
+ const cardsIn = Effect.fn("taskforce.cardsIn")(function* (dir) {
55
+ const names = yield* namesIn(dir, ".md");
56
+ const cards = {};
57
+ for (const name of names) {
58
+ const text = yield* files.read(join(dir, `${name}.md`));
59
+ if (text !== undefined)
60
+ cards[name] = text;
61
+ }
62
+ return cards;
63
+ });
64
+ const textLike = /\.(md|markdown|txt|adoc|rst)$/i;
65
+ /** Every text document under `--context`, recursively, in path order. */
66
+ const contextDocs = Effect.fn("taskforce.contextDocs")(function* (dir) {
67
+ if (dir === undefined)
68
+ return [];
69
+ const entries = yield* Effect.tryPromise(() => readdir(dir, { withFileTypes: true, recursive: true })).pipe(Effect.catch(() => ScriptUsage.make({ message: `--context ${dir} is not a readable directory` })));
70
+ const paths = entries
71
+ .filter((entry) => entry.isFile() && textLike.test(entry.name))
72
+ .map((entry) => join(entry.parentPath, entry.name))
73
+ .sort();
74
+ const docs = [];
75
+ for (const path of paths) {
76
+ const text = yield* files.read(path);
77
+ if (text !== undefined)
78
+ docs.push({ path: path.slice(dir.length + 1), text });
79
+ }
80
+ return docs;
81
+ });
82
+ /** Every note under `.llm4ts/memory/`, recursively, named by its path without `.md`. */
83
+ const memoryNotes = Effect.fn("taskforce.memoryNotes")(function* (dir) {
84
+ const entries = yield* Effect.tryPromise(() => readdir(dir, { withFileTypes: true, recursive: true })).pipe(Effect.catch(() => Effect.succeed([])));
85
+ const notes = [];
86
+ for (const entry of entries.filter((entry) => entry.isFile() && entry.name.endsWith(".md"))) {
87
+ const path = join(entry.parentPath, entry.name);
88
+ const text = yield* files.read(path);
89
+ if (text !== undefined)
90
+ notes.push(parseNote(path.slice(dir.length + 1, -3), text));
91
+ }
92
+ return notes.sort((left, right) => left.name.localeCompare(right.name));
93
+ });
94
+ const program = Effect.gen(function* () {
95
+ const flags = yield* parseTaskforceArgs(process.argv.slice(2));
96
+ const given = yield* resolveFlowInput("", flags.rest);
97
+ const workDir = given.workDir;
98
+ if (flags.ejectPersonas) {
99
+ const written = yield* ejectPersonas(files, workDir);
100
+ yield* Console.log(written.length === 0
101
+ ? `every bundled card is already under ${personasDir(workDir)}`
102
+ : `wrote ${written.length} card(s):\n${written.map((path) => ` ${path}`).join("\n")}`);
103
+ return;
104
+ }
105
+ const custom = yield* cardsIn(personasDir(workDir));
106
+ const memory = !flags.noMemory;
107
+ if (flags.list) {
108
+ const ids = yield* foldersIn(runsDir(workDir));
109
+ const lines = [];
110
+ for (const id of ids) {
111
+ const text = yield* files.read(join(runDir(workDir, id), "plan.md"));
112
+ const plan = text === undefined ? undefined : yield* parsePlan(text).pipe(Effect.option);
113
+ lines.push(plan === undefined || plan._tag === "None"
114
+ ? ` ${id} (no readable plan.md)`
115
+ : ` ${id} ${plan.value.status} ${plan.value.goal}`);
116
+ }
117
+ const cast = yield* resolveCast(custom, defaultAgents, memory);
118
+ yield* Console.log([
119
+ lines.length === 0 ? `no runs under ${runsDir(workDir)}` : "runs:",
120
+ ...lines,
121
+ "",
122
+ `specialists (bundled${Object.keys(custom).length === 0 ? "" : `, ${Object.keys(custom).length} custom`}):`,
123
+ describeCast(cast.all)
124
+ ].join("\n"));
125
+ return;
126
+ }
127
+ const goal = given.prompt.trim();
128
+ const runId = flags.run ?? (goal.length === 0 ? undefined : runSlug(goal));
129
+ if (runId === undefined) {
130
+ return yield* ScriptUsage.make({
131
+ message: `give the goal to start a run, or --run <id> to continue one`
132
+ });
133
+ }
134
+ // An existing run's cast is the file's; --agents only seats a new one.
135
+ const existing = yield* files.read(join(runDir(workDir, runId), "plan.md"));
136
+ const agents = existing === undefined
137
+ ? (flags.agents ?? defaultAgents)
138
+ : (yield* parsePlan(existing, join(runDir(workDir, runId), "plan.md"))).cast.filter((name) => name !== "Chief of Staff" && name !== "Doc Writer");
139
+ const cast = yield* resolveCast(custom, agents, memory);
140
+ const docs = yield* contextDocs(flags.context === undefined ? undefined : resolve(workDir, flags.context));
141
+ const notes = memory ? yield* memoryNotes(join(workDir, ".llm4ts", "memory")) : [];
142
+ const lensCards = yield* cardsIn(lensesDir(workDir));
143
+ const lenses = Object.keys(lensCards).length === 0
144
+ ? bundledLenses.map((lens) => Reviewer.make(lens))
145
+ : Object.entries(lensCards).map(([name, text]) => parseReviewer(name, text));
146
+ const allowedCommand = declaredCommands(yield* files.read(join(workDir, "package.json")), yield* files.read(commandsPath(workDir)));
147
+ const reasoner = yield* reasonerFromEnvironment(process.env);
148
+ const coder = withTurnLimit(yield* coderFromEnvironment(process.env), flags.turns ?? 30);
149
+ const worktreeRoot = worktreeRootFor(workDir, `taskforce-${runId}`, process.env);
150
+ const outcome = yield* runNode({
151
+ workDir,
152
+ workspace: given.workspace,
153
+ userPrompt: goal.length === 0 ? `taskforce ${runId}` : goal,
154
+ coder,
155
+ reasoning: asToolless(reasoner),
156
+ reviewers: [asReadOnly(reasoner)],
157
+ environment: process.env
158
+ }, (context) => stage(context.events, "taskforce", runTaskforce({
159
+ files,
160
+ events: context.events,
161
+ workDir,
162
+ runId,
163
+ goal,
164
+ cast,
165
+ context: docs,
166
+ notes,
167
+ caps: { waves: flags.waves ?? 3, briefs: flags.briefs ?? 12 },
168
+ parallel: flags.parallel ?? context.roster?.slots("planner") ?? 1,
169
+ noPause: flags.noPause,
170
+ keepWork: flags.keepWork,
171
+ memory,
172
+ budget: budget(process.env),
173
+ seats: {
174
+ toolless: context.reasoning,
175
+ readOnly: context.reviewers[0] ?? context.reasoning,
176
+ ...(context.roster === undefined
177
+ ? {}
178
+ : { forSeat: (role) => context.roster?.forRole(role) ?? context.reasoning })
179
+ },
180
+ judgment: judgmentOf(context),
181
+ lenses,
182
+ processes: nodeProcessExecutor,
183
+ allowedCommand,
184
+ workspaceFor: (brief) => Effect.gen(function* () {
185
+ const dir = join(worktreeRoot, brief.id);
186
+ yield* context.git.addWorktreeNewBranch(dir, `taskforce/${runId}/${brief.id}`, "HEAD");
187
+ const rebound = context.contextFor === undefined
188
+ ? context
189
+ : yield* context.contextFor(dir, { label: brief.id });
190
+ return { dir, coder: rebound.coder, diff: rebound.git.diffAll };
191
+ }),
192
+ removeWorkspace: (dir) => context.git.removeWorktree(dir, true),
193
+ now: () => new Date().toISOString()
194
+ })));
195
+ if (outcome._tag === "NothingToDo") {
196
+ yield* Console.log(outcome.message);
197
+ }
198
+ else {
199
+ yield* Console.log(outcome.summary.join("\n"));
200
+ }
201
+ });
202
+ runFlowMain(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llm4ts/shell",
3
- "version": "2.52.0",
3
+ "version": "2.54.0",
4
4
  "description": "Interactive shell and CLI for llm4ts: flow discovery, run-a-flow, and view",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -61,9 +61,9 @@
61
61
  "dependencies": {
62
62
  "@effect/platform-node": "4.0.0",
63
63
  "@effect/platform-node-shared": "4.0.0",
64
- "@llm4ts/core": "2.52.0",
65
- "@llm4ts/flow": "2.52.0",
66
- "@llm4ts/runner": "2.52.0"
64
+ "@llm4ts/core": "2.54.0",
65
+ "@llm4ts/flow": "2.54.0",
66
+ "@llm4ts/runner": "2.54.0"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "effect": "4.0.0"