@claudexor/cli 3.9.8 → 3.10.1

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.
@@ -0,0 +1,240 @@
1
+ import { mkdirSync } from "node:fs";
2
+ import { normalizeRunStartRequest } from "@claudexor/control-api";
3
+ import { loadConfig } from "@claudexor/config";
4
+ import { noProjectRepoRoot } from "@claudexor/util";
5
+ import { restoreRecordedRunReviewRequest } from "@claudexor/schema";
6
+ import { assertPlanImplementReady } from "./plan-implement-readiness.js";
7
+ import { buildRunOrchestrator } from "./run-orchestrator.js";
8
+ import { delegationBeltForRun } from "./delegation-belt-descriptor.js";
9
+ import { accountsMigrationGate } from "./accounts-unified-migration.js";
10
+ import { preflightRunGitRequirement } from "./request-preflight.js";
11
+ import { resolveThreadExecutionWorkspace, threadRunStartRequiresGit, } from "./thread-execution-workspace.js";
12
+ import { threadRunResumeInputs, threadContinuityContext } from "./thread-continuity-context.js";
13
+ /** Agent commands alone own projects, tool execution, and conversation continuity.
14
+ * Model commands are dispatched before entering this run-normalization boundary. */
15
+ export function createDaemonAgentRunner(deps) {
16
+ const { delegationBudgetAuthority, quotaStore, threads, interactions, resources, bus } = deps;
17
+ const NO_PROJECT_ROOT = noProjectRepoRoot();
18
+ return async (params, ctx) => {
19
+ const p = restoreRecordedRunReviewRequest(normalizeRunStartRequest(params));
20
+ const mode = p.mode;
21
+ const noProjectAsk = mode === "ask" && p.scope.kind === "none";
22
+ const repoRoot = p.scope.kind === "project" ? p.scope.root : NO_PROJECT_ROOT;
23
+ const runConfig = loadConfig(repoRoot);
24
+ if (noProjectAsk)
25
+ mkdirSync(NO_PROJECT_ROOT, { recursive: true, mode: 0o700 });
26
+ const orchestrator = buildRunOrchestrator({
27
+ p,
28
+ delegationBudgetAuthority,
29
+ quotaStore: () => quotaStore(),
30
+ // Typed per-harness refusal while a unified-accounts migration is
31
+ // incomplete (a crash between phases) — other harnesses keep working.
32
+ accountsMigrationGate,
33
+ });
34
+ const { threadId, turnId } = threads.assertKnownIds(p.threadId, p.turnId);
35
+ // Plan readiness gate (QA-045 / D17): refuse an Implement whose frozen
36
+ // plan still has open questions BEFORE any worktree, spawn, or spend —
37
+ // so the refusal is a durable, replayable refused turn (the daemon
38
+ // records enqueue_error=plan_not_ready on the turn; retry replays
39
+ // through this fresh preflight). Skipped when the operator explicitly
40
+ // overrode readiness (recorded on the turn at create time). The gate
41
+ // lives at run-start, not in the control API, so retry re-runs it.
42
+ if (p.planRef && typeof p.planRef === "object") {
43
+ const overridden = turnId != null && threads.getTurn(turnId)?.plan_readiness_overridden === true;
44
+ if (!overridden) {
45
+ const planRef = p.planRef;
46
+ assertPlanImplementReady(planRef.runId, planRef.path);
47
+ }
48
+ }
49
+ // Thread turns own a durable job before this fresh Git check. A
50
+ // missing/stub installation therefore records a replayable refusal on
51
+ // the exact turn, and Retry re-runs this boundary without changing any
52
+ // request fields. No worktree or provider exists yet.
53
+ if (turnId) {
54
+ await preflightRunGitRequirement(p, {
55
+ requiresGit: (request) => threadRunStartRequiresGit(request, threadId ? threads.getThread(threadId) : undefined, runConfig.project.constraints.protected_paths, runConfig.trust.access_default),
56
+ });
57
+ }
58
+ const { executionRoot: threadExecutionRoot, inPlace, projectGitInitialization, } = await resolveThreadExecutionWorkspace({
59
+ threadId,
60
+ repoRoot,
61
+ mode,
62
+ access: p.access,
63
+ accessDefault: runConfig.trust.access_default,
64
+ requestedInPlace: p.execution.isolation === "live",
65
+ protectedPaths: runConfig.project.constraints.protected_paths,
66
+ threads,
67
+ });
68
+ const executionRoot = p.execution.workspaceRoot ?? threadExecutionRoot;
69
+ const onRunStart = (info) => {
70
+ ctx.onRunStart?.(info);
71
+ if (!threadId)
72
+ return;
73
+ try {
74
+ if (turnId) {
75
+ threads.bindTurnRun(turnId, info.runId);
76
+ }
77
+ else {
78
+ const turn = threads.createTurn(threadId, String(p.prompt ?? ""), {
79
+ parentRunId: typeof p.parentRunId === "string" ? p.parentRunId : null,
80
+ });
81
+ threads.bindTurnRun(turn.id, info.runId);
82
+ }
83
+ }
84
+ catch {
85
+ /* turn binding must never fail the run */
86
+ }
87
+ };
88
+ // maxSeconds: a hard wall-clock deadline for the WHOLE run (run-scoped,
89
+ // never per-attempt). Combine the daemon's per-run cancel signal with a
90
+ // deadline that aborts with a typed STRING reason so the terminal is
91
+ // `cancelled` + wall_clock_exceeded rather than a bare user cancel.
92
+ const maxSeconds = typeof p.maxSeconds === "number" && p.maxSeconds > 0
93
+ ? // setTimeout 32-bit-ms overflow defense (schema caps at 7 days).
94
+ Math.min(p.maxSeconds, 604_800)
95
+ : null;
96
+ // INV-135 precedence: explicit per-turn profile > thread sticky >
97
+ // unpinned; an explicit NULL forces unpinned (release wave round-11).
98
+ const requestedProfileId = p.credentialProfileId === null
99
+ ? null
100
+ : typeof p.credentialProfileId === "string" && p.credentialProfileId
101
+ ? p.credentialProfileId
102
+ : threadId
103
+ ? (threads.getThread(threadId)?.credential_profile_id ?? null)
104
+ : null;
105
+ const continuityContext = threadContinuityContext({
106
+ threads,
107
+ threadId,
108
+ turnId,
109
+ profileId: requestedProfileId,
110
+ });
111
+ let deadlineTimer;
112
+ let runSignal = ctx.signal;
113
+ if (maxSeconds !== null) {
114
+ const deadline = new AbortController();
115
+ deadlineTimer = setTimeout(() => deadline.abort("wall_clock_exceeded"), maxSeconds * 1000);
116
+ deadlineTimer.unref?.();
117
+ runSignal = ctx.signal ? AbortSignal.any([ctx.signal, deadline.signal]) : deadline.signal;
118
+ }
119
+ const delegationBelt = delegationBeltForRun(p.delegate === true, p.paidBudget);
120
+ return orchestrator
121
+ .run({
122
+ onEventPersist: (event) => {
123
+ // The owning journal partition is the durable terminal
124
+ // authority. EventLog runs this before committing RunFacts.
125
+ threads.recordRunEvent(p, event);
126
+ },
127
+ onEvent: (event) => {
128
+ if (event.type === "harness.event") {
129
+ const payload = event.payload;
130
+ const harnessId = typeof payload["harness_id"] === "string" ? payload["harness_id"] : "";
131
+ if (harnessId)
132
+ quotaStore().ingest(harnessId, payload);
133
+ }
134
+ // Live listeners observe only after journal + RunFacts commit;
135
+ // durable replay stays authoritative if publish throws.
136
+ try {
137
+ bus.publish(event);
138
+ }
139
+ catch { }
140
+ },
141
+ onInteraction: (ctx2) => interactions.register(ctx2, p),
142
+ interactionTimeoutMs: runConfig.global.interaction_timeout_ms,
143
+ threadId,
144
+ executionRoot,
145
+ retryOf: p.retryOf ?? null,
146
+ projectGitInitialization,
147
+ ...threadRunResumeInputs(threads, threadId, requestedProfileId),
148
+ onSessionObserved: threadId
149
+ ? (harnessId, nativeSessionId, observedModel, profileId) => {
150
+ // The EVENT's profile is the cache truth (INV-135): the
151
+ // effective account can differ from the requested one.
152
+ threads.recordSession(threadId, harnessId, nativeSessionId, observedModel, profileId ?? null);
153
+ // The lane (thread, harness, effective profile) has SEEN
154
+ // this turn (INV-137); same key as the session record.
155
+ if (turnId)
156
+ threads.recordLaneCheckpoint(threadId, harnessId, profileId ?? null, turnId);
157
+ }
158
+ : undefined,
159
+ // Continuity facts (INV-137): cheap thread-store data; the engine
160
+ // reads prior outputs + git anchor itself and does the packet math.
161
+ threadContinuity: continuityContext,
162
+ onContinuityResolved: threadId
163
+ ? (tid, disclosure) => threads.setTurnContinuity(tid, {
164
+ kind: disclosure.kind,
165
+ packet_turns: disclosure.packetTurns,
166
+ summarized: disclosure.summarized,
167
+ lane_switched_from: disclosure.laneSwitchedFrom
168
+ ? {
169
+ harness_id: disclosure.laneSwitchedFrom.harness,
170
+ profile_id: disclosure.laneSwitchedFrom.profileId,
171
+ }
172
+ : null,
173
+ })
174
+ : undefined,
175
+ authPreference: p.authPreference,
176
+ credentialProfileId: requestedProfileId,
177
+ parentRunId: p.parentRunId ?? null,
178
+ delegatedFromRunId: p.delegatedFromRunId ?? null,
179
+ delegationAdmissionId: ctx.jobId,
180
+ repoRoot,
181
+ prompt: String(p.prompt ?? ""),
182
+ planRef: p.planRef && typeof p.planRef === "object"
183
+ ? p.planRef
184
+ : undefined,
185
+ instructions: typeof p.instructions === "string" ? p.instructions : undefined,
186
+ denyPaths: Array.isArray(p.denyPaths) ? p.denyPaths : undefined,
187
+ maxTurns: typeof p.maxTurns === "number" && p.maxTurns > 0 ? p.maxTurns : undefined,
188
+ outputSchema: p.outputSchema && typeof p.outputSchema === "object" && !Array.isArray(p.outputSchema)
189
+ ? p.outputSchema
190
+ : undefined,
191
+ attachments: turnId
192
+ ? (threads.getTurn(turnId)?.attachments ?? [])
193
+ : resources().resolve(p.attachments),
194
+ browser: p.browser === true,
195
+ mode: p.mode,
196
+ review: p.review,
197
+ contextMode: noProjectAsk
198
+ ? "off"
199
+ : p.scope.kind === "project"
200
+ ? p.scope.context
201
+ : undefined,
202
+ harnesses: p.harnesses,
203
+ primaryHarness: p.primaryHarness,
204
+ routingGoal: p.routingGoal,
205
+ n: p.n,
206
+ attempts: p.attempts ?? null,
207
+ untilClean: p.untilClean === true,
208
+ deepScan: p.deepScan === true,
209
+ create: p.create === true,
210
+ council: p.council === true,
211
+ delegate: p.delegate === true,
212
+ // Belt descriptor (D32): built once per delegate run with the parent
213
+ // budget snapshot; injected into agent lanes whose adapter can host
214
+ // MCP servers. Null when delegate is off (no belt).
215
+ delegationBelt,
216
+ synthesis: p.synthesis,
217
+ paidBudget: p.paidBudget,
218
+ access: p.access,
219
+ web: p.web ?? p.externalContextPolicy,
220
+ externalContextPolicy: p.externalContextPolicy ?? p.web,
221
+ model: p.model,
222
+ models: p.models,
223
+ effort: p.effort,
224
+ efforts: p.efforts,
225
+ tests: Array.isArray(p.tests) ? p.tests : undefined,
226
+ protectedPathApprovals: Array.isArray(p.protectedPathApprovals)
227
+ ? p.protectedPathApprovals
228
+ : undefined,
229
+ inPlace,
230
+ delegated: p.execution.delegated,
231
+ signal: runSignal,
232
+ onRunStart,
233
+ })
234
+ .finally(() => {
235
+ if (deadlineTimer)
236
+ clearTimeout(deadlineTimer);
237
+ });
238
+ };
239
+ }
240
+ //# sourceMappingURL=daemon-agent-runner.js.map
@@ -0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YACnD,sBAAsB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC;gBAC7D,CAAC,CAAC,CAAC,CAAC,sBAAsB;gBAC1B,CAAC,CAAC,SAAS;YACb,OAAO;YACP,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,SAAS;YAChC,MAAM,EAAE,SAAS;YACjB,UAAU;SACX,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,aAAa;gBAAE,YAAY,CAAC,aAAa,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,204 @@
1
+ import type { AdapterRegistry, ModelAdapter } from "@claudexor/core";
2
+ import { ModelOperations, type CredentialUnusableLedger, type DaemonClient, type ModelOperationDependencies, type QuotaRegistry } from "@claudexor/daemon";
3
+ import { GlobalConfig } from "@claudexor/schema";
4
+ import { accountsMigrationGate } from "./accounts-unified-migration.js";
5
+ import type { RetentionRunner } from "./retention-service.js";
6
+ interface ModelSource {
7
+ adapter: ModelAdapter;
8
+ label: string;
9
+ credentialHarness: string;
10
+ }
11
+ interface Dependencies extends Pick<ModelOperationDependencies, "commands" | "resources" | "warn"> {
12
+ client: Pick<DaemonClient, "enqueue" | "cancel">;
13
+ quota: () => QuotaRegistry;
14
+ config?: () => GlobalConfig;
15
+ registry?: AdapterRegistry;
16
+ sources?: readonly ModelSource[];
17
+ unusable?: CredentialUnusableLedger;
18
+ migrationGate?: typeof accountsMigrationGate;
19
+ }
20
+ /** Model transport composition shares account, quota, command, and retention owners
21
+ * with Agents. It never starts an Agent Run or creates another routing ledger. */
22
+ export declare function createModelServices(deps: Dependencies): {
23
+ operations: ModelOperations;
24
+ routes: {
25
+ modelSources: () => Promise<{
26
+ sources: {
27
+ id: string;
28
+ label: string;
29
+ credentialHarness: string;
30
+ }[];
31
+ }>;
32
+ modelCatalog: (sourceId: string, credentialProfileId?: string, requestedModel?: string) => Promise<{
33
+ source: string;
34
+ credentialProfileId: string;
35
+ accountFingerprint: string | null;
36
+ observedAt: string;
37
+ provenance: string;
38
+ models: {
39
+ id: string;
40
+ label: string | null;
41
+ isDefault: boolean;
42
+ contextWindow: number | null;
43
+ maxContextWindow: number | null;
44
+ maxOutputTokens: number | null;
45
+ inputModalities: string[];
46
+ reasoningEfforts: string[];
47
+ defaultReasoningEffort: string | null;
48
+ supportedOptions: string[];
49
+ }[];
50
+ }>;
51
+ createModelOperation: (request: import("@claudexor/schema").ModelPayloadRef, idempotencyKey: string) => Promise<import("@claudexor/schema").ControlModelOperationDetail>;
52
+ getModelOperation: (id: string) => Promise<{
53
+ id: string;
54
+ state: "cancelled" | "failed" | "interrupted" | "queued" | "running" | "succeeded";
55
+ createdAt: string;
56
+ startedAt: string | null;
57
+ finishedAt: string | null;
58
+ dispatch: {
59
+ state: "not_started" | "response_received" | "started" | "unknown";
60
+ startedAt: string | null;
61
+ route: {
62
+ source: string;
63
+ credentialProfileId: string;
64
+ accountFingerprint: string | null;
65
+ model: string | null;
66
+ } | null;
67
+ };
68
+ response: {
69
+ state: "absent";
70
+ } | {
71
+ state: "ready";
72
+ ref: {
73
+ resourceId: string;
74
+ sha256: string;
75
+ sizeBytes: number;
76
+ };
77
+ readyAt: string;
78
+ expiresAt: string;
79
+ } | {
80
+ state: "acknowledged";
81
+ ref: {
82
+ resourceId: string;
83
+ sha256: string;
84
+ sizeBytes: number;
85
+ };
86
+ releasedAt: string;
87
+ } | {
88
+ state: "expired";
89
+ ref: {
90
+ resourceId: string;
91
+ sha256: string;
92
+ sizeBytes: number;
93
+ };
94
+ releasedAt: string;
95
+ };
96
+ usage: {
97
+ input_tokens: number | null;
98
+ output_tokens: number | null;
99
+ cached_input_tokens: number | null;
100
+ cache_write_tokens: number | null;
101
+ reasoning_tokens: number | null;
102
+ };
103
+ cost: {
104
+ knowledge: "estimated" | "exact" | "unknown";
105
+ billing: "metered" | "proven_zero" | "subscription_entitlement" | "unknown";
106
+ source: string;
107
+ provenance: string[];
108
+ estimatedUsd: number | null;
109
+ cashUsd: number | null;
110
+ valuationUsd: number | null;
111
+ valuationKnowledge: "estimated" | "exact" | "unknown";
112
+ } | null;
113
+ problem: {
114
+ code: string;
115
+ message: string;
116
+ retryable: boolean;
117
+ fieldErrors: Record<string, string[]>;
118
+ requiredActions: string[];
119
+ evidenceRefs: string[];
120
+ context: Record<string, unknown>;
121
+ } | null;
122
+ }>;
123
+ readModelResult: (id: string) => Promise<{
124
+ bytes: Buffer;
125
+ sha256: string;
126
+ }>;
127
+ acknowledgeModelResult: (id: string, sha256: string) => Promise<{
128
+ id: string;
129
+ state: "cancelled" | "failed" | "interrupted" | "queued" | "running" | "succeeded";
130
+ createdAt: string;
131
+ startedAt: string | null;
132
+ finishedAt: string | null;
133
+ dispatch: {
134
+ state: "not_started" | "response_received" | "started" | "unknown";
135
+ startedAt: string | null;
136
+ route: {
137
+ source: string;
138
+ credentialProfileId: string;
139
+ accountFingerprint: string | null;
140
+ model: string | null;
141
+ } | null;
142
+ };
143
+ response: {
144
+ state: "absent";
145
+ } | {
146
+ state: "ready";
147
+ ref: {
148
+ resourceId: string;
149
+ sha256: string;
150
+ sizeBytes: number;
151
+ };
152
+ readyAt: string;
153
+ expiresAt: string;
154
+ } | {
155
+ state: "acknowledged";
156
+ ref: {
157
+ resourceId: string;
158
+ sha256: string;
159
+ sizeBytes: number;
160
+ };
161
+ releasedAt: string;
162
+ } | {
163
+ state: "expired";
164
+ ref: {
165
+ resourceId: string;
166
+ sha256: string;
167
+ sizeBytes: number;
168
+ };
169
+ releasedAt: string;
170
+ };
171
+ usage: {
172
+ input_tokens: number | null;
173
+ output_tokens: number | null;
174
+ cached_input_tokens: number | null;
175
+ cache_write_tokens: number | null;
176
+ reasoning_tokens: number | null;
177
+ };
178
+ cost: {
179
+ knowledge: "estimated" | "exact" | "unknown";
180
+ billing: "metered" | "proven_zero" | "subscription_entitlement" | "unknown";
181
+ source: string;
182
+ provenance: string[];
183
+ estimatedUsd: number | null;
184
+ cashUsd: number | null;
185
+ valuationUsd: number | null;
186
+ valuationKnowledge: "estimated" | "exact" | "unknown";
187
+ } | null;
188
+ problem: {
189
+ code: string;
190
+ message: string;
191
+ retryable: boolean;
192
+ fieldErrors: Record<string, string[]>;
193
+ requiredActions: string[];
194
+ evidenceRefs: string[];
195
+ context: Record<string, unknown>;
196
+ } | null;
197
+ }>;
198
+ cancelModelOperation: (id: string, reason?: import("@claudexor/schema").CancelReasonCode) => Promise<import("@claudexor/schema").ControlModelOperationDetail>;
199
+ };
200
+ withRetention: (run: RetentionRunner) => RetentionRunner;
201
+ close: () => void;
202
+ };
203
+ export {};
204
+ //# sourceMappingURL=model-services.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-services.d.ts","sourceRoot":"","sources":["../src/model-services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGrE,OAAO,EACL,eAAe,EACf,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EACnB,MAAM,mBAAmB,CAAC;AAW3B,OAAO,EAGL,YAAY,EAKb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAGxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,UAAU,WAAW;IACnB,OAAO,EAAE,YAAY,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,UAAU,YAAa,SAAQ,IAAI,CAAC,0BAA0B,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,CAAC;IAChG,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,QAAQ,CAAC,CAAC;IACjD,KAAK,EAAE,MAAM,aAAa,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,YAAY,CAAC;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