@obversa/runtime 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +192 -0
- package/dist/api.d.ts +72 -0
- package/dist/api.js +9775 -0
- package/dist/api.js.map +1 -0
- package/dist/artifacts/conformance.d.ts +1 -0
- package/dist/artifacts/file-store.d.ts +8 -0
- package/dist/artifacts/store.d.ts +1 -0
- package/dist/callback/approval.d.ts +8 -0
- package/dist/callback/client.d.ts +38 -0
- package/dist/callback/gate.d.ts +1 -0
- package/dist/callback/stored-client.d.ts +5 -0
- package/dist/chunk-3L6YNPN6.js +3 -0
- package/dist/chunk-3L6YNPN6.js.map +1 -0
- package/dist/chunk-5GLEABOU.js +3 -0
- package/dist/chunk-5GLEABOU.js.map +1 -0
- package/dist/chunk-DEW5R23M.js +338 -0
- package/dist/chunk-DEW5R23M.js.map +1 -0
- package/dist/chunk-DV5P4QLI.js +3056 -0
- package/dist/chunk-DV5P4QLI.js.map +1 -0
- package/dist/chunk-NIBHM5I5.js +34 -0
- package/dist/chunk-NIBHM5I5.js.map +1 -0
- package/dist/chunk-RZLMX3IA.js +368 -0
- package/dist/chunk-RZLMX3IA.js.map +1 -0
- package/dist/core/agent-md.d.ts +36 -0
- package/dist/core/agent.d.ts +86 -0
- package/dist/core/approval-job.d.ts +43 -0
- package/dist/core/assert-graph.d.ts +34 -0
- package/dist/core/budget.d.ts +49 -0
- package/dist/core/concurrency.d.ts +2 -0
- package/dist/core/condition.d.ts +209 -0
- package/dist/core/context.d.ts +36 -0
- package/dist/core/cost.d.ts +59 -0
- package/dist/core/dag.d.ts +20 -0
- package/dist/core/decision.d.ts +29 -0
- package/dist/core/describe.d.ts +56 -0
- package/dist/core/engine-meta.d.ts +5 -0
- package/dist/core/env-overlay.d.ts +35 -0
- package/dist/core/errors.d.ts +46 -0
- package/dist/core/feedback.d.ts +68 -0
- package/dist/core/git.d.ts +152 -0
- package/dist/core/guards.d.ts +70 -0
- package/dist/core/isolated.d.ts +40 -0
- package/dist/core/job.d.ts +134 -0
- package/dist/core/limits.d.ts +22 -0
- package/dist/core/loop.d.ts +24 -0
- package/dist/core/merge.d.ts +30 -0
- package/dist/core/pipeline.d.ts +35 -0
- package/dist/core/process.d.ts +11 -0
- package/dist/core/progress.d.ts +82 -0
- package/dist/core/redact.d.ts +1 -0
- package/dist/core/stats.d.ts +63 -0
- package/dist/core/team.d.ts +34 -0
- package/dist/core/text.d.ts +8 -0
- package/dist/core/tournament.d.ts +25 -0
- package/dist/core/types.d.ts +650 -0
- package/dist/engines/command-runner.d.ts +1 -0
- package/dist/engines/conformance.d.ts +1 -0
- package/dist/engines/engine.d.ts +4 -0
- package/dist/engines/failure.d.ts +1 -0
- package/dist/engines/fallback.d.ts +35 -0
- package/dist/engines/message-map.d.ts +1 -0
- package/dist/engines/mock.d.ts +1 -0
- package/dist/engines/preflight.d.ts +36 -0
- package/dist/env/command.d.ts +50 -0
- package/dist/env/command.js +65 -0
- package/dist/env/command.js.map +1 -0
- package/dist/env/environment.d.ts +4 -0
- package/dist/env/mock.d.ts +24 -0
- package/dist/events/conformance.d.ts +1 -0
- package/dist/events/envelope.d.ts +1 -0
- package/dist/events/jsonl-store.d.ts +8 -0
- package/dist/events/store.d.ts +1 -0
- package/dist/graph/commands.d.ts +5 -0
- package/dist/graph/conformance.d.ts +32 -0
- package/dist/graph/kernel.d.ts +5 -0
- package/dist/graph/plan.d.ts +1 -0
- package/dist/graph/type.d.ts +7 -0
- package/dist/graph/value.d.ts +1 -0
- package/dist/graph-types/dag.d.ts +137 -0
- package/dist/graph-types/loop.d.ts +194 -0
- package/dist/graph-types/team.d.ts +68 -0
- package/dist/memory.d.ts +82 -0
- package/dist/memory.js +397 -0
- package/dist/memory.js.map +1 -0
- package/dist/proof/acceptance.d.ts +5 -0
- package/dist/proof/artifact.d.ts +6 -0
- package/dist/proof/cache.d.ts +4 -0
- package/dist/runtime/attempt.d.ts +19 -0
- package/dist/runtime/budget.d.ts +4 -0
- package/dist/runtime/engine-availability.d.ts +18 -0
- package/dist/runtime/graph-executor.d.ts +7 -0
- package/dist/runtime/monitor.d.ts +80 -0
- package/dist/runtime/node-lifecycle.d.ts +84 -0
- package/dist/runtime/paths.d.ts +2 -0
- package/dist/runtime/persist.d.ts +31 -0
- package/dist/runtime/preflight-record.d.ts +149 -0
- package/dist/runtime/process-tree.d.ts +1 -0
- package/dist/runtime/result-contract.d.ts +4 -0
- package/dist/runtime/result-parts.d.ts +1 -0
- package/dist/runtime/run-definition.d.ts +24 -0
- package/dist/runtime/run-event.d.ts +9 -0
- package/dist/runtime/runner.d.ts +139 -0
- package/dist/runtime/supervisor.d.ts +111 -0
- package/dist/runtime/team-rooms.d.ts +13 -0
- package/dist/runtime/workspace-policy.d.ts +25 -0
- package/dist/storage/error.d.ts +1 -0
- package/dist/storage/id.d.ts +1 -0
- package/dist/storage/local.d.ts +12 -0
- package/dist/storage/local.js +1492 -0
- package/dist/storage/local.js.map +1 -0
- package/dist/testing.d.ts +15 -0
- package/dist/testing.js +274 -0
- package/dist/testing.js.map +1 -0
- package/dist/workflow-agent-response.d.ts +3 -0
- package/dist/workflow-support.d.ts +36 -0
- package/dist/workflow-support.js +5 -0
- package/dist/workflow-support.js.map +1 -0
- package/dist/workflow.d.ts +73 -0
- package/dist/workspace/conformance.d.ts +1 -0
- package/dist/workspace/git-provider.d.ts +26 -0
- package/dist/workspace/provider.d.ts +2 -0
- package/package.json +91 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Memory } from '@obversa/api';
|
|
2
|
+
import { type AgentResultPart, type Engine, type EngineSelectionRecord, type EngineTransportFailure, type UsageReceipt } from '../engines/engine.js';
|
|
3
|
+
import { type EngineFailureKind } from '../engines/failure.js';
|
|
4
|
+
import { type JsonObject, type JsonValue } from '../graph/value.js';
|
|
5
|
+
import type { AttemptIdentity } from './attempt.js';
|
|
6
|
+
import type { GraphEngineIdentity } from '../graph/type.js';
|
|
7
|
+
import { type AttemptBudgetPolicy, type TokenBudget } from './budget.js';
|
|
8
|
+
import type { ResultContract } from './result-contract.js';
|
|
9
|
+
import type { ExecutionTarget } from '../graph/plan.js';
|
|
10
|
+
import { type NodeWorkspacePolicy } from './workspace-policy.js';
|
|
11
|
+
import { type ActionDecision } from '@obversa/api';
|
|
12
|
+
export { validateActionDecision, type ActionDecision, type AllowActionDecision, type WaitActionDecision, type DenyActionDecision } from '@obversa/api';
|
|
13
|
+
export interface PreparedEngineLane {
|
|
14
|
+
readonly engine: Engine;
|
|
15
|
+
readonly selection: EngineSelectionRecord;
|
|
16
|
+
readonly hardTokenLimitEnforceable: boolean;
|
|
17
|
+
readonly target?: ExecutionTarget;
|
|
18
|
+
}
|
|
19
|
+
import { type NodeDataContext } from '@obversa/api';
|
|
20
|
+
export { type NodeDataContext } from '@obversa/api';
|
|
21
|
+
export interface ModelUnavailableFact {
|
|
22
|
+
readonly schemaVersion: 1;
|
|
23
|
+
readonly identity: AttemptIdentity;
|
|
24
|
+
readonly selection: EngineSelectionRecord;
|
|
25
|
+
readonly effective: EngineSelectionRecord;
|
|
26
|
+
readonly failure: EngineFailureKind;
|
|
27
|
+
readonly target?: ExecutionTarget;
|
|
28
|
+
}
|
|
29
|
+
export interface PreparedNodeAttempt {
|
|
30
|
+
readonly identity: AttemptIdentity;
|
|
31
|
+
readonly nodeId: string;
|
|
32
|
+
readonly input: JsonValue;
|
|
33
|
+
readonly memory: Memory | null;
|
|
34
|
+
readonly prompt: string | null;
|
|
35
|
+
readonly scratchDirectory: string;
|
|
36
|
+
readonly workspace: NodeWorkspacePolicy;
|
|
37
|
+
readonly trustedCaller: JsonObject;
|
|
38
|
+
readonly permissions: readonly string[];
|
|
39
|
+
readonly policy: AttemptBudgetPolicy;
|
|
40
|
+
readonly resultContract: ResultContract | null;
|
|
41
|
+
readonly engineRoute: readonly [PreparedEngineLane] | readonly [PreparedEngineLane, PreparedEngineLane] | null;
|
|
42
|
+
readonly declaredTargets?: readonly ExecutionTarget[];
|
|
43
|
+
readonly runData: ((context: NodeDataContext) => Promise<JsonValue>) | null;
|
|
44
|
+
readonly parseResult: ((part: AgentResultPart, parts: readonly AgentResultPart[]) => JsonValue) | null;
|
|
45
|
+
readonly tokenBudget: TokenBudget | null;
|
|
46
|
+
readonly recordModelUnavailable: (fact: ModelUnavailableFact) => Promise<void>;
|
|
47
|
+
readonly recordEngineAttempt?: (fact: Readonly<{
|
|
48
|
+
requested: GraphEngineIdentity;
|
|
49
|
+
effective: GraphEngineIdentity | null;
|
|
50
|
+
}>) => Promise<void>;
|
|
51
|
+
decideAction(): Promise<ActionDecision>;
|
|
52
|
+
}
|
|
53
|
+
export type NodeAttemptFailureCode = 'INVALID_ATTEMPT' | 'ABORTED' | 'INPUT_LIMIT' | 'ACTION_POLICY' | 'TOKEN_BUDGET' | 'TIMEOUT' | 'EFFECT_FAILED' | 'ENGINE_UNAVAILABLE' | 'MODEL_UNAVAILABLE_RECORD' | 'ENGINE_IDENTITY_UNRESOLVED' | 'RESULT_INVALID' | 'OUTPUT_LIMIT' | 'WORKSPACE_INSPECTION' | 'WORKSPACE_VIOLATION' | 'WORKSPACE_LIMIT';
|
|
54
|
+
export interface NodeAttemptFailure extends JsonObject {
|
|
55
|
+
readonly code: NodeAttemptFailureCode;
|
|
56
|
+
readonly message: string;
|
|
57
|
+
}
|
|
58
|
+
export interface NodeAttemptRecord {
|
|
59
|
+
readonly schemaVersion: 1;
|
|
60
|
+
readonly identity: AttemptIdentity;
|
|
61
|
+
readonly status: 'completed' | 'failed' | 'paused' | 'denied';
|
|
62
|
+
readonly decision: ActionDecision | null;
|
|
63
|
+
readonly failure: NodeAttemptFailure | null;
|
|
64
|
+
readonly result: JsonValue | null;
|
|
65
|
+
readonly parts: readonly AgentResultPart[];
|
|
66
|
+
readonly usage: UsageReceipt;
|
|
67
|
+
readonly requestedEngine: EngineSelectionRecord | null;
|
|
68
|
+
readonly effectiveEngine: EngineSelectionRecord | null;
|
|
69
|
+
readonly unavailableModels: readonly EngineSelectionRecord[];
|
|
70
|
+
readonly transportFailure: EngineTransportFailure | null;
|
|
71
|
+
readonly inputBytes: number;
|
|
72
|
+
readonly outputBytes: number;
|
|
73
|
+
readonly changedPaths: readonly string[];
|
|
74
|
+
readonly foreignPaths: readonly string[];
|
|
75
|
+
readonly filesChanged: number;
|
|
76
|
+
readonly linesChanged: number;
|
|
77
|
+
readonly entryHead: string | null;
|
|
78
|
+
readonly exitHead: string | null;
|
|
79
|
+
readonly headChanged: boolean;
|
|
80
|
+
readonly trustedCaller: JsonObject;
|
|
81
|
+
readonly permissions: readonly string[];
|
|
82
|
+
}
|
|
83
|
+
export declare function validateScratchDirectory(value: string): Promise<string>;
|
|
84
|
+
export declare function executeNodeAttempt(prepared: PreparedNodeAttempt, signal: AbortSignal): Promise<NodeAttemptRecord>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RecordedEngineUsage } from '../core/job.js';
|
|
2
|
+
import type { LoopEvent, Outcome } from '../core/types.js';
|
|
3
|
+
interface RecorderOptions {
|
|
4
|
+
thin?: boolean;
|
|
5
|
+
/** Append to the existing record instead of truncating it. */
|
|
6
|
+
resume?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type RecordedStage = {
|
|
9
|
+
readonly kind: 'interrupted';
|
|
10
|
+
readonly startLine: number;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'completed';
|
|
13
|
+
readonly outcome: Outcome;
|
|
14
|
+
};
|
|
15
|
+
export interface ResumedStageRecords {
|
|
16
|
+
readonly anchors: ReadonlyMap<string, {
|
|
17
|
+
readonly identity: string;
|
|
18
|
+
readonly workspace: string;
|
|
19
|
+
readonly recordId: string;
|
|
20
|
+
}>;
|
|
21
|
+
readonly stages: ReadonlyMap<string, RecordedStage>;
|
|
22
|
+
}
|
|
23
|
+
/** Read the latest stage state and the engine answers recorded for each stage.
|
|
24
|
+
* A missing record has no stage state, so resume starts fresh. */
|
|
25
|
+
export declare function readResumeRecord(path: string): {
|
|
26
|
+
readonly outcomes: ResumedStageRecords;
|
|
27
|
+
readonly usage: ReadonlyMap<string, readonly RecordedEngineUsage[]>;
|
|
28
|
+
};
|
|
29
|
+
/** Append every durable event as one JSON line. */
|
|
30
|
+
export declare function makeRecorder(path: string, options?: RecorderOptions): (event: LoopEvent) => void;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type ArtifactReference } from '../artifacts/store.js';
|
|
2
|
+
import { type DomainEventEnvelope, type EventStreamRef, type StreamRevision } from '../events/envelope.js';
|
|
3
|
+
import type { AgentResult, EngineFailureKind, EngineIncompleteResultEvidence, EngineSelectionRecord, UsageReceipt } from '../engines/engine.js';
|
|
4
|
+
import type { ExecutionTarget } from '../graph/plan.js';
|
|
5
|
+
import { type StorageErrorCode } from '../storage/error.js';
|
|
6
|
+
import { type EngineExclusionKey } from './engine-availability.js';
|
|
7
|
+
import { type RunStorageBinding } from './run-definition.js';
|
|
8
|
+
import { type PreflightPauseResult } from '@obversa/api';
|
|
9
|
+
export { type PreflightPauseResult, type PreflightFailureResult } from '@obversa/api';
|
|
10
|
+
import type { RunPreflightState } from '@obversa/api';
|
|
11
|
+
export type { RunPreflightState } from '@obversa/api';
|
|
12
|
+
export type ProbeStartPayload = {
|
|
13
|
+
readonly laneId: string;
|
|
14
|
+
readonly target: ExecutionTarget;
|
|
15
|
+
readonly selection: EngineSelectionRecord;
|
|
16
|
+
} & ({
|
|
17
|
+
readonly stage: 'static';
|
|
18
|
+
readonly contextNodeId: string | null;
|
|
19
|
+
readonly expectedSelection: EngineSelectionRecord | null;
|
|
20
|
+
} | {
|
|
21
|
+
readonly stage: 'live';
|
|
22
|
+
});
|
|
23
|
+
export type ProbeEvidence = {
|
|
24
|
+
readonly kind: 'complete';
|
|
25
|
+
readonly result: Omit<AgentResult, 'raw'>;
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'incomplete';
|
|
28
|
+
readonly result: Omit<EngineIncompleteResultEvidence, 'raw'>;
|
|
29
|
+
};
|
|
30
|
+
export interface ProbeEvidenceDocument {
|
|
31
|
+
readonly schemaVersion: 1;
|
|
32
|
+
readonly runId: string;
|
|
33
|
+
readonly probeEventId: string;
|
|
34
|
+
readonly evidence: ProbeEvidence;
|
|
35
|
+
}
|
|
36
|
+
export interface ProbeDiagnosticDocument {
|
|
37
|
+
readonly schemaVersion: 1;
|
|
38
|
+
readonly runId: string;
|
|
39
|
+
readonly probeEventId: string;
|
|
40
|
+
readonly detail: string;
|
|
41
|
+
}
|
|
42
|
+
type EvidenceReference = ArtifactReference<'preflight-evidence'>;
|
|
43
|
+
type DiagnosticReference = ArtifactReference<'preflight-diagnostic'>;
|
|
44
|
+
export type StaticOutcome = {
|
|
45
|
+
readonly kind: 'admitted';
|
|
46
|
+
readonly selection: EngineSelectionRecord;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'unsupported';
|
|
49
|
+
} | {
|
|
50
|
+
readonly kind: 'failed';
|
|
51
|
+
readonly failure: EngineFailureKind;
|
|
52
|
+
readonly effective: EngineSelectionRecord | null;
|
|
53
|
+
readonly diagnostic: DiagnosticReference;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'interrupted';
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: 'recording-failed';
|
|
58
|
+
readonly storageCode: StorageErrorCode;
|
|
59
|
+
};
|
|
60
|
+
export type LiveOutcome = {
|
|
61
|
+
readonly usage: UsageReceipt;
|
|
62
|
+
readonly effective: EngineSelectionRecord | null;
|
|
63
|
+
} & ({
|
|
64
|
+
readonly kind: 'succeeded';
|
|
65
|
+
readonly evidence: EvidenceReference;
|
|
66
|
+
readonly diagnostic: DiagnosticReference;
|
|
67
|
+
} | {
|
|
68
|
+
readonly kind: 'failed';
|
|
69
|
+
readonly failure: EngineFailureKind;
|
|
70
|
+
readonly evidence: EvidenceReference | null;
|
|
71
|
+
readonly diagnostic: DiagnosticReference;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: 'interrupted';
|
|
74
|
+
readonly evidence: null;
|
|
75
|
+
readonly diagnostic: null;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: 'recording-failed';
|
|
78
|
+
readonly storageCode: StorageErrorCode;
|
|
79
|
+
readonly evidence: null;
|
|
80
|
+
readonly diagnostic: null;
|
|
81
|
+
});
|
|
82
|
+
export type ProbeFinishPayload = {
|
|
83
|
+
readonly probeEventId: string;
|
|
84
|
+
} & ({
|
|
85
|
+
readonly stage: 'static';
|
|
86
|
+
readonly outcome: StaticOutcome;
|
|
87
|
+
} | {
|
|
88
|
+
readonly stage: 'live';
|
|
89
|
+
readonly outcome: LiveOutcome;
|
|
90
|
+
});
|
|
91
|
+
type PauseReason = 'engine-failure' | 'interrupted' | 'recording-failure';
|
|
92
|
+
export interface PreflightPausedPayload {
|
|
93
|
+
readonly finishedProbeEventId: string;
|
|
94
|
+
readonly reason: PauseReason;
|
|
95
|
+
}
|
|
96
|
+
export interface PreflightResumedPayload {
|
|
97
|
+
readonly preflightEventId: string;
|
|
98
|
+
}
|
|
99
|
+
export interface PreflightFailedPayload {
|
|
100
|
+
readonly laneId: string;
|
|
101
|
+
readonly code: 'PREFLIGHT_FAILED';
|
|
102
|
+
readonly reason: 'no-admissible-target';
|
|
103
|
+
}
|
|
104
|
+
export interface ProbeModelUnavailableFact {
|
|
105
|
+
readonly schemaVersion: 1;
|
|
106
|
+
readonly source: {
|
|
107
|
+
readonly kind: 'preflight';
|
|
108
|
+
readonly probeEventId: string;
|
|
109
|
+
readonly laneId: string;
|
|
110
|
+
};
|
|
111
|
+
readonly target: ExecutionTarget;
|
|
112
|
+
readonly selection: EngineSelectionRecord;
|
|
113
|
+
readonly effective: EngineSelectionRecord;
|
|
114
|
+
readonly failure: EngineFailureKind;
|
|
115
|
+
}
|
|
116
|
+
export interface RecordedProbeStart {
|
|
117
|
+
readonly envelope: DomainEventEnvelope;
|
|
118
|
+
readonly payload: ProbeStartPayload;
|
|
119
|
+
}
|
|
120
|
+
export interface CompletedProbe {
|
|
121
|
+
readonly start: RecordedProbeStart;
|
|
122
|
+
readonly finish: DomainEventEnvelope;
|
|
123
|
+
readonly payload: ProbeFinishPayload;
|
|
124
|
+
readonly evidence: ProbeEvidence | null;
|
|
125
|
+
}
|
|
126
|
+
export interface ValidatedProbeFailure {
|
|
127
|
+
readonly envelope: DomainEventEnvelope;
|
|
128
|
+
readonly fact: ProbeModelUnavailableFact;
|
|
129
|
+
readonly exclusionKeys: readonly EngineExclusionKey[];
|
|
130
|
+
}
|
|
131
|
+
export interface LoadedRunPreflight {
|
|
132
|
+
readonly stream: EventStreamRef;
|
|
133
|
+
readonly revision: StreamRevision;
|
|
134
|
+
readonly events: readonly DomainEventEnvelope[];
|
|
135
|
+
readonly state: RunPreflightState;
|
|
136
|
+
readonly probes: readonly CompletedProbe[];
|
|
137
|
+
readonly openProbe: RecordedProbeStart | null;
|
|
138
|
+
readonly admissionCompletedAtRevision: StreamRevision | null;
|
|
139
|
+
readonly probeFailures: ReadonlyMap<string, ValidatedProbeFailure>;
|
|
140
|
+
}
|
|
141
|
+
/** Private package surface: the executor replays these captured envelopes. */
|
|
142
|
+
export declare function loadRunPreflight(storage: RunStorageBinding, runId: string): Promise<LoadedRunPreflight>;
|
|
143
|
+
/** Read admission state without calling engines, loading a host, or appending events. */
|
|
144
|
+
export declare function readRunPreflight(storage: RunStorageBinding, runId: string): Promise<RunPreflightState>;
|
|
145
|
+
/**
|
|
146
|
+
* The caller must own this run and verify worker cleanup before calling.
|
|
147
|
+
* Close one uncertain check using one expected-revision append; never retry.
|
|
148
|
+
*/
|
|
149
|
+
export declare function interruptRunPreflight(storage: RunStorageBinding, runId: string): Promise<PreflightPauseResult | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { capturePipeOwnerProbe, inspectAttemptMarkedProcesses, inspectOwnedProcessTree, inspectPipeHoldingProcesses, measureOwnedProcessMemory, parseWindowsProcessRows, readAttemptMarkerProcessIds, stopOwnedProcessTree, type OwnedProcessTreeRequest, type PipeOwnerProbe, type ProcessIdentity, type StopOwnedProcessTreeRequest, } from '@obversa/core/command';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type JsonValue } from '../graph/value.js';
|
|
2
|
+
import type { ResultContract, ResultContractDefinition } from '@obversa/api';
|
|
3
|
+
export { type ResultContractRecord, type ResultContract, type ResultContractDefinition } from '@obversa/api';
|
|
4
|
+
export declare function defineResultContract<Schema extends JsonValue, Result extends JsonValue>(definition: ResultContractDefinition<Schema, Result>): ResultContract<Schema, Result>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { assistantResult, engineSelection, finalResultPart, finalResultText, reportedUsage, requireFinalResultText, validateAgentResult, validateIncompleteResultEvidence, } from '@obversa/api';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CompiledGraphDefinition, type RunStorageBinding, type RunStartRecord } from '@obversa/api';
|
|
2
|
+
import { type JsonObject, type RunBrief } from '../graph/value.js';
|
|
3
|
+
import { type ResolvedPlanSnapshot } from '../graph/plan.js';
|
|
4
|
+
export { validateRunDefinition, validateRunStartRecord, validateRunStoragePolicy, validateRunStorageRecord, type StorageProviderRecord, type SensitiveContentPolicy, type RunStoragePolicy, type RunStorageRecord, type RunDefinition, type RunStartedPayload, type NewRunStartedEvent, type RunStartRecord, type RunStorageBinding, } from '@obversa/api';
|
|
5
|
+
export interface PersistRunDefinitionInput {
|
|
6
|
+
readonly runId: string;
|
|
7
|
+
readonly eventId: string;
|
|
8
|
+
readonly timestamp: string;
|
|
9
|
+
readonly graphDefinition: CompiledGraphDefinition;
|
|
10
|
+
readonly resolvedPlan: ResolvedPlanSnapshot;
|
|
11
|
+
readonly resolvedInputs: RunBrief;
|
|
12
|
+
readonly workspaceBinding: JsonObject | null;
|
|
13
|
+
readonly hostBinding: {
|
|
14
|
+
readonly bytes: Uint8Array;
|
|
15
|
+
readonly mediaType: string;
|
|
16
|
+
} | null;
|
|
17
|
+
}
|
|
18
|
+
export interface LoadedRunDefinition {
|
|
19
|
+
readonly record: RunStartRecord;
|
|
20
|
+
readonly resolvedPlan: ResolvedPlanSnapshot;
|
|
21
|
+
readonly hostBindingBytes: Uint8Array | null;
|
|
22
|
+
}
|
|
23
|
+
export declare function persistRunDefinition(binding: RunStorageBinding, input: PersistRunDefinitionInput): Promise<RunStartRecord>;
|
|
24
|
+
export declare function loadRunDefinition(binding: RunStorageBinding, runId: string): Promise<LoadedRunDefinition>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DomainEventEnvelope, type EventStreamRef, type NewDomainEvent } from '../events/envelope.js';
|
|
2
|
+
import { type RunStorageBinding } from './run-definition.js';
|
|
3
|
+
export interface LoadedRunEvents {
|
|
4
|
+
readonly stream: EventStreamRef;
|
|
5
|
+
readonly events: readonly DomainEventEnvelope[];
|
|
6
|
+
}
|
|
7
|
+
export type RunEventAppendCheck = (events: readonly DomainEventEnvelope[]) => 'append' | 'already-stored';
|
|
8
|
+
export declare function readRunEvents(storage: RunStorageBinding, runId: string): Promise<LoadedRunEvents>;
|
|
9
|
+
export declare function appendRunEvent(storage: RunStorageBinding, runId: string, event: NewDomainEvent, check?: RunEventAppendCheck): Promise<void>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runner assembles a `JobContext` and executes a root `Job` (a loop, a dag,
|
|
3
|
+
* or any job). It owns the engine resolver, the abort controller, the shared
|
|
4
|
+
* state, and the stats collector. Hosts observe via `onEvent`.
|
|
5
|
+
*/
|
|
6
|
+
import type { Engine, EngineRef } from '../engines/engine.js';
|
|
7
|
+
import { type StatsSnapshot } from '../core/stats.js';
|
|
8
|
+
import { type CostReport, type PriceTable } from '../core/cost.js';
|
|
9
|
+
import { type BudgetConfig } from '../core/budget.js';
|
|
10
|
+
/** Run-owned keys holding the workflow state read from its record. */
|
|
11
|
+
export declare const RESUME_STAGE_OUTCOMES = "obversa:resumed-stage-outcomes";
|
|
12
|
+
export declare const RESUME_RECORDED_USAGE = "obversa:resumed-recorded-usage";
|
|
13
|
+
import type { Environment } from '../env/environment.js';
|
|
14
|
+
import type { Memory } from '@obversa/api';
|
|
15
|
+
import { type RunMonitor } from './monitor.js';
|
|
16
|
+
import { type RunBrief } from '../graph/value.js';
|
|
17
|
+
import type { Job, LimitPolicy, LoopEvent, Outcome, UsageTotals, RunCallbacks } from '../core/types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Exit code for a `paused` run: EX_TEMPFAIL (sysexits.h). Distinct from `fail`
|
|
20
|
+
* (1) so a wrapper can tell "paused" from "failed".
|
|
21
|
+
*/
|
|
22
|
+
export declare const EXIT_PAUSED = 75;
|
|
23
|
+
export interface RunOptions {
|
|
24
|
+
/** Default engine selected when a job or condition names none. */
|
|
25
|
+
readonly engine?: EngineRef;
|
|
26
|
+
/** Ready-made engines available to jobs and conditions by name. */
|
|
27
|
+
readonly engines?: Readonly<Record<string, Engine>>;
|
|
28
|
+
/** External abort signal. */
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
/** Root working directory the run operates in. Default: process.cwd(). */
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Bring an environment up for the run (the root workspace) before the job and
|
|
34
|
+
* tear it down after, so the gate can test the running thing. You supply the
|
|
35
|
+
* adapter; the runtime owns only the interface. Per-team environments at the
|
|
36
|
+
* worktree boundary are a separate, later binding.
|
|
37
|
+
*/
|
|
38
|
+
environment?: Environment;
|
|
39
|
+
onEvent?: (event: LoopEvent) => void;
|
|
40
|
+
/** Immutable run brief shared by every job. */
|
|
41
|
+
params?: RunBrief;
|
|
42
|
+
/** Seed the shared, mutable run state. */
|
|
43
|
+
state?: Record<string, unknown>;
|
|
44
|
+
/** Memory instance available to every job in the run. */
|
|
45
|
+
memory?: Memory;
|
|
46
|
+
/**
|
|
47
|
+
* The client the run's questions go through (`approval`). Default: a fresh
|
|
48
|
+
* in-memory client for this run, so a run without one forgets its questions
|
|
49
|
+
* when it ends. Pass a client to keep them: the in-memory one across runs
|
|
50
|
+
* in a process, the stored client (`createStoredCallbackClient`) across a
|
|
51
|
+
* process exit.
|
|
52
|
+
*/
|
|
53
|
+
callbacks?: RunCallbacks;
|
|
54
|
+
/** Wait for an outside answer, or return paused (the default). */
|
|
55
|
+
onCallback?: 'wait' | 'exit';
|
|
56
|
+
/**
|
|
57
|
+
* Serve the run's own page on a free loopback port: the declared graph with
|
|
58
|
+
* each step's live state, the returns, the pending questions, the record
|
|
59
|
+
* tail. Off by default; on under `supervise` unless set to false. The
|
|
60
|
+
* address is one `monitor` event and one line in the record, never stdout.
|
|
61
|
+
*/
|
|
62
|
+
monitor?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Cap total tokens (input + output) for the run. A bare number is the limit;
|
|
65
|
+
* pass `{ limit, headroom?, soft? }` for headroom or warn-don't-refuse mode.
|
|
66
|
+
* Engine call sites refuse to spend past it (see `Budget`).
|
|
67
|
+
*/
|
|
68
|
+
budget?: number | BudgetConfig;
|
|
69
|
+
/** Append every structured event as JSONL here, or auto-name one under `.obversa/records`. */
|
|
70
|
+
recordTo?: string | 'auto';
|
|
71
|
+
/**
|
|
72
|
+
* Resume from the record at `recordTo` instead of truncating it: stages
|
|
73
|
+
* whose completion is already recorded are skipped, interrupted stages
|
|
74
|
+
* re-run. Requires an explicit `recordTo` path; a missing record is a
|
|
75
|
+
* fresh run, not an error. Two processes resuming one record at once is
|
|
76
|
+
* out of scope.
|
|
77
|
+
*/
|
|
78
|
+
resume?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Register this run in the global registry (`~/.obversa/runs/<runId>`) and write
|
|
81
|
+
* its live state there, so another process can inspect it. Off by default;
|
|
82
|
+
* opt in to make a run observable from outside.
|
|
83
|
+
*/
|
|
84
|
+
supervise?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Assign the registry id instead of generating one, so an outside controller
|
|
87
|
+
* knows the id before the run registers.
|
|
88
|
+
* Must match the registry alphabet (`[a-z0-9][a-z0-9-]*`); only meaningful
|
|
89
|
+
* with `supervise` or `recordTo: 'auto'`.
|
|
90
|
+
*/
|
|
91
|
+
runId?: string;
|
|
92
|
+
/**
|
|
93
|
+
* How a loop reacts to a rate limit / quota / token budget. Default `auto`:
|
|
94
|
+
* wait out a known reset within `maxWaitMs`, else pause (exit code 75).
|
|
95
|
+
* `wait` waits any known reset with no ceiling; `exit` never waits; `fail` is
|
|
96
|
+
* fatal
|
|
97
|
+
* behaviour.
|
|
98
|
+
*/
|
|
99
|
+
onLimit?: LimitPolicy;
|
|
100
|
+
/** Ceiling on a single interruptible limit-wait, in ms. Default 300000. */
|
|
101
|
+
maxWaitMs?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Price the run's measured token usage (`RunResult.cost`). Prices are
|
|
104
|
+
* caller-supplied — the library hardcodes none. `baselineModel` adds the
|
|
105
|
+
* reconstructed counterfactual: the same token stream at that model's rates.
|
|
106
|
+
*/
|
|
107
|
+
cost?: {
|
|
108
|
+
prices: PriceTable;
|
|
109
|
+
baselineModel?: string;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export interface RunResult {
|
|
113
|
+
outcome: Outcome;
|
|
114
|
+
stats: StatsSnapshot;
|
|
115
|
+
/**
|
|
116
|
+
* What the whole run spent, in the shape `formatEvent` takes, so the totals
|
|
117
|
+
* a run reports can be handed straight back to the line formatter. The same
|
|
118
|
+
* numbers are in `stats`; this is the summary a person reads rather than the
|
|
119
|
+
* per-model record.
|
|
120
|
+
*/
|
|
121
|
+
usage: UsageTotals;
|
|
122
|
+
/** Final token accounting, when a budget was set. */
|
|
123
|
+
budget?: {
|
|
124
|
+
limit: number;
|
|
125
|
+
spent: number;
|
|
126
|
+
remaining: number;
|
|
127
|
+
};
|
|
128
|
+
/** The registry id, when the run was supervised. */
|
|
129
|
+
runId?: string;
|
|
130
|
+
/** The run's page, when `monitor` was on: its address, and a way to close it. */
|
|
131
|
+
monitor?: RunMonitor;
|
|
132
|
+
/** The JSONL event record path, when recording was enabled. */
|
|
133
|
+
recordPath?: string;
|
|
134
|
+
/** The priced receipt, when `RunOptions.cost` was set. */
|
|
135
|
+
cost?: CostReport;
|
|
136
|
+
}
|
|
137
|
+
export declare function run(job: Job, options?: RunOptions): Promise<RunResult>;
|
|
138
|
+
/** Process exit code mapped from a terminal outcome. */
|
|
139
|
+
export declare function exitCodeFor(outcome: Outcome): number;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/** Filesystem-backed status for a run that another process can inspect. */
|
|
2
|
+
import type { JobMeta, LoopEvent, Outcome, ProofRecord, UsageTotals } from '../core/types.js';
|
|
3
|
+
export declare function runsHome(): string;
|
|
4
|
+
export declare function newRunId(title: string): string;
|
|
5
|
+
export interface CurrentWork {
|
|
6
|
+
kind: 'job' | 'dag-node';
|
|
7
|
+
path: string[];
|
|
8
|
+
label?: string;
|
|
9
|
+
node?: string;
|
|
10
|
+
startedAt: number;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
deadlineAt?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface RunLive {
|
|
15
|
+
path: string[];
|
|
16
|
+
iteration: number;
|
|
17
|
+
current?: CurrentWork;
|
|
18
|
+
active?: Record<string, CurrentWork>;
|
|
19
|
+
lastGate?: {
|
|
20
|
+
which: string;
|
|
21
|
+
met: boolean;
|
|
22
|
+
confidence?: number;
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
25
|
+
lastOutcome?: {
|
|
26
|
+
status: string;
|
|
27
|
+
summary?: string;
|
|
28
|
+
late?: boolean;
|
|
29
|
+
};
|
|
30
|
+
usage: {
|
|
31
|
+
inputTokens: number;
|
|
32
|
+
outputTokens: number;
|
|
33
|
+
/** What this run has been served from cache, the figure the line reports. */
|
|
34
|
+
cacheReadInputTokens: number;
|
|
35
|
+
/** What it paid to build that cache, kept separate on purpose. */
|
|
36
|
+
cacheCreationInputTokens: number;
|
|
37
|
+
calls: number;
|
|
38
|
+
unmeasuredCalls: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface RunStatus {
|
|
42
|
+
runId: string;
|
|
43
|
+
pid: number;
|
|
44
|
+
cwd: string;
|
|
45
|
+
title: string;
|
|
46
|
+
startedAt: number;
|
|
47
|
+
updatedAt: number;
|
|
48
|
+
endedAt?: number;
|
|
49
|
+
status: 'running' | Outcome['status'];
|
|
50
|
+
alive?: boolean;
|
|
51
|
+
shape?: JobMeta;
|
|
52
|
+
live: RunLive;
|
|
53
|
+
evidence?: {
|
|
54
|
+
count: number;
|
|
55
|
+
indexPath: string;
|
|
56
|
+
latest?: ProofRecord;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface Supervisor {
|
|
60
|
+
runId: string;
|
|
61
|
+
dir: string;
|
|
62
|
+
sink: (event: LoopEvent) => void;
|
|
63
|
+
finish: (outcome: Outcome) => void;
|
|
64
|
+
}
|
|
65
|
+
export declare function startSupervisor(input: {
|
|
66
|
+
runId: string;
|
|
67
|
+
cwd: string;
|
|
68
|
+
title: string;
|
|
69
|
+
shape?: JobMeta;
|
|
70
|
+
}): Supervisor;
|
|
71
|
+
export declare function isAlive(pid: number): boolean;
|
|
72
|
+
export declare function readRunStatus(runId: string): RunStatus | undefined;
|
|
73
|
+
export declare function listRuns(): RunStatus[];
|
|
74
|
+
export declare function runEventsPath(runId: string): string;
|
|
75
|
+
export declare function runEvidenceIndexPath(runId: string): string;
|
|
76
|
+
export interface RunProgress {
|
|
77
|
+
runId: string;
|
|
78
|
+
status: RunStatus['status'];
|
|
79
|
+
alive?: boolean;
|
|
80
|
+
title: string;
|
|
81
|
+
stage: string;
|
|
82
|
+
iteration: number;
|
|
83
|
+
lastGate?: RunLive['lastGate'];
|
|
84
|
+
lastOutcome?: RunLive['lastOutcome'];
|
|
85
|
+
usage: RunLive['usage'];
|
|
86
|
+
current?: RunLive['current'] & {
|
|
87
|
+
elapsedMs: number;
|
|
88
|
+
remainingMs?: number;
|
|
89
|
+
};
|
|
90
|
+
evidence?: RunStatus['evidence'];
|
|
91
|
+
startedAt: number;
|
|
92
|
+
updatedAt: number;
|
|
93
|
+
blocker?: {
|
|
94
|
+
kind: 'gate-failing' | 'limit-pause' | 'error';
|
|
95
|
+
detail: string;
|
|
96
|
+
};
|
|
97
|
+
recent: string[];
|
|
98
|
+
}
|
|
99
|
+
export declare function readRunProgress(runId: string, options?: {
|
|
100
|
+
recent?: number;
|
|
101
|
+
}): RunProgress | undefined;
|
|
102
|
+
export declare function runningTotal(totals: UsageTotals): string;
|
|
103
|
+
export declare function toLine(value: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* Format one event with optional totals the caller already holds.
|
|
106
|
+
*
|
|
107
|
+
* `StatsSnapshot` accumulates the totals and the monitor's live status tracks
|
|
108
|
+
* them, so nothing here remembers anything: the function stays one event in,
|
|
109
|
+
* one string out. Omitting the totals prints exactly what it printed before.
|
|
110
|
+
*/
|
|
111
|
+
export declare function formatEvent(event: LoopEvent, totals?: UsageTotals): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RunStorageBinding } from './run-definition.js';
|
|
2
|
+
import type { StreamRevision } from '../events/envelope.js';
|
|
3
|
+
export declare function projectTeamRooms(input: {
|
|
4
|
+
readonly storage: RunStorageBinding;
|
|
5
|
+
readonly runId: string;
|
|
6
|
+
readonly directory: string;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
readonly revision: StreamRevision;
|
|
9
|
+
readonly files: readonly {
|
|
10
|
+
readonly roomId: string;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
}[];
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type GitWorkspaceSnapshot } from '../core/git.js';
|
|
2
|
+
import { type JsonObject } from '../graph/value.js';
|
|
3
|
+
import type { NodeWorkspacePolicy } from '@obversa/api';
|
|
4
|
+
export { type WorkspaceMode, type NodeWorkspacePolicy } from '@obversa/api';
|
|
5
|
+
export interface WorkspaceEntry {
|
|
6
|
+
readonly policy: NodeWorkspacePolicy;
|
|
7
|
+
readonly snapshot: GitWorkspaceSnapshot | null;
|
|
8
|
+
}
|
|
9
|
+
export interface WorkspaceAttemptEvidence extends JsonObject {
|
|
10
|
+
readonly entryHead: string | null;
|
|
11
|
+
readonly exitHead: string | null;
|
|
12
|
+
readonly headChanged: boolean;
|
|
13
|
+
readonly changedPaths: readonly string[];
|
|
14
|
+
readonly foreignPaths: readonly string[];
|
|
15
|
+
readonly filesChanged: number;
|
|
16
|
+
readonly linesChanged: number;
|
|
17
|
+
}
|
|
18
|
+
export type WorkspacePolicyErrorCode = 'INVALID_WORKSPACE_POLICY' | 'NOT_GIT_REPOSITORY' | 'GIT_INSPECTION_FAILED' | 'ABORTED';
|
|
19
|
+
export declare class WorkspacePolicyError extends Error {
|
|
20
|
+
readonly code: WorkspacePolicyErrorCode;
|
|
21
|
+
constructor(code: WorkspacePolicyErrorCode, message: string);
|
|
22
|
+
}
|
|
23
|
+
export declare function validateWorkspacePolicy(value: NodeWorkspacePolicy): NodeWorkspacePolicy;
|
|
24
|
+
export declare function captureWorkspaceEntry(value: NodeWorkspacePolicy, signal: AbortSignal): Promise<WorkspaceEntry>;
|
|
25
|
+
export declare function inspectWorkspaceExit(value: NodeWorkspacePolicy, entry: WorkspaceEntry, signal: AbortSignal): Promise<WorkspaceAttemptEvidence>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StorageError, type StorageErrorCode } from '@obversa/api';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { validateStorageId } from '@obversa/api';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createLocalArtifactStore, type LocalArtifactStoreOptions } from '../artifacts/file-store.js';
|
|
2
|
+
import { createLocalEventStore, type LocalEventStoreOptions } from '../events/jsonl-store.js';
|
|
3
|
+
import { type RunStorageBinding, type RunStoragePolicy } from '../runtime/run-definition.js';
|
|
4
|
+
export interface LocalRunStorageOptions {
|
|
5
|
+
readonly directory: string;
|
|
6
|
+
readonly namespace: string;
|
|
7
|
+
readonly policy: RunStoragePolicy;
|
|
8
|
+
readonly knownSecrets?: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function createLocalRunStorage(options: LocalRunStorageOptions): RunStorageBinding;
|
|
11
|
+
export { createLocalArtifactStore, createLocalEventStore, };
|
|
12
|
+
export type { LocalArtifactStoreOptions, LocalEventStoreOptions, };
|