@lmzhen/dsh-evolution-commands 0.19.2 → 0.20.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 CHANGED
@@ -6,7 +6,7 @@ background behaviour of its own.
6
6
 
7
7
  ## Model surface
8
8
 
9
- - **Model-visible:** one direct token — the `/evolution learn` injection — the full learning guidance is injected as a user message in this session; everything else adds no tokens.
9
+ - **Model-visible:** two direct tokens, both injected as user messages in this session — the `/evolution learn` injection (the full learning guidance) and the `maintain handoff` injection (a one-line POINTER to a finished maintenance report plus a report-only protocol: read the file, report per item, change nothing until the operator approves). **Command output never reaches model history**: `/evolution maintain` and every other subcommand answer in the client only. Everything else adds no tokens.
10
10
  - **Prompt prefix / KV cache:** independent of request-prefix construction — it does not alter the assembled prompt or tool list; family rules: `packages/README.md` §"Model-visible prompt prefix and the KV cache".
11
11
  - **Mount it?** yes — the `evolution-commands` row, carried by the `evolution-host`, `evolution-all` and `evolution-preset` bundles.
12
12
 
@@ -17,14 +17,18 @@ The full `/evolution` subcommand table is single-sourced in the family README's
17
17
  ## Known limitations
18
18
 
19
19
  - No known durable consumer gaps at this time. Runtime contracts are covered by package and boundary tests.
