@dsh-enhanced/assistant-goals 0.1.30
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/LICENSE +21 -0
- package/README.md +274 -0
- package/cordis.patch.yml +3 -0
- package/lib/budget-store.d.ts +73 -0
- package/lib/budget-store.d.ts.map +1 -0
- package/lib/budget-store.js +345 -0
- package/lib/budget-store.js.map +1 -0
- package/lib/budget.d.ts +78 -0
- package/lib/budget.d.ts.map +1 -0
- package/lib/budget.js +344 -0
- package/lib/budget.js.map +1 -0
- package/lib/dependency.d.ts +11 -0
- package/lib/dependency.d.ts.map +1 -0
- package/lib/dependency.js +34 -0
- package/lib/dependency.js.map +1 -0
- package/lib/event-wait-store.d.ts +56 -0
- package/lib/event-wait-store.d.ts.map +1 -0
- package/lib/event-wait-store.js +189 -0
- package/lib/event-wait-store.js.map +1 -0
- package/lib/event-wait.d.ts +47 -0
- package/lib/event-wait.d.ts.map +1 -0
- package/lib/event-wait.js +372 -0
- package/lib/event-wait.js.map +1 -0
- package/lib/execution-store.d.ts +23 -0
- package/lib/execution-store.d.ts.map +1 -0
- package/lib/execution-store.js +207 -0
- package/lib/execution-store.js.map +1 -0
- package/lib/execution.d.ts +49 -0
- package/lib/execution.d.ts.map +1 -0
- package/lib/execution.js +438 -0
- package/lib/execution.js.map +1 -0
- package/lib/feedback.d.ts +63 -0
- package/lib/feedback.d.ts.map +1 -0
- package/lib/feedback.js +134 -0
- package/lib/feedback.js.map +1 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +9 -0
- package/lib/index.js.map +1 -0
- package/lib/outcome-store.d.ts +47 -0
- package/lib/outcome-store.d.ts.map +1 -0
- package/lib/outcome-store.js +271 -0
- package/lib/outcome-store.js.map +1 -0
- package/lib/outcome.d.ts +77 -0
- package/lib/outcome.d.ts.map +1 -0
- package/lib/outcome.js +417 -0
- package/lib/outcome.js.map +1 -0
- package/lib/service.d.ts +363 -0
- package/lib/service.d.ts.map +1 -0
- package/lib/service.js +1839 -0
- package/lib/service.js.map +1 -0
- package/lib/store.d.ts +21 -0
- package/lib/store.d.ts.map +1 -0
- package/lib/store.js +577 -0
- package/lib/store.js.map +1 -0
- package/lib/strategy-feedback.d.ts +29 -0
- package/lib/strategy-feedback.d.ts.map +1 -0
- package/lib/strategy-feedback.js +53 -0
- package/lib/strategy-feedback.js.map +1 -0
- package/lib/strategy-identity.d.ts +11 -0
- package/lib/strategy-identity.d.ts.map +1 -0
- package/lib/strategy-identity.js +10 -0
- package/lib/strategy-identity.js.map +1 -0
- package/lib/strategy-store.d.ts +76 -0
- package/lib/strategy-store.d.ts.map +1 -0
- package/lib/strategy-store.js +277 -0
- package/lib/strategy-store.js.map +1 -0
- package/lib/strategy.d.ts +56 -0
- package/lib/strategy.d.ts.map +1 -0
- package/lib/strategy.js +478 -0
- package/lib/strategy.js.map +1 -0
- package/lib/tools.d.ts +4 -0
- package/lib/tools.d.ts.map +1 -0
- package/lib/tools.js +130 -0
- package/lib/tools.js.map +1 -0
- package/lib/types.d.ts +285 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +10 -0
- package/lib/types.js.map +1 -0
- package/lib/verified-artifact.d.ts +72 -0
- package/lib/verified-artifact.d.ts.map +1 -0
- package/lib/verified-artifact.js +142 -0
- package/lib/verified-artifact.js.map +1 -0
- package/lib/verified-workflow.d.ts +120 -0
- package/lib/verified-workflow.d.ts.map +1 -0
- package/lib/verified-workflow.js +253 -0
- package/lib/verified-workflow.js.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +2 -0
- package/lib/version.js.map +1 -0
- package/lib/wake-store.d.ts +38 -0
- package/lib/wake-store.d.ts.map +1 -0
- package/lib/wake-store.js +177 -0
- package/lib/wake-store.js.map +1 -0
- package/lib/wake.d.ts +45 -0
- package/lib/wake.d.ts.map +1 -0
- package/lib/wake.js +327 -0
- package/lib/wake.js.map +1 -0
- package/package.json +143 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type GoalStepFeedback } from './feedback.js';
|
|
2
|
+
import type { GoalBudgetRunUsage } from './budget-store.js';
|
|
3
|
+
import type { StrategyRecord } from './strategy-store.js';
|
|
4
|
+
import type { GoalExecutionRun, GoalRecord } from './types.js';
|
|
5
|
+
export interface GoalStrategyAssessment {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly kind: StrategyRecord['intent']['kind'];
|
|
8
|
+
readonly state: StrategyRecord['state'];
|
|
9
|
+
readonly outcome?: StrategyRecord['outcome'];
|
|
10
|
+
readonly terminationReason?: StrategyRecord['terminationReason'];
|
|
11
|
+
readonly durationMs?: number;
|
|
12
|
+
readonly definitionCurrent: boolean;
|
|
13
|
+
readonly parentRunId: string;
|
|
14
|
+
readonly parentSessionId: string;
|
|
15
|
+
/** Correlation to one exact execution, never causal credit or a strategy verdict. */
|
|
16
|
+
readonly attribution: 'same-parent-step-only';
|
|
17
|
+
readonly parentStep: GoalStepFeedback | null;
|
|
18
|
+
readonly nextAction: 'reconcile-execution' | 'inspect-strategy-execution' | 'await-parent-verification' | 'inspect-parent-verification' | 'revise-solution' | 'review-remaining-goal' | 'plan-current-definition';
|
|
19
|
+
readonly children: ReadonlyArray<Readonly<StrategyRecord['children'][number] & {
|
|
20
|
+
usage?: Readonly<GoalBudgetRunUsage>;
|
|
21
|
+
}>>;
|
|
22
|
+
}
|
|
23
|
+
export interface GoalStrategyHistory {
|
|
24
|
+
readonly available: true;
|
|
25
|
+
readonly records: readonly GoalStrategyAssessment[];
|
|
26
|
+
}
|
|
27
|
+
/** Read-only association. It revalidates the exact parent's independent receipt on every read. */
|
|
28
|
+
export declare function buildGoalStrategyHistory(goal: GoalRecord, strategies: readonly StrategyRecord[], runs: readonly GoalExecutionRun[], lookup: ((id: string) => unknown) | undefined, usage: (runId: string) => Readonly<GoalBudgetRunUsage> | undefined, now: number): GoalStrategyHistory;
|
|
29
|
+
//# sourceMappingUR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AC,UAAU,CAAC,CAAC,MAAM,CAAC,GAAG;QAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAA;KAAE,CAAC,CAAC,CAAA;CAC1H;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,sBAAsB,EAAE,CAAA;CACpD;AAMD,kGAAkG;AAClG,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,SAAS,cAAc,EAAE,EACrC,IAAI,EAAE,SAAS,gBAAgB,EAAE,EACjC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,EAC7C,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,CAAC,kBAAkB,CAAC,GAAG,SAAS,EAClE,GAAG,EAAE,MAAM,GACV,mBAAmB,CAyCrB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { acceptanceCanonicalJson } from '@dsh-enhanced/task-acceptance-contract';
|
|
2
|
+
import { buildGoalFeedback } from './feedback.js';
|
|
3
|
+
const same = (left, right) => {
|
|
4
|
+
try {
|
|
5
|
+
return acceptanceCanonicalJson(left) === acceptanceCanonicalJson(right);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
/** Read-only association. It revalidates the exact parent's independent receipt on every read. */
|
|
12
|
+
export function buildGoalStrategyHistory(goal, strategies, runs, lookup, usage, now) {
|
|
13
|
+
const records = strategies.slice(0, 32).filter(value => value.intent.goalId === goal.id && same(value.intent.scope, goal.scope)).slice(0, 3).map(value => {
|
|
14
|
+
const intent = value.intent;
|
|
15
|
+
const matches = runs.slice(0, 50).filter(run => run.intent.runId === intent.parentRunId
|
|
16
|
+
&& run.intent.task.goal.runId === intent.parentRunId && run.intent.task.ref === intent.parentRunId
|
|
17
|
+
&& run.intent.task.goal.sessionId === intent.parentSessionId && intent.parentSessionId === goal.native.sessionId
|
|
18
|
+
&& run.intent.task.goal.nativeGoalId === goal.native.goalId && run.intent.task.goal.id === goal.id
|
|
19
|
+
&& run.intent.task.goal.definitionVersion === intent.definitionVersion && run.intent.task.goal.definitionDigest === intent.definitionDigest
|
|
20
|
+
&& same(run.intent.scope, intent.scope)
|
|
21
|
+
&& run.dispatchedAt !== undefined && run.dispatchedAt <= intent.createdAt
|
|
22
|
+
&& intent.createdAt < run.intent.admission.expiresAt && intent.expiresAt <= run.intent.admission.expiresAt);
|
|
23
|
+
// Duplicate or absent parents are not resolved by picking whichever receipt passed.
|
|
24
|
+
const assessed = matches.length === 1
|
|
25
|
+
? buildGoalFeedback(goal, matches, lookup, now).verification.history[0] ?? null : null;
|
|
26
|
+
const parentStep = assessed === null ? null : Object.freeze({ ...assessed,
|
|
27
|
+
criteria: Object.freeze(assessed.criteria.slice(0, 3)), criteriaTruncated: assessed.criteriaTruncated || assessed.criteria.length > 3,
|
|
28
|
+
});
|
|
29
|
+
const definitionCurrent = intent.definitionVersion === goal.definition.version && intent.definitionDigest === goal.definition.digest;
|
|
30
|
+
const nextAction = value.state === 'unknown' || value.children.some(child => !child.quiescent)
|
|
31
|
+
|| parentStep?.execution?.quiescent === false ? 'reconcile-execution'
|
|
32
|
+
: !definitionCurrent ? 'plan-current-definition'
|
|
33
|
+
: value.outcome === 'execution-failed' || value.outcome === 'cancelled' ? 'inspect-strategy-execution'
|
|
34
|
+
: value.state === 'prepared' || value.state === 'starting' || parentStep?.status === 'pending' ? 'await-parent-verification'
|
|
35
|
+
: parentStep?.status === 'not-achieved' ? 'revise-solution'
|
|
36
|
+
: parentStep?.status === 'achieved' ? 'review-remaining-goal' : 'inspect-parent-verification';
|
|
37
|
+
return Object.freeze({ id: intent.id, kind: intent.kind, state: value.state,
|
|
38
|
+
...(value.outcome === undefined ? {} : { outcome: value.outcome }),
|
|
39
|
+
...(value.terminationReason === undefined ? {} : { terminationReason: value.terminationReason }),
|
|
40
|
+
...(value.completedAt === undefined ? {} : { durationMs: value.completedAt - intent.createdAt }),
|
|
41
|
+
definitionCurrent, parentRunId: intent.parentRunId, parentSessionId: intent.parentSessionId,
|
|
42
|
+
attribution: 'same-parent-step-only', parentStep, nextAction,
|
|
43
|
+
children: Object.freeze(value.children.map(child => {
|
|
44
|
+
const measured = usage(`strategy-${child.sessionId}`);
|
|
45
|
+
const diagnostics = child.diagnostics === undefined ? undefined : Object.freeze({ ...child.diagnostics,
|
|
46
|
+
...(child.diagnostics.failure === undefined ? {} : { failure: Object.freeze({ ...child.diagnostics.failure }) }),
|
|
47
|
+
});
|
|
48
|
+
return Object.freeze({ ...child, ...(diagnostics === undefined ? {} : { diagnostics }), ...(measured === undefined ? {} : { usage: Object.freeze({ ...measured }) }) });
|
|
49
|
+
})), });
|
|
50
|
+
});
|
|
51
|
+
return Object.freeze({ available: true, records: Object.freeze(records) });
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=strategy-feedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-feedback.js","sourceRoot":"","sources":["../src/strategy-feedback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAChF,OAAO,EAAE,iBAAiB,EAAyB,MAAM,eAAe,CAAA;AA4BxE,MAAM,IAAI,GAAG,CAAC,IAAa,EAAE,KAAc,EAAW,EAAE;IACtD,IAAI,CAAC;QAAC,OAAO,uBAAuB,CAAC,IAAI,CAAC,KAAK,uBAAuB,CAAC,KAAK,CAAC,CAAA;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,KAAK,CAAA;IAAC,CAAC;AACxG,CAAC,CAAA;AAED,kGAAkG;AAClG,MAAM,UAAU,wBAAwB,CACtC,IAAgB,EAChB,UAAqC,EACrC,IAAiC,EACjC,MAA6C,EAC7C,KAAkE,EAClE,GA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
|
+
export declare const STRATEGY_PROVIDER = "assistant-goals-strategy/v1";
|
|
3
|
+
/** The native provider appends its hidden descriptor before the first request. */
|
|
4
|
+
export declare function strategyDescriptor(agent: Agent): {
|
|
5
|
+
version: number;
|
|
6
|
+
mode: string;
|
|
7
|
+
provider: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
} | undefined;
|
|
10
|
+
export declare function isStrategyChild(agent: Agent): boolean;
|
|
11
|
+
//# sourceMappingURL=strategy-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-identity.d.ts","sourceRoot":"","sources":["../src/strategy-identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAEnD,eAAO,MAAM,iBAAiB,gCAAgC,CAAA;AAE9D,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAGhI;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const STRATEGY_PROVIDER = 'assistant-goals-strategy/v1';
|
|
2
|
+
/** The native provider appends its hidden descriptor before the first request. */
|
|
3
|
+
export function strategyDescriptor(agent) {
|
|
4
|
+
const event = agent.session.snapshotEvents().find(value => String(value.type) === 'subagent/descriptor');
|
|
5
|
+
return event?.data;
|
|
6
|
+
}
|
|
7
|
+
export function isStrategyChild(agent) {
|
|
8
|
+
return strategyDescriptor(agent)?.provider === STRATEGY_PROVIDER;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=strategy-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-identity.js","sourceRoot":"","sources":["../src/strategy-identity.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,6BAA6B,CAAA;AAE9D,kFAAkF;AAClF,MAAM,UAAU,kBAAkB,CAAC,KAAY;IAC7C,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,qBAAqB,CAAC,CAAA;IACxG,OAAO,KAAK,EAAE,IAAuF,CAAA;AACvG,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAY;IAC1C,OAAO,kBAAkB,CAAC,KAAK,CAAC,EAAE,QAAQ,KAAK,iBAAiB,CAAA;AAClE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { GoalScope } from './types.js';
|
|
2
|
+
export type StrategyScope = GoalScope;
|
|
3
|
+
export type StrategyKind = 'investigate' | 'review' | 'compare';
|
|
4
|
+
export interface StrategyIntent {
|
|
5
|
+
id: string;
|
|
6
|
+
goalId: string;
|
|
7
|
+
parentRunId: string;
|
|
8
|
+
parentSessionId: string;
|
|
9
|
+
definitionVersion: number;
|
|
10
|
+
definitionDigest: string;
|
|
11
|
+
scope: GoalScope;
|
|
12
|
+
kind: StrategyKind;
|
|
13
|
+
requestDigest: string;
|
|
14
|
+
provider: string;
|
|
15
|
+
model: string;
|
|
16
|
+
maxChildren: number;
|
|
17
|
+
maxDurationMs: number;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
expiresAt: number;
|
|
20
|
+
}
|
|
21
|
+
export interface StrategyRecord {
|
|
22
|
+
intent: StrategyIntent;
|
|
23
|
+
state: 'prepared' | 'starting' | 'settled' | 'unknown';
|
|
24
|
+
version: number;
|
|
25
|
+
children: Array<{
|
|
26
|
+
sessionId: string;
|
|
27
|
+
stopReason: string;
|
|
28
|
+
quiescent: boolean;
|
|
29
|
+
diagnostics?: StrategyChildDiagnostics;
|
|
30
|
+
}>;
|
|
31
|
+
completedAt?: number;
|
|
32
|
+
outcome?: 'advice' | 'execution-failed' | 'cancelled' | 'unknown';
|
|
33
|
+
outputDigest?: string;
|
|
34
|
+
terminationReason?: StrategyTerminationReason;
|
|
35
|
+
}
|
|
36
|
+
export interface StrategyChildDiagnostics {
|
|
37
|
+
toolRejections: number;
|
|
38
|
+
output: 'not-observed' | 'accepted' | 'empty-or-oversized';
|
|
39
|
+
failure?: StrategyFailure;
|
|
40
|
+
}
|
|
41
|
+
export interface StrategyFailure {
|
|
42
|
+
stage: 'admission' | 'request-limit' | 'meter' | 'reserve' | 'stream' | 'usage' | 'settlement';
|
|
43
|
+
dispatched: boolean;
|
|
44
|
+
}
|
|
45
|
+
export type StrategyTerminationReason = 'deadline' | 'parent-authority-changed' | 'cancelled' | 'execution-failed' | 'unconfirmed-stop' | 'completed' | 'recovered-unknown' | 'unknown';
|
|
46
|
+
type Settlement = {
|
|
47
|
+
children: Array<{
|
|
48
|
+
sessionId: string;
|
|
49
|
+
stopReason: string;
|
|
50
|
+
quiescent: boolean;
|
|
51
|
+
diagnostics: StrategyChildDiagnostics;
|
|
52
|
+
}>;
|
|
53
|
+
outcome: 'advice' | 'execution-failed' | 'cancelled' | 'unknown';
|
|
54
|
+
outputDigest?: string;
|
|
55
|
+
quiescent: boolean;
|
|
56
|
+
terminationReason: StrategyTerminationReason;
|
|
57
|
+
};
|
|
58
|
+
/** Private durable ledger. A recovered intent is terminally unknown and is never replayed. */
|
|
59
|
+
export declare class GoalStrategyStore {
|
|
60
|
+
#private;
|
|
61
|
+
constructor(path: string);
|
|
62
|
+
prepare(input: StrategyIntent): {
|
|
63
|
+
record: StrategyRecord;
|
|
64
|
+
created: boolean;
|
|
65
|
+
};
|
|
66
|
+
/** Persists the provider-construction attempt before the native driver starts it. */
|
|
67
|
+
dispatch(id: string, expectedVersion: number, now: number): StrategyRecord;
|
|
68
|
+
bindChild(id: string, expectedVersion: number, sessionId: string, now: number): StrategyRecord;
|
|
69
|
+
settle(id: string, expectedVersion: number, input: Settlement, now: number): StrategyRecord;
|
|
70
|
+
inspect(scope: StrategyScope, id: string): StrategyRecord | undefined;
|
|
71
|
+
list(scope: StrategyScope, goalId: string, limit?: number): readonly StrategyRecord[];
|
|
72
|
+
recoverIncomplete(now: number): void;
|
|
73
|
+
close(): void;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=strategy-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-store.d.ts","sourceRoot":"","sources":["../src/strategy-store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAG3C,MAAM,MAAM,aAAa,GAAG,SAAS,CAAA;AACrC,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE/D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;IAC7H,KAAK,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,YAAY,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAC/K;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;IAC/F,QAAQ,EAAE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iB;;gBAEhB,IAAI,EAAE,MAAM;IA0CxB,OAAO,CAAC,KAAK,EAAE,cAAc,GAAG;QAAE,MAAM,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE;IAU5E,qFAAqF;IACrF,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc;IAO1E,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc;IAQ9F,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc;IAc3F,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAKrE,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,SAAS,cAAc,EAAE;IAKjF,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIpC,KAAK,IAAI,IAAI;CACd"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import { acceptanceCanonicalJson, acceptanceDigest } from '@dsh-enhanced/task-acceptance-contract';
|
|
3
|
+
import { GoalStoreError } from './types.js';
|
|
4
|
+
import { prepareGoalStoreDatabaseFile } from './store.js';
|
|
5
|
+
const idPattern = /^[A-Za-z0-9_.:-]{1,512}$/u;
|
|
6
|
+
const digestPattern = /^[a-f0-9]{64}$/u;
|
|
7
|
+
const states = new Set(['prepared', 'starting', 'settled', 'unknown']);
|
|
8
|
+
const outcomes = new Set(['advice', 'execution-failed', 'cancelled', 'unknown']);
|
|
9
|
+
const terminationReasons = new Set(['deadline', 'parent-authority-changed', 'cancelled', 'execution-failed', 'unconfirmed-stop', 'completed', 'recovered-unknown', 'unknown']);
|
|
10
|
+
const failureStages = new Set(['admission', 'request-limit', 'meter', 'reserve', 'stream', 'usage', 'settlement']);
|
|
11
|
+
function fail(code) { throw new GoalStoreError(code); }
|
|
12
|
+
const parse = (value) => { try {
|
|
13
|
+
return JSON.parse(value);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return fail('schema');
|
|
17
|
+
} };
|
|
18
|
+
const same = (left, right) => acceptanceDigest(left) === acceptanceDigest(right);
|
|
19
|
+
const freeze = (value) => { if (value && typeof value === 'object') {
|
|
20
|
+
for (const child of Object.values(value))
|
|
21
|
+
freeze(child);
|
|
22
|
+
Object.freeze(value);
|
|
23
|
+
} ; return value; };
|
|
24
|
+
const clone = (value) => freeze(JSON.parse(JSON.stringify(value)));
|
|
25
|
+
const text = (value, maximum = 512) => typeof value === 'string' && value.length > 0 && value.length <= maximum;
|
|
26
|
+
const time = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
27
|
+
const positive = (value, maximum = Number.MAX_SAFE_INTEGER) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 1 && value <= maximum;
|
|
28
|
+
function scopeInput(value) {
|
|
29
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length !== 5)
|
|
30
|
+
fail('invalid-input');
|
|
31
|
+
const scope = value;
|
|
32
|
+
if (!text(scope.principalId) || !text(scope.principalRecordId) || !positive(scope.principalVersion, 1_000_000_000) || !text(scope.workspace, 4096) || !scope.workspace.startsWith('/') || !text(scope.preset))
|
|
33
|
+
fail('invalid-input');
|
|
34
|
+
return clone({ principalId: scope.principalId, principalRecordId: scope.principalRecordId, principalVersion: scope.principalVersion, workspace: scope.workspace, preset: scope.preset });
|
|
35
|
+
}
|
|
36
|
+
function intentInput(value) {
|
|
37
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length !== 15)
|
|
38
|
+
fail('invalid-input');
|
|
39
|
+
const input = value;
|
|
40
|
+
if (![input.id, input.goalId, input.parentRunId, input.parentSessionId].every(item => typeof item === 'string' && idPattern.test(item))
|
|
41
|
+
|| !positive(input.definitionVersion, 1_000_000_000) || !digestPattern.test(input.definitionDigest) || !digestPattern.test(input.requestDigest)
|
|
42
|
+
|| !['investigate', 'review', 'compare'].includes(input.kind) || !text(input.provider) || !text(input.model)
|
|
43
|
+
|| !positive(input.maxChildren, 2) || !positive(input.maxDurationMs, 300_000) || !time(input.createdAt) || !time(input.expiresAt)
|
|
44
|
+
|| input.expiresAt <= input.createdAt || input.expiresAt - input.createdAt > input.maxDurationMs)
|
|
45
|
+
fail('invalid-input');
|
|
46
|
+
const scope = scopeInput(input.scope);
|
|
47
|
+
return clone({ id: input.id, goalId: input.goalId, parentRunId: input.parentRunId, parentSessionId: input.parentSessionId, definitionVersion: input.definitionVersion, definitionDigest: input.definitionDigest, scope, kind: input.kind, requestDigest: input.requestDigest, provider: input.provider, model: input.model, maxChildren: input.maxChildren, maxDurationMs: input.maxDurationMs, createdAt: input.createdAt, expiresAt: input.expiresAt });
|
|
48
|
+
}
|
|
49
|
+
function diagnosticsInput(value) {
|
|
50
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || ![2, 3].includes(Object.keys(value).length))
|
|
51
|
+
fail('invalid-input');
|
|
52
|
+
const input = value;
|
|
53
|
+
if (!Object.keys(input).every(key => key === 'toolRejections' || key === 'output' || key === 'failure')
|
|
54
|
+
|| !Object.keys(input).includes('toolRejections') || !Object.keys(input).includes('output')
|
|
55
|
+
|| !Number.isSafeInteger(input.toolRejections) || input.toolRejections < 0 || input.toolRejections > 1_000_000
|
|
56
|
+
|| !['not-observed', 'accepted', 'empty-or-oversized'].includes(input.output))
|
|
57
|
+
fail('invalid-input');
|
|
58
|
+
if (input.failure !== undefined && (!input.failure || typeof input.failure !== 'object' || Array.isArray(input.failure)
|
|
59
|
+
|| !same(Object.keys(input.failure).sort(), ['dispatched', 'stage']) || !failureStages.has(input.failure.stage) || typeof input.failure.dispatched !== 'boolean'))
|
|
60
|
+
fail('invalid-input');
|
|
61
|
+
return clone({ toolRejections: input.toolRejections, output: input.output, ...(input.failure === undefined ? {} : { failure: { stage: input.failure.stage, dispatched: input.failure.dispatched } }) });
|
|
62
|
+
}
|
|
63
|
+
function childrenInput(value, maximum) {
|
|
64
|
+
if (!Array.isArray(value) || value.length > maximum)
|
|
65
|
+
fail('invalid-input');
|
|
66
|
+
const children = value.map(child => {
|
|
67
|
+
if (!child || typeof child !== 'object' || Array.isArray(child) || ![3, 4].includes(Object.keys(child).length))
|
|
68
|
+
fail('invalid-input');
|
|
69
|
+
const input = child;
|
|
70
|
+
if (!Object.keys(input).every(key => key === 'sessionId' || key === 'stopReason' || key === 'quiescent' || key === 'diagnostics')
|
|
71
|
+
|| (typeof input.sessionId !== 'string' || !idPattern.test(input.sessionId)) || !text(input.stopReason) || typeof input.quiescent !== 'boolean')
|
|
72
|
+
fail('invalid-input');
|
|
73
|
+
return { sessionId: input.sessionId, stopReason: input.stopReason, quiescent: input.quiescent, ...(input.diagnostics === undefined ? {} : { diagnostics: diagnosticsInput(input.diagnostics) }) };
|
|
74
|
+
});
|
|
75
|
+
if (new Set(children.map(child => child.sessionId)).size !== children.length)
|
|
76
|
+
fail('invalid-input');
|
|
77
|
+
return clone(children);
|
|
78
|
+
}
|
|
79
|
+
function settlementInput(value, maxChildren) {
|
|
80
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || ![4, 5].includes(Object.keys(value).length))
|
|
81
|
+
fail('invalid-input');
|
|
82
|
+
const input = value;
|
|
83
|
+
const keys = Object.keys(input);
|
|
84
|
+
if (!keys.every(key => ['children', 'outcome', 'outputDigest', 'quiescent', 'terminationReason'].includes(key)) || !keys.includes('children') || !keys.includes('outcome') || !keys.includes('quiescent') || !keys.includes('terminationReason') || (keys.length === 5 && !keys.includes('outputDigest'))
|
|
85
|
+
|| !outcomes.has(input.outcome) || !terminationReasons.has(input.terminationReason) || typeof input.quiescent !== 'boolean' || (input.outputDigest !== undefined && !digestPattern.test(input.outputDigest)))
|
|
86
|
+
fail('invalid-input');
|
|
87
|
+
const children = childrenInput(input.children, maxChildren);
|
|
88
|
+
if (children.some(child => child.diagnostics === undefined))
|
|
89
|
+
fail('invalid-input');
|
|
90
|
+
return clone({ children: children, outcome: input.outcome, ...(input.outputDigest === undefined ? {} : { outputDigest: input.outputDigest }), quiescent: input.quiescent, terminationReason: input.terminationReason });
|
|
91
|
+
}
|
|
92
|
+
function record(row) {
|
|
93
|
+
const intent = intentInput(parse(row.intent_json));
|
|
94
|
+
if (!states.has(row.state) || !positive(row.version, 1_000_000_000) || row.scope_key !== acceptanceCanonicalJson(intent.scope) || row.goal_id !== intent.goalId || row.created_at !== intent.createdAt)
|
|
95
|
+
fail('schema');
|
|
96
|
+
const children = childrenInput(parse(row.children_json), intent.maxChildren);
|
|
97
|
+
const completedAt = row.completed_at === null ? undefined : time(row.completed_at) ? row.completed_at : fail('schema');
|
|
98
|
+
const outcome = row.outcome === null ? undefined : outcomes.has(row.outcome) ? row.outcome : fail('schema');
|
|
99
|
+
const outputDigest = row.output_digest === null ? undefined : digestPattern.test(row.output_digest) ? row.output_digest : fail('schema');
|
|
100
|
+
const terminationReason = row.termination_reason === null ? undefined : terminationReasons.has(row.termination_reason) ? row.termination_reason : fail('schema');
|
|
101
|
+
if (row.state === 'prepared' && (children.length !== 0 || completedAt !== undefined || outcome !== undefined || outputDigest !== undefined || terminationReason !== undefined))
|
|
102
|
+
fail('schema');
|
|
103
|
+
if (row.state === 'starting' && (completedAt !== undefined || outcome !== undefined || outputDigest !== undefined || terminationReason !== undefined))
|
|
104
|
+
fail('schema');
|
|
105
|
+
if ((row.state === 'settled' || row.state === 'unknown') && (completedAt === undefined || outcome === undefined || terminationReason === undefined || completedAt < intent.createdAt))
|
|
106
|
+
fail('schema');
|
|
107
|
+
if (row.state === 'unknown' && outcome !== 'unknown')
|
|
108
|
+
fail('schema');
|
|
109
|
+
return freeze({ intent, state: row.state, version: row.version, children, ...(completedAt === undefined ? {} : { completedAt }), ...(outcome === undefined ? {} : { outcome }), ...(outputDigest === undefined ? {} : { outputDigest }), ...(terminationReason === undefined ? {} : { terminationReason }) });
|
|
110
|
+
}
|
|
111
|
+
/** Private durable ledger. A recovered intent is terminally unknown and is never replayed. */
|
|
112
|
+
export class GoalStrategyStore {
|
|
113
|
+
#database;
|
|
114
|
+
constructor(path) {
|
|
115
|
+
if (path !== ':memory:')
|
|
116
|
+
prepareGoalStoreDatabaseFile(path);
|
|
117
|
+
this.#database = new DatabaseSync(path, { enableForeignKeyConstraints: true });
|
|
118
|
+
try {
|
|
119
|
+
this.#database.exec('PRAGMA foreign_keys = ON; PRAGMA busy_timeout = 250; PRAGMA journal_mode = WAL; PRAGMA synchronous = FULL;');
|
|
120
|
+
const version = this.#database.prepare('PRAGMA user_version').get().user_version;
|
|
121
|
+
const tables = this.#database.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name").all().map(row => row.name);
|
|
122
|
+
if (version === 0 && tables.length === 0)
|
|
123
|
+
this.#database.exec(`BEGIN IMMEDIATE;
|
|
124
|
+
CREATE TABLE goal_strategy_records (id TEXT PRIMARY KEY, intent_json TEXT NOT NULL, state TEXT NOT NULL CHECK(state IN ('prepared','starting','settled','unknown')), version INTEGER NOT NULL, children_json TEXT NOT NULL, completed_at INTEGER, outcome TEXT CHECK(outcome IN ('advice','execution-failed','cancelled','unknown')), output_digest TEXT, scope_key TEXT NOT NULL, goal_id TEXT NOT NULL, created_at INTEGER NOT NULL, termination_reason TEXT CHECK(termination_reason IN ('deadline','parent-authority-changed','cancelled','execution-failed','unconfirmed-stop','completed','recovered-unknown','unknown'))) STRICT;
|
|
125
|
+
CREATE INDEX goal_strategy_scope_goal_created ON goal_strategy_records(scope_key, goal_id, created_at DESC, id ASC);
|
|
126
|
+
PRAGMA user_version = 2; COMMIT;`);
|
|
127
|
+
else if (version === 1 && same(tables, ['goal_strategy_records'])) {
|
|
128
|
+
this.#database.exec('BEGIN IMMEDIATE;');
|
|
129
|
+
try {
|
|
130
|
+
this.#validate(true);
|
|
131
|
+
this.#database.exec(`
|
|
132
|
+
ALTER TABLE goal_strategy_records ADD COLUMN termination_reason TEXT CHECK(termination_reason IN ('deadline','parent-authority-changed','cancelled','execution-failed','unconfirmed-stop','completed','recovered-unknown','unknown'));
|
|
133
|
+
UPDATE goal_strategy_records SET termination_reason = CASE WHEN state IN ('settled', 'unknown') THEN 'unknown' ELSE NULL END;
|
|
134
|
+
PRAGMA user_version = 2;`);
|
|
135
|
+
this.#validate();
|
|
136
|
+
this.#database.exec('COMMIT;');
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
try {
|
|
140
|
+
this.#database.exec('ROLLBACK;');
|
|
141
|
+
}
|
|
142
|
+
catch { }
|
|
143
|
+
;
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (version !== 2 || !same(tables, ['goal_strategy_records']))
|
|
148
|
+
fail('schema');
|
|
149
|
+
this.#validate();
|
|
150
|
+
if (path !== ':memory:')
|
|
151
|
+
prepareGoalStoreDatabaseFile(path);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
this.#database.close();
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
#validate(legacy = false) {
|
|
159
|
+
const columns = this.#database.prepare('PRAGMA table_info(goal_strategy_records)').all().map(row => row.name);
|
|
160
|
+
const schema = this.#database.prepare("SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = 'goal_strategy_records'").get();
|
|
161
|
+
if (!schema || !same(columns, ['id', 'intent_json', 'state', 'version', 'children_json', 'completed_at', 'outcome', 'output_digest', 'scope_key', 'goal_id', 'created_at', ...(legacy ? [] : ['termination_reason'])]) || !/\bSTRICT\b/u.test(schema.sql))
|
|
162
|
+
fail('schema');
|
|
163
|
+
const index = this.#database.prepare("SELECT name FROM sqlite_schema WHERE type = 'index' AND name = 'goal_strategy_scope_goal_created'").get();
|
|
164
|
+
if (!index)
|
|
165
|
+
fail('schema');
|
|
166
|
+
const check = this.#database.prepare('PRAGMA quick_check').get();
|
|
167
|
+
if (check.quick_check !== 'ok')
|
|
168
|
+
fail('schema');
|
|
169
|
+
for (const row of this.#database.prepare(`SELECT id, intent_json, state, version, children_json, completed_at, outcome, output_digest, ${legacy ? "CASE WHEN state IN ('settled', 'unknown') THEN 'unknown' ELSE NULL END AS termination_reason" : 'termination_reason'}, scope_key, goal_id, created_at FROM goal_strategy_records`).all()) {
|
|
170
|
+
const value = record(row);
|
|
171
|
+
if (value.intent.id !== row.id)
|
|
172
|
+
fail('schema');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
#get(id) {
|
|
176
|
+
const row = this.#database.prepare('SELECT id, intent_json, state, version, children_json, completed_at, outcome, output_digest, termination_reason, scope_key, goal_id, created_at FROM goal_strategy_records WHERE id = ?').get(id);
|
|
177
|
+
return row === undefined ? undefined : record(row);
|
|
178
|
+
}
|
|
179
|
+
#write(sql, ...values) { try {
|
|
180
|
+
return Number(this.#database.prepare(sql).run(...values).changes);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
fail('conflict');
|
|
184
|
+
} }
|
|
185
|
+
prepare(input) {
|
|
186
|
+
const intent = intentInput(input);
|
|
187
|
+
this.#database.exec('BEGIN IMMEDIATE;');
|
|
188
|
+
try {
|
|
189
|
+
const existing = this.#get(intent.id);
|
|
190
|
+
if (existing) {
|
|
191
|
+
if (!same(existing.intent, intent))
|
|
192
|
+
fail('conflict');
|
|
193
|
+
this.#database.exec('COMMIT;');
|
|
194
|
+
return freeze({ record: existing, created: false });
|
|
195
|
+
}
|
|
196
|
+
this.#write("INSERT INTO goal_strategy_records(id, intent_json, state, version, children_json, scope_key, goal_id, created_at) VALUES (?, ?, 'prepared', 1, '[]', ?, ?, ?)", intent.id, JSON.stringify(intent), acceptanceCanonicalJson(intent.scope), intent.goalId, intent.createdAt);
|
|
197
|
+
const result = this.#get(intent.id);
|
|
198
|
+
this.#database.exec('COMMIT;');
|
|
199
|
+
return freeze({ record: result, created: true });
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
try {
|
|
203
|
+
this.#database.exec('ROLLBACK;');
|
|
204
|
+
}
|
|
205
|
+
catch { }
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** Persists the provider-construction attempt before the native driver starts it. */
|
|
210
|
+
dispatch(id, expectedVersion, now) {
|
|
211
|
+
if (!idPattern.test(id) || !positive(expectedVersion, 1_000_000_000) || !time(now))
|
|
212
|
+
fail('invalid-input');
|
|
213
|
+
const found = this.#get(id);
|
|
214
|
+
if (!found)
|
|
215
|
+
fail('not-found');
|
|
216
|
+
if (found.state !== 'prepared' || found.version !== expectedVersion || now < found.intent.createdAt || now >= found.intent.expiresAt)
|
|
217
|
+
fail('conflict');
|
|
218
|
+
if (this.#write("UPDATE goal_strategy_records SET state = 'starting', version = version + 1 WHERE id = ? AND state = 'prepared' AND version = ?", id, expectedVersion) !== 1)
|
|
219
|
+
fail('conflict');
|
|
220
|
+
return this.#get(id);
|
|
221
|
+
}
|
|
222
|
+
bindChild(id, expectedVersion, sessionId, now) {
|
|
223
|
+
if (!idPattern.test(id) || !positive(expectedVersion, 1_000_000_000) || !idPattern.test(sessionId) || !time(now))
|
|
224
|
+
fail('invalid-input');
|
|
225
|
+
const found = this.#get(id);
|
|
226
|
+
if (!found)
|
|
227
|
+
fail('not-found');
|
|
228
|
+
if (found.state !== 'starting' || found.version !== expectedVersion || now < found.intent.createdAt || now >= found.intent.expiresAt || found.children.length >= found.intent.maxChildren || found.children.some(child => child.sessionId === sessionId))
|
|
229
|
+
fail('conflict');
|
|
230
|
+
const children = [...found.children, { sessionId, stopReason: 'pending', quiescent: false, diagnostics: { toolRejections: 0, output: 'not-observed' } }];
|
|
231
|
+
if (this.#write("UPDATE goal_strategy_records SET children_json = ?, version = version + 1 WHERE id = ? AND state = 'starting' AND version = ?", JSON.stringify(children), id, expectedVersion) !== 1)
|
|
232
|
+
fail('conflict');
|
|
233
|
+
return this.#get(id);
|
|
234
|
+
}
|
|
235
|
+
settle(id, expectedVersion, input, now) {
|
|
236
|
+
if (!idPattern.test(id) || !positive(expectedVersion, 1_000_000_000) || !time(now))
|
|
237
|
+
fail('invalid-input');
|
|
238
|
+
const found = this.#get(id);
|
|
239
|
+
if (!found)
|
|
240
|
+
fail('not-found');
|
|
241
|
+
const value = settlementInput(input, found.intent.maxChildren);
|
|
242
|
+
if (found.state !== 'starting' || found.version !== expectedVersion || now < found.intent.createdAt)
|
|
243
|
+
fail('conflict');
|
|
244
|
+
const bound = new Set(found.children.map(child => child.sessionId));
|
|
245
|
+
const settled = new Set(value.children.map(child => child.sessionId));
|
|
246
|
+
if (bound.size !== settled.size || [...bound].some(sessionId => !settled.has(sessionId)) || (bound.size === 0 && value.outcome === 'advice'))
|
|
247
|
+
fail('conflict');
|
|
248
|
+
const incomplete = value.children.some(child => child.stopReason === 'pending' || !child.quiescent);
|
|
249
|
+
const state = value.quiescent && !incomplete && value.outcome !== 'unknown' ? 'settled' : 'unknown';
|
|
250
|
+
const outcome = state === 'settled' ? value.outcome : 'unknown';
|
|
251
|
+
const outputDigest = state === 'settled' ? value.outputDigest ?? null : null;
|
|
252
|
+
if (this.#write('UPDATE goal_strategy_records SET state = ?, version = version + 1, children_json = ?, completed_at = ?, outcome = ?, output_digest = ?, termination_reason = ? WHERE id = ? AND state = \'starting\' AND version = ?', state, JSON.stringify(value.children), now, outcome, outputDigest, value.terminationReason, id, expectedVersion) !== 1)
|
|
253
|
+
fail('conflict');
|
|
254
|
+
return this.#get(id);
|
|
255
|
+
}
|
|
256
|
+
inspect(scope, id) {
|
|
257
|
+
if (!idPattern.test(id))
|
|
258
|
+
fail('invalid-input');
|
|
259
|
+
const key = acceptanceCanonicalJson(scopeInput(scope));
|
|
260
|
+
const row = this.#database.prepare('SELECT id, intent_json, state, version, children_json, completed_at, outcome, output_digest, termination_reason, scope_key, goal_id, created_at FROM goal_strategy_records WHERE id = ? AND scope_key = ?').get(id, key);
|
|
261
|
+
return row === undefined ? undefined : record(row);
|
|
262
|
+
}
|
|
263
|
+
list(scope, goalId, limit = 20) {
|
|
264
|
+
if (!idPattern.test(goalId) || !positive(limit, 100))
|
|
265
|
+
fail('invalid-input');
|
|
266
|
+
const key = acceptanceCanonicalJson(scopeInput(scope));
|
|
267
|
+
const rows = this.#database.prepare('SELECT id, intent_json, state, version, children_json, completed_at, outcome, output_digest, termination_reason, scope_key, goal_id, created_at FROM goal_strategy_records WHERE scope_key = ? AND goal_id = ? ORDER BY created_at DESC, id ASC LIMIT ?').all(key, goalId, limit);
|
|
268
|
+
return freeze(rows.map(record));
|
|
269
|
+
}
|
|
270
|
+
recoverIncomplete(now) {
|
|
271
|
+
if (!time(now))
|
|
272
|
+
fail('invalid-input');
|
|
273
|
+
this.#write("UPDATE goal_strategy_records SET state = 'unknown', version = version + 1, completed_at = ?, outcome = 'unknown', output_digest = NULL, termination_reason = 'recovered-unknown' WHERE state IN ('prepared', 'starting')", now);
|
|
274
|
+
}
|
|
275
|
+
close() { this.#database.close(); }
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=strategy-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-store.js","sourceRoot":"","sources":["../src/strategy-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AAuBzD,MAAM,SAAS,GAAG,2BAA2B,CAAA;AAC7C,MAAM,aAAa,GAAG,iBAAiB,CAAA;AAC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CAAC;YAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAAC,MAAM,GAAG,GAAG,uBAAuB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;QACnI,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,yPAAyP,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAU,CAAA;QAC/T,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IACjC,CAAC;IACD,iBAAiB,CAAC,GAAW;QAC3B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,IAAI,CAAC,eAAe,CAAC,CAAA;QACrC,IAAI,CAAC,MAAM,CAAC,0NAA0N,EAAE,GAAG,CAAC,CAAA;IAC9O,CAAC;IACD,KAAK,KAAW,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA,CAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
3
|
+
import type { GoalBudgetRuntime } from './budget.js';
|
|
4
|
+
import type { StrategyChildDiagnostics, StrategyKind, StrategyRecord, StrategyTerminationReason } from './strategy-store.js';
|
|
5
|
+
import type { GoalExecutionRun, GoalRecord, GoalScope } from './types.js';
|
|
6
|
+
export interface GoalStrategyConfig {
|
|
7
|
+
maxDurationMs: number;
|
|
8
|
+
maxPromptBytes: number;
|
|
9
|
+
maxOutputBytes: number;
|
|
10
|
+
maxRunsPerGoal: number;
|
|
11
|
+
}
|
|
12
|
+
export interface GoalStrategyInput {
|
|
13
|
+
kind: StrategyKind;
|
|
14
|
+
question: string;
|
|
15
|
+
context?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface GoalStrategyResult {
|
|
18
|
+
strategyId: string;
|
|
19
|
+
outcome: 'advice' | 'execution-failed' | 'cancelled' | 'unknown';
|
|
20
|
+
advice: string[];
|
|
21
|
+
terminationReason: StrategyTerminationReason;
|
|
22
|
+
children: Array<{
|
|
23
|
+
sessionId: string;
|
|
24
|
+
stopReason: string;
|
|
25
|
+
quiescent: boolean;
|
|
26
|
+
diagnostics?: StrategyChildDiagnostics;
|
|
27
|
+
}>;
|
|
28
|
+
unverified: true;
|
|
29
|
+
}
|
|
30
|
+
/** Strict, side-effect-free configuration boundary used by service preauthorization. */
|
|
31
|
+
export declare function validateGoalStrategyConfig(input?: Partial<GoalStrategyConfig>): Readonly<GoalStrategyConfig>;
|
|
32
|
+
/** Detach only finite plain strings; no caller-owned objects reach a strategy child. */
|
|
33
|
+
export declare function validateGoalStrategyInput(input: unknown): Readonly<GoalStrategyInput>;
|
|
34
|
+
type Current = {
|
|
35
|
+
record: GoalRecord;
|
|
36
|
+
run: GoalExecutionRun;
|
|
37
|
+
signal: AbortSignal;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Host-only one-shot strategy runner. Strategy output is deliberately advice
|
|
41
|
+
* only: it never feeds a verifier or changes a goal's native lifecycle.
|
|
42
|
+
*/
|
|
43
|
+
export declare class GoalStrategyRuntime {
|
|
44
|
+
#private;
|
|
45
|
+
private readonly ctx;
|
|
46
|
+
readonly config: Readonly<GoalStrategyConfig>;
|
|
47
|
+
private readonly callbacks;
|
|
48
|
+
constructor(ctx: Context, path: string, config: Readonly<GoalStrategyConfig>, callbacks: {
|
|
49
|
+
current(parent: Agent): Current;
|
|
50
|
+
budget: GoalBudgetRuntime;
|
|
51
|
+
});
|
|
52
|
+
list: (scope: GoalScope, goalId: string) => readonly StrategyRecord[];
|
|
53
|
+
run(parent: Agent, raw: GoalStrategyInput, signal: AbortSignal): Promise<GoalStrategyResult>;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["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