@fractalsynapse/dsh-chapters 0.2.32 → 0.2.34

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.
Files changed (69) hide show
  1. package/cordis.patch.yml +17 -6
  2. package/docs/architecture.md +305 -1
  3. package/docs/backlog.md +36 -1
  4. package/docs/contract.md +79 -2
  5. package/docs/development.md +45 -1
  6. package/docs/host-compaction-seam.md +68 -0
  7. package/docs/plans-carriage.md +32 -2
  8. package/docs/project-state.md +180 -2
  9. package/docs/verify.md +70 -0
  10. package/lib/archive.d.ts +11 -0
  11. package/lib/archive.js +27 -1
  12. package/lib/archive.js.map +1 -1
  13. package/lib/auto-save.js +7 -3
  14. package/lib/auto-save.js.map +1 -1
  15. package/lib/client.js +1 -1
  16. package/lib/client.js.map +1 -1
  17. package/lib/continue-core.d.ts +18 -3
  18. package/lib/continue-core.js +48 -16
  19. package/lib/continue-core.js.map +1 -1
  20. package/lib/engine-core.d.ts +95 -10
  21. package/lib/engine-core.js +90 -21
  22. package/lib/engine-core.js.map +1 -1
  23. package/lib/engine.d.ts +34 -0
  24. package/lib/engine.js +124 -8
  25. package/lib/engine.js.map +1 -1
  26. package/lib/goal-carriage.d.ts +62 -0
  27. package/lib/goal-carriage.js +92 -0
  28. package/lib/goal-carriage.js.map +1 -0
  29. package/lib/index.d.ts +16 -0
  30. package/lib/index.js +210 -108
  31. package/lib/index.js.map +1 -1
  32. package/lib/injections.d.ts +5 -1
  33. package/lib/injections.js +27 -4
  34. package/lib/injections.js.map +1 -1
  35. package/lib/log-shape.d.ts +55 -1
  36. package/lib/log-shape.js +85 -1
  37. package/lib/log-shape.js.map +1 -1
  38. package/lib/preset.d.ts +17 -2
  39. package/lib/preset.js +23 -2
  40. package/lib/preset.js.map +1 -1
  41. package/lib/prompt.d.ts +11 -0
  42. package/lib/prompt.js +79 -7
  43. package/lib/prompt.js.map +1 -1
  44. package/lib/registry.d.ts +23 -2
  45. package/lib/registry.js +18 -3
  46. package/lib/registry.js.map +1 -1
  47. package/lib/render.d.ts +104 -5
  48. package/lib/render.js +299 -60
  49. package/lib/render.js.map +1 -1
  50. package/lib/repair-run.js +2 -0
  51. package/lib/repair-run.js.map +1 -1
  52. package/lib/repair.d.ts +1 -1
  53. package/lib/repair.js +40 -0
  54. package/lib/repair.js.map +1 -1
  55. package/lib/save-core.d.ts +20 -0
  56. package/lib/save-core.js +71 -20
  57. package/lib/save-core.js.map +1 -1
  58. package/lib/store.d.ts +3 -1
  59. package/lib/store.js +7 -2
  60. package/lib/store.js.map +1 -1
  61. package/lib/tools-row.js +8 -1
  62. package/lib/tools-row.js.map +1 -1
  63. package/lib/tools.js +57 -10
  64. package/lib/tools.js.map +1 -1
  65. package/lib/types.d.ts +7 -0
  66. package/lib/types.js.map +1 -1
  67. package/lib/version.d.ts +1 -1
  68. package/lib/version.js +1 -1
  69. package/package.json +5 -1