20
- - **`/evolution maintain` runs in the BACKGROUND (0.19.0).** The command answers with a run id and the scan keeps working: read it with `/evolution maintain report <id>` (a run that produced nothing answers "no result" instead of an empty plan) or `/evolution maintain status [<id>]` (in flight plus the recent terminal states). The run's lifetime belongs to this plugin through `evolution-core`'s run registry, **not** to the request that started it: the desktop shell ends a request at ~305 s (measured four times) while the same scan completes in 949.7 s on the web plane, and `maintainTimeoutMs` (default 600000) bounds the run itself. **Cancelling the request no longer stops the scan** — use `/evolution maintain cancel <id>`, or unmount the row. The plan is written once at settle to `<evolutionHome>/reports/maintain-<runId>.{json,md}`, under the same per-home reports window the curator's reports use.
21
- - **Cross-plane run state is eventual, and the shared index is the truth for runs this process does not own (0.19.1).** Two hosts sharing one `DSH_HOME` (the desktop app and a `dsh web` plane) read and write `evolution/runs.json` together. `begin()` resolves only after its row is in that index, so a plane reading the answer "started" finds the run; a run another plane owns is re-read at this plane's **next** read, and it stops being live in exactly two ways — its owner settled it (that terminal state is adopted) or its owner died (converged to `failed(orphan)`, with the reason spelled out). Runs this process owns keep memory as the truth. No timer and no heartbeat sits behind this: 0.19.0 skipped ids it already knew, which left an observing plane reporting `running` forever and refusing its own `maintain` until it restarted. The rule is monotonic on BOTH sides (0.19.2): the read side adopts a terminal row, and the write side never puts a row this process does not own back to `running` over the terminal state its owner wrote — so a settled run cannot be resurrected by this plane's own later write. Two hosts sharing one home must be on the SAME machine: `isProcessAlive(pid)` does not cross machines.
20
+ - **`/evolution maintain` runs in the BACKGROUND (0.19.0).** The command answers with a run id and the scan keeps working: read it with `/evolution maintain report [<id>]` (a run that produced nothing answers "no result" instead of an empty plan) or `/evolution maintain status [<id>]` (in flight plus the recent terminal states). Since 0.20.0 the id may be **omitted** on `report`, `cancel` and `handoff`: it then means the newest run in this home, and an unreadable `runs.json` answers "the run index is not readable" for that form rather than guessing. The run's lifetime belongs to this plugin through `evolution-core`'s run registry, **not** to the request that started it: the desktop shell ends a request at ~305 s (measured four times) while the same scan completes in 949.7 s on the web plane, and `maintainTimeoutMs` (default 600000) bounds the run itself. **Cancelling the request no longer stops the scan** — use `/evolution maintain cancel <id>`, or unmount the row. The plan is written once at settle to `<evolutionHome>/reports/maintain-<runId>.{json,md}`, under the same per-home reports window the curator's reports use.
21
+ - **`maintain handoff` is a SOFT gate (0.20.0, accepted).** The injected protocol asks the model to report and wait for the user's reply, and "what was approved" lives only in that conversation — the family keeps no approval record of its own. Escalate to the existing `evolution-approval` channel when unattended bulk skill edits, a multi-person audit trail, or non-repudiation become requirements.
22
+ - **`maintain handoff` reports a run whose state is not `succeeded` as "ready" when a report file exists (0.20.0, accepted).** A failed or cancelled run writes the same `.json`/`.md` pair (the failure text is the report), so the injection fires and the protocol's first line — read the file — is what tells the model what happened. Tightening it to `succeeded` only is a behavior choice, not a defect fix.
23
+ - **The injected pointer names the `.md` digest without re-probing it (0.20.0, accepted).** `reportDigestPath` swaps the `.json` suffix; the writer emits both files in one settle, so a hand-deleted `.md` beside a live `.json` would name a missing file.
24
+ - **The id-less forms repeat the same resolve skeleton three times (0.20.0, recorded).** `report`, `cancel` and `handoff` each run `syncRuns` → id-less `newestRun` → three-state error reporting; the wording is shared through `unreadableIndex`/`unreadableForId`, the skeleton is not. Extracting one resolver is the next batch's refactor.
25
+ - **Cross-plane run state is eventual, and the shared index is the truth for runs this process does not own (0.19.1).** Two hosts sharing one `DSH_HOME` (the desktop app and a `dsh web` plane) read and write `evolution/runs.json` together. `begin()` resolves only after its row is in that index, so a plane reading the answer "started" finds the run; a run another plane owns is re-read at this plane's **next** read, and it stops being live in exactly two ways — its owner settled it (that terminal state is adopted) or its owner died (converged to `failed(orphan)`, with the reason spelled out). Runs this process owns keep memory as the truth. No timer and no heartbeat sits behind this: 0.19.0 skipped ids it already knew, which left an observing plane reporting `running` forever and refusing its own `maintain` until it restarted. The rule is monotonic on BOTH sides (0.19.2): the read side adopts a terminal row, and the write side never puts a row this process does not own back to `running` over the terminal state its owner wrote — so a settled run cannot be resurrected by this plane's own later write. Two hosts sharing one home must be on the SAME machine: `isProcessAlive(pid)` does not cross machines. Structurally (0.19.3) a row has **exactly one writer — the process that started it**: this process's rows live in its own map, every other row is whatever the index says (rebuilt on each read), and a settled row is **never** shown as running again — a stale writer that puts `running` back is refused on read and repaired on the next write.
22
26
  - **① variant form: the `/evolution …` command face is visible in every session** (accepted, not fixed). Commands are registered in scope layers, and the family registers once on the host plane, so a session on a platform original preset still lists the management-only subcommands even though no automatic family behaviour reaches it. The difference and its reasoning are single-sourced in `INSTALL.md` ("Known difference").
23
27
 
24
28
  **Runtime invariant:** No companion is published. The platform auto-assembles nothing and the family mounts no `<pkg>/invariant` cordis row, so a companion here would never execute (v37 S2.1 / I-3).
25
29
 
26
30
  ## Notes and history
27
31
 
28
- - P2-22 (v11) correction: this package's **only** direct model-visible token is the `/evolution learn` injection — the full learning guidance is injected as a user message in this session.
32
+ - P2-22 (v11) correction: this package's direct model-visible tokens are the `/evolution learn` injection (the full learning guidance) and — since 0.20.0 — the `maintain handoff` injection (a report pointer plus the report-only protocol). Both are injected as user messages in this session; see **Model surface** above for the current count.
29
33
  - **① variant form: the `/evolution …` command face is visible in every session** (accepted, not fixed: 0.3.78).
