@telora/daemon 0.16.25 → 0.16.27

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 (44) hide show
  1. package/build-info.json +5 -3
  2. package/dist/focus-executor.d.ts.map +1 -1
  3. package/dist/focus-executor.js +10 -3
  4. package/dist/focus-executor.js.map +1 -1
  5. package/dist/focus-loop.d.ts +4 -5
  6. package/dist/focus-loop.d.ts.map +1 -1
  7. package/dist/focus-loop.js +7 -23
  8. package/dist/focus-loop.js.map +1 -1
  9. package/dist/queries/verification.d.ts +12 -2
  10. package/dist/queries/verification.d.ts.map +1 -1
  11. package/dist/queries/verification.js +11 -3
  12. package/dist/queries/verification.js.map +1 -1
  13. package/dist/realign-apply.d.ts +2 -1
  14. package/dist/realign-apply.d.ts.map +1 -1
  15. package/dist/realign-apply.js +27 -0
  16. package/dist/realign-apply.js.map +1 -1
  17. package/dist/spawn-environment.d.ts +38 -2
  18. package/dist/spawn-environment.d.ts.map +1 -1
  19. package/dist/spawn-environment.js +17 -0
  20. package/dist/spawn-environment.js.map +1 -1
  21. package/dist/spawner-lifecycle.d.ts +23 -0
  22. package/dist/spawner-lifecycle.d.ts.map +1 -1
  23. package/dist/spawner-lifecycle.js +90 -5
  24. package/dist/spawner-lifecycle.js.map +1 -1
  25. package/dist/spawner.d.ts +1 -1
  26. package/dist/spawner.d.ts.map +1 -1
  27. package/dist/spawner.js +1 -1
  28. package/dist/spawner.js.map +1 -1
  29. package/dist/team-spawner.d.ts.map +1 -1
  30. package/dist/team-spawner.js +29 -4
  31. package/dist/team-spawner.js.map +1 -1
  32. package/dist/verification-engine.d.ts +9 -7
  33. package/dist/verification-engine.d.ts.map +1 -1
  34. package/dist/verification-engine.js +13 -12
  35. package/dist/verification-engine.js.map +1 -1
  36. package/dist/verify-restatement.d.ts +45 -0
  37. package/dist/verify-restatement.d.ts.map +1 -0
  38. package/dist/verify-restatement.js +85 -0
  39. package/dist/verify-restatement.js.map +1 -0
  40. package/package.json +1 -1
  41. package/dist/de-reconciliation.d.ts +0 -62
  42. package/dist/de-reconciliation.d.ts.map +0 -1
  43. package/dist/de-reconciliation.js +0 -187
  44. package/dist/de-reconciliation.js.map +0 -1
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Verify-time desired-effect restatement authoring.
3
+ *
4
+ * When the verification engine produces a 'passed' verdict for an injection,
5
+ * it authors the positive desired-effect restatement for each targeted UDE and
6
+ * passes the prose INTO the verify call. The edge `reality_tree_verify_injection`
7
+ * then applies the supplied prose as the UDE's new base statement (no LLM in the
8
+ * edge). Authoring is therefore an OUTPUT of verification, gated by the same
9
+ * evidence that produced the passing verdict -- not a separate pre-write step or
10
+ * a per-tick reconciliation scan.
11
+ *
12
+ * Reuses the de-restatement prose helper (authorRestatement) -- it does NOT
13
+ * duplicate the prompt/model logic. Injection-conditioned: each UDE becomes the
14
+ * positive state it reaches given the resolving injection.
15
+ *
16
+ * @module verify-restatement
17
+ */
18
+ import { callApi as defaultCallApi } from './queries/shared.js';
19
+ import { authorRestatement as defaultAuthorRestatement, needsRestatement, } from './de-restatement.js';
20
+ /**
21
+ * Author a positive desired-effect restatement for each UDE the injection
22
+ * targets, returning them for the caller to pass into the verify call.
23
+ *
24
+ * Injection-conditioned on the injection's own statement. Best-effort and
25
+ * idempotent at the prose level: a target that already carries a positive
26
+ * frt_statement (target-time intent) reuses it rather than re-authoring. A
27
+ * per-target authoring failure is swallowed (that target is omitted, and the
28
+ * edge falls back to promoting any target-time frt_statement) so one failure
29
+ * never aborts verify.
30
+ *
31
+ * Returns an empty array when focusId is null or the injection is not found in
32
+ * the focus's active tree(s).
33
+ */
34
+ export async function authorTargetRestatements(injectionNodeId, focusId, deps = {}) {
35
+ const callApi = deps.callApi ?? defaultCallApi;
36
+ const author = deps.authorRestatement ?? defaultAuthorRestatement;
37
+ const out = [];
38
+ if (!focusId)
39
+ return out;
40
+ const treesResp = await callApi('reality_tree_list', { focusId });
41
+ const trees = (treesResp.items ?? []).filter((t) => t.status === 'active');
42
+ for (const tree of trees) {
43
+ const [nodesResp, edgesResp] = await Promise.all([
44
+ callApi('reality_tree_node_list', { treeId: tree.id, status: 'active' }),
45
+ callApi('reality_tree_edge_list', { treeId: tree.id }),
46
+ ]);
47
+ const nodes = nodesResp.items ?? [];
48
+ const edges = edgesResp.items ?? [];
49
+ const nodeById = new Map(nodes.map((n) => [n.id, n]));
50
+ const injection = nodeById.get(injectionNodeId);
51
+ if (!injection || injection.nodeType !== 'injection')
52
+ continue; // not in this tree
53
+ const injectionStatements = injection.statement.trim() !== '' ? [injection.statement] : undefined;
54
+ for (const e of edges) {
55
+ if (e.edgeType !== 'targets' || e.fromNodeId !== injectionNodeId)
56
+ continue;
57
+ const target = nodeById.get(e.toNodeId);
58
+ if (!target || target.nodeType !== 'undesired_effect')
59
+ continue;
60
+ // Reuse a positive target-time frt_statement (intent) if present; else
61
+ // author the positive prose now, gated by this passing verdict.
62
+ if (target.frtStatement && !needsRestatement(target.frtStatement)) {
63
+ out.push({ nodeId: target.id, statement: target.frtStatement });
64
+ continue;
65
+ }
66
+ try {
67
+ const text = await author({
68
+ udeStatement: target.statement,
69
+ injectionStatements,
70
+ evidence: target.evidence ?? undefined,
71
+ });
72
+ if (text && text.trim() !== '') {
73
+ out.push({ nodeId: target.id, statement: text.trim() });
74
+ }
75
+ }
76
+ catch {
77
+ // best-effort: omit this target; the edge falls back to promoting any
78
+ // target-time frt_statement (or node_type-only flip).
79
+ }
80
+ }
81
+ return out; // injection found and processed
82
+ }
83
+ return out;
84
+ }
85
+ //# sourceMappingURL=verify-restatement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-restatement.js","sourceRoot":"","sources":["../src/verify-restatement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,iBAAiB,IAAI,wBAAwB,EAC7C,gBAAgB,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EAAE,CAAC,CAAC;gBAC1D,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,sEAAsE;gBACtE,sDAAsD;YACxD,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC,CAAC,gCAAgC;IAC9C,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telora/daemon",
3
- "version": "0.16.25",
3
+ "version": "0.16.27",
4
4
  "description": "Agent orchestration daemon for Telora - spawns and manages Claude Code instances",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,62 +0,0 @@