@@ -0,0 +1,62 @@
1
+ /**
2
+ * #349 — carry the active goal across a renewal, conservatively.
3
+ *
4
+ * THE SCOPE OF THIS MODULE, AND WHY IT IS NOT THE WHOLE ISSUE.
5
+ * #349's fuller ask is to RE-ESTABLISH the goal on the child via `ctx.get('goals').create(agent, …)`, which
6
+ * sidesteps the `requireDirectHuman` gate that guards the `create_goal` TOOL. The issue explicitly reserves
7
+ * that as a maintainer decision ("Confirm with the maintainer whether plugin-authored goal creation is the
8
+ * desired authority model before shipping — **if not, the notice must at least instruct the human to
9
+ * re-arm, and say so loudly**"). This file implements THAT FALLBACK: the objective is stated in the child's
10
+ * notice and the human is told, in the notice itself, that only they can re-arm. It creates nothing, calls
11
+ * no goal service, and therefore needs no authority widening to ship.
12
+ *
13
+ * WHAT THE LOG CAN AND CANNOT SAY — measured, not assumed (three production logs):
14
+ * `goal/change` data keys : kind, version, operation, goal, roundsStarted, createdAt, updatedAt
15
+ * operations : create, edit, pause, resume, block, complete, clear
16
+ * goal object keys : id, revision, objective, phase, maxGoalRounds, blockedReason
17
+ * `todo/write` : { todos: [{ content, status ∈ in_progress | pending | completed }] }
18
+ *
19
+ * So `phase` IS recoverable by folding durable events, and this module uses that. **`activation`
20
+ * (armed/disarmed) is NOT**: `dsh-goal` keeps it process-local in a WeakMap, which is why `index.ts` reads
21
+ * the goal signal from the service and comments that folding the log would be dishonest. Nothing here
22
+ * claims armedness — the notice says who can change it, because a stale claim about the driver's state is
23
+ * the same defect as a health check that cannot fail.
24
+ *
25
+ * One selector, one renderer, used by every renewal surface, per the "one predicate per semantic decision"
26
+ * rule (#59) that this release keeps having to re-apply.
27
+ */
28
+ import type { SessionEventLike } from './types.ts';
29
+ export interface GoalSnapshot {
30
+ id: string;
31
+ revision: number;
32
+ objective: string;
33
+ /** From the event's `goal.phase`; absent on hosts that never set it. */
34
+ phase: string;
35
+ /** The last operation folded — drives the wording, including the re-arm instruction. */
36
+ operation: string;
37
+ maxGoalRounds?: number | undefined;
38
+ blockedReason?: string | undefined;
39
+ roundsStarted?: number | undefined;
40
+ /** Seq of the event this was folded from, so a reader can go look. */
41
+ seq: number;
42
+ /** True when the goal is over: the objective may be stated, but not as live direction. */
43
+ finished: boolean;
44
+ }
45
+ /**
46
+ * Fold the session's `goal/change` events into the goal as it stands now.
47
+ *
48
+ * Returns null when there is no goal at all, and when the LAST act on it was `clear` — a cleared goal is
49
+ * not a goal, and carrying it forward would have the child pursuing a purpose the human ended. A
50
+ * `complete` goal returns a snapshot flagged `finished`, because the trajectory fact ("the objective was
51
+ * achieved at seq N") is worth stating while "keep working toward it" is not.
52
+ */
53
+ export declare function foldGoalFromLog(events: readonly SessionEventLike[]): GoalSnapshot | null;
54
+ /**
55
+ * The notice block for a carried goal. Empty string means "inject nothing" — the tape-safety rule every
56
+ * optional notice section follows (`rulesSection`, `plansSection`): a session that never used a goal pays
57
+ * zero bytes, so the archives and recorded requests of ordinary sessions are untouched by this feature.
58
+ *
59
+ * `budgetChars` bounds the OBJECTIVE text only; the instruction lines are fixed and never cut, because a
60
+ * truncated "only a human can re-arm" sentence is worse than no sentence.
61
+ */
62
+ export declare function renderGoalCarriage(goal: GoalSnapshot | null, budgetChars: number): string;
@@ -0,0 +1,92 @@
1
+ const GOAL_OPERATIONS = new Set(['create', 'edit', 'pause', 'resume', 'block', 'complete', 'clear']);
2
+ /**
3
+ * Fold the session's `goal/change` events into the goal as it stands now.
4
+ *
5
+ * Returns null when there is no goal at all, and when the LAST act on it was `clear` — a cleared goal is
6
+ * not a goal, and carrying it forward would have the child pursuing a purpose the human ended. A
7
+ * `complete` goal returns a snapshot flagged `finished`, because the trajectory fact ("the objective was
8
+ * achieved at seq N") is worth stating while "keep working toward it" is not.
9
+ */
10
+ export function foldGoalFromLog(events) {
11
+ let current = null;
12
+ // Carried separately from `current` because TypeScript narrows the assignment target to null
13
+ // before its first write inside the loop, so reading `current.objective` there is a type error even
14
+ // though a previous iteration may have set it. The extra binding is also clearer about intent.
15
+ let lastObjective = '';
16
+ for (const ev of events) {
17
+ if (ev.type !== 'goal/change')
18
+ continue;
19
+ const data = (ev.data ?? {});
20
+ const operation = typeof data.operation === 'string' ? data.operation : '';
21
+ // Unknown operations are IGNORED rather than guessed: a host that adds one must not silently
22
+ // rewrite the child's understanding of its own purpose. (The known set was measured, above.)
23
+ if (!GOAL_OPERATIONS.has(operation))
24
+ continue;
25
+ const g = (data.goal ?? {});
26
+ const id = typeof g.id === 'string' ? g.id : '';
27
+ if (id === '')
28
+ continue;
29
+ const objective = typeof g.objective === 'string' ? g.objective : '';
30
+ const revision = typeof g.revision === 'number' ? g.revision : 0;
31
+ const phase = typeof g.phase === 'string' ? g.phase : 'active';
32
+ if (operation === 'clear') {
33
+ current = null;
34
+ continue;
35
+ }
36
+ const num = (v) => (typeof v === 'number' ? v : undefined);
37
+ current = {
38
+ id,
39
+ revision,
40
+ // A later event may omit the objective (e.g. a bare pause); keep the one we already have rather
41
+ // than blanking the thing this module exists to carry.
42
+ objective: objective !== '' ? objective : lastObjective,
43
+ phase: operation === 'pause' ? 'paused'
44
+ : operation === 'block' ? 'blocked'
45
+ : operation === 'resume' ? 'active'
46
+ : operation === 'complete' ? 'complete' : phase,
47
+ operation,
48
+ maxGoalRounds: num(g.maxGoalRounds),
49
+ blockedReason: typeof g.blockedReason === 'string' && g.blockedReason !== '' ? g.blockedReason : undefined,
50
+ roundsStarted: num(data.roundsStarted),
51
+ seq: ev.seq,
52
+ finished: operation === 'complete' || phase === 'complete',
53
+ };
54
+ lastObjective = current.objective;
55
+ }
56
+ return current;
57
+ }
58
+ /**
59
+ * The notice block for a carried goal. Empty string means "inject nothing" — the tape-safety rule every
60
+ * optional notice section follows (`rulesSection`, `plansSection`): a session that never used a goal pays
61
+ * zero bytes, so the archives and recorded requests of ordinary sessions are untouched by this feature.
62
+ *
63
+ * `budgetChars` bounds the OBJECTIVE text only; the instruction lines are fixed and never cut, because a
64
+ * truncated "only a human can re-arm" sentence is worse than no sentence.
65
+ */
66
+ export function renderGoalCarriage(goal, budgetChars) {
67
+ if (goal === null || goal.objective === '')
68
+ return '';
69
+ const head = goal.finished ? '## Goal (completed — do not resume it)' : '## Goal (carried from the parent session)';
70
+ const lines = [head];
71
+ const cap = `round cap ${String(goal.maxGoalRounds ?? 'unbounded')}, revision ${String(goal.revision)}, phase ${goal.phase}`;
72
+ lines.push(`Status: ${cap} (from seq ${String(goal.seq)}).`);
73
+ const objective = goal.objective.replace(/\s+/g, ' ').trim();
74
+ if (objective.length > budgetChars) {
75
+ lines.push(`Objective (first ${String(budgetChars)} of ${String(objective.length)} chars): ${objective.slice(0, budgetChars)}…`);
76
+ lines.push('(the whole text is in the parent log and in the chapters that archived it — this is a display budget, never a data decision)');
77
+ }
78
+ else {
79
+ lines.push(`Objective: ${objective}`);
80
+ }
81
+ if (goal.phase === 'blocked' && goal.blockedReason !== undefined)
82
+ lines.push(`Blocked on: ${goal.blockedReason}`);
83
+ // The point of the conservative path: the child CANNOT arm its own goal, so say who can, loudly, in
84
+ // the one place the child is guaranteed to read at birth.
85
+ if (!goal.finished) {
86
+ lines.push(goal.phase === 'active'
87
+ ? 'This goal is NOT armed in the child: a continuation child cannot create or resume a goal (the host requires a direct human turn). Only the human can send /goal resume or re-cut the objective.'
88
+ : `Goal is ${goal.phase}. The child cannot change that — only the human can send /goal resume.`);
89
+ }
90
+ return lines.join('\n');
91
+ }
92
+ //# sourceMappingURL=goal-carriage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"goal-carriage.js","sourceRoot":"","sources":["../src/goal-carriage.ts"],"names":[],"mappings":"AA8CA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;AAEpG;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,MAAmC;IACjE,IAAI,OAAO,GAAwB,IAAI,CAAA;IACvC,6FAA6F;IAC7F,oGAAoG;IACpG,+FAA+F;IAC/F,IAAI,aAAa,GAAG,EAAE,CAAA;IACtB,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;QACxB,IAAI,EAAE,CAAC,IAAI,KAAK,aAAa;YAAE,SAAQ;QACvC,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,CAA4B,CAAA;QACvD,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAA;QAC1E,6FAA6F;QAC7F,6FAA6F;QAC7F,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,SAAQ;QAE7C,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAA4B,CAAA;QACtD,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QAC/C,I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AG,CAAC,CAAA;QAChI,KAAK,CAAC,IAAI,CAAC,8HAA8H,CAAC,CAAA;IAC5I,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC,cAAc,SAAS,EAAE,CAAC,CAAA;IACvC,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,aAAa,EAAE,CAAC,CAAA;IACjH,oGAAoG;IACpG,0DAA0D;IAC1D,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,QAAQ;YAChC,CAAC,CAAC,iMAAiM;YACnM,CAAC,CAAC,WAAW,IAAI,CAAC,KAAK,wEAAwE,CAAC,CAAA;IACpG,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC"}
package/lib/index.d.ts CHANGED
@@ -87,6 +87,10 @@ export interface Config {
87
87
  planInlineChars: number;
88
88
  callArgArtifactTokens: number;
89
89
  plansInNotice: boolean;
90
+ /** #349: carry the parent session's goal into the child's continuation notice. */
91
+ goalInNotice: boolean;
92
+ /** #349: budget in chars for the objective text inside that block. */
93
+ goalNoticeChars: number;
90
94
  /** Teach the child its lookup verbs (read / chapters_artifact / chapters_search). */
91
95
  retrievalHints: boolean;
92
96
  /** Seed plan mode into continuation children (plans-carriage § 10). */
@@ -239,6 +243,18 @@ export declare function rosterRemediation(presetId: string): string;
239
243
  * Exported so the four arms of that line are tested without booting a host — the line IS the
240
244
  * health signal a user reads, and an untested health signal is how the silent case survived. */
241
245
  export declare function reportPresetRoster(ctx: HostCtx, presetId: string): Promise<RosterVerdict>;
246
+ /**
247
+ * The healthy boot line, in one place so the site can be TESTED against it (#355 docs audit).
248
+ *
249
+ * `operations/install.md` tells a user to compare their boot output with a quoted sample and treats any
250
+ * difference as a named problem — which makes a drifted sample actively harmful. The line this plugin
251
+ * prints carries a trailing clause (` — chapter-form compaction and continuations will compose`) and the
252
+ * page showed the short form without it, so a correctly installed system looked wrong by the page's own
253
+ * rule. The sample is now derived from this function by `tests/unit/roster-line-docs.test.ts`, so the two
254
+ * cannot separate again — the same shape of fix as #351's recompute-the-table row: stop trusting that a
255
+ * quoted string matches its source, and make a test fail when it does not.
256
+ */
257
+ export declare const rosterHealthyLine: (presetId: string, mounted: string) => string;
242
258
  /** One phrase describing what the host's inventory says about the preset's own rows.
243
259
  * Never throws: an unavailable inventory must degrade the line, not the boot check. */
244
260
  export declare function describeMountedRows(presets: PresetRegistryLike | undefined, presetId: string): Promise<string>;