30
34
  - The injection goes through the agent's waking primitive (`followup`, falling back to `inject` when the host lacks it), **called on the agent instance**: the platform's `Agent.followup` is a prototype method (`this.send(...)`), so a detached reference throws and queues nothing (0.3.73 fix; the same shape is pinned by rule N13b in `packages/scripts/verify-arch-guards.mjs`, which masks comments and string literals before matching and self-tests its detector at startup).
package/lib/index.js CHANGED
@@ -1339,12 +1339,16 @@ const COMMAND_ENTRIES = [
1339
1339
  summary: "看维护扫描:在飞的那次(含已跑多久)或某个 run 的终态"
1340
1340
  },
1341
1341
  {
1342
- usage: "maintain report <id>",
1343
- summary: "读某个 run 的结果正文(没有结果就明说,不装成空结果)"
1342
+ usage: "maintain report [<id>]",
1343
+ summary: "读某个 run 的结果正文(省略 id 取本 home 最新一条;没有结果就明说,不装成空结果)"
1344
1344
  },
1345
1345
  {
1346
- usage: "maintain cancel <id>",
1347
- summary: "停掉在飞的那次维护扫描"
1346
+ usage: "maintain handoff [<id>]",
1347
+ summary: "把某次维护报告交给模型:注入指针与汇报协议,模型只汇报、等你确认后再动手"
1348
+ },
1349
+ {
1350
+ usage: "maintain cancel [<id>]",
1351
+ summary: "停掉在飞的那次维护扫描(省略 id 仅当最新一条是本进程在跑的那次)"
1348
1352
  },
