agent-lyceum 0.38.0 → 0.40.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.
- package/README.md +1 -0
- package/README.zh-TW.md +1 -0
- package/dist/cli.js +2 -0
- package/dist/format.d.ts +3 -0
- package/dist/format.js +6 -1
- package/dist/prompt.d.ts +11 -1
- package/dist/prompt.js +20 -3
- package/dist/run-session.d.ts +2 -0
- package/dist/run-session.js +13 -2
- package/dist/scaffold.d.ts +2 -0
- package/dist/scaffold.js +3 -1
- package/dist/web-console.d.ts +28 -0
- package/dist/web-console.js +54 -0
- package/package.json +1 -1
- package/web/dist/commands.js +285 -0
- package/web/dist/public/assets/index-71AXqmZQ.js +10 -0
- package/web/dist/public/assets/index-BC6ou2wZ.css +2 -0
- package/web/dist/public/index.html +3 -2
- package/web/dist/server/api.js +184 -0
- package/web/dist/server/guard.js +35 -16
- package/web/dist/server/http.js +10 -4
- package/web/dist/server/runner.js +171 -0
- package/web/dist/start.js +39 -4
- package/web/dist/public/assets/index-C5Kk_orF.css +0 -2
- package/web/dist/public/assets/index-MnFKWkw_.js +0 -9
package/README.md
CHANGED
|
@@ -88,6 +88,7 @@ Likewise, older versions refuse a `project.yaml` that contains `verify` ("Unreco
|
|
|
88
88
|
| Run lifecycle, parallel agents, several runs at once, follow-ups, opening a PR | [How a run works](docs/how-it-works.md) |
|
|
89
89
|
| What agents may write, sandbox levels, known gaps | [Write scope](docs/write-scope.md) |
|
|
90
90
|
| Letting an agent search or fetch the web | [Web access](docs/web-access.md) |
|
|
91
|
+
| Running commands from the browser | [Web console](docs/web-console.md) |
|
|
91
92
|
| Live run status inside Claude Code (a framed, state-coloured tree of agents; pane or full-width band) | [Monitor mod](docs/monitor.md) |
|
|
92
93
|
| All commands in full | [Commands](docs/commands.md) |
|
|
93
94
|
| A task file template (scope, acceptance criteria, verification) | [Task template](docs/task-template.md) |
|
package/README.zh-TW.md
CHANGED
|
@@ -88,6 +88,7 @@ agents:
|
|
|
88
88
|
| run 的生命週期、平行 agent、同時多個 run、追加需求、開 PR | [一次執行如何運作](docs/how-it-works.zh-TW.md) |
|
|
89
89
|
| agent 能寫什麼、沙箱等級、已知缺口 | [寫入範圍](docs/write-scope.zh-TW.md) |
|
|
90
90
|
| 讓 agent 搜尋或讀取網頁 | [網路存取](docs/web-access.zh-TW.md) |
|
|
91
|
+
| 在瀏覽器執行指令 | [網頁操作台](docs/web-console.zh-TW.md) |
|
|
91
92
|
| 在 Claude Code 內看即時 run 狀態(每個 agent 一個依狀態上色的外框,樹狀排列;面板或整寬橫幅) | [監控 mod](docs/monitor.zh-TW.md) |
|
|
92
93
|
| 所有指令的完整說明 | [指令](docs/commands.zh-TW.md) |
|
|
93
94
|
| 任務檔範本(範圍、驗收條件、驗證指令) | [任務檔範本](docs/task-template.zh-TW.md) |
|
package/dist/cli.js
CHANGED
|
@@ -32,6 +32,7 @@ import { onlyAgent, soloProject } from "./solo.js";
|
|
|
32
32
|
import { DEMO_PROJECT, DEMO_TASK, defaultDemoDir, detectRuntime, prepareDemo } from "./demo.js";
|
|
33
33
|
import { claudeQuota, codexQuota } from "./quota.js";
|
|
34
34
|
import { summarizeProgress } from "./summarize.js";
|
|
35
|
+
import { createConsoleDeps } from "./web-console.js";
|
|
35
36
|
const program = new Command();
|
|
36
37
|
program
|
|
37
38
|
.name("agent-lyceum")
|
|
@@ -783,6 +784,7 @@ program
|
|
|
783
784
|
heartbeatMs: beat * 1000,
|
|
784
785
|
identity: { version, home: home() },
|
|
785
786
|
allowHosts: opts.allowHost,
|
|
787
|
+
console: createConsoleDeps(home(), fileURLToPath(import.meta.url)),
|
|
786
788
|
factory: {
|
|
787
789
|
list: () => listProjects(home()).map((item) => item.name),
|
|
788
790
|
watch: (name, onFrame) => createStatusWatcher({
|
package/dist/format.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface DoneContract {
|
|
|
24
24
|
outcome?: RunOutcome;
|
|
25
25
|
/** What the report lacks; empty when the contract is met. */
|
|
26
26
|
missing: string[];
|
|
27
|
+
/** Advisory only: sections a `completed` report should carry but that never reject it. */
|
|
28
|
+
warnings: string[];
|
|
27
29
|
/** First lines of `## Verification`, for display. */
|
|
28
30
|
verification?: string;
|
|
29
31
|
}
|
|
@@ -32,6 +34,7 @@ export interface DoneContract {
|
|
|
32
34
|
* a `completed` report must also carry `## Files`, `## Verification` and `## Decisions` and leave no checklist step unticked
|
|
33
35
|
* (the report's own `## Steps`, else the run's latest `stateSteps`).
|
|
34
36
|
*/
|
|
37
|
+
export declare const ADVISORY_DONE_SECTIONS: readonly ["Spot-check", "Quiz"];
|
|
35
38
|
export declare function doneContract(meta: Record<string, unknown>, body: string, stateSteps?: Step[]): DoneContract;
|
|
36
39
|
export interface DigestSection {
|
|
37
40
|
label: string;
|
package/dist/format.js
CHANGED
|
@@ -80,8 +80,10 @@ export const DECLARABLE_OUTCOMES = ["completed", "partial", "blocked", "failed"]
|
|
|
80
80
|
* a `completed` report must also carry `## Files`, `## Verification` and `## Decisions` and leave no checklist step unticked
|
|
81
81
|
* (the report's own `## Steps`, else the run's latest `stateSteps`).
|
|
82
82
|
*/
|
|
83
|
+
export const ADVISORY_DONE_SECTIONS = ["Spot-check", "Quiz"];
|
|
83
84
|
export function doneContract(meta, body, stateSteps) {
|
|
84
85
|
const missing = [];
|
|
86
|
+
const warnings = [];
|
|
85
87
|
const declared = String(meta.outcome ?? "").trim().toLowerCase();
|
|
86
88
|
const outcome = DECLARABLE_OUTCOMES.includes(declared) ? declared : undefined;
|
|
87
89
|
if (!outcome)
|
|
@@ -92,6 +94,9 @@ export function doneContract(meta, body, stateSteps) {
|
|
|
92
94
|
if (!have.has(h.toLowerCase()))
|
|
93
95
|
missing.push(`\`## ${h}\``);
|
|
94
96
|
if (outcome === "completed") {
|
|
97
|
+
for (const h of ADVISORY_DONE_SECTIONS)
|
|
98
|
+
if (!have.has(h.toLowerCase()))
|
|
99
|
+
warnings.push(`\`## ${h}\``);
|
|
95
100
|
const own = parseSteps(body);
|
|
96
101
|
const open = (own.length ? own : (stateSteps ?? [])).filter((x) => !x.done);
|
|
97
102
|
if (open.length)
|
|
@@ -106,7 +111,7 @@ export function doneContract(meta, body, stateSteps) {
|
|
|
106
111
|
.join(" ")
|
|
107
112
|
.slice(0, 400) || undefined
|
|
108
113
|
: undefined;
|
|
109
|
-
return { outcome, missing, verification };
|
|
114
|
+
return { outcome, missing, warnings, verification };
|
|
110
115
|
}
|
|
111
116
|
const DIGEST_MAX_LINES = 3;
|
|
112
117
|
const DIGEST_MAX_CHARS = 80;
|
package/dist/prompt.d.ts
CHANGED
|
@@ -40,7 +40,17 @@ export declare function buildSystemPrompt(project: ResolvedProject, agent: Resol
|
|
|
40
40
|
* at most `LEAD_BATCH_LIMIT` on the same thread.
|
|
41
41
|
*/
|
|
42
42
|
export declare function pickMessages(project: ResolvedProject, agent: ResolvedAgent, queue: Message[]): Message[];
|
|
43
|
-
|
|
43
|
+
/** Most bytes of the user's original task put into a teammate's wake-up prompt. */
|
|
44
|
+
export declare const USER_TASK_LIMIT: number;
|
|
45
|
+
/**
|
|
46
|
+
* The user's original task for a teammate's wake-up (`<user_task>`), so a reviewer or QA can judge the work against what the user asked,
|
|
47
|
+
* not only against the lead's reading of it. Not for the lead (it has the task as its first mail), and not when a mail already carries the tag.
|
|
48
|
+
*/
|
|
49
|
+
export declare function userTaskBlock(project: ResolvedProject, agent: ResolvedAgent, unread: Message[], task: string | undefined, file?: string): string[];
|
|
50
|
+
export declare function buildUserPrompt(project: ResolvedProject, agent: ResolvedAgent, unread: Message[], handleCount?: number, handoff?: boolean, userTask?: {
|
|
51
|
+
text: string;
|
|
52
|
+
file?: string;
|
|
53
|
+
}): string;
|
|
44
54
|
export interface TidyRecordsContext {
|
|
45
55
|
/** The project records folder (`<shared>/common/records`). */
|
|
46
56
|
dir: string;
|
package/dist/prompt.js
CHANGED
|
@@ -130,7 +130,7 @@ export function buildSoloSystemPrompt(project, agent) {
|
|
|
130
130
|
? "Do the task you are given. Your final reply text is printed to the user as your answer, so end with the answer or a short report of what you did; nothing else is delivered."
|
|
131
131
|
: "");
|
|
132
132
|
if (!isCall) {
|
|
133
|
-
lines.push("## Finishing", `When the job is finished, create a Markdown file (any name ending in \`.md\`) directly inside \`${outboxDir(project, agent.name)}\` with this exact shape:`, "", "```", "---", "type: done", "subject: <short subject>", "outcome: completed|partial|blocked|failed", "---", "", "## Result", "## Files", "## Verification", "## Not done", "```", "", "That ends the run. `## Result` is the actual deliverable or conclusion (not just \"done\"), `## Files` the paths you created or changed, `## Verification` what you ran or checked and what it showed, `## Decisions` the choices you made that the task did not specify and the assumptions you relied on (or `None`), `## Not done` anything skipped or unverified (or `None`). Only `completed` means success and it needs all five headings; if work remains or is blocked say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A summary in your reply text is never delivered: without a `done` mail the run ends as idle with no report. " + OPEN_PR_RULE);
|
|
133
|
+
lines.push("## Finishing", `When the job is finished, create a Markdown file (any name ending in \`.md\`) directly inside \`${outboxDir(project, agent.name)}\` with this exact shape:`, "", "```", "---", "type: done", "subject: <short subject>", "outcome: completed|partial|blocked|failed", "---", "", "## Result", "## Files", "## Verification", "## Not done", "```", "", "That ends the run. `## Result` is the actual deliverable or conclusion (not just \"done\"), `## Files` the paths you created or changed, `## Verification` what you ran or checked and what it showed, `## Decisions` the choices you made that the task did not specify and the assumptions you relied on (or `None`), `## Not done` anything skipped or unverified (or `None`). Only `completed` means success and it needs all five headings; it should also carry `## Spot-check` (which sources you re-opened and what they showed) and `## Quiz` (questions the user should be able to answer if they read your work), which are not enforced but flagged when missing; if work remains or is blocked say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A summary in your reply text is never delivered: without a `done` mail the run ends as idle with no report. " + OPEN_PR_RULE);
|
|
134
134
|
}
|
|
135
135
|
const shared = sharedDir(project);
|
|
136
136
|
if (!isCall && shared)
|
|
@@ -185,7 +185,7 @@ export function buildSystemPrompt(project, agent) {
|
|
|
185
185
|
: `Report results to the lead by mail; the lead decides what happens next.`, isLead
|
|
186
186
|
? "Each wake-up handles one message, except that several `reply`/`failure` messages waiting together are handed to you in one wake-up: weigh them together, then decide the next step once."
|
|
187
187
|
: "Each wake-up handles one message, except that consecutive `reply`/`failure` messages on the same thread may be handed to you together: handle them together. Do the work it asks, then send the replies that are needed, then stop.", "Mail that repeats an earlier mail of yours to the same agent (same type, same text) is not sent again; you are told, and should wait for the answer or ask for something different instead of resending.", "", "## Message format", "The body of every `task` and `reply` must contain these `##` headings, exactly as written (write `None` under a heading if there is nothing to say).", "A `task` or `reply` missing a heading is sent back to you (at most twice per sender + type + subject); after that it is delivered with a warning flagged to the recipient.", "", `- \`task\`: ${REQUIRED_SECTIONS.task.map((h) => `\`## ${h}\``).join(", ")} (Upstream = id of the mail this task derives from, or \`None\`).`, `- \`reply\`: ${REQUIRED_SECTIONS.reply.map((h) => `\`## ${h}\``).join(", ")}.`, isLead
|
|
188
|
-
? "- `done`: your final report to the user (shown when the run ends, saved as `result.md`). Its frontmatter must contain `outcome: completed|partial|blocked|failed`, and the body the headings `## Result` (the actual deliverable or conclusion, not just \"done\"), `## Files` (paths created or changed), `## Verification` (what you ran or checked, and what it showed), `## Decisions` (choices you made that the task did not specify and assumptions you relied on, or `None`) and `## Not done` (anything skipped or unverified, or `None`). Only `completed` means success, and it needs all five headings and every checklist step ticked; if work remains or is blocked, say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A `done` that breaks this is sent back to you and does not end the run. " + OPEN_PR_RULE
|
|
188
|
+
? "- `done`: your final report to the user (shown when the run ends, saved as `result.md`). Its frontmatter must contain `outcome: completed|partial|blocked|failed`, and the body the headings `## Result` (the actual deliverable or conclusion, not just \"done\"), `## Files` (paths created or changed), `## Verification` (what you ran or checked, and what it showed), `## Decisions` (choices you made that the task did not specify and assumptions you relied on, or `None`) and `## Not done` (anything skipped or unverified, or `None`). Only `completed` means success, and it needs all five headings and every checklist step ticked; it should also carry `## Spot-check` (which sources you re-opened and what they showed) and `## Quiz` (questions the user should be able to answer if they read your work), which are not enforced but flagged when missing; if work remains or is blocked, say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A `done` that breaks this is sent back to you and does not end the run. " + OPEN_PR_RULE
|
|
189
189
|
: "- `done` has no required headings.", ...(agent.canAskUser
|
|
190
190
|
? [
|
|
191
191
|
"",
|
|
@@ -279,7 +279,23 @@ export function pickMessages(project, agent, queue) {
|
|
|
279
279
|
}
|
|
280
280
|
return run;
|
|
281
281
|
}
|
|
282
|
-
|
|
282
|
+
/** Most bytes of the user's original task put into a teammate's wake-up prompt. */
|
|
283
|
+
export const USER_TASK_LIMIT = 4 * 1024;
|
|
284
|
+
/**
|
|
285
|
+
* The user's original task for a teammate's wake-up (`<user_task>`), so a reviewer or QA can judge the work against what the user asked,
|
|
286
|
+
* not only against the lead's reading of it. Not for the lead (it has the task as its first mail), and not when a mail already carries the tag.
|
|
287
|
+
*/
|
|
288
|
+
export function userTaskBlock(project, agent, unread, task, file) {
|
|
289
|
+
if (!task?.trim() || agent.name === project.lead)
|
|
290
|
+
return [];
|
|
291
|
+
if (unread.some((m) => m.body.includes("<user_task>")))
|
|
292
|
+
return [];
|
|
293
|
+
const raw = Buffer.from(task.trim(), "utf8");
|
|
294
|
+
const shown = cutUtf8(raw, USER_TASK_LIMIT);
|
|
295
|
+
const text = shown.length === raw.length ? task.trim() : `${shown.toString("utf8")}\n[agent-lyceum: cut at ${shown.length} of ${raw.length} bytes${file ? `; the whole task is in \`${file}\`` : ""}]`;
|
|
296
|
+
return ["", '<user_task note="the user\'s original request, verbatim; judge the work against it, not only against the lead\'s acceptance criteria">', text, "</user_task>"];
|
|
297
|
+
}
|
|
298
|
+
export function buildUserPrompt(project, agent, unread, handleCount = 1, handoff = false, userTask) {
|
|
283
299
|
const parts = [];
|
|
284
300
|
const common = readCapped(commonFile(project), COMMON_LIMIT);
|
|
285
301
|
parts.push('<shared_context source="COMMON.md">');
|
|
@@ -300,6 +316,7 @@ export function buildUserPrompt(project, agent, unread, handleCount = 1, handoff
|
|
|
300
316
|
if (view)
|
|
301
317
|
parts.push("", `<${tag}>`, view, `</${tag}>`); // nothing recorded yet: no tag, no tokens
|
|
302
318
|
}
|
|
319
|
+
parts.push(...userTaskBlock(project, agent, unread, userTask?.text, userTask?.file));
|
|
303
320
|
const handoffFile = handoff ? sharedIndex(project) : undefined;
|
|
304
321
|
const notes = handoffFile ? readCapped(handoffFile, HANDOFF_LIMIT) : undefined;
|
|
305
322
|
if (handoffFile && notes?.text.trim()) {
|
package/dist/run-session.d.ts
CHANGED
|
@@ -157,6 +157,8 @@ export declare class RunSession {
|
|
|
157
157
|
private stallHeld;
|
|
158
158
|
private pendingAgents;
|
|
159
159
|
private pickBatch;
|
|
160
|
+
/** The run's original task as the user wrote it (`task.md` in the run folder), for the teammates' prompts; undefined when there is none. */
|
|
161
|
+
private userTask;
|
|
160
162
|
private wake;
|
|
161
163
|
/**
|
|
162
164
|
* The earlier failed attempts at these messages and the drafts they left, for the invoke that `attemptId` is about to make.
|
package/dist/run-session.js
CHANGED
|
@@ -561,6 +561,12 @@ export class RunSession {
|
|
|
561
561
|
return [must(pending[0], "an agent to wake")];
|
|
562
562
|
return pending;
|
|
563
563
|
}
|
|
564
|
+
/** The run's original task as the user wrote it (`task.md` in the run folder), for the teammates' prompts; undefined when there is none. */
|
|
565
|
+
userTask() {
|
|
566
|
+
const file = path.join(this.runDir, "task.md");
|
|
567
|
+
const got = readFileCapped(file, 64 * 1024);
|
|
568
|
+
return got?.text.trim() ? { text: got.text, file } : undefined;
|
|
569
|
+
}
|
|
564
570
|
async wake(agent) {
|
|
565
571
|
const { invoke, say, cfg, runDir, project, log, state, claims, attempts, noSessionNoted, opts, cooldowns } = this;
|
|
566
572
|
const queue = listUnread(project, agent.name);
|
|
@@ -579,7 +585,7 @@ export class RunSession {
|
|
|
579
585
|
workDir,
|
|
580
586
|
workspace: spaces[agent.name],
|
|
581
587
|
systemPrompt: buildSystemPrompt(aproject, agent),
|
|
582
|
-
userPrompt: buildUserPrompt(project, agent, queue, unread.length, (state.reopened?.length ?? 0) > 0),
|
|
588
|
+
userPrompt: buildUserPrompt(project, agent, queue, unread.length, (state.reopened?.length ?? 0) > 0, this.userTask()),
|
|
583
589
|
timeoutSec: cfg.wake_timeout_sec,
|
|
584
590
|
};
|
|
585
591
|
// Without a fallback chain (one candidate) the loop, its output and its records are exactly those of plain retries (spec 20.2 decision 11).
|
|
@@ -994,7 +1000,12 @@ export class RunSession {
|
|
|
994
1000
|
const spec = bad ? project.verify?.commands.find((c) => c.name === bad.name) : undefined;
|
|
995
1001
|
this.dispatcherVerification = bad ? { passed: false, text: `FAILED: ${bad.name} (${spec?.run ?? "?"}) ${describeFailure(bad, spec?.timeout_sec)}` } : { passed: true, text: `passed (${verified.record.commands.map((c) => c.name).join(", ")})` };
|
|
996
1002
|
}
|
|
997
|
-
const
|
|
1003
|
+
const advisory = contract?.warnings.length ? `> [agent-lyceum] Format warning: this report has no ${contract.warnings.join(", ")} section (advisory; the report was accepted).\n\n` : "";
|
|
1004
|
+
if (advisory) {
|
|
1005
|
+
say(` done report accepted without ${contract?.warnings.join(", ")} (advisory)`);
|
|
1006
|
+
log("done-advisory", { missing: contract?.warnings });
|
|
1007
|
+
}
|
|
1008
|
+
const report = `# ${route.done.subject}\n\n**Outcome:** ${this.doneOutcome}${this.doneNote ? ` (${this.doneNote})` : ""}\n\n${advisory}${route.done.body.trimEnd()}\n${verified ? `\n${verificationSection(verified.record, must(project.verify, "verify settings"), verified.cwd)}` : ""}`;
|
|
998
1009
|
atomicWrite(path.join(runDir, RESULT_FILE), report);
|
|
999
1010
|
atomicWrite(path.join(runDir, `done-${(state.reopened?.length ?? 0) + 1}.md`), report);
|
|
1000
1011
|
this.pendingDoneFile = route.done.file;
|
package/dist/scaffold.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** The lead's guidance on `parallel: true` (spec 23.12 point 5). Only `init` writes it, into a new lead AGENT.md. */
|
|
2
2
|
export declare const LEAD_PARALLEL_HINT = "Mark a task `parallel: true` only when it is independent and touches different files from the other open tasks; list each task's files in `## Scope` first; shared components, types, routes and tokens go first, alone.";
|
|
3
|
+
/** The lead's guidance on the `## Decisions` and `## Not done` sections of `done`. Only `init` writes it, into a new lead AGENT.md. */
|
|
4
|
+
export declare const LEAD_DONE_HINT = " Under `## Decisions` list every decision or assumption made without an answer from the user, each with the alternative you rejected; under `## Not done` say what the checks did not cover.";
|
|
3
5
|
export declare const GLOBAL_TEAM_YAML = "# Global agent library. Projects pick agents from here by name and may override any field.\n# Relative paths here are resolved against this folder. \"~\" is allowed.\nagents:\n lead:\n runtime: claude-code # claude-code | codex\n agent_md: agents/lead/AGENT.md\n memory: { global: agents/lead/memory }\n # model: opus # most capable model: keep it for the lead\n fe-member:\n runtime: claude-code\n agent_md: agents/fe-member/AGENT.md\n memory: { global: agents/fe-member/memory }\n # model: sonnet # cheaper model for routine work\n qa-member:\n runtime: claude-code\n agent_md: agents/qa-member/AGENT.md\n memory: { global: agents/qa-member/memory }\n # model: sonnet # cheaper model for routine work\n # Model hints (comments only):\n # - a read-only search/explorer role suits \"model: haiku\", the cheapest tier (the alias resolves per provider; on the Anthropic API it is claude-haiku-5-5).\n # - a reviewer can run on the other runtime (\"runtime: codex\"); leave the codex model unset to use the CLI default.\n";
|
|
4
6
|
export interface InitResult {
|
|
5
7
|
home: string;
|
package/dist/scaffold.js
CHANGED
|
@@ -3,6 +3,8 @@ import path from "node:path";
|
|
|
3
3
|
import { assertName, homePaths, projectPaths } from "./paths.js";
|
|
4
4
|
/** The lead's guidance on `parallel: true` (spec 23.12 point 5). Only `init` writes it, into a new lead AGENT.md. */
|
|
5
5
|
export const LEAD_PARALLEL_HINT = "Mark a task `parallel: true` only when it is independent and touches different files from the other open tasks; list each task's files in `## Scope` first; shared components, types, routes and tokens go first, alone.";
|
|
6
|
+
/** The lead's guidance on the `## Decisions` and `## Not done` sections of `done`. Only `init` writes it, into a new lead AGENT.md. */
|
|
7
|
+
export const LEAD_DONE_HINT = " Under `## Decisions` list every decision or assumption made without an answer from the user, each with the alternative you rejected; under `## Not done` say what the checks did not cover.";
|
|
6
8
|
const PERSONAS = {
|
|
7
9
|
lead: `# Lead
|
|
8
10
|
|
|
@@ -14,7 +16,7 @@ You coordinate the team. You receive the user's task, break it into concrete pie
|
|
|
14
16
|
- When a teammate reports back, decide the next step: assign follow-up work, ask another teammate to verify, or accept the result.
|
|
15
17
|
- Teammates cannot message each other by default; route everything through yourself.
|
|
16
18
|
- ${LEAD_PARALLEL_HINT}
|
|
17
|
-
- When the whole job is verified and finished, send a \`done\` message summarising what was delivered
|
|
19
|
+
- When the whole job is verified and finished, send a \`done\` message summarising what was delivered.${LEAD_DONE_HINT}
|
|
18
20
|
`,
|
|
19
21
|
"fe-member": `# Frontend member
|
|
20
22
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** What the web page's command console needs from this side of the package (`web/` cannot import `src/`). Same shape as `ConsoleDeps` in `web/src/server/api.ts`. */
|
|
2
|
+
export declare function createConsoleDeps(home: string, cliFile: string): {
|
|
3
|
+
home: string;
|
|
4
|
+
cli: {
|
|
5
|
+
execPath: string;
|
|
6
|
+
args: readonly string[];
|
|
7
|
+
};
|
|
8
|
+
projectDir: (name: string) => string | undefined;
|
|
9
|
+
readAsk(project: string, runId: string): {
|
|
10
|
+
status: "answered" | "pending";
|
|
11
|
+
questions: {
|
|
12
|
+
id: string;
|
|
13
|
+
text: string;
|
|
14
|
+
asker: string;
|
|
15
|
+
options?: string[] | undefined;
|
|
16
|
+
suggested?: {
|
|
17
|
+
value: string;
|
|
18
|
+
reason?: string;
|
|
19
|
+
} | undefined;
|
|
20
|
+
answer?: string | undefined;
|
|
21
|
+
delivered: boolean;
|
|
22
|
+
}[];
|
|
23
|
+
} | undefined;
|
|
24
|
+
saveAnswers(project: string, runId: string, answers: Record<string, string>, assumeDefaults: boolean): {
|
|
25
|
+
complete: boolean;
|
|
26
|
+
problems: string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { prepareAnswers } from "./ask-answer.js";
|
|
4
|
+
import { readAskReply, writeAskReply } from "./ask-reply.js";
|
|
5
|
+
import { listProjects } from "./config.js";
|
|
6
|
+
import { NAME_RE, projectPaths } from "./paths.js";
|
|
7
|
+
/** What the web page's command console needs from this side of the package (`web/` cannot import `src/`). Same shape as `ConsoleDeps` in `web/src/server/api.ts`. */
|
|
8
|
+
export function createConsoleDeps(home, cliFile) {
|
|
9
|
+
const projectDir = (name) => listProjects(home).find((p) => p.name === name)?.dir;
|
|
10
|
+
const runDirOf = (project, runId) => {
|
|
11
|
+
if (!NAME_RE.test(project) || !NAME_RE.test(runId) || !projectDir(project))
|
|
12
|
+
return undefined;
|
|
13
|
+
const dir = path.join(projectPaths(home, project).runs, runId);
|
|
14
|
+
return fs.existsSync(dir) ? dir : undefined;
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
home,
|
|
18
|
+
cli: { execPath: process.execPath, args: [...process.execArgv, cliFile] },
|
|
19
|
+
projectDir,
|
|
20
|
+
readAsk(project, runId) {
|
|
21
|
+
const dir = runDirOf(project, runId);
|
|
22
|
+
const reply = dir ? readAskReply(dir) : undefined;
|
|
23
|
+
if (!reply)
|
|
24
|
+
return undefined;
|
|
25
|
+
return {
|
|
26
|
+
status: reply.status,
|
|
27
|
+
questions: reply.questions.map((q) => ({
|
|
28
|
+
id: q.id,
|
|
29
|
+
text: q.text,
|
|
30
|
+
asker: q.asker,
|
|
31
|
+
...(q.options ? { options: q.options } : {}),
|
|
32
|
+
...(q.suggested ? { suggested: q.suggested } : {}),
|
|
33
|
+
...(q.answer ? { answer: q.answer.value } : {}),
|
|
34
|
+
delivered: q.delivered === true,
|
|
35
|
+
})),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
saveAnswers(project, runId, answers, assumeDefaults) {
|
|
39
|
+
const dir = runDirOf(project, runId);
|
|
40
|
+
const reply = dir ? readAskReply(dir) : undefined;
|
|
41
|
+
if (!dir || !reply)
|
|
42
|
+
return { complete: false, problems: ["這次任務沒有待回答的問題。"] };
|
|
43
|
+
writeAskReply(dir, {
|
|
44
|
+
...reply,
|
|
45
|
+
questions: reply.questions.map((q) => {
|
|
46
|
+
const value = answers[q.id]?.trim();
|
|
47
|
+
return q.delivered || !value ? q : { ...q, answer: { value, by: "user" } };
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
const checked = prepareAnswers(dir, { assumeDefaults });
|
|
51
|
+
return { complete: checked.complete, problems: checked.problems };
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/** The command table shared by the server (validates a body, builds argv) and the page (draws the forms). Pure: no node imports. */
|
|
2
|
+
export class ArgError extends Error {
|
|
3
|
+
field;
|
|
4
|
+
constructor(field, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.field = field;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
10
|
+
const RUN_NAME_RE = /^[a-z0-9-]{1,30}$/;
|
|
11
|
+
const PATH_RE = /^(\/|~\/|[A-Za-z]:[\\/])/;
|
|
12
|
+
const RUNTIMES = ["claude-code", "codex"];
|
|
13
|
+
const LAYERS = ["project", "global"];
|
|
14
|
+
export const TEXT_LIMIT = 200_000;
|
|
15
|
+
function text(body, name, o) {
|
|
16
|
+
const raw = body[name];
|
|
17
|
+
const empty = raw === undefined || raw === null || (typeof raw === "string" && raw.trim() === "");
|
|
18
|
+
if (empty) {
|
|
19
|
+
if (o.required)
|
|
20
|
+
throw new ArgError(name, `${o.what}必填。`);
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (typeof raw !== "string")
|
|
24
|
+
throw new ArgError(name, `${o.what}格式不對。`);
|
|
25
|
+
const value = raw.trim();
|
|
26
|
+
if (value.includes("\u0000"))
|
|
27
|
+
throw new ArgError(name, `${o.what}含有不能用的字元。`);
|
|
28
|
+
if (value.length > (o.max ?? 256))
|
|
29
|
+
throw new ArgError(name, `${o.what}太長。`);
|
|
30
|
+
if (o.re && !o.re.test(value))
|
|
31
|
+
throw new ArgError(name, `${o.what}格式不對。`);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function flag(body, name) {
|
|
35
|
+
const raw = body[name];
|
|
36
|
+
if (raw === undefined || raw === null || raw === false)
|
|
37
|
+
return false;
|
|
38
|
+
if (raw !== true)
|
|
39
|
+
throw new ArgError(name, "這個選項只能是勾選或不勾選。");
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
const need = (value) => value;
|
|
43
|
+
const project = (b) => need(text(b, "project", { required: true, re: NAME_RE, what: "專案" }));
|
|
44
|
+
const oneOf = (b, name, allowed, what) => {
|
|
45
|
+
const v = text(b, name, { what });
|
|
46
|
+
if (v !== undefined && !allowed.includes(v))
|
|
47
|
+
throw new ArgError(name, `${what}只能是 ${allowed.join("、")}。`);
|
|
48
|
+
return v;
|
|
49
|
+
};
|
|
50
|
+
const PROJECT_FIELD = { name: "project", label: "專案", kind: "text", required: true };
|
|
51
|
+
const always = (m) => () => m;
|
|
52
|
+
const normal = () => "normal";
|
|
53
|
+
const noTarget = () => "";
|
|
54
|
+
export const COMMANDS = {
|
|
55
|
+
init: {
|
|
56
|
+
id: "init",
|
|
57
|
+
label: "初始化 home",
|
|
58
|
+
scope: "home",
|
|
59
|
+
fields: [],
|
|
60
|
+
mode: always("short"),
|
|
61
|
+
tier: normal,
|
|
62
|
+
target: noTarget,
|
|
63
|
+
argv: () => ["init", "-y"],
|
|
64
|
+
},
|
|
65
|
+
"project.list": {
|
|
66
|
+
id: "project.list",
|
|
67
|
+
label: "列出專案",
|
|
68
|
+
scope: "home",
|
|
69
|
+
fields: [],
|
|
70
|
+
mode: always("short"),
|
|
71
|
+
tier: normal,
|
|
72
|
+
target: noTarget,
|
|
73
|
+
argv: () => ["project"],
|
|
74
|
+
},
|
|
75
|
+
"project.add": {
|
|
76
|
+
id: "project.add",
|
|
77
|
+
label: "註冊專案",
|
|
78
|
+
scope: "home",
|
|
79
|
+
fields: [
|
|
80
|
+
{ name: "name", label: "專案名稱", kind: "text", required: true },
|
|
81
|
+
{ name: "dir", label: "repo 的絕對路徑", kind: "text", required: true, help: "agent 會在這個資料夾工作。" },
|
|
82
|
+
],
|
|
83
|
+
mode: always("short"),
|
|
84
|
+
tier: normal,
|
|
85
|
+
target: noTarget,
|
|
86
|
+
argv: (b) => {
|
|
87
|
+
const name = need(text(b, "name", { required: true, re: NAME_RE, what: "專案名稱" }));
|
|
88
|
+
const dir = need(text(b, "dir", { required: true, re: PATH_RE, what: "路徑", max: 1024 }));
|
|
89
|
+
if (dir.startsWith("~"))
|
|
90
|
+
throw new ArgError("dir", "路徑請用絕對路徑,不支援 ~。");
|
|
91
|
+
return ["project", "add", name, "--dir", dir];
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
"project.remove": {
|
|
95
|
+
id: "project.remove",
|
|
96
|
+
label: "移除專案",
|
|
97
|
+
scope: "home",
|
|
98
|
+
fields: [
|
|
99
|
+
{ name: "name", label: "專案名稱", kind: "text", required: true },
|
|
100
|
+
{ name: "purge", label: "連這個專案的所有 context 一起刪除", kind: "checkbox" },
|
|
101
|
+
],
|
|
102
|
+
mode: always("short"),
|
|
103
|
+
tier: (b) => (b.purge === true ? "typed" : "confirm"),
|
|
104
|
+
target: (b) => String(b.name ?? ""),
|
|
105
|
+
argv: (b) => {
|
|
106
|
+
const name = need(text(b, "name", { required: true, re: NAME_RE, what: "專案名稱" }));
|
|
107
|
+
return ["project", "remove", name, ...(flag(b, "purge") ? ["--purge"] : [])];
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
run: {
|
|
111
|
+
id: "run",
|
|
112
|
+
label: "新任務",
|
|
113
|
+
scope: "project",
|
|
114
|
+
fields: [
|
|
115
|
+
PROJECT_FIELD,
|
|
116
|
+
{ name: "task", label: "任務", kind: "textarea", required: true },
|
|
117
|
+
{ name: "name", label: "任務名稱(可留空)", kind: "text", help: "小寫英數與 -,最多 30 字。" },
|
|
118
|
+
{ name: "agent", label: "只交給這一位 agent(可留空)", kind: "text" },
|
|
119
|
+
{ name: "assumeDefaults", label: "有建議值的問題直接採用,不暫停", kind: "checkbox" },
|
|
120
|
+
],
|
|
121
|
+
mode: always("detached"),
|
|
122
|
+
tier: normal,
|
|
123
|
+
target: noTarget,
|
|
124
|
+
argv: (b) => {
|
|
125
|
+
const out = ["run", "-p", project(b)];
|
|
126
|
+
const name = text(b, "name", { re: RUN_NAME_RE, what: "任務名稱" });
|
|
127
|
+
if (name)
|
|
128
|
+
out.push("--name", name);
|
|
129
|
+
const agent = text(b, "agent", { re: NAME_RE, what: "agent" });
|
|
130
|
+
if (agent)
|
|
131
|
+
out.push("--agent", agent);
|
|
132
|
+
if (flag(b, "assumeDefaults"))
|
|
133
|
+
out.push("--assume-defaults");
|
|
134
|
+
out.push("--", need(text(b, "task", { required: true, what: "任務", max: TEXT_LIMIT })));
|
|
135
|
+
return out;
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
call: {
|
|
139
|
+
id: "call",
|
|
140
|
+
label: "呼叫單一 agent",
|
|
141
|
+
scope: "home",
|
|
142
|
+
fields: [
|
|
143
|
+
{ name: "agent", label: "agent(全域 library 裡的名稱)", kind: "text", required: true },
|
|
144
|
+
{ name: "dir", label: "工作目錄(絕對路徑)", kind: "text", required: true },
|
|
145
|
+
{ name: "task", label: "任務", kind: "textarea", required: true },
|
|
146
|
+
],
|
|
147
|
+
mode: always("detached"),
|
|
148
|
+
tier: normal,
|
|
149
|
+
target: noTarget,
|
|
150
|
+
argv: (b) => {
|
|
151
|
+
const agent = need(text(b, "agent", { required: true, re: NAME_RE, what: "agent" }));
|
|
152
|
+
const dir = need(text(b, "dir", { required: true, re: PATH_RE, what: "工作目錄", max: 1024 }));
|
|
153
|
+
return ["call", agent, "--dir", dir, "--", need(text(b, "task", { required: true, what: "任務", max: TEXT_LIMIT }))];
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
resume: {
|
|
157
|
+
id: "resume",
|
|
158
|
+
label: "續跑/追問",
|
|
159
|
+
scope: "project",
|
|
160
|
+
fields: [
|
|
161
|
+
PROJECT_FIELD,
|
|
162
|
+
{ name: "run", label: "任務 id", kind: "text", required: true },
|
|
163
|
+
{ name: "followup", label: "追問(只用在已完成的任務,可留空)", kind: "textarea" },
|
|
164
|
+
{ name: "assumeDefaults", label: "有建議值的問題直接採用", kind: "checkbox" },
|
|
165
|
+
],
|
|
166
|
+
mode: always("detached"),
|
|
167
|
+
tier: normal,
|
|
168
|
+
target: noTarget,
|
|
169
|
+
argv: (b) => {
|
|
170
|
+
const p = project(b);
|
|
171
|
+
const run = need(text(b, "run", { required: true, re: NAME_RE, what: "任務 id", max: 120 }));
|
|
172
|
+
const answer = flag(b, "answer");
|
|
173
|
+
const followup = text(b, "followup", { what: "追問", max: TEXT_LIMIT });
|
|
174
|
+
if (answer && followup)
|
|
175
|
+
throw new ArgError("followup", "回答問題時不能同時追問。");
|
|
176
|
+
const out = ["resume", "-p", p];
|
|
177
|
+
if (flag(b, "assumeDefaults"))
|
|
178
|
+
out.push("--assume-defaults");
|
|
179
|
+
if (answer)
|
|
180
|
+
out.push("--answer", "--no-edit");
|
|
181
|
+
out.push("--", run);
|
|
182
|
+
if (followup)
|
|
183
|
+
out.push(followup);
|
|
184
|
+
return out;
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
clear: {
|
|
188
|
+
id: "clear",
|
|
189
|
+
label: "刪除任務",
|
|
190
|
+
scope: "project",
|
|
191
|
+
fields: [
|
|
192
|
+
PROJECT_FIELD,
|
|
193
|
+
{ name: "run", label: "任務 id", kind: "text", required: true },
|
|
194
|
+
{ name: "dryRun", label: "只預覽,不刪除", kind: "checkbox" },
|
|
195
|
+
{ name: "keepWorktrees", label: "保留 agent 的 worktree 與分支", kind: "checkbox" },
|
|
196
|
+
],
|
|
197
|
+
mode: always("short"),
|
|
198
|
+
tier: (b) => (b.dryRun === true ? "normal" : "confirm"),
|
|
199
|
+
target: noTarget,
|
|
200
|
+
argv: (b) => {
|
|
201
|
+
const p = project(b);
|
|
202
|
+
const run = need(text(b, "run", { required: true, re: NAME_RE, what: "任務 id", max: 120 }));
|
|
203
|
+
return ["clear", "-p", p, ...(flag(b, "dryRun") ? ["--dry-run"] : []), ...(flag(b, "keepWorktrees") ? ["--keep-worktrees"] : []), "--", run];
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
"clear.lock": {
|
|
207
|
+
id: "clear.lock",
|
|
208
|
+
label: "清除殘留的 run lock",
|
|
209
|
+
scope: "project",
|
|
210
|
+
fields: [PROJECT_FIELD, { name: "run", label: "任務 id(只有一個 lock 時可留空)", kind: "text" }],
|
|
211
|
+
mode: always("short"),
|
|
212
|
+
tier: () => "typed",
|
|
213
|
+
target: (b) => (typeof b.run === "string" && b.run.trim() ? b.run.trim() : String(b.project ?? "")),
|
|
214
|
+
argv: (b) => {
|
|
215
|
+
const p = project(b);
|
|
216
|
+
const run = text(b, "run", { re: NAME_RE, what: "任務 id", max: 120 });
|
|
217
|
+
return ["clear", "-p", p, "--lock", "--force", ...(run ? ["--", run] : [])];
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
doctor: {
|
|
221
|
+
id: "doctor",
|
|
222
|
+
label: "檢查設定",
|
|
223
|
+
scope: "project",
|
|
224
|
+
fields: [PROJECT_FIELD, { name: "resolved", label: "顯示合併後的設定與來源", kind: "checkbox" }],
|
|
225
|
+
mode: always("short"),
|
|
226
|
+
tier: normal,
|
|
227
|
+
target: noTarget,
|
|
228
|
+
argv: (b) => ["doctor", "-p", project(b), ...(flag(b, "resolved") ? ["--resolved"] : [])],
|
|
229
|
+
},
|
|
230
|
+
tidy: {
|
|
231
|
+
id: "tidy",
|
|
232
|
+
label: "整理記憶",
|
|
233
|
+
scope: "project",
|
|
234
|
+
fields: [
|
|
235
|
+
PROJECT_FIELD,
|
|
236
|
+
{ name: "agent", label: "只整理這一位 agent(可留空)", kind: "text" },
|
|
237
|
+
{ name: "layer", label: "層級", kind: "select", options: LAYERS },
|
|
238
|
+
{ name: "dryRun", label: "只預覽,不整理", kind: "checkbox" },
|
|
239
|
+
{ name: "undo", label: "還原某次整理(填時間戳,需指定 agent)", kind: "text" },
|
|
240
|
+
],
|
|
241
|
+
mode: (b) => (b.dryRun === true || (typeof b.undo === "string" && b.undo.trim() !== "") ? "short" : "detached"),
|
|
242
|
+
tier: (b) => (b.dryRun === true ? "normal" : "confirm"),
|
|
243
|
+
target: noTarget,
|
|
244
|
+
argv: (b) => {
|
|
245
|
+
const p = project(b);
|
|
246
|
+
const agent = text(b, "agent", { re: NAME_RE, what: "agent" });
|
|
247
|
+
const layer = oneOf(b, "layer", LAYERS, "層級");
|
|
248
|
+
const dryRun = flag(b, "dryRun");
|
|
249
|
+
const undo = text(b, "undo", { re: NAME_RE, what: "時間戳", max: 64 });
|
|
250
|
+
if (undo !== undefined) {
|
|
251
|
+
if (dryRun)
|
|
252
|
+
throw new ArgError("undo", "還原不能和預覽一起用。");
|
|
253
|
+
if (!agent)
|
|
254
|
+
throw new ArgError("agent", "還原要指定是哪一位 agent。");
|
|
255
|
+
}
|
|
256
|
+
const out = ["tidy", "-p", p];
|
|
257
|
+
if (agent)
|
|
258
|
+
out.push("--agent", agent);
|
|
259
|
+
if (layer)
|
|
260
|
+
out.push("--layer", layer);
|
|
261
|
+
if (dryRun)
|
|
262
|
+
out.push("--dry-run");
|
|
263
|
+
if (undo !== undefined)
|
|
264
|
+
out.push("--undo", undo);
|
|
265
|
+
return out;
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
demo: {
|
|
269
|
+
id: "demo",
|
|
270
|
+
label: "示範",
|
|
271
|
+
scope: "home",
|
|
272
|
+
fields: [
|
|
273
|
+
{ name: "runtime", label: "執行環境(可留空,自動偵測)", kind: "select", options: RUNTIMES },
|
|
274
|
+
{ name: "setupOnly", label: "只建立沙盒,不跑 agent", kind: "checkbox" },
|
|
275
|
+
],
|
|
276
|
+
mode: (b) => (b.setupOnly === true ? "short" : "detached"),
|
|
277
|
+
tier: normal,
|
|
278
|
+
target: noTarget,
|
|
279
|
+
argv: (b) => {
|
|
280
|
+
const runtime = oneOf(b, "runtime", RUNTIMES, "執行環境");
|
|
281
|
+
return ["demo", "-y", ...(runtime ? ["--runtime", runtime] : []), ...(flag(b, "setupOnly") ? ["--setup-only"] : [])];
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
export const COMMAND_IDS = Object.keys(COMMANDS);
|