@codetreker/daynight 0.21.9 → 0.21.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +204 -27
  2. package/dist/api/client.d.ts +3 -1
  3. package/dist/api/client.js +12 -1
  4. package/dist/api/client.js.map +1 -1
  5. package/dist/api/parse.d.ts +2 -1
  6. package/dist/api/parse.js +8 -0
  7. package/dist/api/parse.js.map +1 -1
  8. package/dist/api/types.d.ts +7 -0
  9. package/dist/cli/commands.js +2 -0
  10. package/dist/cli/commands.js.map +1 -1
  11. package/dist/commands/worker/cleanup.d.ts +6 -0
  12. package/dist/commands/worker/cleanup.js +173 -0
  13. package/dist/commands/worker/cleanup.js.map +1 -0
  14. package/dist/commands/worker/config.d.ts +21 -0
  15. package/dist/commands/worker/config.js +144 -0
  16. package/dist/commands/worker/config.js.map +1 -0
  17. package/dist/commands/worker/coordinator.d.ts +34 -0
  18. package/dist/commands/worker/coordinator.js +508 -0
  19. package/dist/commands/worker/coordinator.js.map +1 -0
  20. package/dist/commands/worker/definition.d.ts +2 -0
  21. package/dist/commands/worker/definition.js +14 -0
  22. package/dist/commands/worker/definition.js.map +1 -0
  23. package/dist/commands/worker/diagnostics.d.ts +20 -0
  24. package/dist/commands/worker/diagnostics.js +56 -0
  25. package/dist/commands/worker/diagnostics.js.map +1 -0
  26. package/dist/commands/worker/execution.d.ts +41 -0
  27. package/dist/commands/worker/execution.js +255 -0
  28. package/dist/commands/worker/execution.js.map +1 -0
  29. package/dist/commands/worker/herdr/agents.d.ts +185 -0
  30. package/dist/commands/worker/herdr/agents.js +654 -0
  31. package/dist/commands/worker/herdr/agents.js.map +1 -0
  32. package/dist/commands/worker/herdr/arguments.d.ts +8 -0
  33. package/dist/commands/worker/herdr/arguments.js +58 -0
  34. package/dist/commands/worker/herdr/arguments.js.map +1 -0
  35. package/dist/commands/worker/herdr/command.d.ts +22 -0
  36. package/dist/commands/worker/herdr/command.js +115 -0
  37. package/dist/commands/worker/herdr/command.js.map +1 -0
  38. package/dist/commands/worker/herdr/instance.d.ts +56 -0
  39. package/dist/commands/worker/herdr/instance.js +322 -0
  40. package/dist/commands/worker/herdr/instance.js.map +1 -0
  41. package/dist/commands/worker/herdr/preflight.d.ts +40 -0
  42. package/dist/commands/worker/herdr/preflight.js +251 -0
  43. package/dist/commands/worker/herdr/preflight.js.map +1 -0
  44. package/dist/commands/worker/herdr/rpc.d.ts +29 -0
  45. package/dist/commands/worker/herdr/rpc.js +186 -0
  46. package/dist/commands/worker/herdr/rpc.js.map +1 -0
  47. package/dist/commands/worker/herdr.d.ts +95 -0
  48. package/dist/commands/worker/herdr.js +35 -0
  49. package/dist/commands/worker/herdr.js.map +1 -0
  50. package/dist/commands/worker/index.d.ts +10 -0
  51. package/dist/commands/worker/index.js +14 -0
  52. package/dist/commands/worker/index.js.map +1 -0
  53. package/dist/commands/worker/prompts.d.ts +4 -0
  54. package/dist/commands/worker/prompts.js +64 -0
  55. package/dist/commands/worker/prompts.js.map +1 -0
  56. package/dist/commands/worker/remote.d.ts +18 -0
  57. package/dist/commands/worker/remote.js +134 -0
  58. package/dist/commands/worker/remote.js.map +1 -0
  59. package/dist/commands/worker/runtime.d.ts +8 -0
  60. package/dist/commands/worker/runtime.js +246 -0
  61. package/dist/commands/worker/runtime.js.map +1 -0
  62. package/dist/commands/worker/store.d.ts +55 -5
  63. package/dist/commands/worker/store.js +381 -26
  64. package/dist/commands/worker/store.js.map +1 -1
  65. package/dist/commands/worker/types.d.ts +37 -1
  66. package/dist/commands/worker/worktrees.d.ts +1 -0
  67. package/dist/commands/worker/worktrees.js +9 -0
  68. package/dist/commands/worker/worktrees.js.map +1 -1
  69. package/dist/config/document.d.ts +1 -1
  70. package/dist/config/document.js +1 -0
  71. package/dist/config/document.js.map +1 -1
  72. package/package.json +2 -2