1
- /**
2
- * Desired-effect restatement reconciliation backstop.
3
- *
4
- * Runs inside the focus-loop realign phase (NOT a separate opt-out env loop).
5
- * Each tick it finds desired_effect nodes that lack a positive restatement and
6
- * authors one via the de-restatement helper, guaranteeing the focus invariant:
7
- * no desired_effect node carries raw UDE text.
8
- *
9
- * Two cases (mirroring the two flip surfaces -- see graph-verification.ts):
10
- * - OVERLAY: a both-scoped node whose FRT overlay was flipped to
11
- * desired_effect but whose frt_statement was never authored
12
- * (frtNodeType='desired_effect' AND needsRestatement(frtStatement)). The
13
- * positive text is written to frt_statement. This covers UI/agent target
14
- * flips and the historical nodes left by migration 20260523095104.
15
- * - BASE: a node already promoted to node_type='desired_effect' whose base
16
- * statement still equals the pre-flip UDE text (per reality_tree_node_history
17
- * previous_node_type='undesired_effect'). The positive text is written to
18
- * statement. This covers verify auto-flips and human-UI base flips.
19
- *
20
- * Per-node failures are collected and never abort the pass (mirrors
21
- * applyRatifiedProposals). Running once backfills historical nodes, so there is
22
- * no separate one-shot script.
23
- *
24
- * @module de-reconciliation
25
- */
26
- import { type RestatementInputs, type RestatementOptions } from './de-restatement.js';
27
- export type AuthorRestatementFn = (inputs: RestatementInputs, opts?: RestatementOptions) => Promise<string>;
28
- export interface ReconcileDeps {
29
- callApi?: <T>(action: string, params?: Record<string, unknown>) => Promise<T>;
30
- /** Authors a positive desired-effect sentence. Defaults to the de-restatement helper. */
31
- authorRestatement?: AuthorRestatementFn;
32
- }
33
- export interface ReconcileResult {
34
- /** Nodes that had a positive statement authored + written this pass. */
35
- authored: number;
36
- /** Desired-effect nodes that already carried positive text (predicate skip). */
37
- skipped: number;
38
- /** Nodes whose authoring/write failed (collected, non-fatal). */
39
- failed: number;
40
- errors: string[];
41
- }
42
- /**
43
- * Author frt_statement for an injection's UDE targets that still lack positive
44
- * text, BEFORE the injection is verified. The edge verify path cannot run the
45
- * LLM helper, so the daemon authors here first; verify's existing promotion
46
- * (`if (frt_statement) statement = frt_statement`) then carries the positive
47
- * text into current reality, closing the gap where a verified former-UDE would
48
- * otherwise read negatively until the next reconciliation tick.
49
- *
50
- * Injection-conditioned on the injection's own statement. Best-effort and
51
- * idempotent: targets already carrying positive frt_statement are skipped.
52
- * Used by the daemon verification engine right before verifyInjection.
53
- */
54
- export declare function authorInjectionTargetRestatements(injectionNodeId: string, focusId: string | null, deps?: ReconcileDeps): Promise<ReconcileResult>;
55
- /**
56
- * Author positive restatements for every desired_effect node in the focus's
57
- * active reality tree(s) that still lacks one. Idempotent: a node already
58
- * carrying positive text is skipped (no write), so a second pass over the same
59
- * tree performs zero writes.
60
- */
61
- export declare function reconcileDesiredEffectRestatements(focusId: string, deps?: ReconcileDeps): Promise<ReconcileResult>;
62
- //# sourceMappingURL=de-reconciliation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"de-reconciliation.d.ts","sourceRoot":"","sources":["../src/de-reconciliation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,qBAAqB,CAAC;AAS7B,MAAM,MAAM,mBAAmB,GAAG,CAChC,MAAM,EAAE,iBAAiB,EACzB,IAAI,CAAC,EAAE,kBAAkB,KACtB,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9E,yFAAyF;IACzF,iBAAiB,CAAC,EAAE,mBAAmB,CAAC;CACzC;AAED,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAYD;;;;;;;;;;;GAWG;AACH,wBAAsB,iCAAiC,CACrD,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,eAAe,CAAC,CAgD1B;AAmBD;;;;;GAKG;AACH,wBAAsB,kCAAkC,CACtD,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,eAAe,CAAC,CA8E1B"}
@@ -1,187 +0,0 @@
1
- /**
2
- * Desired-effect restatement reconciliation backstop.
3
- *
4
- * Runs inside the focus-loop realign phase (NOT a separate opt-out env loop).
5
- * Each tick it finds desired_effect nodes that lack a positive restatement and
6
- * authors one via the de-restatement helper, guaranteeing the focus invariant:
7
- * no desired_effect node carries raw UDE text.
8
- *
9
- * Two cases (mirroring the two flip surfaces -- see graph-verification.ts):
10
- * - OVERLAY: a both-scoped node whose FRT overlay was flipped to
11
- * desired_effect but whose frt_statement was never authored
12
- * (frtNodeType='desired_effect' AND needsRestatement(frtStatement)). The
13
- * positive text is written to frt_statement. This covers UI/agent target
14
- * flips and the historical nodes left by migration 20260523095104.
15
- * - BASE: a node already promoted to node_type='desired_effect' whose base
16
- * statement still equals the pre-flip UDE text (per reality_tree_node_history
17
- * previous_node_type='undesired_effect'). The positive text is written to
18
- * statement. This covers verify auto-flips and human-UI base flips.
19
- *
20
- * Per-node failures are collected and never abort the pass (mirrors
21
- * applyRatifiedProposals). Running once backfills historical nodes, so there is
22
- * no separate one-shot script.
23
- *
24
- * @module de-reconciliation
25
- */
26
- import { callApi as defaultCallApi } from './queries/shared.js';
27
- import { authorRestatement as defaultAuthorRestatement, needsRestatement, } from './de-restatement.js';
28
- /**
29
- * Author frt_statement for an injection's UDE targets that still lack positive
30
- * text, BEFORE the injection is verified. The edge verify path cannot run the
31
- * LLM helper, so the daemon authors here first; verify's existing promotion
32
- * (`if (frt_statement) statement = frt_statement`) then carries the positive
33
- * text into current reality, closing the gap where a verified former-UDE would
34
- * otherwise read negatively until the next reconciliation tick.
35
- *
36
- * Injection-conditioned on the injection's own statement. Best-effort and
37
- * idempotent: targets already carrying positive frt_statement are skipped.
38
- * Used by the daemon verification engine right before verifyInjection.
39
- */
40
- export async function authorInjectionTargetRestatements(injectionNodeId, focusId, deps = {}) {
41
- const callApi = deps.callApi ?? defaultCallApi;
42
- const author = deps.authorRestatement ?? defaultAuthorRestatement;
43
- const result = { authored: 0, skipped: 0, failed: 0, errors: [] };
44
- if (!focusId)
45
- return result;
46
- const treesResp = await callApi('reality_tree_list', { focusId });
47
- const trees = (treesResp.items ?? []).filter((t) => t.status === 'active');
48
- for (const tree of trees) {
49
- const [nodesResp, edgesResp] = await Promise.all([
50
- callApi('reality_tree_node_list', { treeId: tree.id, status: 'active' }),
51
- callApi('reality_tree_edge_list', { treeId: tree.id }),
52
- ]);
53
- const nodes = nodesResp.items ?? [];
54
- const edges = edgesResp.items ?? [];
55
- const nodeById = new Map(nodes.map((n) => [n.id, n]));
56
- const injection = nodeById.get(injectionNodeId);
57
- if (!injection || injection.nodeType !== 'injection')
58
- continue; // not in this tree
59
- const injectionStatements = injection.statement.trim() !== '' ? [injection.statement] : undefined;
60
- for (const e of edges) {
61
- if (e.edgeType !== 'targets' || e.fromNodeId !== injectionNodeId)
62
- continue;
63
- const target = nodeById.get(e.toNodeId);
64
- if (!target || target.nodeType !== 'undesired_effect')
65
- continue;
66
- if (!needsRestatement(target.frtStatement)) {
67
- result.skipped += 1;
68
- continue;
69
- }
70
- try {
71
- const text = await author({
72
- udeStatement: target.statement,
73
- injectionStatements,
74
- evidence: target.evidence ?? undefined,
75
- });
76
- await callApi('reality_tree_node_update', { nodeId: target.id, frtStatement: text });
77
- result.authored += 1;
78
- }
79
- catch (err) {
80
- result.failed += 1;
81
- result.errors.push(`pre-verify ${target.id}: ${err.message}`);
82
- }
83
- }
84
- return result; // injection found and processed
85
- }
86
- return result;
87
- }
88
- /** Statements of injection nodes with a live 'targets' edge to the given node. */
89
- function injectionStatementsTargeting(nodeId, edges, nodeById) {
90
- const out = [];
91
- for (const e of edges) {
92
- if (e.edgeType !== 'targets' || e.toNodeId !== nodeId)
93
- continue;
94
- const from = nodeById.get(e.fromNodeId);
95
- if (from && from.nodeType === 'injection' && from.statement.trim() !== '') {
96
- out.push(from.statement);
97
- }
98
- }
99
- return out;
100
- }
101
- /**
102
- * Author positive restatements for every desired_effect node in the focus's
103
- * active reality tree(s) that still lacks one. Idempotent: a node already
104
- * carrying positive text is skipped (no write), so a second pass over the same
105
- * tree performs zero writes.
106
- */
107
- export async function reconcileDesiredEffectRestatements(focusId, deps = {}) {
108
- const callApi = deps.callApi ?? defaultCallApi;
109
- const author = deps.authorRestatement ?? defaultAuthorRestatement;
110
- const result = { authored: 0, skipped: 0, failed: 0, errors: [] };
111
- const treesResp = await callApi('reality_tree_list', { focusId });
112
- const trees = (treesResp.items ?? []).filter((t) => t.status === 'active');
113
- if (trees.length === 0)
114
- return result;
115
- for (const tree of trees) {
116
- const [nodesResp, edgesResp] = await Promise.all([
117
- callApi('reality_tree_node_list', { treeId: tree.id, status: 'active' }),
118
- callApi('reality_tree_edge_list', { treeId: tree.id }),
119
- ]);
120
- const nodes = nodesResp.items ?? [];
121
- const edges = edgesResp.items ?? [];
122
- const nodeById = new Map(nodes.map((n) => [n.id, n]));
123
- // --- OVERLAY case: frt_node_type flipped to desired_effect, frt_statement unauthored.
124
- for (const node of nodes) {
125
- if (node.frtNodeType !== 'desired_effect')
126
- continue;
127
- if (!needsRestatement(node.frtStatement)) {
128
- result.skipped += 1;
129
- continue;
130
- }
131
- const injectionStatements = injectionStatementsTargeting(node.id, edges, nodeById);
132
- try {
133
- const text = await author({
134
- udeStatement: node.statement,
135
- injectionStatements: injectionStatements.length > 0 ? injectionStatements : undefined,
136
- evidence: node.evidence ?? undefined,
137
- });
138
- await callApi('reality_tree_node_update', { nodeId: node.id, frtStatement: text });
139
- result.authored += 1;
140
- }
141
- catch (err) {
142
- result.failed += 1;
143
- result.errors.push(`overlay ${node.id}: ${err.message}`);
144
- }
145
- }
146
- // --- BASE case: node promoted to desired_effect but base statement still the UDE text.
147
- const deNodes = nodes.filter((n) => n.nodeType === 'desired_effect');
148
- for (const node of deNodes) {
149
- let hist;
150
- try {
151
- hist = await callApi('reality_tree_injection_history', {
152
- nodeId: node.id,
153
- });
154
- }
155
- catch (err) {
156
- result.failed += 1;
157
- result.errors.push(`base-history ${node.id}: ${err.message}`);
158
- continue;
159
- }
160
- // The flip that turned this node from a UDE into a DE.
161
- const flip = (hist.history ?? []).find((h) => h.previousNodeType === 'undesired_effect');
162
- if (!flip)
163
- continue; // not a UDE->DE flip we can reconcile from history
164
- if (!needsRestatement(node.statement, flip.previousStatement)) {
165
- result.skipped += 1;
166
- continue;
167
- }
168
- const injectionStatements = flip.injection?.statement?.trim()
169
- ? [flip.injection.statement]
170
- : [];
171
- try {
172
- const text = await author({
173
- udeStatement: flip.previousStatement ?? node.statement,
174
- injectionStatements: injectionStatements.length > 0 ? injectionStatements : undefined,
175
- });
176
- await callApi('reality_tree_node_update', { nodeId: node.id, statement: text });
177
- result.authored += 1;
178
- }
179
- catch (err) {
180
- result.failed += 1;
181
- result.errors.push(`base ${node.id}: ${err.message}`);
182
- }
183
- }
184
- }
185
- return result;
186
- }
187
- //# sourceMappingUR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