@telora/daemon 0.16.25 → 0.16.33
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/build-info.json +6 -3
- package/dist/circuit-wedge-watcher.d.ts +48 -0
- package/dist/circuit-wedge-watcher.d.ts.map +1 -0
- package/dist/circuit-wedge-watcher.js +94 -0
- package/dist/circuit-wedge-watcher.js.map +1 -0
- package/dist/focus-executor.d.ts.map +1 -1
- package/dist/focus-executor.js +16 -3
- package/dist/focus-executor.js.map +1 -1
- package/dist/focus-loop.d.ts +4 -5
- package/dist/focus-loop.d.ts.map +1 -1
- package/dist/focus-loop.js +7 -23
- package/dist/focus-loop.js.map +1 -1
- package/dist/queries/shared.d.ts +35 -0
- package/dist/queries/shared.d.ts.map +1 -1
- package/dist/queries/shared.js +64 -7
- package/dist/queries/shared.js.map +1 -1
- package/dist/queries/verification.d.ts +12 -2
- package/dist/queries/verification.d.ts.map +1 -1
- package/dist/queries/verification.js +11 -3
- package/dist/queries/verification.js.map +1 -1
- package/dist/realign-apply.d.ts +2 -1
- package/dist/realign-apply.d.ts.map +1 -1
- package/dist/realign-apply.js +27 -0
- package/dist/realign-apply.js.map +1 -1
- package/dist/spawn-environment.d.ts +38 -2
- package/dist/spawn-environment.d.ts.map +1 -1
- package/dist/spawn-environment.js +17 -0
- package/dist/spawn-environment.js.map +1 -1
- package/dist/spawner-lifecycle.d.ts +23 -0
- package/dist/spawner-lifecycle.d.ts.map +1 -1
- package/dist/spawner-lifecycle.js +90 -5
- package/dist/spawner-lifecycle.js.map +1 -1
- package/dist/spawner.d.ts +1 -1
- package/dist/spawner.d.ts.map +1 -1
- package/dist/spawner.js +1 -1
- package/dist/spawner.js.map +1 -1
- package/dist/team-spawner.d.ts.map +1 -1
- package/dist/team-spawner.js +35 -4
- package/dist/team-spawner.js.map +1 -1
- package/dist/telemetry-writer.d.ts +20 -1
- package/dist/telemetry-writer.d.ts.map +1 -1
- package/dist/telemetry-writer.js +121 -7
- package/dist/telemetry-writer.js.map +1 -1
- package/dist/trigger-executor.d.ts.map +1 -1
- package/dist/trigger-executor.js +6 -0
- package/dist/trigger-executor.js.map +1 -1
- package/dist/unified-shell.d.ts.map +1 -1
- package/dist/unified-shell.js +8 -0
- package/dist/unified-shell.js.map +1 -1
- package/dist/verification-engine.d.ts +9 -7
- package/dist/verification-engine.d.ts.map +1 -1
- package/dist/verification-engine.js +13 -12
- package/dist/verification-engine.js.map +1 -1
- package/dist/verify-restatement.d.ts +45 -0
- package/dist/verify-restatement.d.ts.map +1 -0
- package/dist/verify-restatement.js +85 -0
- package/dist/verify-restatement.js.map +1 -0
- package/package.json +1 -1
- package/dist/de-reconciliation.d.ts +0 -62
- package/dist/de-reconciliation.d.ts.map +0 -1
- package/dist/de-reconciliation.js +0 -187
- package/dist/de-reconciliation.js.map +0 -1
package/dist/queries/shared.js
CHANGED
|
@@ -33,9 +33,22 @@ export { createTransform, mapDefinedKeys };
|
|
|
33
33
|
// 30s poll interval means a short cooldown won't cause hammering.
|
|
34
34
|
// failureThreshold=5, cooldownMs=15s for quick recovery.
|
|
35
35
|
//
|
|
36
|
-
// activity:
|
|
37
|
-
// gaps. Standard threshold with moderate
|
|
38
|
-
// failureThreshold=5, cooldownMs=30s.
|
|
36
|
+
// activity: Control-plane session lifecycle and git-activity writes. Important
|
|
37
|
+
// but can tolerate brief gaps. Standard threshold with moderate
|
|
38
|
+
// cooldown. failureThreshold=5, cooldownMs=30s.
|
|
39
|
+
// NOTE: this is a CONTROL-PLANE concern. Observability writes
|
|
40
|
+
// (telemetry) must NOT share it -- see the 'telemetry' concern
|
|
41
|
+
// below and the Daemon Resilience Hardening focus. A poisoned
|
|
42
|
+
// telemetry row tripping this breaker would also gate session
|
|
43
|
+
// creation, which is the 2026-05-28 incident this isolation fixes.
|
|
44
|
+
//
|
|
45
|
+
// telemetry: Observability ingest ONLY (token/cost metrics + tool events).
|
|
46
|
+
// Isolated from the control plane so a telemetry-only failure can
|
|
47
|
+
// never open the breaker that gates session creation / active-session
|
|
48
|
+
// reads / git-activity. Higher failure tolerance and a longer cooldown
|
|
49
|
+
// than 'activity' -- telemetry loss is non-fatal and we would rather
|
|
50
|
+
// shed observability writes than hammer a failing ingest endpoint.
|
|
51
|
+
// failureThreshold=8, cooldownMs=30s, maxCooldownMs=180s.
|
|
39
52
|
//
|
|
40
53
|
// delivery: Most critical -- guards, workflow transitions, issue queries.
|
|
41
54
|
// Keep threshold moderate but recover quickly.
|
|
@@ -59,6 +72,12 @@ const circuitBreakers = {
|
|
|
59
72
|
maxCooldownMs: 180000,
|
|
60
73
|
label: 'activity',
|
|
61
74
|
}),
|
|
75
|
+
telemetry: new CircuitBreaker({
|
|
76
|
+
failureThreshold: 8,
|
|
77
|
+
cooldownMs: 30000,
|
|
78
|
+
maxCooldownMs: 180000,
|
|
79
|
+
label: 'telemetry',
|
|
80
|
+
}),
|
|
62
81
|
delivery: new CircuitBreaker({
|
|
63
82
|
failureThreshold: 5,
|
|
64
83
|
cooldownMs: 15000,
|
|
@@ -66,6 +85,23 @@ const circuitBreakers = {
|
|
|
66
85
|
label: 'delivery',
|
|
67
86
|
}),
|
|
68
87
|
};
|
|
88
|
+
export const CONCERN_CLASS = {
|
|
89
|
+
heartbeat: 'control-plane',
|
|
90
|
+
polling: 'control-plane',
|
|
91
|
+
activity: 'control-plane',
|
|
92
|
+
telemetry: 'observability',
|
|
93
|
+
delivery: 'control-plane',
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Actions that are observability/telemetry writes. They MUST resolve to an
|
|
97
|
+
* observability-class concern -- never a control-plane circuit. Declared in
|
|
98
|
+
* source (not in the test) so the invariant is part of the contract.
|
|
99
|
+
*/
|
|
100
|
+
export const OBSERVABILITY_ACTIONS = new Set([
|
|
101
|
+
'telemetry-ingest-metrics',
|
|
102
|
+
'telemetry-ingest-events',
|
|
103
|
+
'daemon_report_telemetry',
|
|
104
|
+
]);
|
|
69
105
|
/**
|
|
70
106
|
* Map API actions to their circuit breaker concern.
|
|
71
107
|
* Actions not listed here fall through to the 'delivery' breaker (general-purpose).
|
|
@@ -82,15 +118,18 @@ const actionToConcern = {
|
|
|
82
118
|
daemon_get_merge_conflict_deliveries: 'polling',
|
|
83
119
|
daemon_update_focus_status: 'delivery',
|
|
84
120
|
daemon_get_focus_workflow: 'delivery',
|
|
85
|
-
// Activity tracking concern (session
|
|
121
|
+
// Activity tracking concern (CONTROL-PLANE session lifecycle)
|
|
86
122
|
daemon_update_session: 'activity',
|
|
87
123
|
daemon_create_session: 'activity',
|
|
88
124
|
daemon_get_active_sessions: 'activity',
|
|
89
125
|
daemon_get_active_session_count: 'activity',
|
|
90
126
|
daemon_get_session_aggregates: 'activity',
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
// Telemetry concern (OBSERVABILITY ingest -- isolated from the control plane
|
|
128
|
+
// so a telemetry-only failure cannot wedge session creation; see the
|
|
129
|
+
// Daemon Resilience Hardening focus / 2026-05-28 incident).
|
|
130
|
+
daemon_report_telemetry: 'telemetry',
|
|
131
|
+
'telemetry-ingest-metrics': 'telemetry',
|
|
132
|
+
'telemetry-ingest-events': 'telemetry',
|
|
94
133
|
// Worktree state concern (delivery-critical -- affects worktree lifecycle)
|
|
95
134
|
daemon_worktree_upsert: 'delivery',
|
|
96
135
|
daemon_worktree_remove: 'delivery',
|
|
@@ -123,6 +162,24 @@ const actionToConcern = {
|
|
|
123
162
|
function getConcernForAction(action) {
|
|
124
163
|
return actionToConcern[action] ?? 'delivery';
|
|
125
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Resolve the CircuitBreaker instance that guards a given API action.
|
|
167
|
+
*
|
|
168
|
+
* Exposed for diagnostics and for the resilience-hardening invariant tests
|
|
169
|
+
* that assert observability actions (telemetry) resolve to a DISTINCT breaker
|
|
170
|
+
* from control-plane actions (session creation, git activity).
|
|
171
|
+
*/
|
|
172
|
+
export function getCircuitBreakerForAction(action) {
|
|
173
|
+
return circuitBreakers[getConcernForAction(action)];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Read-only view of the action -> circuit-breaker-concern mapping.
|
|
177
|
+
* Exposed for the cascade-prevention invariant test, which enumerates it to
|
|
178
|
+
* assert observability actions never share a concern with control-plane ones.
|
|
179
|
+
*/
|
|
180
|
+
export function getActionConcernMap() {
|
|
181
|
+
return actionToConcern;
|
|
182
|
+
}
|
|
126
183
|
// ---------------------------------------------------------------------------
|
|
127
184
|
// API client (daemon-core backed)
|
|
128
185
|
// ---------------------------------------------------------------------------
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/queries/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,GAEf,MAAM,qBAAqB,CAAC;AAE7B,8EAA8E;AAC9E,uEAAuE;AACvE,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAE3C,8EAA8E;AAC9E,+BAA+B;AAC/B,8EAA8E;AAC9E,oEAAoE;AACpE,iFAAiF;AAEjF,qCAAqC;AACrC,EAAE;AACF,wEAAwE;AACxE,+EAA+E;AAC/E,sEAAsE;AACtE,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,qEAAqE;AACrE,EAAE;AACF,8EAA8E;AAC9E,+
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/queries/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,GAEf,MAAM,qBAAqB,CAAC;AAE7B,8EAA8E;AAC9E,uEAAuE;AACvE,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAE3C,8EAA8E;AAC9E,+BAA+B;AAC/B,8EAA8E;AAC9E,oEAAoE;AACpE,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AAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,OAAO,SAAS,EAAE,CAAC,mBAAmB,EAAE,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,MAAc,EACd,SAAkC,EAAE;IAEpC,OAAO,SAAS,EAAE,CAAC,OAAO,CAAI,MAAM,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAc,EACd,MAAoB,EACpB,SAAkC,EAAE;IAEpC,OAAO,SAAS,EAAE,CAAC,gBAAgB,CAAI,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAc,EACd,SAAkC,EAAE;IAEpC,OAAO,SAAS,EAAE,CAAC,WAAW,CAAI,MAAM,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -20,8 +20,18 @@ export interface PendingVerification {
|
|
|
20
20
|
}
|
|
21
21
|
export declare function getPendingVerifications(productId?: string): Promise<PendingVerification[]>;
|
|
22
22
|
export declare function recordDeliveryVerificationOutcome(deliveryId: string, outcome: VerificationOutcome): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
export
|
|
23
|
+
/** Per-target positive base statement carried into the verify call. */
|
|
24
|
+
export interface VerifyRestatement {
|
|
25
|
+
nodeId: string;
|
|
26
|
+
statement: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compound op: retires the injection and promotes its FRT overlay to CRT.
|
|
30
|
+
* Optional per-target restatements (authored on the passing verdict) are
|
|
31
|
+
* applied by the edge as each targeted UDE's new base statement; the edge
|
|
32
|
+
* never authors prose itself.
|
|
33
|
+
*/
|
|
34
|
+
export declare function verifyInjectionOnPass(injectionNodeId: string, restatements?: VerifyRestatement[]): Promise<void>;
|
|
25
35
|
/**
|
|
26
36
|
* Same compound op as `verifyInjectionOnPass` but captures evidence text on
|
|
27
37
|
* the injection node first. Mirrors the two-step write that the MCP
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/queries/verification.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG,YAAY,GAAG,eAAe,CAAC;AAClF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACnD,mBAAmB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAChD,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAMhC;AAED,wBAAsB,iCAAiC,CACrD,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,
|
|
1
|
+
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/queries/verification.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG,YAAY,GAAG,eAAe,CAAC;AAClF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACnD,mBAAmB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAChD,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAMhC;AAED,wBAAsB,iCAAiC,CACrD,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,uEAAuE;AACvE,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,eAAe,EAAE,MAAM,EACvB,YAAY,CAAC,EAAE,iBAAiB,EAAE,GACjC,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,2BAA2B,CAC/C,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
|
@@ -13,9 +13,17 @@ export async function getPendingVerifications(productId) {
|
|
|
13
13
|
export async function recordDeliveryVerificationOutcome(deliveryId, outcome) {
|
|
14
14
|
await callApi('daemon_record_delivery_verification_outcome', { deliveryId, outcome });
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Compound op: retires the injection and promotes its FRT overlay to CRT.
|
|
18
|
+
* Optional per-target restatements (authored on the passing verdict) are
|
|
19
|
+
* applied by the edge as each targeted UDE's new base statement; the edge
|
|
20
|
+
* never authors prose itself.
|
|
21
|
+
*/
|
|
22
|
+
export async function verifyInjectionOnPass(injectionNodeId, restatements) {
|
|
23
|
+
const body = { injectionNodeId };
|
|
24
|
+
if (restatements && restatements.length > 0)
|
|
25
|
+
body.restatements = restatements;
|
|
26
|
+
await callApi('reality_tree_verify_injection', body);
|
|
19
27
|
}
|
|
20
28
|
/**
|
|
21
29
|
* Same compound op as `verifyInjectionOnPass` but captures evidence text on
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/queries/verification.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAiBtC,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,SAAkB;IAElB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAC5B,kCAAkC,EAClC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAC/B,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,UAAkB,EAClB,OAA4B;IAE5B,MAAM,OAAO,CAAC,6CAA6C,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;AACxF,CAAC;
|
|
1
|
+
{"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/queries/verification.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAiBtC,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,SAAkB;IAElB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAC5B,kCAAkC,EAClC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAC/B,CAAC;IACF,OAAO,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,UAAkB,EAClB,OAA4B;IAE5B,MAAM,OAAO,CAAC,6CAA6C,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;AACxF,CAAC;AAQD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,eAAuB,EACvB,YAAkC;IAElC,MAAM,IAAI,GAA4B,EAAE,eAAe,EAAE,CAAC;IAC1D,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC;QAAE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IAC9E,MAAM,OAAO,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,eAAuB,EACvB,QAAgB;IAEhB,MAAM,OAAO,CAAC,0BAA0B,EAAE;QACxC,MAAM,EAAE,eAAe;QACvB,QAAQ;KACT,CAAC,CAAC;IACH,MAAM,OAAO,CAAC,+BAA+B,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/realign-apply.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* - retire_node -- soft-retire node (cascade handled by edge function)
|
|
12
12
|
* - change_node_type -- update node_type
|
|
13
13
|
* - flip_ude_to_de -- promote UDE -> DE (constrained change_node_type)
|
|
14
|
+
* - demote_de_to_ude -- reverse a DE -> UDE (records a symmetric history snapshot)
|
|
14
15
|
*
|
|
15
16
|
* Failures on a single proposal MUST NOT abort the rest -- we collect the
|
|
16
17
|
* error and continue. The dispatcher only marks_applied on success.
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
*/
|
|
20
21
|
import { type RestatementInputs, type RestatementOptions } from './de-restatement.js';
|
|
21
22
|
/** Local string-literal union -- intentionally not imported from supabase types. */
|
|
22
|
-
export type ProposalKind = 'update_statement' | 'add_node' | 'retire_node' | 'change_node_type' | 'flip_ude_to_de';
|
|
23
|
+
export type ProposalKind = 'update_statement' | 'add_node' | 'retire_node' | 'change_node_type' | 'flip_ude_to_de' | 'demote_de_to_ude';
|
|
23
24
|
export interface DriftProposal {
|
|
24
25
|
id: string;
|
|
25
26
|
organizationId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realign-apply.d.ts","sourceRoot":"","sources":["../src/realign-apply.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"realign-apply.d.ts","sourceRoot":"","sources":["../src/realign-apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,qBAAqB,CAAC;AAqB7B,oFAAoF;AACpF,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,UAAU,GACV,aAAa,GACb,kBAAkB,GAClB,gBAAgB,GAChB,kBAAkB,CAAC;AAEvB,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACjD,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;IAC1D,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAOD,iFAAiF;AACjF,MAAM,MAAM,mBAAmB,GAAG,CAChC,MAAM,EAAE,iBAAiB,EACzB,IAAI,CAAC,EAAE,kBAAkB,KACtB,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,MAAM,WAAW,iBAAiB;IAChC,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,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAoPD;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CAwC9B"}
|
package/dist/realign-apply.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* - retire_node -- soft-retire node (cascade handled by edge function)
|
|
12
12
|
* - change_node_type -- update node_type
|
|
13
13
|
* - flip_ude_to_de -- promote UDE -> DE (constrained change_node_type)
|
|
14
|
+
* - demote_de_to_ude -- reverse a DE -> UDE (records a symmetric history snapshot)
|
|
14
15
|
*
|
|
15
16
|
* Failures on a single proposal MUST NOT abort the rest -- we collect the
|
|
16
17
|
* error and continue. The dispatcher only marks_applied on success.
|
|
@@ -187,12 +188,38 @@ const handleFlipUdeToDe = async (proposal, callApi, deps) => {
|
|
|
187
188
|
}
|
|
188
189
|
await callApi('reality_tree_node_update', updates);
|
|
189
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* demote_de_to_ude -- reverse a desired_effect back to an undesired_effect.
|
|
193
|
+
* The inverse of the UDE->DE flip, for correcting an erroneous or regressed
|
|
194
|
+
* flip. Routes through the dedicated `reality_tree_node_demote` edge action so
|
|
195
|
+
* the demote records a symmetric reality_tree_node_history snapshot and clears
|
|
196
|
+
* the FRT overlay in one place. proposed_correction, when present, is the UDE
|
|
197
|
+
* statement to restore; proposed_metadata.injectionId, when present, attributes
|
|
198
|
+
* the history snapshot (else the edge resolves it from the node's flip history).
|
|
199
|
+
*
|
|
200
|
+
* Human/agent-triggered only: the audit/propose phase never emits this kind.
|
|
201
|
+
*/
|
|
202
|
+
const handleDemoteDeToUde = async (proposal, callApi) => {
|
|
203
|
+
if (!proposal.nodeId) {
|
|
204
|
+
throw new Error('demote_de_to_ude: nodeId is required');
|
|
205
|
+
}
|
|
206
|
+
const body = { nodeId: proposal.nodeId };
|
|
207
|
+
const udeStatement = proposal.proposedCorrection?.trim();
|
|
208
|
+
if (udeStatement)
|
|
209
|
+
body.statement = udeStatement;
|
|
210
|
+
const meta = proposal.proposedMetadata ?? {};
|
|
211
|
+
if (typeof meta.injectionId === 'string' && meta.injectionId) {
|
|
212
|
+
body.injectionId = meta.injectionId;
|
|
213
|
+
}
|
|
214
|
+
await callApi('reality_tree_node_demote', body);
|
|
215
|
+
};
|
|
190
216
|
const HANDLERS = {
|
|
191
217
|
update_statement: handleUpdateStatement,
|
|
192
218
|
add_node: handleAddNode,
|
|
193
219
|
retire_node: handleRetireNode,
|
|
194
220
|
change_node_type: handleChangeNodeType,
|
|
195
221
|
flip_ude_to_de: handleFlipUdeToDe,
|
|
222
|
+
demote_de_to_ude: handleDemoteDeToUde,
|
|
196
223
|
};
|
|
197
224
|
// ---------------------------------------------------------------------------
|
|
198
225
|
// Dispatcher
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realign-apply.js","sourceRoot":"","sources":["../src/realign-apply.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"realign-apply.js","sourceRoot":"","sources":["../src/realign-apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,iBAAiB,IAAI,wBAAwB,GAG9C,MAAM,qBAAqB,CAAC;AAE7B,mFAAmF;AACnF,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,WAAW,CAAU,CAAC;AAG1F,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAU,CAAC;AAG9D,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,UAAgC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxF,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,WAAiC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzF,CAAC;AA0ED;;;;GAIG;AACH,KAAK,UAAU,kBAAkB,CAC/B,MAAc,EACd,MAAc,EACd,OAAgB;IAEhB,MAAM,GAAG,GAAG,MAAM,OAAO,CACvB,wBAAwB,EACxB,EAAE,MAAM,EAAE,CACX,CAAC;IACF,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;IAC5D,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,O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GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QACjF,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -12,13 +12,22 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { DaemonConfig } from './types.js';
|
|
14
14
|
/**
|
|
15
|
-
* IDs for OTEL resource attribute correlation.
|
|
16
|
-
*
|
|
15
|
+
* IDs for OTEL resource attribute correlation. The org/focus/session/delivery
|
|
16
|
+
* fields are optional -- not every spawn knows all of them.
|
|
17
17
|
*
|
|
18
18
|
* `phase` and `stage` tag the spend with the controllable lever: the
|
|
19
19
|
* loop/execution phase (audit/realign_crt/propose_injections/execute/gate/
|
|
20
20
|
* evaluate) and the workflow stage active at spawn. They flow through to the
|
|
21
21
|
* agent_telemetry_metrics.phase / .stage columns via the OTLP receiver.
|
|
22
|
+
*
|
|
23
|
+
* They are OPTIONAL on this base type and REQUIRED on `LeveredSpawnIds` (below).
|
|
24
|
+
* The contract is enforced through the type system rather than a post-hoc
|
|
25
|
+
* boundary lint (see the repo principle "prevent at source, not at boundary"):
|
|
26
|
+
* the levered spawn paths -- the focus team-lead, the audit assessor, and any
|
|
27
|
+
* future spawn that runs an attributable phase -- accept `LeveredSpawnIds`, so a
|
|
28
|
+
* caller that forgets phase or stage fails to TYPECHECK. The base `SpawnIds`
|
|
29
|
+
* variant remains only for spawns where a lever value is genuinely not
|
|
30
|
+
* applicable, and those call sites must document why.
|
|
22
31
|
*/
|
|
23
32
|
export interface SpawnIds {
|
|
24
33
|
orgId?: string;
|
|
@@ -28,6 +37,28 @@ export interface SpawnIds {
|
|
|
28
37
|
phase?: string;
|
|
29
38
|
stage?: string;
|
|
30
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Spawn IDs for a LEVERED spawn path -- one that runs an attributable execution
|
|
42
|
+
* phase against a known workflow stage. `phase` and `stage` are REQUIRED here,
|
|
43
|
+
* so the compiler rejects any levered spawn that drops the lever. This is the
|
|
44
|
+
* type-level prevent-at-source guard that closes the live (non-legacy) share of
|
|
45
|
+
* the unattributed phase/stage telemetry bucket: the gap can no longer be
|
|
46
|
+
* reintroduced silently because it becomes a compile error.
|
|
47
|
+
*/
|
|
48
|
+
export interface LeveredSpawnIds extends SpawnIds {
|
|
49
|
+
phase: string;
|
|
50
|
+
stage: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Build a clean environment for a LEVERED spawn -- the focus team-lead, the
|
|
54
|
+
* audit assessor, or any spawn running an attributable execution phase against
|
|
55
|
+
* a known workflow stage. Delegates to buildSpawnEnvironment; the only
|
|
56
|
+
* difference is the parameter type: `LeveredSpawnIds` makes `phase` and `stage`
|
|
57
|
+
* REQUIRED, so a levered caller that forgets the lever fails to compile. This is
|
|
58
|
+
* the prevent-at-source guard for telemetry phase/stage coverage -- use this
|
|
59
|
+
* entry point for every spawn that has a sensible phase + stage.
|
|
60
|
+
*/
|
|
61
|
+
export declare function buildLeveredSpawnEnvironment(config: DaemonConfig, ids: LeveredSpawnIds): Record<string, string | undefined>;
|
|
31
62
|
/**
|
|
32
63
|
* Build a clean environment for a spawned agent or team lead process.
|
|
33
64
|
*
|
|
@@ -37,6 +68,11 @@ export interface SpawnIds {
|
|
|
37
68
|
* - Strips CLAUDECODE, CLAUDE_CODE_*, and CLAUDECODE_* (except CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS)
|
|
38
69
|
* - Injects OTel telemetry env vars when config.telemetry.enabled is true
|
|
39
70
|
* - Includes telora.delivery_id in OTEL_RESOURCE_ATTRIBUTES only when deliveryId is provided
|
|
71
|
+
*
|
|
72
|
+
* Accepts the base `SpawnIds` (phase/stage optional). Levered spawns should call
|
|
73
|
+
* buildLeveredSpawnEnvironment instead, which requires the lever fields. This
|
|
74
|
+
* base form remains for narrow spawns where a lever value is genuinely not
|
|
75
|
+
* applicable (and for tests that exercise the env plumbing without a phase).
|
|
40
76
|
*/
|
|
41
77
|
export declare function buildSpawnEnvironment(config: DaemonConfig, ids: SpawnIds): Record<string, string | undefined>;
|
|
42
78
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-environment.d.ts","sourceRoot":"","sources":["../src/spawn-environment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C
|
|
1
|
+
{"version":3,"file":"spawn-environment.d.ts","sourceRoot":"","sources":["../src/spawn-environment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,eAAe,GACnB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAEpC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,QAAQ,GACZ,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CA8BpC;AAED;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAcjC"}
|
|
@@ -12,6 +12,18 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { stripClaudeCodeEnvVars, buildOtelEnv } from '@telora/daemon-core';
|
|
14
14
|
import { callApi } from './queries/shared.js';
|
|
15
|
+
/**
|
|
16
|
+
* Build a clean environment for a LEVERED spawn -- the focus team-lead, the
|
|
17
|
+
* audit assessor, or any spawn running an attributable execution phase against
|
|
18
|
+
* a known workflow stage. Delegates to buildSpawnEnvironment; the only
|
|
19
|
+
* difference is the parameter type: `LeveredSpawnIds` makes `phase` and `stage`
|
|
20
|
+
* REQUIRED, so a levered caller that forgets the lever fails to compile. This is
|
|
21
|
+
* the prevent-at-source guard for telemetry phase/stage coverage -- use this
|
|
22
|
+
* entry point for every spawn that has a sensible phase + stage.
|
|
23
|
+
*/
|
|
24
|
+
export function buildLeveredSpawnEnvironment(config, ids) {
|
|
25
|
+
return buildSpawnEnvironment(config, ids);
|
|
26
|
+
}
|
|
15
27
|
/**
|
|
16
28
|
* Build a clean environment for a spawned agent or team lead process.
|
|
17
29
|
*
|
|
@@ -21,6 +33,11 @@ import { callApi } from './queries/shared.js';
|
|
|
21
33
|
* - Strips CLAUDECODE, CLAUDE_CODE_*, and CLAUDECODE_* (except CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS)
|
|
22
34
|
* - Injects OTel telemetry env vars when config.telemetry.enabled is true
|
|
23
35
|
* - Includes telora.delivery_id in OTEL_RESOURCE_ATTRIBUTES only when deliveryId is provided
|
|
36
|
+
*
|
|
37
|
+
* Accepts the base `SpawnIds` (phase/stage optional). Levered spawns should call
|
|
38
|
+
* buildLeveredSpawnEnvironment instead, which requires the lever fields. This
|
|
39
|
+
* base form remains for narrow spawns where a lever value is genuinely not
|
|
40
|
+
* applicable (and for tests that exercise the env plumbing without a phase).
|
|
24
41
|
*/
|
|
25
42
|
export function buildSpawnEnvironment(config, ids) {
|
|
26
43
|
// Start with a clean copy that has daemon-specific vars set,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-environment.js","sourceRoot":"","sources":["../src/spawn-environment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"spawn-environment.js","sourceRoot":"","sources":["../src/spawn-environment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AA0C9C;;;;;;;;GAQG;AACH,MAAM,UAAU,4BAA4B,CAC1C,MAAoB,EACpB,GAAoB;IAEpB,OAAO,qBAAqB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAoB,EACpB,GAAa;IAEb,6DAA6D;IAC7D,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,sBAAsB,CACrC;QACE,GAAG,OAAO,CAAC,GAAG;QACd,mBAAmB,EAAE,GAAG;QACxB,kBAAkB,EAAE,WAAW;QAC/B,4DAA4D;QAC5D,oCAAoC,EAAE,GAAG;KAC1C,EACD,EAAE,QAAQ,EAAE,CAAC,sCAAsC,CAAC,EAAE,CACvD,CAAC;IAEF,2DAA2D;IAC3D,MAAM,OAAO,GAAG,YAAY,CAAC;QAC3B,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO;QACjC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI;QAC3B,kBAAkB,EAAE;YAClB,eAAe,EAAE,GAAG,CAAC,KAAK;YAC1B,iBAAiB,EAAE,GAAG,CAAC,OAAO;YAC9B,oBAAoB,EAAE,GAAG,CAAC,UAAU;YACpC,mBAAmB,EAAE,GAAG,CAAC,SAAS;YAClC,cAAc,EAAE,GAAG,CAAC,KAAK;YACzB,cAAc,EAAE,GAAG,CAAC,KAAK;SAC1B;KACF,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEjC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,SAAiB;IAEjB,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAA4B,gBAAgB,EAAE;gBACxE,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClB,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;YAC1C,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,4EAA4E;QAC9E,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* including termination, status queries, and merge conflict resolution agents.
|
|
6
6
|
*/
|
|
7
7
|
import type { DaemonConfig, RunningAgent } from './types.js';
|
|
8
|
+
import { type TokenUsage } from '@telora/daemon-core';
|
|
9
|
+
import { type TelemetryMetricRow } from './telemetry-writer.js';
|
|
8
10
|
/**
|
|
9
11
|
* Terminate a running agent.
|
|
10
12
|
* Sends a shutdown message via stdin, then escalates to SIGTERM/SIGKILL.
|
|
@@ -78,6 +80,27 @@ export interface AuditSpawnResult {
|
|
|
78
80
|
*/
|
|
79
81
|
sessionId?: string | null;
|
|
80
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Build a telemetry metric row from an audit assessor's stream-json `result`
|
|
85
|
+
* event usage. Exported so the capture-path mapping is unit-testable WITHOUT
|
|
86
|
+
* spawning a process -- mirrors loop-llm-client's exported buildLoopMetricRow.
|
|
87
|
+
*
|
|
88
|
+
* --print one-shot sessions produce NO OTLP rows (the OTLP exporter only fires
|
|
89
|
+
* for long-lived interactive sessions), so without this the 509+ audit runs
|
|
90
|
+
* spend zero captured tokens despite being the live differential-loop LLM cost.
|
|
91
|
+
* This is the audit analogue of loop-llm-client's raw-fetch capture path.
|
|
92
|
+
*/
|
|
93
|
+
export declare function buildAuditMetricRow(params: {
|
|
94
|
+
organizationId: string;
|
|
95
|
+
focusId: string | null;
|
|
96
|
+
sessionId: string | null;
|
|
97
|
+
cycleNumber: number;
|
|
98
|
+
usage: TokenUsage;
|
|
99
|
+
/** result.total_cost_usd when the event carried one (finite); else null. */
|
|
100
|
+
totalCostUsd: number | null;
|
|
101
|
+
periodStart: string;
|
|
102
|
+
periodEnd: string;
|
|
103
|
+
}): TelemetryMetricRow;
|
|
81
104
|
/**
|
|
82
105
|
* Spawn the Claude Code CLI as the audit assessor (INJ-E: resumable).
|
|
83
106
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawner-lifecycle.d.ts","sourceRoot":"","sources":["../src/spawner-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"spawner-lifecycle.d.ts","sourceRoot":"","sources":["../src/spawner-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE7D,OAAO,EAML,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG9E;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CA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AAI,CAAC;IACxB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAcD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,4EAA4E;IAC5E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,kBAAkB,CA4BrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAwHxF"}
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { spawn } from 'node:child_process';
|
|
8
8
|
import { runGitSync } from './git-types.js';
|
|
9
|
-
import { sendMessage, stripClaudeCodeEnvVars, StreamJsonParser } from '@telora/daemon-core';
|
|
9
|
+
import { sendMessage, stripClaudeCodeEnvVars, StreamJsonParser, } from '@telora/daemon-core';
|
|
10
10
|
import { safeSendSignal, safeCloseStdin } from './spawner-stream-handlers.js';
|
|
11
|
-
import {
|
|
11
|
+
import { buildLeveredSpawnEnvironment } from './spawn-environment.js';
|
|
12
|
+
import { bufferMetric } from './telemetry-writer.js';
|
|
13
|
+
import { estimateLoopCostUsd } from './loop-llm-client.js';
|
|
12
14
|
/**
|
|
13
15
|
* Terminate a running agent.
|
|
14
16
|
* Sends a shutdown message via stdin, then escalates to SIGTERM/SIGKILL.
|
|
@@ -151,6 +153,56 @@ export async function spawnResolutionAgent(params) {
|
|
|
151
153
|
});
|
|
152
154
|
});
|
|
153
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Default model tag stamped onto audit-capture rows. The audit assessor spawns
|
|
158
|
+
* with audit-phase.ts AUDIT_DEFAULT_MODEL ('sonnet'); estimateLoopCostUsd matches
|
|
159
|
+
* the pricing table by substring ('sonnet'), so this drives the cost estimate
|
|
160
|
+
* when the result event omits total_cost_usd. Kept as a local literal so this
|
|
161
|
+
* module does not import audit-phase.ts (which imports spawner.ts -> cycle).
|
|
162
|
+
*
|
|
163
|
+
* MODEL PIN (checked 2026-05-27): 'sonnet' resolves to the current Sonnet family
|
|
164
|
+
* and is NOT retired; matches loop-llm-client DEFAULT_MODEL 'claude-sonnet-4-6'.
|
|
165
|
+
*/
|
|
166
|
+
const AUDIT_CAPTURE_MODEL = 'sonnet';
|
|
167
|
+
/**
|
|
168
|
+
* Build a telemetry metric row from an audit assessor's stream-json `result`
|
|
169
|
+
* event usage. Exported so the capture-path mapping is unit-testable WITHOUT
|
|
170
|
+
* spawning a process -- mirrors loop-llm-client's exported buildLoopMetricRow.
|
|
171
|
+
*
|
|
172
|
+
* --print one-shot sessions produce NO OTLP rows (the OTLP exporter only fires
|
|
173
|
+
* for long-lived interactive sessions), so without this the 509+ audit runs
|
|
174
|
+
* spend zero captured tokens despite being the live differential-loop LLM cost.
|
|
175
|
+
* This is the audit analogue of loop-llm-client's raw-fetch capture path.
|
|
176
|
+
*/
|
|
177
|
+
export function buildAuditMetricRow(params) {
|
|
178
|
+
const { organizationId, focusId, sessionId, cycleNumber, usage, totalCostUsd, periodStart, periodEnd } = params;
|
|
179
|
+
const start = Date.parse(periodStart);
|
|
180
|
+
const end = Date.parse(periodEnd);
|
|
181
|
+
const activeMs = Number.isFinite(start) && Number.isFinite(end) && end >= start ? end - start : 0;
|
|
182
|
+
const cost = totalCostUsd !== null && Number.isFinite(totalCostUsd)
|
|
183
|
+
? totalCostUsd
|
|
184
|
+
: estimateLoopCostUsd(AUDIT_CAPTURE_MODEL, usage);
|
|
185
|
+
return {
|
|
186
|
+
organization_id: organizationId,
|
|
187
|
+
focus_id: focusId,
|
|
188
|
+
delivery_id: null,
|
|
189
|
+
session_id: sessionId,
|
|
190
|
+
input_tokens: usage.input_tokens ?? 0,
|
|
191
|
+
output_tokens: usage.output_tokens ?? 0,
|
|
192
|
+
cache_read_tokens: usage.cache_read_input_tokens ?? 0,
|
|
193
|
+
cache_creation_tokens: usage.cache_creation_input_tokens ?? 0,
|
|
194
|
+
cost_usd: cost,
|
|
195
|
+
active_time_ms: activeMs,
|
|
196
|
+
tool_call_count: 0,
|
|
197
|
+
tool_error_count: 0,
|
|
198
|
+
model: AUDIT_CAPTURE_MODEL,
|
|
199
|
+
phase: 'audit',
|
|
200
|
+
stage: null,
|
|
201
|
+
metadata: { source: 'audit-assessor', cycleNumber },
|
|
202
|
+
period_start: periodStart,
|
|
203
|
+
period_end: periodEnd,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
154
206
|
/**
|
|
155
207
|
* Spawn the Claude Code CLI as the audit assessor (INJ-E: resumable).
|
|
156
208
|
*
|
|
@@ -177,15 +229,21 @@ export async function spawnAuditAgent(opts) {
|
|
|
177
229
|
args.push(prompt);
|
|
178
230
|
// Build clean environment via buildSpawnEnvironment which strips any
|
|
179
231
|
// inherited Claude Code session markers that would otherwise hang us.
|
|
180
|
-
|
|
232
|
+
// Levered spawn: phase + stage are REQUIRED, so the audit assessor cannot
|
|
233
|
+
// drop the telemetry lever silently. The audit assessor runs the loop's audit
|
|
234
|
+
// phase against the reality tree (not a workflow stage), so stage mirrors the
|
|
235
|
+
// phase as 'audit' -- the audit pass has no workflow-stage dimension, and
|
|
236
|
+
// tagging it 'audit' keeps audit spend a self-contained, attributable bucket.
|
|
237
|
+
const spawnEnv = buildLeveredSpawnEnvironment(config, {
|
|
181
238
|
orgId: config.organizationId,
|
|
182
239
|
focusId,
|
|
183
|
-
// The audit assessor runs the loop's audit phase; tag its spend so audit
|
|
184
|
-
// cost (and no-op-audit spend) is attributable by phase.
|
|
185
240
|
phase: 'audit',
|
|
241
|
+
stage: 'audit',
|
|
186
242
|
});
|
|
187
243
|
// Distinguishes this from focus team sessions for downstream consumers.
|
|
188
244
|
spawnEnv.TELORA_DAEMON_AUDIT_CYCLE = String(cycleNumber);
|
|
245
|
+
// Bracket the spawn so the captured metric row carries a real active window.
|
|
246
|
+
const periodStart = new Date().toISOString();
|
|
189
247
|
return await new Promise((resolve) => {
|
|
190
248
|
let child;
|
|
191
249
|
try {
|
|
@@ -218,6 +276,33 @@ export async function spawnAuditAgent(opts) {
|
|
|
218
276
|
// Swallow parser errors (non-JSON lines from a stub) -- the raw-stdout
|
|
219
277
|
// fallback covers that case; we must not let an unhandled 'error' throw.
|
|
220
278
|
parser.on('error', () => { });
|
|
279
|
+
// Capture token/cost from the stream-json `result` event. --print one-shot
|
|
280
|
+
// sessions produce NO OTLP rows (the OTLP exporter only fires for long-lived
|
|
281
|
+
// interactive sessions), so without this the audit assessor's spend never
|
|
282
|
+
// reaches agent_telemetry_metrics -- this is the audit analogue of
|
|
283
|
+
// loop-llm-client's raw-fetch capture (loop-llm-client.ts:207-221).
|
|
284
|
+
// Best-effort: a capture failure must NEVER break the audit.
|
|
285
|
+
parser.on('result', (ev) => {
|
|
286
|
+
if (!ev.usage)
|
|
287
|
+
return;
|
|
288
|
+
try {
|
|
289
|
+
bufferMetric(buildAuditMetricRow({
|
|
290
|
+
organizationId: config.organizationId,
|
|
291
|
+
focusId,
|
|
292
|
+
sessionId: parser.sessionId ?? null,
|
|
293
|
+
cycleNumber,
|
|
294
|
+
usage: ev.usage,
|
|
295
|
+
totalCostUsd: typeof ev.total_cost_usd === 'number' && Number.isFinite(ev.total_cost_usd)
|
|
296
|
+
? ev.total_cost_usd
|
|
297
|
+
: null,
|
|
298
|
+
periodStart,
|
|
299
|
+
periodEnd: new Date().toISOString(),
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
console.log(`[audit] Telemetry capture failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
221
306
|
child.stdout?.on('data', (chunk) => { rawStdout += chunk.toString('utf8'); });
|
|
222
307
|
child.stderr?.on('data', (chunk) => { stderr += chunk.toString('utf8'); });
|
|
223
308
|
const timer = setTimeout(() => {
|