@@ -0,0 +1,56 @@
1
+ import { appendFile, mkdir } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export const createWorkerDiagnostics = async (options) => {
4
+ await mkdir(options.paths.logsDirectory, { recursive: true, mode: 0o700 });
5
+ const filename = path.join(options.paths.logsDirectory, `worker-${new Date().toISOString().slice(0, 10)}.jsonl`);
6
+ const redact = (value) => {
7
+ let result = value;
8
+ for (const secret of options.secrets === undefined ? [] : options.secrets) {
9
+ if (secret.length !== 0)
10
+ for (const representation of new Set([secret, encodeURIComponent(secret)]))
11
+ result = result.replaceAll(representation, "[redacted]");
12
+ }
13
+ return result.replace(/\b(Bearer\s+)[^\s"']+/gi, "$1[redacted]").replace(/\b(https?:\/\/)[^\s/@]+:[^\s/@]+@/gi, "$1[redacted]@");
14
+ };
15
+ const describeError = (value, depth = 0) => {
16
+ if (value instanceof Error)
17
+ return {
18
+ name: value.name, message: redact(value.message),
19
+ ...(value.cause === undefined || depth >= 6 ? {} : { cause: describeError(value.cause, depth + 1) }),
20
+ ...(value instanceof AggregateError && depth < 6 ? { errors: value.errors.map((error) => describeError(error, depth + 1)) } : {}),
21
+ };
22
+ return redact(String(value));
23
+ };
24
+ let pending = Promise.resolve();
25
+ let failed;
26
+ const emit = (event) => {
27
+ const task = event.task;
28
+ const record = {
29
+ timestamp: new Date().toISOString(), workerId: options.workerId, platform: options.platform,
30
+ kind: event.kind, message: redact(event.message),
31
+ ...(task === undefined ? {} : {
32
+ serverOrigin: task.serverOrigin, projectId: task.projectId, taskId: task.taskId, claimId: task.claimId,
33
+ status: task.status, repositoryPath: task.repositoryPath, agent: task.configuration?.agent,
34
+ recovery: task.recovery, cleanup: task.cleanup,
35
+ }),
36
+ ...(event.error === undefined ? {} : { error: describeError(event.error) }),
37
+ };
38
+ const serialized = JSON.stringify(record, (_key, value) => typeof value === "string" ? redact(value) : value);
39
+ if (failed === undefined)
40
+ pending = pending.then(() => appendFile(filename, `${serialized}\n`, { mode: 0o600 })).catch((cause) => { failed = cause; });
41
+ try {
42
+ options.log?.(`${record.timestamp} ${record.kind}${task === undefined ? "" : ` ${task.projectId}/${task.taskId}/${task.claimId} ${task.status}`} ${record.message}${event.error === undefined ? "" : ` ${JSON.stringify(describeError(event.error))}`}\n`);
43
+ }
44
+ catch (cause) {
45
+ if (failed === undefined)
46
+ failed = cause;
47
+ }
48
+ };
49
+ return {
50
+ emit,
51
+ flush: async () => { await pending; if (failed !== undefined)
52
+ throw failed; },
53
+ filename,
54
+ };
55
+ };
56
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../../src/commands/worker/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,IAAI,MAAM,WAAW,CAAC;AAO7B,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAAE,OAG7C,EAAE,EAAE;IACH,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3E,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,UAAU,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC;IACjH,MAAM,MAAM,GAAG,CAAC,KAAa,EAAU,EAAE;QACvC,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC1E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,KAAK,MAAM,cAAc,IAAI,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;oBAAE,MAAM,GAAG,MAAM,CAAC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CAAC;YAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAAC,CAAC;QACnQ,OAAO,KAAK,EAAE,CAAC;YAAC,IAAI,MAAM,KAAK,SAAS;gBAAE,MAAM,GAAG,KAAK,CAAC;QAAC,CAAC;IAC7D,CAAC,CAAC;IACF,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,KAAK,IAAmB,EAAE,GAAG,MAAM,OAAO,CAAC,CAAC,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,MAAM,CAAC,CAAC,CAAC;QAC5F,QAAQ;KACT,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { Operation } from "../../api/operation.js";
2
+ import type { TaskPlatform, WorkerAgent } from "../../api/types.js";
3
+ import type { HerdrExecutionContext, HerdrOwnedWorkspace, HerdrTaskBinding, WorkerHerdrAdapter } from "./herdr.js";
4
+ import type { WorkerStore } from "./store.js";
5
+ import type { LocalTask } from "./types.js";
6
+ import type { createWorkerGitManager } from "./worktrees.js";
7
+ export type WorkerEvent = {
8
+ kind: string;
9
+ message: string;
10
+ task?: LocalTask;
11
+ error?: unknown;
12
+ };
13
+ export type WorkerGitManager = ReturnType<typeof createWorkerGitManager>;
14
+ export type ExecutionDependencies = {
15
+ store: WorkerStore;
16
+ git: WorkerGitManager;
17
+ herdr: WorkerHerdrAdapter;
18
+ platform: TaskPlatform;
19
+ buildPrompt: (task: LocalTask, platform: TaskPlatform) => string;
20
+ emit: (event: WorkerEvent) => void;
21
+ now: () => number;
22
+ };
23
+ export declare const isWorkerCancellation: (error: unknown, signal: AbortSignal) => boolean;
24
+ export declare const workerOperation: <T>(action: (operation: Operation) => Promise<T>, signal?: AbortSignal, totalMs?: number) => Promise<T>;
25
+ export declare const executionContext: (task: LocalTask, agent?: WorkerAgent) => HerdrExecutionContext;
26
+ export declare const taskBinding: (task: LocalTask) => HerdrTaskBinding | null;
27
+ export declare const ownedWorkspace: (task: LocalTask, resources: readonly HerdrOwnedWorkspace[]) => HerdrOwnedWorkspace | undefined;
28
+ export declare const actualTaskPane: (task: LocalTask, resources: readonly HerdrOwnedWorkspace[]) => {
29
+ binding: HerdrTaskBinding;
30
+ cwd: string | null;
31
+ kind: WorkerAgent | null;
32
+ status: string;
33
+ launchPending: boolean;
34
+ interactiveReady: boolean;
35
+ nativeSession: import("./herdr.js").HerdrNativeReference | null;
36
+ stateChangeSeq: number | null;
37
+ completionSeq: number | null;
38
+ } | undefined;
39
+ export declare const createExecutionDriver: (deps: ExecutionDependencies) => {
40
+ advance: (input: LocalTask, resources: readonly HerdrOwnedWorkspace[], signal?: AbortSignal) => Promise<LocalTask>;
41
+ };
@@ -0,0 +1,255 @@
1
+ import path from "node:path";
2
+ import { createOperation, OperationError } from "../../api/operation.js";
3
+ import { HerdrAgentActionError } from "./herdr.js";
4
+ import { buildHerdrAgentArguments } from "./herdr/arguments.js";
5
+ export const isWorkerCancellation = (error, signal) => {
6
+ if (!signal.aborted)
7
+ return false;
8
+ if (error instanceof AggregateError && error.errors.some((failure) => !isWorkerCancellation(failure, signal)))
9
+ return false;
10
+ return error === signal.reason ||
11
+ (error instanceof OperationError && error.kind === "cancelled" && error.cause === signal.reason) ||
12
+ (error instanceof Error && error.cause !== undefined && isWorkerCancellation(error.cause, signal));
13
+ };
14
+ export const workerOperation = async (action, signal, totalMs = 120_000) => {
15
+ const operation = createOperation({ ...(signal === undefined ? {} : { signal }), limits: { totalMs } });
16
+ try {
17
+ return await action(operation);
18
+ }
19
+ finally {
20
+ operation.dispose();
21
+ }
22
+ };
23
+ export const executionContext = (task, agent) => {
24
+ const selected = task.configuration?.agent ?? agent;
25
+ if (selected === undefined)
26
+ throw new Error("The original native agent kind is unavailable; the execution was retained.");
27
+ return { serverOrigin: task.serverOrigin, projectId: task.projectId, taskId: task.taskId, claimId: task.claimId, worktreeId: task.worktreeId,
28
+ cwd: task.resources.worktree?.worktreePath ?? path.join(task.repositoryPath, ".worktrees", "daynight", task.taskId), agent: selected };
29
+ };
30
+ export const taskBinding = (task) => {
31
+ const binding = task.resources.herdr;
32
+ const terminalId = task.nativeExecution?.terminalId;
33
+ return binding === null || terminalId === null || terminalId === undefined ? null : { ...binding, terminalId };
34
+ };
35
+ export const ownedWorkspace = (task, resources) => resources.find(({ owner }) => owner.serverOrigin === task.serverOrigin && owner.projectId === task.projectId && owner.taskId === task.taskId && owner.claimId === task.claimId && owner.worktreeId === task.worktreeId);
36
+ export const actualTaskPane = (task, resources) => {
37
+ const workspace = ownedWorkspace(task, resources);
38
+ if (workspace === undefined)
39
+ return undefined;
40
+ const binding = task.resources.herdr;
41
+ if (binding !== null && workspace.workspaceId === binding.workspaceId)
42
+ return workspace.panes.find((pane) => pane.binding.paneId === binding.paneId);
43
+ if (workspace.panes.length !== 1)
44
+ throw new Error("The original task workspace has ambiguous panes; it was retained.");
45
+ return workspace.panes[0];
46
+ };
47
+ const sameBinding = (left, right) => left.session === right.session && left.workspaceId === right.workspaceId && left.paneId === right.paneId && left.terminalId === right.terminalId;
48
+ const live = (observation) => observation.kind !== null || observation.launchPending || observation.interactiveReady;
49
+ export const createExecutionDriver = (deps) => {
50
+ const refresh = (task) => {
51
+ const current = deps.store.getTask(task);
52
+ if (current === null)
53
+ throw new Error("The local execution record disappeared.");
54
+ return current;
55
+ };
56
+ const rememberStop = async (task, binding, signal) => {
57
+ if (task.nativeExecution?.stopObservation !== null && task.nativeExecution?.stopObservation !== undefined)
58
+ return;
59
+ try {
60
+ const observation = await workerOperation((operation) => deps.herdr.tasks.captureStop(executionContext(task), binding, operation), signal);
61
+ deps.store.recordStopObservation(task, observation, deps.now());
62
+ }
63
+ catch (error) {
64
+ deps.emit({ kind: "stop-observation-unavailable", task, message: "Original native process identities are not yet available; cold recovery remains fenced.", error });
65
+ }
66
+ };
67
+ const rememberNative = (task, nativeSession) => nativeSession === null ? refresh(task) : deps.store.bindNativeSession(task, { source: "herdr", sessionId: nativeSession.sessionId }, deps.now());
68
+ const prepareWorkspace = async (task, signal) => {
69
+ deps.store.markWorkspaceSubmitting(task, deps.now());
70
+ try {
71
+ return await workerOperation((operation) => deps.herdr.tasks.prepareWorkspace(executionContext(task), operation), signal);
72
+ }
73
+ catch (error) {
74
+ if (error instanceof HerdrAgentActionError && error.action === "workspace.create" && error.submission !== "unknown")
75
+ deps.store.recordWorkspaceNotSubmitted(task, error.submission === "rejected" ? { definiteRejection: true } : { notSubmitted: true }, deps.now());
76
+ throw error;
77
+ }
78
+ };
79
+ const rebind = async (task, actual, signal) => {
80
+ const original = taskBinding(task);
81
+ if (original === null)
82
+ throw new Error("The original Herdr terminal identity is unavailable; recovery was paused.");
83
+ const context = executionContext(task);
84
+ if (task.nativeExecution?.workspaceSubmission === "unknown" && actual === null)
85
+ throw new HerdrAgentActionError("The original replacement workspace request has an unknown outcome; absence does not authorize another creation.", "workspace.create", "unknown");
86
+ const evidence = task.nativeExecution?.stopObservation;
87
+ if (task.nativeExecution?.launchSubmission === "never-submitted") {
88
+ if (actual !== null)
89
+ await workerOperation((operation) => deps.herdr.tasks.confirmEmptyPane(context, actual, operation), signal);
90
+ }
91
+ else {
92
+ if (evidence === null || evidence === undefined)
93
+ throw new Error("The original persisted native stop observation is missing; recovery cannot infer that the agent stopped.");
94
+ if (actual === null)
95
+ await workerOperation((operation) => deps.herdr.tasks.confirmMissingWorkspaceStopped(context, original, evidence, operation), signal);
96
+ else if (sameBinding(original, actual))
97
+ await workerOperation((operation) => deps.herdr.tasks.confirmStopped(context, original, evidence, operation), signal);
98
+ else if (original.workspaceId !== actual.workspaceId || original.paneId !== actual.paneId)
99
+ await workerOperation((operation) => deps.herdr.tasks.confirmReplacedStop(context, original, actual, evidence, operation), signal);
100
+ else
101
+ await workerOperation((operation) => deps.herdr.tasks.confirmRestoredStop(context, original, actual, evidence, operation), signal);
102
+ }
103
+ if (task.nativeExecution?.workspaceSubmission === "unknown") {
104
+ // The exact observed replacement establishes the previous create outcome. Its
105
+ // environment receipt is unavailable, so a subsequent empty-pane rebind replaces it.
106
+ return deps.store.rebindHerdrExecution(task, original, actual, null, { originalAgentStopped: true, oldWorkspaceClosed: true }, deps.now());
107
+ }
108
+ await workerOperation((operation) => deps.herdr.tasks.closeWorkspace(context, actual === null ? original : actual, { agentStopped: true }, operation), signal);
109
+ const prepared = await prepareWorkspace(task, signal);
110
+ return deps.store.rebindHerdrExecution(task, original, prepared.binding, prepared.workspaceEvidence, { originalAgentStopped: true, oldWorkspaceClosed: true }, deps.now());
111
+ };
112
+ return {
113
+ advance: async (input, resources, signal) => {
114
+ let task = refresh(input);
115
+ if (task.cleanup !== null || task.control !== null)
116
+ throw new Error("Cleanup or source management prevents ordinary execution.");
117
+ if (task.configuration === null)
118
+ throw new Error("The original frozen execution configuration is missing; restore it before retrying.");
119
+ if (task.recovery.pauseReason !== null && !task.recovery.retryAuthorized && (task.resources.worktree === null || task.resources.herdr === null))
120
+ return task;
121
+ if (task.status !== "active")
122
+ throw new Error("Only an active execution may prepare resources.");
123
+ const original = actualTaskPane(task, resources);
124
+ if (task.resources.nativeSession === null && task.nativeExecution?.launchSubmission !== "never-submitted") {
125
+ if (original === undefined || (!live(original) && original.nativeSession === null))
126
+ throw new Error("The original native session ID is missing; recover its exact history identity before preparing replacement resources.");
127
+ if (original.nativeSession !== null && task.resources.herdr !== null)
128
+ task = rememberNative(task, original.nativeSession);
129
+ }
130
+ if (task.resources.worktree === null) {
131
+ const binding = task.nativeExecution?.launchSubmission === "never-submitted"
132
+ ? await workerOperation((operation) => deps.git.prepareWorktree(task, operation), signal, 180_000)
133
+ : await workerOperation((operation) => deps.git.findWorktree(task, operation), signal);
134
+ if (binding === null)
135
+ throw new Error("The original native launch provenance and owned worktree are unavailable; a fresh worktree cannot substitute for recovery.");
136
+ task = deps.store.bindWorktree(task, binding, deps.now());
137
+ }
138
+ else
139
+ await workerOperation((operation) => deps.git.verifyWorktree(task, operation), signal);
140
+ const actual = actualTaskPane(task, resources);
141
+ if (actual?.nativeSession !== undefined && actual.nativeSession !== null && task.resources.nativeSession !== null && actual.nativeSession.sessionId !== task.resources.nativeSession.sessionId)
142
+ throw new Error("The actual native history differs from the original execution; its resources were retained.");
143
+ let binding = taskBinding(task);
144
+ if (binding === null) {
145
+ if (task.resources.herdr !== null)
146
+ throw new Error("The original Herdr terminal identity is missing; an existing binding cannot be guessed.");
147
+ if (actual !== undefined) {
148
+ task = deps.store.bindHerdrExecution(task, actual.binding, null, deps.now());
149
+ binding = actual.binding;
150
+ }
151
+ else {
152
+ if (task.nativeExecution?.workspaceSubmission === "unknown")
153
+ throw new HerdrAgentActionError("The original workspace creation has an unknown outcome; the absent snapshot does not authorize replay.", "workspace.create", "unknown");
154
+ const prepared = await prepareWorkspace(task, signal);
155
+ task = deps.store.bindHerdrExecution(task, prepared.binding, prepared.workspaceEvidence, deps.now());
156
+ binding = prepared.binding;
157
+ }
158
+ }
159
+ else if ((actual !== undefined && !sameBinding(binding, actual.binding)) || ownedWorkspace(task, resources) === undefined) {
160
+ if (task.recovery.pauseReason !== null && !task.recovery.retryAuthorized)
161
+ return task;
162
+ if (task.nativeExecution?.workspaceSubmission === "unknown" && actual === undefined)
163
+ throw new HerdrAgentActionError("The original replacement workspace request is unresolved; the absent snapshot cannot authorize replay.", "workspace.create", "unknown");
164
+ if (task.nativeExecution?.launchSubmission !== "never-submitted" && task.nativeExecution?.workspaceSubmission !== "unknown") {
165
+ if (task.resources.nativeSession === null)
166
+ throw new Error("The original native history identity is unavailable; missing Herdr resources do not authorize a new conversation.");
167
+ task = deps.store.beginRecovery(task, deps.now());
168
+ }
169
+ task = await rebind(task, actual?.binding ?? null, signal);
170
+ binding = taskBinding(task);
171
+ }
172
+ const context = executionContext(task);
173
+ const before = await workerOperation((operation) => deps.herdr.tasks.observe(context, binding, operation), signal);
174
+ task = rememberNative(task, before.nativeSession);
175
+ if (live(before)) {
176
+ await rememberStop(task, binding, signal);
177
+ task = refresh(task);
178
+ const native = task.nativeExecution;
179
+ if (native?.launchSubmission === "acknowledged" && native.promptSubmission === "not-submitted" && native.launchEvidence !== null && before.status !== "blocked" && (task.recovery.pauseReason === null || task.recovery.retryAuthorized)) {
180
+ if (task.recovery.retryAuthorized)
181
+ task = deps.store.beginRecovery(task, deps.now());
182
+ const originalNativeId = task.resources.nativeSession?.sessionId;
183
+ const resumedArgv = originalNativeId === undefined ? null : [context.agent, ...buildHerdrAgentArguments(task.configuration, originalNativeId)];
184
+ const resumeSessionId = resumedArgv !== null && native.launchEvidence.argv.length === resumedArgv.length && native.launchEvidence.argv.every((argument, index) => argument === resumedArgv[index]) ? originalNativeId : undefined;
185
+ const prompt = deps.buildPrompt(task, deps.platform);
186
+ deps.store.markNativePromptSubmitting(task, deps.now());
187
+ try {
188
+ const outcome = await workerOperation((operation) => deps.herdr.tasks.start(context, binding, { configuration: task.configuration, prompt, initialPromptNotSubmitted: true, launchEvidence: native.launchEvidence, workspaceEvidence: native.workspaceEvidence,
189
+ ...(resumeSessionId === undefined ? {} : { resumeSessionId }) }, operation), signal);
190
+ if (outcome.kind === "rebind-required")
191
+ throw new Error(`The original deferred startup input is fenced: ${outcome.reason}.`);
192
+ deps.store.recordNativeStartOutcome(task, { ...(outcome.launchEvidence === null ? {} : { launchEvidence: outcome.launchEvidence }), promptSubmission: outcome.promptSubmission }, deps.now());
193
+ task = rememberNative(task, outcome.observation.nativeSession);
194
+ }
195
+ catch (error) {
196
+ if (error instanceof HerdrAgentActionError)
197
+ deps.store.recordNativeStartOutcome(task, { ...(error.launchEvidence === null ? {} : { launchEvidence: error.launchEvidence }), promptSubmission: error.promptSubmission === null ? "unknown" : error.promptSubmission }, deps.now());
198
+ throw error;
199
+ }
200
+ }
201
+ deps.emit({ kind: before.status === "blocked" ? "waiting" : "reconnected", task: refresh(task), message: before.status === "blocked" ? "The original agent is waiting for input; attach to its private Herdr session." : "Observed the original live agent without replaying its startup input." });
202
+ return refresh(task);
203
+ }
204
+ if (task.recovery.pauseReason !== null && !task.recovery.retryAuthorized)
205
+ return task;
206
+ const native = task.nativeExecution;
207
+ if (native === null)
208
+ throw new Error("The original native launch provenance is missing; a new launch would be unsafe.");
209
+ if (native.launchSubmission !== "never-submitted") {
210
+ if (task.resources.nativeSession === null)
211
+ throw new Error("The original launch may have been submitted but its native history identity is unavailable; no second agent was started.");
212
+ deps.store.beginRecovery(task, deps.now());
213
+ task = refresh(task);
214
+ task = await rebind(task, binding, signal);
215
+ binding = taskBinding(task);
216
+ }
217
+ else if (native.workspaceEvidence === null) {
218
+ task = await rebind(task, binding, signal);
219
+ binding = taskBinding(task);
220
+ }
221
+ if (task.nativeExecution.workspaceEvidence === null) {
222
+ task = await rebind(task, binding, signal);
223
+ binding = taskBinding(task);
224
+ }
225
+ if (task.recovery.retryAuthorized)
226
+ task = deps.store.beginRecovery(task, deps.now());
227
+ const prompt = deps.buildPrompt(task, deps.platform);
228
+ deps.store.markNativeLaunchSubmitting(task, deps.now());
229
+ try {
230
+ const outcome = await workerOperation((operation) => deps.herdr.tasks.start(executionContext(task), binding, { configuration: task.configuration, prompt,
231
+ workspaceEvidence: task.nativeExecution.workspaceEvidence, ...(task.resources.nativeSession === null ? {} : { resumeSessionId: task.resources.nativeSession.sessionId }) }, operation), signal);
232
+ if (outcome.kind === "rebind-required")
233
+ throw new Error(`The native launch was fenced: ${outcome.reason}.`);
234
+ if (outcome.kind === "reconnected")
235
+ throw new Error("An unexpected live agent was observed during a fresh launch; its input was retained.");
236
+ deps.store.recordNativeStartOutcome(task, { ...(outcome.launchEvidence === null ? {} : { launchEvidence: outcome.launchEvidence }), promptSubmission: outcome.promptSubmission }, deps.now());
237
+ task = rememberNative(task, outcome.observation.nativeSession);
238
+ await rememberStop(task, binding, signal);
239
+ deps.emit({ kind: outcome.kind === "waiting" ? "waiting" : "started", task: refresh(task), message: task.resources.nativeSession === null ? "Native launch acknowledged; waiting for the original agent." : "Managed startup input submitted to the original native conversation." });
240
+ return refresh(task);
241
+ }
242
+ catch (error) {
243
+ if (error instanceof HerdrAgentActionError) {
244
+ if (error.action === "agent.start" && error.submission !== "unknown" && error.launchEvidence === null && task.nativeExecution?.launchSubmission === "never-submitted") {
245
+ deps.store.recordNativeLaunchNotSubmitted(task, error.submission === "rejected" ? { definiteRejection: true } : { notSubmitted: true }, deps.now());
246
+ }
247
+ else
248
+ deps.store.recordNativeStartOutcome(task, { ...(error.launchEvidence === null ? {} : { launchEvidence: error.launchEvidence }), promptSubmission: error.promptSubmission === null ? "unknown" : error.promptSubmission }, deps.now());
249
+ }
250
+ throw error;
251
+ }
252
+ },
253
+ };
254
+ };
255
+ //# sourceMappingURL=execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.js","sourceRoot":"","sources":["../../../src/commands/worker/execution.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAiBhE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAE,MAAmB,EAAW,EAAE;IACnF,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAClC,IAAI,KAAK,YAAY,cAAc,IAAI,KAAK,CAAC,MAAM,C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CAAC,CAAC,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;gBAC/O,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,185 @@
1
+ import type { Operation } from "../../../api/operation.js";
2
+ import type { WorkerAgent } from "../../../api/types.js";
3
+ import type { HerdrAgentConfiguration } from "./arguments.js";
4
+ import type { HerdrRpcClient } from "./rpc.js";
5
+ export type { HerdrAgentConfiguration } from "./arguments.js";
6
+ export { buildHerdrAgentArguments, validateHerdrAgentArguments } from "./arguments.js";
7
+ export type HerdrExecutionContext = {
8
+ serverOrigin: string;
9
+ projectId: string;
10
+ taskId: string;
11
+ claimId: string;
12
+ worktreeId: string;
13
+ cwd: string;
14
+ agent: WorkerAgent;
15
+ };
16
+ export type HerdrExecutionOwner = Pick<HerdrExecutionContext, "serverOrigin" | "projectId" | "taskId" | "claimId" | "worktreeId">;
17
+ export type HerdrTaskBinding = {
18
+ session: string;
19
+ workspaceId: string;
20
+ paneId: string;
21
+ terminalId: string;
22
+ };
23
+ export type HerdrWorkspaceEvidence = {
24
+ binding: HerdrTaskBinding;
25
+ ownerLabel: string;
26
+ environment: HerdrWorkspaceEnvironment;
27
+ };
28
+ export type HerdrPreparedWorkspace = {
29
+ binding: HerdrTaskBinding;
30
+ workspaceEvidence: HerdrWorkspaceEvidence | null;
31
+ };
32
+ export type HerdrLaunchEvidence = {
33
+ binding: HerdrTaskBinding;
34
+ ownerLabel: string;
35
+ agent: WorkerAgent;
36
+ argv: readonly string[];
37
+ referenceBaseline: "empty";
38
+ workspaceEvidence: HerdrWorkspaceEvidence;
39
+ };
40
+ export type HerdrNativeReference = {
41
+ source: string;
42
+ agent: WorkerAgent;
43
+ sessionId: string;
44
+ };
45
+ export type HerdrAgentObservation = {
46
+ binding: HerdrTaskBinding;
47
+ kind: string | null;
48
+ name: string | null;
49
+ status: string;
50
+ launchPending: boolean;
51
+ interactiveReady: boolean;
52
+ nativeSession: HerdrNativeReference | null;
53
+ stateChangeSeq: number | null;
54
+ completionSeq: number | null;
55
+ };
56
+ export type HerdrStopObservation = {
57
+ binding: HerdrTaskBinding;
58
+ ownerLabel: string;
59
+ agent: WorkerAgent;
60
+ nativeSessionId: string | null;
61
+ shellPid: number;
62
+ processIds: readonly number[];
63
+ observedAt: number;
64
+ };
65
+ export type HerdrOwnedWorkspace = {
66
+ owner: HerdrExecutionOwner;
67
+ workspaceId: string;
68
+ panes: {
69
+ binding: HerdrTaskBinding;
70
+ cwd: string | null;
71
+ kind: WorkerAgent | null;
72
+ status: string;
73
+ launchPending: boolean;
74
+ interactiveReady: boolean;
75
+ nativeSession: HerdrNativeReference | null;
76
+ stateChangeSeq: number | null;
77
+ completionSeq: number | null;
78
+ }[];
79
+ };
80
+ export type HerdrAgentPreflight = {
81
+ verifyStart(input: {
82
+ context: HerdrExecutionContext;
83
+ configuration: HerdrAgentConfiguration;
84
+ resumeSessionId?: string;
85
+ }, operation: Operation): Promise<unknown>;
86
+ };
87
+ export type HerdrWorkspaceEnvironment = Readonly<{
88
+ XDG_CONFIG_HOME: string;
89
+ XDG_STATE_HOME: string;
90
+ }>;
91
+ export declare const herdrExecutionLabel: (context: HerdrExecutionContext) => string;
92
+ export declare const herdrExecutionAgentName: (context: HerdrExecutionContext) => string;
93
+ export declare const parseHerdrExecutionLabel: (label: string) => HerdrExecutionOwner | null;
94
+ export declare class HerdrAgentActionError extends Error {
95
+ readonly action: string;
96
+ readonly submission: "not-submitted" | "rejected" | "unknown";
97
+ readonly promptSubmission: "not-submitted" | "submitted" | "unknown" | null;
98
+ readonly launchEvidence: HerdrLaunchEvidence | null;
99
+ constructor(message: string, action: string, submission: "not-submitted" | "rejected" | "unknown", options?: ErrorOptions & {
100
+ promptSubmission?: "not-submitted" | "submitted" | "unknown";
101
+ launchEvidence?: HerdrLaunchEvidence;
102
+ });
103
+ }
104
+ export declare const createHerdrAgentManager: (options: {
105
+ rpc: HerdrRpcClient;
106
+ session: string;
107
+ preflight: HerdrAgentPreflight;
108
+ workspaceEnvironment: HerdrWorkspaceEnvironment;
109
+ processExecuting?: (pid: number) => Promise<boolean>;
110
+ pollIntervalMs?: number;
111
+ }) => {
112
+ listResources: (operation: Operation) => Promise<HerdrOwnedWorkspace[]>;
113
+ prepareWorkspace: (context: HerdrExecutionContext, operation: Operation) => Promise<HerdrPreparedWorkspace>;
114
+ observe: (context: HerdrExecutionContext, binding: HerdrTaskBinding, operation: Operation) => Promise<HerdrAgentObservation>;
115
+ start: (context: HerdrExecutionContext, binding: HerdrTaskBinding, input: {
116
+ configuration: HerdrAgentConfiguration;
117
+ prompt: string;
118
+ resumeSessionId?: string;
119
+ initialPromptNotSubmitted?: true;
120
+ launchEvidence?: HerdrLaunchEvidence;
121
+ workspaceEvidence?: HerdrWorkspaceEvidence | null;
122
+ }, operation: Operation) => Promise<{
123
+ kind: "rebind-required";
124
+ reason: "retained-native-reference" | "unverified-launch" | "unverified-workspace-environment";
125
+ observation: HerdrAgentObservation;
126
+ promptSubmission: "not-submitted";
127
+ launchEvidence: null;
128
+ } | {
129
+ kind: "reconnected";
130
+ observation: HerdrAgentObservation;
131
+ promptSubmission: "not-submitted";
132
+ launchEvidence: null;
133
+ } | {
134
+ kind: "waiting";
135
+ observation: HerdrAgentObservation;
136
+ promptSubmission: "not-submitted";
137
+ launchEvidence: HerdrLaunchEvidence | null;
138
+ } | {
139
+ kind: "started";
140
+ observation: HerdrAgentObservation;
141
+ promptSubmission: "submitted";
142
+ launchEvidence: HerdrLaunchEvidence | null;
143
+ } | {
144
+ kind: "waiting";
145
+ observation: HerdrAgentObservation;
146
+ promptSubmission: "submitted";
147
+ launchEvidence: HerdrLaunchEvidence | null;
148
+ }>;
149
+ submitPrompt: (context: HerdrExecutionContext, binding: HerdrTaskBinding, prompt: string, operation: Operation) => Promise<{
150
+ submission: "submitted";
151
+ observation: HerdrAgentObservation;
152
+ }>;
153
+ captureStop: (context: HerdrExecutionContext, binding: HerdrTaskBinding, operation: Operation) => Promise<HerdrStopObservation>;
154
+ requestGracefulStop: (context: HerdrExecutionContext, binding: HerdrTaskBinding, operation: Operation) => Promise<{
155
+ submission: "submitted";
156
+ observation: HerdrAgentObservation;
157
+ }>;
158
+ confirmEmptyPane: (context: HerdrExecutionContext, binding: HerdrTaskBinding, operation: Operation) => Promise<{
159
+ noNativeProcess: true;
160
+ }>;
161
+ confirmStopped: (context: HerdrExecutionContext, binding: HerdrTaskBinding, evidence: HerdrStopObservation, operation: Operation) => Promise<{
162
+ agentStopped: true;
163
+ }>;
164
+ confirmMissingWorkspaceStopped: (context: HerdrExecutionContext, originalBinding: HerdrTaskBinding, evidence: HerdrStopObservation, operation: Operation) => Promise<{
165
+ agentStopped: true;
166
+ }>;
167
+ confirmRestoredStop: (context: HerdrExecutionContext, originalBinding: HerdrTaskBinding, restoredBinding: HerdrTaskBinding, evidence: HerdrStopObservation, operation: Operation) => Promise<{
168
+ agentStopped: true;
169
+ binding: HerdrTaskBinding;
170
+ }>;
171
+ confirmReplacedStop: (context: HerdrExecutionContext, originalBinding: HerdrTaskBinding, replacementBinding: HerdrTaskBinding, evidence: HerdrStopObservation, operation: Operation) => Promise<{
172
+ agentStopped: true;
173
+ binding: HerdrTaskBinding;
174
+ }>;
175
+ forceStop: (context: HerdrExecutionContext, binding: HerdrTaskBinding, evidence: HerdrStopObservation, operation: Operation) => Promise<{
176
+ agentStopped: true;
177
+ originalPaneClosed: true;
178
+ }>;
179
+ closeWorkspace: (context: HerdrExecutionContext, binding: HerdrTaskBinding, proof: {
180
+ agentStopped: true;
181
+ }, operation: Operation) => Promise<{
182
+ workspaceClosed: true;
183
+ }>;
184
+ };
185
+ export type HerdrAgentManager = ReturnType<typeof createHerdrAgentManager>;