1349
1353
  {
1350
1354
  usage: "migrate",
@@ -1396,6 +1400,7 @@ const Config = z.object({
1396
1400
  skillsRoot: z.string().default(""),
1397
1401
  maintainCooldownMs: z.number().min(0).default(3e4),
1398
1402
  maintainTimeoutMs: z.number().min(1).default(6e5),
1403
+ maintainHandoffOnSettle: z.boolean().default(false),
1399
1404
  threatExemptLabels: z.array(z.string()).default([])
1400
1405
  });
1401
1406
  /** How one run reads in `maintain status` output. */
@@ -1406,6 +1411,65 @@ function renderRunRecord(record) {
1406
1411
  if (record.resultRef !== void 0) parts.push(`→ ${record.resultRef}`);
1407
1412
  return parts.join(" ");
1408
1413
  }
1414
+ /** The newest MAINTENANCE run this home knows — the default when a subcommand omits its id
1415
+ * (G2/0.20.0). The registry view is newest-first and already carries the cross-plane rows. The
1416
+ * index is a file a user can hand-edit, so a row with a blank id is skipped rather than answered
1417
+ * from (review P2-7: it produced text like `Run (succeeded) …`). `RunKind` has one member today,
1418
+ * so kind needs no filter — a second kind must add one here when it lands. */
1419
+ function newestRun(registry) {
1420
+ return registry.runs().find((record) => record.id.trim() !== "");
1421
+ }
1422
+ /** Sentence F, ONE wording for the three id-less forms (design `10` cell 13): an index that could
1423
+ * not be read must never answer as "there is no recent run" (G2/0.20.0). */
1424
+ function unreadableIndex(note) {
1425
+ return `The home's run index is not readable (${note ?? "unknown reason"}) — this is NOT "there is no recent run".`;
1426
+ }
1427
+ /** The explicit-id twin of {@link unreadableIndex}, worded like `maintain status` so the four
1428
+ * readers cannot drift (review P1-1). */
1429
+ function unreadableForId(id, note) {
1430
+ return `Run ${id} is not in this process's history, and the home's run index is not readable (${note ?? "unknown reason"}) — that is NOT proof the run never happened.`;
1431
+ }
1432
+ /** The reader-facing report path: the `.md` digest beside the run's `.json` result. */
1433
+ function reportDigestPath(record) {
1434
+ return (record.resultRef ?? join(evolutionHome(), "reports", `maintain-${record.id}.json`)).replace(/\.json$/, ".md");
1435
+ }
1436
+ /** Deliver one handoff message through the waking primitive, called ON the receiver
1437
+ * (family checklist new-consumer: N13b fails a wake primitive read into a local — the
1438
+ * 0.3.73 incident ate review prompts for six days). Falls back to the non-waking
1439
+ * `inject`, exactly like `/evolution learn`. @returns true when the receiver woke,
1440
+ * false when the message was only queued, `undefined` when neither primitive exists. */
1441
+ function deliverHandoff(agent, message) {
1442
+ if (typeof agent.followup === "function") {
1443
+ agent.followup(message);
1444
+ return true;
1445
+ }
1446
+ if (typeof agent.inject === "function") {
1447
+ agent.inject(message);
1448
+ return false;
1449
+ }
1450
+ }
1451
+ /** The model-facing handoff message (G2/0.20.0): a POINTER to the report plus the
1452
+ * report-only protocol. ONE builder shared by `maintain handoff` and the settle-time
1453
+ * automatic handoff, so the two cannot drift. Missing counts are omitted, never guessed. */
1454
+ function handoffPrompt(input) {
1455
+ const counts = [
1456
+ input.verdict === void 0 ? void 0 : `verdict=${input.verdict}`,
1457
+ input.recommendationCount === void 0 ? void 0 : `${input.recommendationCount} recommendations`,
1458
+ input.needsHumanCount === void 0 ? void 0 : `${input.needsHumanCount} of them need your user's confirmation`
1459
+ ].filter((part) => part !== void 0);
1460
+ return [
1461
+ `${`[evolution maintain] The maintenance report for run ${input.runId} is ready: ${input.reportPath}`}${counts.length === 0 ? "" : ` (${counts.join(", ")}; each item has a stable [n] id)`}.`,
1462
+ "",
1463
+ "This turn is REPORT-ONLY. Read the file, then tell your user what it found and what it proposes — one line",
1464
+ "per item: [n] | what would change | which skills | why (the finding) | undo | needs-your-confirmation?",
1465
+ "Lead with the items that need confirmation. Do NOT edit, restructure, archive or rename anything in this",
1466
+ "turn, and start no other skill work: your user must approve which items to carry out. When they reply by [n]",
1467
+ "ids, carry out ONLY the approved items, one at a time, and read each item's undo line before you touch",
1468
+ "anything; if an item has no undo line, treat it as irreversible and ask first. Apply every change through",
1469
+ "the skill-writing tool (skill_manage) — never edit SKILL.md or its support files with generic file tools:",
1470
+ "an out-of-band edit leaves no version in skill history and no audit record."
1471
+ ].join("\n");
1472
+ }
1409
1473
  /**
1410
1474
  * Write one run's result to its ONE home: `<evolutionHome>/reports/maintain-<id>.json`
1411
1475
  * plus the `.md` digest, then sweep that window.
@@ -1475,7 +1539,8 @@ async function readRunReport(io, record) {
1475
1539
  const parsed = JSON.parse(probed.value);
1476
1540
  return {
1477
1541
  kind: "present",
1478
- text: `${`Maintenance run ${record.id} — ${record.state}${record.failure === void 0 ? "" : ` (${record.failure})`}`}\n${typeof parsed.text === "string" && parsed.text.trim() !== "" ? parsed.text : renderRunRecord(record)}`
1542
+ text: `${`Maintenance run ${record.id} — ${record.state}${record.failure === void 0 ? "" : ` (${record.failure})`}`}\n${typeof parsed.text === "string" && parsed.text.trim() !== "" ? parsed.text : renderRunRecord(record)}`,
1543
+ report: parsed
1479
1544
  };
1480
1545
  } catch (error) {
1481
1546
  return {
@@ -1751,7 +1816,7 @@ function apply(ctx, rawConfig = {}) {
1751
1816
  agent.followup(message);
1752
1817
  woke = true;
1753
1818
  } else if (typeof agent.inject === "function") agent.inject(message);
1754
- else return err(errorText("e-305-the-invocation-agent-exposes"));
1819
+ else return err(errorText("e-305-the-invocation-agent-exposes", { a1: "this learn request" }));
1755
1820
  const eventIo = ctx.get("evolutionIo")?.provider();
1756
1821
  if (eventIo) appendEvolutionEvent(eventIo, eventsFile(evolutionRoot()), {
1757
1822
  type: "learn",
@@ -1812,6 +1877,7 @@ function apply(ctx, rawConfig = {}) {
1812
1877
  }
1813
1878
  const runHome = evolutionHome();
1814
1879
  const runRoot = evolutionRoot();
1880
+ const runAgent = invocationAgent;
1815
1881
  const handle = await registry.begin("maintain");
1816
1882
  (async () => {
1817
1883
  try {
@@ -1842,7 +1908,11 @@ function apply(ctx, rawConfig = {}) {
1842
1908
  runId: handle.id,
1843
1909
  ...outcome.ok ? {
1844
1910
  verdict: outcome.verdict,
1845
- recommendationCount: outcome.recommendationCount
1911
+ recommendationCount: outcome.recommendationCount,
1912
+ items: outcome.items,
1913
+ notes: outcome.notes,
1914
+ forcedHuman: outcome.forcedHuman,
1915
+ needsHumanCount: outcome.needsHumanCount
1846
1916
  } : {},
1847
1917
  ...outcome.ok ? {} : { failure: handle.signal.aborted ? "cancelled: the scan was stopped before it settled" : outcome.error ?? "Maintenance scan failed." },
1848
1918
  startedAt: handle.startedAt,
@@ -1857,16 +1927,44 @@ function apply(ctx, rawConfig = {}) {
1857
1927
  ...resultRef === void 0 ? {} : { resultRef },
1858
1928
  ...outcome.ok ? {} : { failure: handle.signal.aborted ? "cancelled: the scan was stopped before it settled" : outcome.error ?? "Maintenance scan failed." }
1859
1929
  });
1860
- if (outcome.ok) appendEvolutionEvent(ioRegistry.provider(), eventsFile(runRoot), {
1861
- type: "maintain",
1862
- source: "manual",
1863
- runId: handle.id,
1864
- verdict: outcome.verdict,
1865
- recommendations: outcome.recommendationCount
1866
- }).catch((error) => {
1867
- ctx.logger.warn(`evolution-commands: failed to record maintain event: ${String(error)}`);
1868
- });
1869
- else ctx.logger.warn(`evolution-commands: maintenance run ${handle.id} produced no plan (${outcome.error ?? "unknown reason"})`);
1930
+ if (outcome.ok) {
1931
+ appendEvolutionEvent(ioRegistry.provider(), eventsFile(runRoot), {
1932
+ type: "maintain",
1933
+ source: "manual",
1934
+ runId: handle.id,
1935
+ verdict: outcome.verdict,
1936
+ recommendations: outcome.recommendationCount
1937
+ }).catch((error) => {
1938
+ ctx.logger.warn(`evolution-commands: failed to record maintain event: ${String(error)}`);
1939
+ });
1940
+ if (config.maintainHandoffOnSettle === true && resultRef !== void 0 && runAgent !== void 0) try {
1941
+ if (deliverHandoff(runAgent, createUserMessage({
1942
+ content: [{
1943
+ type: "text",
1944
+ text: handoffPrompt({
1945
+ runId: handle.id,
1946
+ reportPath: reportDigestPath({
1947
+ id: handle.id,
1948
+ resultRef
1949
+ }),
1950
+ verdict: outcome.verdict,
1951
+ recommendationCount: outcome.recommendationCount,
1952
+ needsHumanCount: outcome.needsHumanCount
1953
+ })
1954
+ }],
1955
+ source: {
1956
+ kind: "evolution-commands",
1957
+ form: "notice",
1958
+ summary: "maintenance report handoff (auto)"
1959
+ }
1960
+ })) === void 0) ctx.logger.warn(`evolution-commands: the automatic report handoff for run ${handle.id} could not be delivered — this host exposes neither followup nor inject; the report is at ${reportDigestPath({
1961
+ id: handle.id,
1962
+ resultRef
1963
+ })}`);
1964
+ } catch (error) {
1965
+ ctx.logger.warn(`evolution-commands: automatic report handoff failed (${String(error)})`);
1966
+ }
1967
+ } else ctx.logger.warn(`evolution-commands: maintenance run ${handle.id} produced no plan (${outcome.error ?? "unknown reason"})`);
1870
1968
  } catch (error) {
1871
1969
  const aborted = handle.signal.aborted;
1872
1970
  const failure = aborted ? "cancelled: the scan was stopped before it settled" : `Maintenance scan failed: ${error instanceof Error ? error.message : String(error)}`;
@@ -1905,15 +2003,22 @@ function apply(ctx, rawConfig = {}) {
1905
2003
  const recent = all.filter((record) => record.state !== "running").slice(0, 5);
1906
2004
  return ok([live.length === 0 ? "No maintenance run in flight." : `In flight:\n${live.map(renderRunRecord).join("\n")}`, recent.length === 0 ? "" : `Recent:\n${recent.map(renderRunRecord).join("\n")}`].filter((part) => part !== "").join("\n"));
1907
2005
  }
1908
- const maintainReport = /^maintain\s+report\s+(\S+)\s*$/.exec(input);
2006
+ const maintainReport = /^maintain\s+report(?:\s+(\S+))?\s*$/.exec(input);
1909
2007
  if (maintainReport) {
1910
2008
  const registry = runs;
1911
2009
  if (!registry) return err("Evolution IO registry not mounted — run results unavailable.");
1912
- await syncRuns(registry);
2010
+ const synced = await syncRuns(registry);
1913
2011
  const wanted = maintainReport[1];
1914
- if (wanted === void 0) return err("maintain report needs a run id: /evolution maintain report <id>.");
1915
- const record = registry.find(wanted);
1916
- if (!record) return err(`No run ${wanted} in this home — /evolution maintain status lists the recent ones.`);
2012
+ if (wanted === void 0 && !synced.ok) return err(unreadableIndex(synced.note));
2013
+ const record = wanted === void 0 ? newestRun(registry) : registry.find(wanted);
2014
+ if (!record) {
2015
+ if (wanted !== void 0) {
2016
+ if (!synced.ok) return err(unreadableForId(wanted, synced.note));
2017
+ return err(`No run ${wanted} in this home — /evolution maintain status lists the recent ones.`);
2018
+ }
2019
+ return err("No maintenance run recorded in this home yet — /evolution maintain starts one.");
2020
+ }
2021
+ if (wanted === void 0 && record.state === "running") return err(`The newest run ${record.id} is still running — its report appears when it settles; /evolution maintain status ${record.id} shows where it is.`);
1917
2022
  const ioRegistry = ctx.get("evolutionIo");
1918
2023
  if (!ioRegistry) return err("Evolution IO registry not mounted — run results unavailable.");
1919
2024
  const probed = await readRunReport(ioRegistry.provider(), record);
@@ -1921,22 +2026,72 @@ function apply(ctx, rawConfig = {}) {
1921
2026
  if (probed.kind === "unknown") return err(`Run ${record.id} has a report that could not be read (${probed.reason}) — this is not "no result".`);
1922
2027
  return ok(probed.text);
1923
2028
  }
1924
- const maintainCancel = /^maintain\s+cancel\s+(\S+)\s*$/.exec(input);
2029
+ const maintainCancel = /^maintain\s+cancel(?:\s+(\S+))?\s*$/.exec(input);
1925
2030
  if (maintainCancel) {
1926
2031
  const registry = runs;
1927
2032
  if (!registry) return err("Evolution IO registry not mounted — run cancellation unavailable.");
1928
- await syncRuns(registry);
2033
+ const synced = await syncRuns(registry);
1929
2034
  const wanted = maintainCancel[1];
1930
- if (wanted === void 0) return err("maintain cancel needs a run id: /evolution maintain cancel <id>.");
1931
- const record = registry.find(wanted);
1932
- if (!record) return err(`No run ${wanted} in this home — /evolution maintain status lists the recent ones.`);
2035
+ if (wanted === void 0 && !synced.ok) return err(unreadableIndex(synced.note));
2036
+ const record = wanted === void 0 ? newestRun(registry) : registry.find(wanted);
2037
+ if (!record) {
2038
+ if (wanted !== void 0) {
2039
+ if (!synced.ok) return err(unreadableForId(wanted, synced.note));
2040
+ return err(`No run ${wanted} in this home — /evolution maintain status lists the recent ones.`);
2041
+ }
2042
+ return err("No maintenance run recorded in this home yet — /evolution maintain starts one.");
2043
+ }
2044
+ const idlessHint = wanted === void 0 ? " Pass an id to cancel a specific run: /evolution maintain status lists them." : "";
1933
2045
  if (!registry.cancel(record.id)) {
1934
2046
  if (record.state === "running") return err(`Run ${record.id} is running in ANOTHER process sharing this home — it can only be cancelled there.`);
1935
- return err(`Run ${record.id} is already ${record.state} — nothing to cancel.`);
2047
+ return err(`Run ${record.id} is already ${record.state} — nothing to cancel.${idlessHint}`);
1936
2048
  }
1937
2049
  return ok(`Maintenance run ${record.id} cancelled — the scan stops at its next checkpoint. /evolution maintain status ${record.id} shows the terminal state.`);
1938
2050
  }
1939
- if (/^maintain\b/.test(input)) return err("Unknown maintain arguments: expected `maintain`, `maintain --timeout <ms>` / `maintain --timeout=<ms>`, `maintain status [<id>]`, `maintain report <id>` or `maintain cancel <id>`. Got: " + input);
2051
+ const maintainHandoff = /^maintain\s+handoff(?:\s+(\S+))?\s*$/.exec(input);
2052
+ if (maintainHandoff) {
2053
+ const registry = runs;
2054
+ if (!registry) return err("Evolution IO registry not mounted — the report cannot be handed over.");
2055
+ const synced = await syncRuns(registry);
2056
+ const wanted = maintainHandoff[1];
2057
+ if (wanted === void 0 && !synced.ok) return err(unreadableIndex(synced.note));
2058
+ const record = wanted === void 0 ? newestRun(registry) : registry.find(wanted);
2059
+ if (!record) {
2060
+ if (wanted !== void 0) {
2061
+ if (!synced.ok) return err(unreadableForId(wanted, synced.note));
2062
+ return err(`No run ${wanted} in this home — /evolution maintain status lists the recent ones.`);
2063
+ }
2064
+ return err("No maintenance run recorded in this home yet — /evolution maintain starts one.");
2065
+ }
2066
+ if (wanted === void 0 && record.state === "running") return err(`The newest run ${record.id} is still running — its report appears when it settles; /evolution maintain status ${record.id} shows where it is.`);
2067
+ const ioRegistry = ctx.get("evolutionIo");
2068
+ if (!ioRegistry) return err("Evolution IO registry not mounted — the report cannot be handed over.");
2069
+ const probed = await readRunReport(ioRegistry.provider(), record);
2070
+ if (probed.kind === "missing") return err(`Run ${record.id} (${record.state}) has NO result: no report was written${record.failure === void 0 ? "" : ` (${record.failure})`}.`);
2071
+ if (probed.kind === "unknown") return err(`Run ${record.id} has a report that could not be read (${probed.reason}) — this is not "no result".`);
2072
+ const missingAgent = agentMissing("handoff");
2073
+ if (missingAgent) return missingAgent;
2074
+ const woke = deliverHandoff(invocationAgent, createUserMessage({
2075
+ content: [{
2076
+ type: "text",
2077
+ text: handoffPrompt({
2078
+ runId: record.id,
2079
+ reportPath: reportDigestPath(record),
2080
+ verdict: probed.report.verdict,
2081
+ recommendationCount: probed.report.recommendationCount,
2082
+ needsHumanCount: probed.report.needsHumanCount
2083
+ })
2084
+ }],
2085
+ source: {
2086
+ kind: "evolution-commands",
2087
+ form: "notice",
2088
+ summary: "maintenance report handoff"
2089
+ }
2090
+ }));
2091
+ if (woke === void 0) return err(errorText("e-305-the-invocation-agent-exposes", { a1: "this maintenance handoff" }));
2092
+ return ok(woke ? `Handed run ${record.id} to the model — report: ${reportDigestPath(record)}. It will read the file and follow the action lines.` : `Handed run ${record.id} to the model, queued — this host exposes no wake-up channel, so it is read on your next message.`);
2093
+ }
2094
+ if (/^maintain\b/.test(input)) return err("Unknown maintain arguments: expected `maintain`, `maintain --timeout <ms>` / `maintain --timeout=<ms>`, `maintain status [<id>]`, `maintain report [<id>]`, `maintain handoff [<id>]` or `maintain cancel [<id>]`. Got: " + input);
1940
2095
  const presetInstall = /^preset install(?: --base (\S+))?$/.exec(input);
1941
2096
  if (presetInstall !== null || /^preset\b/.test(input)) {
1942
2097
  if (presetInstall === null) return err("Unknown preset arguments: expected `preset install` or `preset install --base <name>[,<name>...]` (the names live in the agent package's bases.json). Got: " + input);
@@ -36,6 +36,10 @@ export interface Config {
36
36
  * 4-8 min — the 13:38 successful run used --timeout 600000; the old 120s
37
37
  * default deadlined bare runs mid-analysis (14:37 run aborted at 119.94s). */
38
38
  maintainTimeoutMs?: number | undefined;
39
+ /** G2 (0.20.0): when a scan settles successfully, hand its report to the model
40
+ * automatically (the same pointer+protocol injection `maintain handoff` performs).
41
+ * Default false: the injection wakes a turn, which costs a model call. */
42
+ maintainHandoffOnSettle?: boolean | undefined;
39
43
  /** Threat-scan exemption labels for WRITE-path skill mutations (P2-18).
40
44
  * Threaded into the SkillLibrary this package constructs for `restructure`
41
45
  * (its only write path); the core-side constructor option carries the same
@@ -51,12 +55,14 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
51
55
  skillsRoot: z<string, string, "defined">;
52
56
  maintainCooldownMs: z<number, number, "defined">;
53
57
  maintainTimeoutMs: z<number, number, "defined">;
58
+ maintainHandoffOnSettle: z<boolean, boolean, "defined">;
54
59
  threatExemptLabels: z<string[], string[], "defined">;
55
60
  }>>, Schemastery.ObjectT<NoInfer<{
56
61
  root: z<string, string, "defined">;
57
62
  skillsRoot: z<string, string, "defined">;
58
63
  maintainCooldownMs: z<number, number, "defined">;
59
64
  maintainTimeoutMs: z<number, number, "defined">;
65
+ maintainHandoffOnSettle: z<boolean, boolean, "defined">;
60
66
  threatExemptLabels: z<string[], string[], "defined">;
61
67
  }>>, "plain">;
62
68
  export declare function apply(ctx: Context, rawConfig?: Config): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-commands",
3
3
  "description": "Human commands for the evolution family (/evolution pending|curator|maintain|doctor) (community build)",
4
- "version": "0.19.2",
4
+ "version": "0.20.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -27,12 +27,12 @@
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
29
  "@deepseek-ai/schemastery": "^3.18.4",
30
- "@lmzhen/dsh-evolution-approval": "^0.19.2",
31
- "@lmzhen/dsh-evolution-core": "^0.19.2",
32
- "@lmzhen/dsh-evolution-maintenance": "^0.19.2"
30
+ "@lmzhen/dsh-evolution-approval": "^0.20.0",
31
+ "@lmzhen/dsh-evolution-core": "^0.20.0",
32
+ "@lmzhen/dsh-evolution-maintenance": "^0.20.0"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@lmzhen/dsh-evolution-agent-preset": "^0.19.2"
35
+ "@lmzhen/dsh-evolution-agent-preset": "^0.20.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@deepseek-ai/cordis": "^4.0.1",