@bastani/atomic 0.9.85 → 0.9.86
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/CHANGELOG.md +40 -0
- package/dist/builtin/intercom/CHANGELOG.md +34 -0
- package/dist/builtin/intercom/README.md +10 -9
- package/dist/builtin/intercom/broker/away-asks.ts +272 -0
- package/dist/builtin/intercom/broker/broker.ts +171 -9
- package/dist/builtin/intercom/broker/client.ts +5 -3
- package/dist/builtin/intercom/broker/held-reply-targets.ts +5 -0
- package/dist/builtin/intercom/broker/multinode-router.ts +16 -7
- package/dist/builtin/intercom/broker/paths.ts +5 -0
- package/dist/builtin/intercom/broker/pending-question-index.ts +124 -0
- package/dist/builtin/intercom/broker/released-asker-replies.ts +39 -0
- package/dist/builtin/intercom/broker/send-handler.ts +44 -3
- package/dist/builtin/intercom/broker/terminal-questions.ts +2 -0
- package/dist/builtin/intercom/index.bundle.mjs +799 -177
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/retry-policy.ts +1 -1
- package/dist/builtin/intercom/skills/intercom/SKILL.md +29 -35
- package/dist/builtin/intercom/types.ts +7 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +40 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +2765 -2719
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +24 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/authoring.d.ts +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +371 -193
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +358 -181
- package/dist/builtin/workflows/src/index.js +356 -183
- package/dist/builtin/workflows/src/local-worker-entry.mjs +358 -181
- package/dist/builtin/workflows/src/shared/worktree-restore-outcome.d.ts +16 -0
- package/dist/builtin/workflows/src/workers/workspace-binding.d.ts +13 -2
- package/dist/core/agent-session-methods.d.ts +1 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +2 -35
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +3 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +12 -5
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +14 -1
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +3 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/resume/index.d.ts +1 -1
- package/dist/core/resume/index.d.ts.map +1 -1
- package/dist/core/resume/index.js +1 -1
- package/dist/core/resume/index.js.map +1 -1
- package/dist/core/resume/path-mapping.d.ts +10 -0
- package/dist/core/resume/path-mapping.d.ts.map +1 -1
- package/dist/core/resume/path-mapping.js +20 -0
- package/dist/core/resume/path-mapping.js.map +1 -1
- package/dist/core/resume/session-resume.d.ts +5 -0
- package/dist/core/resume/session-resume.d.ts.map +1 -1
- package/dist/core/resume/session-resume.js +24 -9
- package/dist/core/resume/session-resume.js.map +1 -1
- package/dist/core/session-worktree-snapshots.d.ts +5 -8
- package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
- package/dist/core/session-worktree-snapshots.js +34 -99
- package/dist/core/session-worktree-snapshots.js.map +1 -1
- package/dist/core/skill-catalog.d.ts +11 -0
- package/dist/core/skill-catalog.d.ts.map +1 -1
- package/dist/core/skill-catalog.js +31 -0
- package/dist/core/skill-catalog.js.map +1 -1
- package/dist/core/tasks/agent-adapter.d.ts +2 -0
- package/dist/core/tasks/agent-adapter.d.ts.map +1 -1
- package/dist/core/tasks/agent-adapter.js +5 -1
- package/dist/core/tasks/agent-adapter.js.map +1 -1
- package/dist/core/tasks/supervisor.d.ts +17 -0
- package/dist/core/tasks/supervisor.d.ts.map +1 -1
- package/dist/core/tasks/supervisor.js +12 -6
- package/dist/core/tasks/supervisor.js.map +1 -1
- package/dist/core/tasks/task-view-source.d.ts +10 -0
- package/dist/core/tasks/task-view-source.d.ts.map +1 -1
- package/dist/core/tasks/task-view-source.js +24 -1
- package/dist/core/tasks/task-view-source.js.map +1 -1
- package/dist/core/worktree-snapshot/best-restore.d.ts +45 -0
- package/dist/core/worktree-snapshot/best-restore.d.ts.map +1 -0
- package/dist/core/worktree-snapshot/best-restore.js +92 -0
- package/dist/core/worktree-snapshot/best-restore.js.map +1 -0
- package/dist/core/worktree-snapshot/git.d.ts +2 -2
- package/dist/core/worktree-snapshot/git.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/git.js +2 -5
- package/dist/core/worktree-snapshot/git.js.map +1 -1
- package/dist/core/worktree-snapshot/index.d.ts +1 -0
- package/dist/core/worktree-snapshot/index.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/index.js +1 -0
- package/dist/core/worktree-snapshot/index.js.map +1 -1
- package/dist/core/worktree-snapshot/restore.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/restore.js +18 -2
- package/dist/core/worktree-snapshot/restore.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/chat-autocomplete.d.ts +7 -0
- package/dist/modes/interactive/chat-autocomplete.d.ts.map +1 -0
- package/dist/modes/interactive/chat-autocomplete.js +85 -0
- package/dist/modes/interactive/chat-autocomplete.js.map +1 -0
- package/dist/modes/interactive/components/task-transcript-page.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-transcript-page.js +8 -0
- package/dist/modes/interactive/components/task-transcript-page.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +3 -79
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
- package/dist/modes/interactive/skill-command-autocomplete.d.ts +6 -0
- package/dist/modes/interactive/skill-command-autocomplete.d.ts.map +1 -1
- package/dist/modes/interactive/skill-command-autocomplete.js +18 -2
- package/dist/modes/interactive/skill-command-autocomplete.js.map +1 -1
- package/docs/background-tasks.md +1 -1
- package/docs/intercom/operations.md +4 -4
- package/docs/intercom/reference.md +39 -8
- package/docs/intercom.md +26 -9
- package/docs/skills.md +3 -1
- package/docs/subagents.md +2 -0
- package/docs/workflows/api-reference.md +3 -3
- package/docs/workflows/operations.md +2 -2
- package/docs/worktree-snapshots.md +10 -4
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { CompactionReason } from "../agent-session.js";
|
|
3
|
+
import { type SkillCatalogCommand } from "../skill-catalog.ts";
|
|
3
4
|
import type { TaskId, TaskRecord } from "./contracts.js";
|
|
4
5
|
import type { OwnerTaskStore, TaskActivity } from "./owner-store.js";
|
|
5
6
|
import { type TaskTranscriptSource } from "./supervisor.js";
|
|
@@ -33,6 +34,13 @@ export interface TaskTranscriptFollow {
|
|
|
33
34
|
/** The transcript has no live tail; a view reads it again when the task changes. */
|
|
34
35
|
readonly historyOnly: boolean;
|
|
35
36
|
}
|
|
37
|
+
/** What a chat of an agent task completes, as plain data: its session's cwd and the skill commands it offers. */
|
|
38
|
+
export interface TaskCommandCatalog {
|
|
39
|
+
/** The working directory `@` and path completions resolve against. */
|
|
40
|
+
readonly cwd: string;
|
|
41
|
+
/** The session's `/skill:` commands; empty when its settings do not offer skills as commands. */
|
|
42
|
+
readonly skillCommands: readonly Pick<SkillCatalogCommand, "name" | "description" | "sourceInfo">[];
|
|
43
|
+
}
|
|
36
44
|
/** The prompt and latest reply of an agent task, for its detail page. */
|
|
37
45
|
export interface TaskDetailText {
|
|
38
46
|
readonly prompt?: string;
|
|
@@ -75,6 +83,8 @@ export interface TaskViewSource {
|
|
|
75
83
|
* messaged.
|
|
76
84
|
*/
|
|
77
85
|
sendTaskMessage?(id: TaskId, text: string): Promise<void>;
|
|
86
|
+
/** What a chat of an agent task completes: its session's cwd and skill commands. Absent where unknown. */
|
|
87
|
+
taskCommands?(id: TaskId): TaskCommandCatalog | undefined | Promise<TaskCommandCatalog | undefined>;
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
80
90
|
* The tasks `launcher` launched, from `source`: a subagent's own shells and the subagents it launched, as a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-view-source.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/task-view-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"task-view-source.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/task-view-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEnF,OAAO,KAAK,EAAe,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAEN,KAAK,oBAAoB,EAKzB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,MAAM,cAAc,CAAC,CAAC,IACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACxC;IAAE,QAAQ,CAAC,EAAE,EAAE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,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3D,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IACrE;;;;OAIG;IACH,eAAe,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,0GAA0G;IAC1G,YAAY,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC;CACpG;AASD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAwC/F;AAYD,kEAAkE;AAClE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc,CA8KzE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { sessionEntryToContextMessages } from "../session-manager-history.js";
|
|
3
|
+
import { expandSkillCommand } from "../skill-catalog.js";
|
|
3
4
|
import { taskOutputText } from "./command-output.js";
|
|
4
5
|
import { TaskMessageError, TaskMessageTimeoutError } from "./message-error.js";
|
|
5
6
|
import { taskExtensionStatuses, taskOwnTranscriptEntries, taskTranscriptSource, watchTaskExtensionStatuses, } from "./supervisor.js";
|
|
@@ -24,6 +25,7 @@ export function launchedTaskViewSource(source, launcher) {
|
|
|
24
25
|
return existing;
|
|
25
26
|
const launched = (tasks) => tasks.filter((task) => task.parentTaskId === launcher);
|
|
26
27
|
const sendTaskMessage = root.sendTaskMessage;
|
|
28
|
+
const taskCommands = root.taskCommands;
|
|
27
29
|
const view = {
|
|
28
30
|
get tasks() {
|
|
29
31
|
return launched(root.tasks);
|
|
@@ -50,6 +52,7 @@ export function launchedTaskViewSource(source, launcher) {
|
|
|
50
52
|
...(sendTaskMessage === undefined
|
|
51
53
|
? {}
|
|
52
54
|
: { sendTaskMessage: (id, text) => sendTaskMessage.call(root, id, text) }),
|
|
55
|
+
...(taskCommands === undefined ? {} : { taskCommands: (id) => taskCommands.call(root, id) }),
|
|
53
56
|
};
|
|
54
57
|
views.set(launcher, view);
|
|
55
58
|
launchedViewRoots.set(view, root);
|
|
@@ -199,6 +202,23 @@ export function ownerTaskViewSource(store) {
|
|
|
199
202
|
const task = lease(id);
|
|
200
203
|
return task.ok ? taskExtensionStatuses(task.value) : NO_STATUSES;
|
|
201
204
|
},
|
|
205
|
+
taskCommands(id) {
|
|
206
|
+
const task = lease(id);
|
|
207
|
+
const bound = task.ok ? taskTranscriptSource(task.value) : undefined;
|
|
208
|
+
const commands = bound?.ok ? bound.value.session.commands?.() : undefined;
|
|
209
|
+
if (commands === undefined)
|
|
210
|
+
return undefined;
|
|
211
|
+
return {
|
|
212
|
+
cwd: commands.cwd,
|
|
213
|
+
skillCommands: commands.skillCommandsEnabled
|
|
214
|
+
? commands.skills.commands.map(({ name, description, sourceInfo }) => ({
|
|
215
|
+
name,
|
|
216
|
+
description,
|
|
217
|
+
sourceInfo,
|
|
218
|
+
}))
|
|
219
|
+
: [],
|
|
220
|
+
};
|
|
221
|
+
},
|
|
202
222
|
watchExtensionStatuses(id, listener) {
|
|
203
223
|
const task = lease(id);
|
|
204
224
|
return task.ok ? watchTaskExtensionStatuses(task.value, listener) : () => { };
|
|
@@ -212,9 +232,12 @@ export function ownerTaskViewSource(store) {
|
|
|
212
232
|
const target = session?.completionSource?.intercomTarget;
|
|
213
233
|
if (session?.sendMessage === undefined || target === undefined)
|
|
214
234
|
throw new TaskMessageError("messages-unsupported", { taskId: id });
|
|
235
|
+
// The message reaches the task as Intercom text, which its session does not expand, so a skill command is
|
|
236
|
+
// expanded here from the task's own skills, as its session would expand it. A selector naming none is sent as typed.
|
|
237
|
+
const skills = session.commands?.().skills;
|
|
215
238
|
let delivery;
|
|
216
239
|
try {
|
|
217
|
-
delivery = await session.sendMessage(text);
|
|
240
|
+
delivery = await session.sendMessage(skills === undefined ? text : expandSkillCommand(skills, text));
|
|
218
241
|
}
|
|
219
242
|
catch (cause) {
|
|
220
243
|
throw new TaskMessageError("delivery-unconfirmed", { taskId: id, target }, { cause });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-view-source.js","sourceRoot":"","sources":["../../../src/core/tasks/task-view-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAAO,EAGN,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,GAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AA0E7D,MAAM,WAAW,GAAgC,IAAI,GAAG,EAAE,CAAC;AAC3D,MAAM,OAAO,GAAG,IAAI,OAAO,EAAkC,CAAC;AAC9D,4FAA4F;AAC5F,MAAM,aAAa,GAAG,IAAI,OAAO,EAA+C,CAAC;AACjF,8DAA8D;AAC9D,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAkC,CAAC;AAExE;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAsB,EAAE,QAAgB;IAC9E,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC;IACrD,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAA0B,CAAC;IAC3E,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAA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AAS,EAAE,QAAQ,CAAC,SAAS;iBAC7B,CAAC,CAAC;YACJ,MAAM,IAAI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,kBAAkB,EAAE;gBACpG,MAAM,EAAE,EAAE;gBACV,MAAM;gBACN,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;aACrE,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { CompactionReason } from \"../agent-session.js\";\nimport { sessionEntryToContextMessages } from \"../session-manager-history.ts\";\nimport { taskOutputText } from \"./command-output.js\";\nimport type { OperationId, TaskId, TaskRecord } from \"./contracts.js\";\nimport { TaskMessageError, TaskMessageTimeoutError } from \"./message-error.js\";\nimport type { OwnerTaskStore, TaskActivity } from \"./owner-store.js\";\nimport {\n\ttype TaskMessageDelivery,\n\ttype TaskTranscriptSource,\n\ttaskExtensionStatuses,\n\ttaskOwnTranscriptEntries,\n\ttaskTranscriptSource,\n\twatchTaskExtensionStatuses,\n} from \"./supervisor.js\";\nimport { readTaskTranscriptSnapshot } from \"./transcript.js\";\n\nexport type TaskViewResult<T> =\n\t| { readonly ok: true; readonly value: T }\n\t| { readonly ok: false; readonly error: { readonly message: string } };\n\n/** A retained slice of a shell task's output, as text. */\nexport interface TaskOutputView {\n\treadonly text: string;\n\t/** Some of the requested bytes are no longer retained. */\n\treadonly omitted: boolean;\n}\n\n/** One page of an agent task's transcript, oldest first. */\nexport interface TaskTranscriptView {\n\treadonly messages: readonly AgentMessage[];\n\t/** Cursor of the page before this one, when earlier messages are retained. */\n\treadonly nextCursor?: string;\n\t/** On the latest page: why the task's session is compacting at the time of the read. */\n\treadonly compactionReason?: CompactionReason;\n}\n\n/** How an open transcript of a task follows it: through its live session, or by reading it again. */\nexport interface TaskTranscriptFollow {\n\t/** The task's session in this process, when it publishes live updates. */\n\treadonly session?: TaskTranscriptSource;\n\t/** The transcript has no live tail; a view reads it again when the task changes. */\n\treadonly historyOnly: boolean;\n}\n\n/** The prompt and latest reply of an agent task, for its detail page. */\nexport interface TaskDetailText {\n\treadonly prompt?: string;\n\treadonly output?: string;\n}\n\n/**\n * What the task inspector and a chat's task footer read and do: a session's own task store, or\n * the tasks of a session that runs in another process (a workflow stage on a local worker). It\n * names tasks by id, so a view never holds a task lease.\n */\nexport interface TaskViewSource {\n\treadonly tasks: readonly TaskRecord[];\n\treadonly backgroundTasks: readonly TaskRecord[];\n\treadonly settlementOrder: ReadonlyMap<TaskId, bigint>;\n\trecentActivity(id: TaskId): TaskActivity[];\n\tactivityOmitted(id: TaskId): boolean;\n\tsubscribe(listener: () => void): () => void;\n\tforegroundTask(id: TaskId): Promise<TaskViewResult<{ readonly kind: string }>>;\n\t/** Asks the task to stop; a failed request says why. */\n\tcancelTask(id: TaskId): Promise<TaskViewResult<undefined>>;\n\tstdinAvailable(id: TaskId): boolean;\n\twriteTaskInput(id: TaskId, text: string): Promise<TaskViewResult<{ readonly acceptedBytes: number }>>;\n\treadTaskOutput(\n\t\tid: TaskId,\n\t\trange: { readonly start: string; readonly maximumBytes: number },\n\t): Promise<TaskViewResult<TaskOutputView>>;\n\t/** Synchronous where the task's session is in this process, so a view reads it in the same turn. */\n\ttaskDetailText(id: TaskId): TaskDetailText | Promise<TaskDetailText>;\n\treadTaskTranscript(\n\t\tid: TaskId,\n\t\tcursor?: string,\n\t): TaskViewResult<TaskTranscriptView> | Promise<TaskViewResult<TaskTranscriptView>>;\n\tfollowTaskTranscript(id: TaskId): TaskTranscriptFollow | undefined;\n\textensionStatuses(id: TaskId): ReadonlyMap<string, string>;\n\twatchExtensionStatuses(id: TaskId, listener: () => void): () => void;\n\t/**\n\t * Sends `text` to an agent task through its Intercom target, as a message typed into its transcript. Resolves\n\t * once the channel confirmed delivery; rejects with a {@link TaskMessageError}. Absent where tasks cannot be\n\t * messaged.\n\t */\n\tsendTaskMessage?(id: TaskId, text: string): Promise<void>;\n}\n\nconst NO_STATUSES: ReadonlyMap<string, string> = new Map();\nconst sources = new WeakMap<OwnerTaskStore, TaskViewSource>();\n/** Each launched-task view by the task that launched them, under the view of every task. */\nconst launchedViews = new WeakMap<TaskViewSource, Map<TaskId, TaskViewSource>>();\n/** The view of every task a launched-task view reads from. */\nconst launchedViewRoots = new WeakMap<TaskViewSource, TaskViewSource>();\n\n/**\n * The tasks `launcher` launched, from `source`: a subagent's own shells and the subagents it launched, as a\n * subagent's chat lists them. Every task action goes to `source`. A view of a nested subagent reads the same tasks as\n * its parent's view, and each task has one view, so a chat that compares its view keeps its open task list.\n */\nexport function launchedTaskViewSource(source: TaskViewSource, launcher: TaskId): TaskViewSource {\n\tconst root = launchedViewRoots.get(source) ?? source;\n\tconst views = launchedViews.get(root) ?? new Map<TaskId, TaskViewSource>();\n\tlaunchedViews.set(root, views);\n\tconst existing = views.get(launcher);\n\tif (existing !== undefined) return existing;\n\tconst launched = (tasks: readonly TaskRecord[]) => tasks.filter((task) => task.parentTaskId === launcher);\n\tconst sendTaskMessage = root.sendTaskMessage;\n\tconst view: TaskViewSource = {\n\t\tget tasks() {\n\t\t\treturn launched(root.tasks);\n\t\t},\n\t\tget backgroundTasks() {\n\t\t\treturn launched(root.backgroundTasks);\n\t\t},\n\t\tget settlementOrder() {\n\t\t\treturn root.settlementOrder;\n\t\t},\n\t\trecentActivity: (id) => root.recentActivity(id),\n\t\tactivityOmitted: (id) => root.activityOmitted(id),\n\t\tsubscribe: (listener) => root.subscribe(listener),\n\t\tforegroundTask: (id) => root.foregroundTask(id),\n\t\tcancelTask: (id) => root.cancelTask(id),\n\t\tstdinAvailable: (id) => root.stdinAvailable(id),\n\t\twriteTaskInput: (id, text) => root.writeTaskInput(id, text),\n\t\treadTaskOutput: (id, range) => root.readTaskOutput(id, range),\n\t\ttaskDetailText: (id) => root.taskDetailText(id),\n\t\treadTaskTranscript: (id, cursor) => root.readTaskTranscript(id, cursor),\n\t\tfollowTaskTranscript: (id) => root.followTaskTranscript(id),\n\t\textensionStatuses: (id) => root.extensionStatuses(id),\n\t\twatchExtensionStatuses: (id, listener) => root.watchExtensionStatuses(id, listener),\n\t\t...(sendTaskMessage === undefined\n\t\t\t? {}\n\t\t\t: { sendTaskMessage: (id: TaskId, text: string) => sendTaskMessage.call(root, id, text) }),\n\t};\n\tviews.set(launcher, view);\n\tlaunchedViewRoots.set(view, root);\n\treturn view;\n}\n\nfunction messageText(message: AgentMessage): string | undefined {\n\tif (message.role !== \"user\" && message.role !== \"assistant\") return undefined;\n\tconst content = message.content;\n\tif (typeof content === \"string\") return content;\n\treturn content\n\t\t.filter((block): block is Extract<typeof block, { type: \"text\" }> => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\");\n}\n\n/** The task view of a session's own task store; one per store. */\nexport function ownerTaskViewSource(store: OwnerTaskStore): TaskViewSource {\n\tconst existing = sources.get(store);\n\tif (existing !== undefined) return existing;\n\tconst lease = (id: TaskId) => store.resolveTask(id);\n\tconst source: TaskViewSource = {\n\t\tget tasks() {\n\t\t\treturn store.tasks;\n\t\t},\n\t\tget backgroundTasks() {\n\t\t\treturn store.backgroundTasks;\n\t\t},\n\t\tget settlementOrder() {\n\t\t\treturn store.settlementOrder;\n\t\t},\n\t\trecentActivity: (id) => store.recentActivity(id),\n\t\tactivityOmitted: (id) => store.activityOmitted(id),\n\t\tsubscribe: (listener) => store.subscribe(listener),\n\t\tasync foregroundTask(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst result = await store.supervisor.foregroundTask(task.value);\n\t\t\treturn result.ok\n\t\t\t\t? { ok: true, value: { kind: result.value.kind } }\n\t\t\t\t: { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tasync cancelTask(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst result = await store.supervisor.cancelTask(task.value, \"user\");\n\t\t\treturn result.ok ? { ok: true, value: undefined } : { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tstdinAvailable(id) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok && store.supervisor.taskStdin(task.value).ok;\n\t\t},\n\t\tasync writeTaskInput(id, text) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst stdin = store.supervisor.taskStdin(task.value);\n\t\t\tif (!stdin.ok) return { ok: false, error: { message: stdin.error.message } };\n\t\t\tconst result = await store.supervisor.writeTaskInput(stdin.value, randomUUID() as OperationId, {\n\t\t\t\tkind: \"bytes\",\n\t\t\t\tbytes: Buffer.from(`${text}\\n`),\n\t\t\t});\n\t\t\treturn result.ok\n\t\t\t\t? { ok: true, value: { acceptedBytes: result.value.acceptedBytes } }\n\t\t\t\t: { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tasync readTaskOutput(id, range) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst page = await store.supervisor.readTaskOutput(task.value, {\n\t\t\t\tstart: range.start,\n\t\t\t\tmaximumBytes: range.maximumBytes,\n\t\t\t});\n\t\t\treturn page.ok\n\t\t\t\t? { ok: true, value: { text: taskOutputText(page.value), omitted: page.value.omittedRanges.length > 0 } }\n\t\t\t\t: { ok: false, error: { message: page.error.message } };\n\t\t},\n\t\ttaskDetailText(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return {};\n\t\t\tconst entries = taskOwnTranscriptEntries(task.value);\n\t\t\tif (entries === undefined) return {};\n\t\t\tconst messages = entries.flatMap((entry) => (entry.type === \"message\" ? [entry.message] : []));\n\t\t\tconst prompt = messages.find((message) => message.role === \"user\");\n\t\t\tconst response = messages\n\t\t\t\t.slice()\n\t\t\t\t.reverse()\n\t\t\t\t.find((message) => message.role === \"assistant\");\n\t\t\tconst promptText = prompt === undefined ? undefined : messageText(prompt);\n\t\t\tconst outputText = response === undefined ? undefined : messageText(response);\n\t\t\treturn {\n\t\t\t\t...(promptText === undefined ? {} : { prompt: promptText }),\n\t\t\t\t...(outputText === undefined ? {} : { output: outputText }),\n\t\t\t};\n\t\t},\n\t\treadTaskTranscript(id, cursor) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst page = readTaskTranscriptSnapshot(task.value, cursor);\n\t\t\tconst bound = taskTranscriptSource(task.value);\n\t\t\tif (!bound.ok || (!page.ok && !bound.value.session.subscribe))\n\t\t\t\treturn { ok: false, error: { message: \"Transcript unavailable\" } };\n\t\t\tconst items = page.ok ? page.value.items : [];\n\t\t\tconst entryIds = new Set(items.map((item) => item.source.entryId));\n\t\t\tconst itemIds = new Set(items.map((item) => item.id));\n\t\t\tconst messages = bound.value.session.getEntries().flatMap<AgentMessage>((entry) => {\n\t\t\t\tif (!entryIds.has(entry.id)) return [];\n\t\t\t\tif (entry.type !== \"message\") return sessionEntryToContextMessages(entry);\n\t\t\t\tconst message = entry.message;\n\t\t\t\tif (message.role === \"assistant\")\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...message,\n\t\t\t\t\t\t\tcontent: message.content.filter((_, index) => itemIds.has(`${entry.id}:${index}`)),\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\treturn message.role === \"user\" || message.role === \"toolResult\" ? [message] : [];\n\t\t\t});\n\t\t\tconst compactionReason = cursor === undefined ? bound.value.session.getCompactionReason?.() : undefined;\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tvalue: {\n\t\t\t\t\tmessages,\n\t\t\t\t\t...(page.ok && page.value.nextCursor !== undefined ? { nextCursor: page.value.nextCursor } : {}),\n\t\t\t\t\t...(compactionReason === undefined ? {} : { compactionReason }),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tfollowTaskTranscript(id) {\n\t\t\tconst task = lease(id);\n\t\t\tconst bound = task.ok ? taskTranscriptSource(task.value) : undefined;\n\t\t\tif (!bound?.ok) return undefined;\n\t\t\treturn { session: bound.value.session, historyOnly: bound.value.session.subscribe === undefined };\n\t\t},\n\t\textensionStatuses(id) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok ? taskExtensionStatuses(task.value) : NO_STATUSES;\n\t\t},\n\t\twatchExtensionStatuses(id, listener) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok ? watchTaskExtensionStatuses(task.value, listener) : () => {};\n\t\t},\n\t\tasync sendTaskMessage(id, text) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) throw new TaskMessageError(\"task-unavailable\", { taskId: id });\n\t\t\tconst bound = taskTranscriptSource(task.value);\n\t\t\tconst session = bound.ok ? bound.value.session : undefined;\n\t\t\tconst target = session?.completionSource?.intercomTarget;\n\t\t\tif (session?.sendMessage === undefined || target === undefined)\n\t\t\t\tthrow new TaskMessageError(\"messages-unsupported\", { taskId: id });\n\t\t\tlet delivery: TaskMessageDelivery;\n\t\t\ttry {\n\t\t\t\tdelivery = await session.sendMessage(text);\n\t\t\t} catch (cause) {\n\t\t\t\tthrow new TaskMessageError(\"delivery-unconfirmed\", { taskId: id, target }, { cause });\n\t\t\t}\n\t\t\tif (delivery.delivered) return;\n\t\t\tif (delivery.reason === \"unconfirmed\")\n\t\t\t\tthrow new TaskMessageTimeoutError({\n\t\t\t\t\ttaskId: id,\n\t\t\t\t\ttarget,\n\t\t\t\t\ttimeoutMs: delivery.timeoutMs,\n\t\t\t\t\telapsedMs: delivery.elapsedMs,\n\t\t\t\t});\n\t\t\tthrow new TaskMessageError(delivery.reason === \"lost\" ? \"delivery-unconfirmed\" : \"delivery-refused\", {\n\t\t\t\ttaskId: id,\n\t\t\t\ttarget,\n\t\t\t\t...(delivery.detail === undefined ? {} : { detail: delivery.detail }),\n\t\t\t});\n\t\t},\n\t};\n\tsources.set(store, source);\n\treturn source;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"task-view-source.js","sourceRoot":"","sources":["../../../src/core/tasks/task-view-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAA4B,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAAO,EAGN,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,GAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAoF7D,MAAM,WAAW,GAAgC,IAAI,GAAG,EAAE,CAAC;AAC3D,MAAM,OAAO,GAAG,IAAI,OAAO,EAAkC,CAAC;AAC9D,4FAA4F;AAC5F,MAAM,aAAa,GAAG,IAAI,OAAO,EAA+C,CAAC;AACjF,8DAA8D;AAC9D,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAkC,CAAC;AAExE;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAsB,EAAE,QAAgB;IAC9E,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC;IACrD,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAA0B,CAAC;IAC3E,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE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QAAQ,CAAC,SAAS;iBAC7B,CAAC,CAAC;YACJ,MAAM,IAAI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,kBAAkB,EAAE;gBACpG,MAAM,EAAE,EAAE;gBACV,MAAM;gBACN,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;aACrE,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { CompactionReason } from \"../agent-session.js\";\nimport { sessionEntryToContextMessages } from \"../session-manager-history.ts\";\nimport { expandSkillCommand, type SkillCatalogCommand } from \"../skill-catalog.ts\";\nimport { taskOutputText } from \"./command-output.js\";\nimport type { OperationId, TaskId, TaskRecord } from \"./contracts.js\";\nimport { TaskMessageError, TaskMessageTimeoutError } from \"./message-error.js\";\nimport type { OwnerTaskStore, TaskActivity } from \"./owner-store.js\";\nimport {\n\ttype TaskMessageDelivery,\n\ttype TaskTranscriptSource,\n\ttaskExtensionStatuses,\n\ttaskOwnTranscriptEntries,\n\ttaskTranscriptSource,\n\twatchTaskExtensionStatuses,\n} from \"./supervisor.js\";\nimport { readTaskTranscriptSnapshot } from \"./transcript.js\";\n\nexport type TaskViewResult<T> =\n\t| { readonly ok: true; readonly value: T }\n\t| { readonly ok: false; readonly error: { readonly message: string } };\n\n/** A retained slice of a shell task's output, as text. */\nexport interface TaskOutputView {\n\treadonly text: string;\n\t/** Some of the requested bytes are no longer retained. */\n\treadonly omitted: boolean;\n}\n\n/** One page of an agent task's transcript, oldest first. */\nexport interface TaskTranscriptView {\n\treadonly messages: readonly AgentMessage[];\n\t/** Cursor of the page before this one, when earlier messages are retained. */\n\treadonly nextCursor?: string;\n\t/** On the latest page: why the task's session is compacting at the time of the read. */\n\treadonly compactionReason?: CompactionReason;\n}\n\n/** How an open transcript of a task follows it: through its live session, or by reading it again. */\nexport interface TaskTranscriptFollow {\n\t/** The task's session in this process, when it publishes live updates. */\n\treadonly session?: TaskTranscriptSource;\n\t/** The transcript has no live tail; a view reads it again when the task changes. */\n\treadonly historyOnly: boolean;\n}\n\n/** What a chat of an agent task completes, as plain data: its session's cwd and the skill commands it offers. */\nexport interface TaskCommandCatalog {\n\t/** The working directory `@` and path completions resolve against. */\n\treadonly cwd: string;\n\t/** The session's `/skill:` commands; empty when its settings do not offer skills as commands. */\n\treadonly skillCommands: readonly Pick<SkillCatalogCommand, \"name\" | \"description\" | \"sourceInfo\">[];\n}\n\n/** The prompt and latest reply of an agent task, for its detail page. */\nexport interface TaskDetailText {\n\treadonly prompt?: string;\n\treadonly output?: string;\n}\n\n/**\n * What the task inspector and a chat's task footer read and do: a session's own task store, or\n * the tasks of a session that runs in another process (a workflow stage on a local worker). It\n * names tasks by id, so a view never holds a task lease.\n */\nexport interface TaskViewSource {\n\treadonly tasks: readonly TaskRecord[];\n\treadonly backgroundTasks: readonly TaskRecord[];\n\treadonly settlementOrder: ReadonlyMap<TaskId, bigint>;\n\trecentActivity(id: TaskId): TaskActivity[];\n\tactivityOmitted(id: TaskId): boolean;\n\tsubscribe(listener: () => void): () => void;\n\tforegroundTask(id: TaskId): Promise<TaskViewResult<{ readonly kind: string }>>;\n\t/** Asks the task to stop; a failed request says why. */\n\tcancelTask(id: TaskId): Promise<TaskViewResult<undefined>>;\n\tstdinAvailable(id: TaskId): boolean;\n\twriteTaskInput(id: TaskId, text: string): Promise<TaskViewResult<{ readonly acceptedBytes: number }>>;\n\treadTaskOutput(\n\t\tid: TaskId,\n\t\trange: { readonly start: string; readonly maximumBytes: number },\n\t): Promise<TaskViewResult<TaskOutputView>>;\n\t/** Synchronous where the task's session is in this process, so a view reads it in the same turn. */\n\ttaskDetailText(id: TaskId): TaskDetailText | Promise<TaskDetailText>;\n\treadTaskTranscript(\n\t\tid: TaskId,\n\t\tcursor?: string,\n\t): TaskViewResult<TaskTranscriptView> | Promise<TaskViewResult<TaskTranscriptView>>;\n\tfollowTaskTranscript(id: TaskId): TaskTranscriptFollow | undefined;\n\textensionStatuses(id: TaskId): ReadonlyMap<string, string>;\n\twatchExtensionStatuses(id: TaskId, listener: () => void): () => void;\n\t/**\n\t * Sends `text` to an agent task through its Intercom target, as a message typed into its transcript. Resolves\n\t * once the channel confirmed delivery; rejects with a {@link TaskMessageError}. Absent where tasks cannot be\n\t * messaged.\n\t */\n\tsendTaskMessage?(id: TaskId, text: string): Promise<void>;\n\t/** What a chat of an agent task completes: its session's cwd and skill commands. Absent where unknown. */\n\ttaskCommands?(id: TaskId): TaskCommandCatalog | undefined | Promise<TaskCommandCatalog | undefined>;\n}\n\nconst NO_STATUSES: ReadonlyMap<string, string> = new Map();\nconst sources = new WeakMap<OwnerTaskStore, TaskViewSource>();\n/** Each launched-task view by the task that launched them, under the view of every task. */\nconst launchedViews = new WeakMap<TaskViewSource, Map<TaskId, TaskViewSource>>();\n/** The view of every task a launched-task view reads from. */\nconst launchedViewRoots = new WeakMap<TaskViewSource, TaskViewSource>();\n\n/**\n * The tasks `launcher` launched, from `source`: a subagent's own shells and the subagents it launched, as a\n * subagent's chat lists them. Every task action goes to `source`. A view of a nested subagent reads the same tasks as\n * its parent's view, and each task has one view, so a chat that compares its view keeps its open task list.\n */\nexport function launchedTaskViewSource(source: TaskViewSource, launcher: TaskId): TaskViewSource {\n\tconst root = launchedViewRoots.get(source) ?? source;\n\tconst views = launchedViews.get(root) ?? new Map<TaskId, TaskViewSource>();\n\tlaunchedViews.set(root, views);\n\tconst existing = views.get(launcher);\n\tif (existing !== undefined) return existing;\n\tconst launched = (tasks: readonly TaskRecord[]) => tasks.filter((task) => task.parentTaskId === launcher);\n\tconst sendTaskMessage = root.sendTaskMessage;\n\tconst taskCommands = root.taskCommands;\n\tconst view: TaskViewSource = {\n\t\tget tasks() {\n\t\t\treturn launched(root.tasks);\n\t\t},\n\t\tget backgroundTasks() {\n\t\t\treturn launched(root.backgroundTasks);\n\t\t},\n\t\tget settlementOrder() {\n\t\t\treturn root.settlementOrder;\n\t\t},\n\t\trecentActivity: (id) => root.recentActivity(id),\n\t\tactivityOmitted: (id) => root.activityOmitted(id),\n\t\tsubscribe: (listener) => root.subscribe(listener),\n\t\tforegroundTask: (id) => root.foregroundTask(id),\n\t\tcancelTask: (id) => root.cancelTask(id),\n\t\tstdinAvailable: (id) => root.stdinAvailable(id),\n\t\twriteTaskInput: (id, text) => root.writeTaskInput(id, text),\n\t\treadTaskOutput: (id, range) => root.readTaskOutput(id, range),\n\t\ttaskDetailText: (id) => root.taskDetailText(id),\n\t\treadTaskTranscript: (id, cursor) => root.readTaskTranscript(id, cursor),\n\t\tfollowTaskTranscript: (id) => root.followTaskTranscript(id),\n\t\textensionStatuses: (id) => root.extensionStatuses(id),\n\t\twatchExtensionStatuses: (id, listener) => root.watchExtensionStatuses(id, listener),\n\t\t...(sendTaskMessage === undefined\n\t\t\t? {}\n\t\t\t: { sendTaskMessage: (id: TaskId, text: string) => sendTaskMessage.call(root, id, text) }),\n\t\t...(taskCommands === undefined ? {} : { taskCommands: (id: TaskId) => taskCommands.call(root, id) }),\n\t};\n\tviews.set(launcher, view);\n\tlaunchedViewRoots.set(view, root);\n\treturn view;\n}\n\nfunction messageText(message: AgentMessage): string | undefined {\n\tif (message.role !== \"user\" && message.role !== \"assistant\") return undefined;\n\tconst content = message.content;\n\tif (typeof content === \"string\") return content;\n\treturn content\n\t\t.filter((block): block is Extract<typeof block, { type: \"text\" }> => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\");\n}\n\n/** The task view of a session's own task store; one per store. */\nexport function ownerTaskViewSource(store: OwnerTaskStore): TaskViewSource {\n\tconst existing = sources.get(store);\n\tif (existing !== undefined) return existing;\n\tconst lease = (id: TaskId) => store.resolveTask(id);\n\tconst source: TaskViewSource = {\n\t\tget tasks() {\n\t\t\treturn store.tasks;\n\t\t},\n\t\tget backgroundTasks() {\n\t\t\treturn store.backgroundTasks;\n\t\t},\n\t\tget settlementOrder() {\n\t\t\treturn store.settlementOrder;\n\t\t},\n\t\trecentActivity: (id) => store.recentActivity(id),\n\t\tactivityOmitted: (id) => store.activityOmitted(id),\n\t\tsubscribe: (listener) => store.subscribe(listener),\n\t\tasync foregroundTask(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst result = await store.supervisor.foregroundTask(task.value);\n\t\t\treturn result.ok\n\t\t\t\t? { ok: true, value: { kind: result.value.kind } }\n\t\t\t\t: { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tasync cancelTask(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst result = await store.supervisor.cancelTask(task.value, \"user\");\n\t\t\treturn result.ok ? { ok: true, value: undefined } : { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tstdinAvailable(id) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok && store.supervisor.taskStdin(task.value).ok;\n\t\t},\n\t\tasync writeTaskInput(id, text) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst stdin = store.supervisor.taskStdin(task.value);\n\t\t\tif (!stdin.ok) return { ok: false, error: { message: stdin.error.message } };\n\t\t\tconst result = await store.supervisor.writeTaskInput(stdin.value, randomUUID() as OperationId, {\n\t\t\t\tkind: \"bytes\",\n\t\t\t\tbytes: Buffer.from(`${text}\\n`),\n\t\t\t});\n\t\t\treturn result.ok\n\t\t\t\t? { ok: true, value: { acceptedBytes: result.value.acceptedBytes } }\n\t\t\t\t: { ok: false, error: { message: result.error.message } };\n\t\t},\n\t\tasync readTaskOutput(id, range) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst page = await store.supervisor.readTaskOutput(task.value, {\n\t\t\t\tstart: range.start,\n\t\t\t\tmaximumBytes: range.maximumBytes,\n\t\t\t});\n\t\t\treturn page.ok\n\t\t\t\t? { ok: true, value: { text: taskOutputText(page.value), omitted: page.value.omittedRanges.length > 0 } }\n\t\t\t\t: { ok: false, error: { message: page.error.message } };\n\t\t},\n\t\ttaskDetailText(id) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return {};\n\t\t\tconst entries = taskOwnTranscriptEntries(task.value);\n\t\t\tif (entries === undefined) return {};\n\t\t\tconst messages = entries.flatMap((entry) => (entry.type === \"message\" ? [entry.message] : []));\n\t\t\tconst prompt = messages.find((message) => message.role === \"user\");\n\t\t\tconst response = messages\n\t\t\t\t.slice()\n\t\t\t\t.reverse()\n\t\t\t\t.find((message) => message.role === \"assistant\");\n\t\t\tconst promptText = prompt === undefined ? undefined : messageText(prompt);\n\t\t\tconst outputText = response === undefined ? undefined : messageText(response);\n\t\t\treturn {\n\t\t\t\t...(promptText === undefined ? {} : { prompt: promptText }),\n\t\t\t\t...(outputText === undefined ? {} : { output: outputText }),\n\t\t\t};\n\t\t},\n\t\treadTaskTranscript(id, cursor) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) return { ok: false, error: { message: task.error.message } };\n\t\t\tconst page = readTaskTranscriptSnapshot(task.value, cursor);\n\t\t\tconst bound = taskTranscriptSource(task.value);\n\t\t\tif (!bound.ok || (!page.ok && !bound.value.session.subscribe))\n\t\t\t\treturn { ok: false, error: { message: \"Transcript unavailable\" } };\n\t\t\tconst items = page.ok ? page.value.items : [];\n\t\t\tconst entryIds = new Set(items.map((item) => item.source.entryId));\n\t\t\tconst itemIds = new Set(items.map((item) => item.id));\n\t\t\tconst messages = bound.value.session.getEntries().flatMap<AgentMessage>((entry) => {\n\t\t\t\tif (!entryIds.has(entry.id)) return [];\n\t\t\t\tif (entry.type !== \"message\") return sessionEntryToContextMessages(entry);\n\t\t\t\tconst message = entry.message;\n\t\t\t\tif (message.role === \"assistant\")\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...message,\n\t\t\t\t\t\t\tcontent: message.content.filter((_, index) => itemIds.has(`${entry.id}:${index}`)),\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\treturn message.role === \"user\" || message.role === \"toolResult\" ? [message] : [];\n\t\t\t});\n\t\t\tconst compactionReason = cursor === undefined ? bound.value.session.getCompactionReason?.() : undefined;\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tvalue: {\n\t\t\t\t\tmessages,\n\t\t\t\t\t...(page.ok && page.value.nextCursor !== undefined ? { nextCursor: page.value.nextCursor } : {}),\n\t\t\t\t\t...(compactionReason === undefined ? {} : { compactionReason }),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tfollowTaskTranscript(id) {\n\t\t\tconst task = lease(id);\n\t\t\tconst bound = task.ok ? taskTranscriptSource(task.value) : undefined;\n\t\t\tif (!bound?.ok) return undefined;\n\t\t\treturn { session: bound.value.session, historyOnly: bound.value.session.subscribe === undefined };\n\t\t},\n\t\textensionStatuses(id) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok ? taskExtensionStatuses(task.value) : NO_STATUSES;\n\t\t},\n\t\ttaskCommands(id) {\n\t\t\tconst task = lease(id);\n\t\t\tconst bound = task.ok ? taskTranscriptSource(task.value) : undefined;\n\t\t\tconst commands = bound?.ok ? bound.value.session.commands?.() : undefined;\n\t\t\tif (commands === undefined) return undefined;\n\t\t\treturn {\n\t\t\t\tcwd: commands.cwd,\n\t\t\t\tskillCommands: commands.skillCommandsEnabled\n\t\t\t\t\t? commands.skills.commands.map(({ name, description, sourceInfo }) => ({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\tsourceInfo,\n\t\t\t\t\t\t}))\n\t\t\t\t\t: [],\n\t\t\t};\n\t\t},\n\t\twatchExtensionStatuses(id, listener) {\n\t\t\tconst task = lease(id);\n\t\t\treturn task.ok ? watchTaskExtensionStatuses(task.value, listener) : () => {};\n\t\t},\n\t\tasync sendTaskMessage(id, text) {\n\t\t\tconst task = lease(id);\n\t\t\tif (!task.ok) throw new TaskMessageError(\"task-unavailable\", { taskId: id });\n\t\t\tconst bound = taskTranscriptSource(task.value);\n\t\t\tconst session = bound.ok ? bound.value.session : undefined;\n\t\t\tconst target = session?.completionSource?.intercomTarget;\n\t\t\tif (session?.sendMessage === undefined || target === undefined)\n\t\t\t\tthrow new TaskMessageError(\"messages-unsupported\", { taskId: id });\n\t\t\t// The message reaches the task as Intercom text, which its session does not expand, so a skill command is\n\t\t\t// expanded here from the task's own skills, as its session would expand it. A selector naming none is sent as typed.\n\t\t\tconst skills = session.commands?.().skills;\n\t\t\tlet delivery: TaskMessageDelivery;\n\t\t\ttry {\n\t\t\t\tdelivery = await session.sendMessage(skills === undefined ? text : expandSkillCommand(skills, text));\n\t\t\t} catch (cause) {\n\t\t\t\tthrow new TaskMessageError(\"delivery-unconfirmed\", { taskId: id, target }, { cause });\n\t\t\t}\n\t\t\tif (delivery.delivered) return;\n\t\t\tif (delivery.reason === \"unconfirmed\")\n\t\t\t\tthrow new TaskMessageTimeoutError({\n\t\t\t\t\ttaskId: id,\n\t\t\t\t\ttarget,\n\t\t\t\t\ttimeoutMs: delivery.timeoutMs,\n\t\t\t\t\telapsedMs: delivery.elapsedMs,\n\t\t\t\t});\n\t\t\tthrow new TaskMessageError(delivery.reason === \"lost\" ? \"delivery-unconfirmed\" : \"delivery-refused\", {\n\t\t\t\ttaskId: id,\n\t\t\t\ttarget,\n\t\t\t\t...(delivery.detail === undefined ? {} : { detail: delivery.detail }),\n\t\t\t});\n\t\t},\n\t};\n\tsources.set(store, source);\n\treturn source;\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type RestoreDegradedWorktreeOptions, type RestoredWorktree, type RestoreWorktreeSnapshotOptions } from "./restore.ts";
|
|
2
|
+
import type { WorkspaceBinding, WorktreeDegradedRestore, WorktreeRestoreWarning, WorktreeSnapshot, WorktreeUnrestored } from "./types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a failed restore of one checkout leaves the resume able to continue without the exact state (#4733): any
|
|
5
|
+
* typed workspace or Git failure, except a snapshot record that fails the security checks (`invalid-snapshot`) and a
|
|
6
|
+
* target that holds other files (`unsafe-target`), which refuse the resume.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isRecoverableRestoreFailure(error: unknown): error is Error;
|
|
9
|
+
export interface RestoreBestWorktreeOptions extends RestoreDegradedWorktreeOptions {
|
|
10
|
+
/** What the exact restore rebuilds: `snapshot` itself (the default), or a binding found among `snapshots`. */
|
|
11
|
+
readonly target?: WorkspaceBinding;
|
|
12
|
+
/** Recorded snapshots the exact restore of `target` searches. */
|
|
13
|
+
readonly snapshots?: readonly WorktreeSnapshot[];
|
|
14
|
+
/** What restores exactly instead of `restoreWorktree`. */
|
|
15
|
+
readonly restore?: (target: WorkspaceBinding | WorktreeSnapshot, options: RestoreWorktreeSnapshotOptions) => Promise<Pick<RestoredWorktree, "path"> & Partial<Pick<RestoredWorktree, "warnings">>>;
|
|
16
|
+
}
|
|
17
|
+
/** The best restore of a checkout this host could make (#4733, #4738). */
|
|
18
|
+
export type BestWorktreeRestore = {
|
|
19
|
+
readonly status: "restored";
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly warnings: readonly WorktreeRestoreWarning[];
|
|
22
|
+
/** Present when the worktree holds less than the snapshot: what it holds and what is missing. */
|
|
23
|
+
readonly degraded?: WorktreeDegradedRestore;
|
|
24
|
+
}
|
|
25
|
+
/** Nothing of the snapshot could be restored here; `reason` says why. Nothing was written. */
|
|
26
|
+
| {
|
|
27
|
+
readonly status: "unrestored";
|
|
28
|
+
readonly reason: Error;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Restores `snapshot` into a new worktree as well as this host can (#4733): exactly; else, after a failure a degraded
|
|
32
|
+
* restore can follow, its recorded `HEAD` with the change sets that apply, or the closest commit it can fetch; else
|
|
33
|
+
* nothing, resolving `unrestored` with the exact restore's failure. Rejects with a failure that is not recoverable
|
|
34
|
+
* (`invalid-snapshot`, `unsafe-target`, or an error that is not a typed workspace or Git failure), and, once `signal`
|
|
35
|
+
* aborted, with the failure the abort caused.
|
|
36
|
+
*/
|
|
37
|
+
export declare function restoreBestWorktree(snapshot: WorktreeSnapshot, options?: RestoreBestWorktreeOptions): Promise<BestWorktreeRestore>;
|
|
38
|
+
/** What a resume tells about a checkout it continued without: why, as a clause, and what to do. */
|
|
39
|
+
export declare function unrestoredReason(snapshot: WorktreeSnapshot, reason: Error): {
|
|
40
|
+
detail: string;
|
|
41
|
+
hint: string;
|
|
42
|
+
};
|
|
43
|
+
/** The record of a checkout a resume continued without, in `continuedIn`, because of `reason` (#4733). */
|
|
44
|
+
export declare function unrestoredRecord(snapshot: WorktreeSnapshot, reason: Error, continuedIn: string, place: WorktreeUnrestored["place"], at?: string): WorktreeUnrestored;
|
|
45
|
+
//# sourceMappingURL=best-restore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"best-restore.d.ts","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/best-restore.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,8BAA8B,EAGnC,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACX,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAK1E;AAED,MAAM,WAAW,0BAA2B,S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,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC,EAClC,EAAE,SAA2B,GAC3B,kBAAkB,CAUpB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isGitUnavailableError, isWorkspaceError, isWorkspaceRestoreError } from "./errors.js";
|
|
2
|
+
import { isDegradableRestoreFailure, restoreDegradedWorktree, restoreWorktree, } from "./restore.js";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a failed restore of one checkout leaves the resume able to continue without the exact state (#4733): any
|
|
5
|
+
* typed workspace or Git failure, except a snapshot record that fails the security checks (`invalid-snapshot`) and a
|
|
6
|
+
* target that holds other files (`unsafe-target`), which refuse the resume.
|
|
7
|
+
*/
|
|
8
|
+
export function isRecoverableRestoreFailure(error) {
|
|
9
|
+
if (isWorkspaceRestoreError(error) && (error.code === "invalid-snapshot" || error.code === "unsafe-target")) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return (isWorkspaceError(error) && error.code !== "invalid-setting") || isGitUnavailableError(error);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Restores `snapshot` into a new worktree as well as this host can (#4733): exactly; else, after a failure a degraded
|
|
16
|
+
* restore can follow, its recorded `HEAD` with the change sets that apply, or the closest commit it can fetch; else
|
|
17
|
+
* nothing, resolving `unrestored` with the exact restore's failure. Rejects with a failure that is not recoverable
|
|
18
|
+
* (`invalid-snapshot`, `unsafe-target`, or an error that is not a typed workspace or Git failure), and, once `signal`
|
|
19
|
+
* aborted, with the failure the abort caused.
|
|
20
|
+
*/
|
|
21
|
+
export async function restoreBestWorktree(snapshot, options = {}) {
|
|
22
|
+
const { target, snapshots, restore = restoreWorktree, candidates, ...shared } = options;
|
|
23
|
+
try {
|
|
24
|
+
const exact = await restore(target ?? snapshot, { ...shared, ...(snapshots === undefined ? {} : { snapshots }) });
|
|
25
|
+
return { status: "restored", path: exact.path, warnings: exact.warnings ?? [] };
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (options.signal?.aborted || !isRecoverableRestoreFailure(error))
|
|
29
|
+
throw error;
|
|
30
|
+
if (isDegradableRestoreFailure(error)) {
|
|
31
|
+
try {
|
|
32
|
+
const degraded = await restoreDegradedWorktree(snapshot, error, {
|
|
33
|
+
...shared,
|
|
34
|
+
...(candidates === undefined ? {} : { candidates }),
|
|
35
|
+
});
|
|
36
|
+
return { status: "restored", ...degraded };
|
|
37
|
+
}
|
|
38
|
+
catch (degradedError) {
|
|
39
|
+
if (options.signal?.aborted || !isRecoverableRestoreFailure(degradedError))
|
|
40
|
+
throw degradedError;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { status: "unrestored", reason: error };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** What a resume tells about a checkout it continued without: why, as a clause, and what to do. */
|
|
47
|
+
export function unrestoredReason(snapshot, reason) {
|
|
48
|
+
const head = snapshot.head.slice(0, 12);
|
|
49
|
+
if (isGitUnavailableError(reason)) {
|
|
50
|
+
return {
|
|
51
|
+
detail: `Git is unavailable here (${reason.code}), which checking and restoring it need`,
|
|
52
|
+
hint: reason.hint ?? "",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (isWorkspaceRestoreError(reason)) {
|
|
56
|
+
switch (reason.code) {
|
|
57
|
+
case "commits-unavailable":
|
|
58
|
+
return {
|
|
59
|
+
detail: reason.reason === "denied-history"
|
|
60
|
+
? `its commit ${head} is not on its recorded remotes, and its unpushed commits touch files snapshots never copy`
|
|
61
|
+
: reason.reason === "bundle-over-cap"
|
|
62
|
+
? `its commit ${head} is not on its recorded remotes, and its unpushed commits were too large to record`
|
|
63
|
+
: `its commit ${head} and the commits around it are not on its recorded remotes`,
|
|
64
|
+
hint: reason.hint,
|
|
65
|
+
};
|
|
66
|
+
case "snapshot-not-found":
|
|
67
|
+
return { detail: "the session holds no record of its snapshot", hint: reason.hint };
|
|
68
|
+
case "blob-missing":
|
|
69
|
+
case "blob-corrupt":
|
|
70
|
+
return { detail: "part of its recorded content is not in this storage", hint: reason.hint };
|
|
71
|
+
default:
|
|
72
|
+
return { detail: reason.summary, hint: reason.hint };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
detail: isWorkspaceError(reason) ? reason.summary : reason.message,
|
|
77
|
+
hint: isWorkspaceError(reason) ? reason.hint : "",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** The record of a checkout a resume continued without, in `continuedIn`, because of `reason` (#4733). */
|
|
81
|
+
export function unrestoredRecord(snapshot, reason, continuedIn, place, at = new Date().toISOString()) {
|
|
82
|
+
return {
|
|
83
|
+
snapshotId: snapshot.id,
|
|
84
|
+
continuedIn,
|
|
85
|
+
place,
|
|
86
|
+
cause: isWorkspaceError(reason) || isGitUnavailableError(reason) ? reason.code : "error",
|
|
87
|
+
...(isWorkspaceRestoreError(reason) && reason.reason !== undefined ? { causeReason: String(reason.reason) } : {}),
|
|
88
|
+
...unrestoredReason(snapshot, reason),
|
|
89
|
+
at,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=best-restore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"best-restore.js","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/best-restore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC/F,OAAO,EACN,0BAA0B,EAI1B,uBAAuB,EACvB,eAAe,GACf,MAAM,cAAc,CAAC;AAStB;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,KAAc;IACzD,IAAI,uBAAuB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE,CAAC;QAC7G,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CAAC,gBAAgB,CAAC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C,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACvD,CAAC;IACF,CAAC;IACD,OAAO;QACN,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO;QAClE,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;KACjD,CAAC;AACH,CAAC;AAED,0GAA0G;AAC1G,MAAM,UAAU,gBAAgB,CAC/B,QAA0B,EAC1B,MAAa,EACb,WAAmB,EACnB,KAAkC,EAClC,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;IAE7B,OAAO;QACN,UAAU,EAAE,QAAQ,CAAC,EAAE;QACvB,WAAW;QACX,KAAK;QACL,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;QACxF,GAAG,CAAC,uBAAuB,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjH,GAAG,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC;QACrC,EAAE;KACF,CAAC;AACH,CAAC","sourcesContent":["import { isGitUnavailableError, isWorkspaceError, isWorkspaceRestoreError } from \"./errors.ts\";\nimport {\n\tisDegradableRestoreFailure,\n\ttype RestoreDegradedWorktreeOptions,\n\ttype RestoredWorktree,\n\ttype RestoreWorktreeSnapshotOptions,\n\trestoreDegradedWorktree,\n\trestoreWorktree,\n} from \"./restore.ts\";\nimport type {\n\tWorkspaceBinding,\n\tWorktreeDegradedRestore,\n\tWorktreeRestoreWarning,\n\tWorktreeSnapshot,\n\tWorktreeUnrestored,\n} from \"./types.ts\";\n\n/**\n * Whether a failed restore of one checkout leaves the resume able to continue without the exact state (#4733): any\n * typed workspace or Git failure, except a snapshot record that fails the security checks (`invalid-snapshot`) and a\n * target that holds other files (`unsafe-target`), which refuse the resume.\n */\nexport function isRecoverableRestoreFailure(error: unknown): error is Error {\n\tif (isWorkspaceRestoreError(error) && (error.code === \"invalid-snapshot\" || error.code === \"unsafe-target\")) {\n\t\treturn false;\n\t}\n\treturn (isWorkspaceError(error) && error.code !== \"invalid-setting\") || isGitUnavailableError(error);\n}\n\nexport interface RestoreBestWorktreeOptions extends RestoreDegradedWorktreeOptions {\n\t/** What the exact restore rebuilds: `snapshot` itself (the default), or a binding found among `snapshots`. */\n\treadonly target?: WorkspaceBinding;\n\t/** Recorded snapshots the exact restore of `target` searches. */\n\treadonly snapshots?: readonly WorktreeSnapshot[];\n\t/** What restores exactly instead of `restoreWorktree`. */\n\treadonly restore?: (\n\t\ttarget: WorkspaceBinding | WorktreeSnapshot,\n\t\toptions: RestoreWorktreeSnapshotOptions,\n\t) => Promise<Pick<RestoredWorktree, \"path\"> & Partial<Pick<RestoredWorktree, \"warnings\">>>;\n}\n\n/** The best restore of a checkout this host could make (#4733, #4738). */\nexport type BestWorktreeRestore =\n\t| {\n\t\t\treadonly status: \"restored\";\n\t\t\treadonly path: string;\n\t\t\treadonly warnings: readonly WorktreeRestoreWarning[];\n\t\t\t/** Present when the worktree holds less than the snapshot: what it holds and what is missing. */\n\t\t\treadonly degraded?: WorktreeDegradedRestore;\n\t }\n\t/** Nothing of the snapshot could be restored here; `reason` says why. Nothing was written. */\n\t| { readonly status: \"unrestored\"; readonly reason: Error };\n\n/**\n * Restores `snapshot` into a new worktree as well as this host can (#4733): exactly; else, after a failure a degraded\n * restore can follow, its recorded `HEAD` with the change sets that apply, or the closest commit it can fetch; else\n * nothing, resolving `unrestored` with the exact restore's failure. Rejects with a failure that is not recoverable\n * (`invalid-snapshot`, `unsafe-target`, or an error that is not a typed workspace or Git failure), and, once `signal`\n * aborted, with the failure the abort caused.\n */\nexport async function restoreBestWorktree(\n\tsnapshot: WorktreeSnapshot,\n\toptions: RestoreBestWorktreeOptions = {},\n): Promise<BestWorktreeRestore> {\n\tconst { target, snapshots, restore = restoreWorktree, candidates, ...shared } = options;\n\ttry {\n\t\tconst exact = await restore(target ?? snapshot, { ...shared, ...(snapshots === undefined ? {} : { snapshots }) });\n\t\treturn { status: \"restored\", path: exact.path, warnings: exact.warnings ?? [] };\n\t} catch (error) {\n\t\tif (options.signal?.aborted || !isRecoverableRestoreFailure(error)) throw error;\n\t\tif (isDegradableRestoreFailure(error)) {\n\t\t\ttry {\n\t\t\t\tconst degraded = await restoreDegradedWorktree(snapshot, error, {\n\t\t\t\t\t...shared,\n\t\t\t\t\t...(candidates === undefined ? {} : { candidates }),\n\t\t\t\t});\n\t\t\t\treturn { status: \"restored\", ...degraded };\n\t\t\t} catch (degradedError) {\n\t\t\t\tif (options.signal?.aborted || !isRecoverableRestoreFailure(degradedError)) throw degradedError;\n\t\t\t}\n\t\t}\n\t\treturn { status: \"unrestored\", reason: error };\n\t}\n}\n\n/** What a resume tells about a checkout it continued without: why, as a clause, and what to do. */\nexport function unrestoredReason(snapshot: WorktreeSnapshot, reason: Error): { detail: string; hint: string } {\n\tconst head = snapshot.head.slice(0, 12);\n\tif (isGitUnavailableError(reason)) {\n\t\treturn {\n\t\t\tdetail: `Git is unavailable here (${reason.code}), which checking and restoring it need`,\n\t\t\thint: reason.hint ?? \"\",\n\t\t};\n\t}\n\tif (isWorkspaceRestoreError(reason)) {\n\t\tswitch (reason.code) {\n\t\t\tcase \"commits-unavailable\":\n\t\t\t\treturn {\n\t\t\t\t\tdetail:\n\t\t\t\t\t\treason.reason === \"denied-history\"\n\t\t\t\t\t\t\t? `its commit ${head} is not on its recorded remotes, and its unpushed commits touch files snapshots never copy`\n\t\t\t\t\t\t\t: reason.reason === \"bundle-over-cap\"\n\t\t\t\t\t\t\t\t? `its commit ${head} is not on its recorded remotes, and its unpushed commits were too large to record`\n\t\t\t\t\t\t\t\t: `its commit ${head} and the commits around it are not on its recorded remotes`,\n\t\t\t\t\thint: reason.hint,\n\t\t\t\t};\n\t\t\tcase \"snapshot-not-found\":\n\t\t\t\treturn { detail: \"the session holds no record of its snapshot\", hint: reason.hint };\n\t\t\tcase \"blob-missing\":\n\t\t\tcase \"blob-corrupt\":\n\t\t\t\treturn { detail: \"part of its recorded content is not in this storage\", hint: reason.hint };\n\t\t\tdefault:\n\t\t\t\treturn { detail: reason.summary, hint: reason.hint };\n\t\t}\n\t}\n\treturn {\n\t\tdetail: isWorkspaceError(reason) ? reason.summary : reason.message,\n\t\thint: isWorkspaceError(reason) ? reason.hint : \"\",\n\t};\n}\n\n/** The record of a checkout a resume continued without, in `continuedIn`, because of `reason` (#4733). */\nexport function unrestoredRecord(\n\tsnapshot: WorktreeSnapshot,\n\treason: Error,\n\tcontinuedIn: string,\n\tplace: WorktreeUnrestored[\"place\"],\n\tat = new Date().toISOString(),\n): WorktreeUnrestored {\n\treturn {\n\t\tsnapshotId: snapshot.id,\n\t\tcontinuedIn,\n\t\tplace,\n\t\tcause: isWorkspaceError(reason) || isGitUnavailableError(reason) ? reason.code : \"error\",\n\t\t...(isWorkspaceRestoreError(reason) && reason.reason !== undefined ? { causeReason: String(reason.reason) } : {}),\n\t\t...unrestoredReason(snapshot, reason),\n\t\tat,\n\t};\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { redactUrlCredentials } from "../error-contract.ts";
|
|
1
2
|
import { GitUnavailableError } from "./errors.ts";
|
|
2
3
|
/** The Git executable snapshot operations run, with the environment it needs (a provisioned Git may need some). */
|
|
3
4
|
export interface GitExecutable {
|
|
@@ -47,8 +48,7 @@ export interface GitRunResult {
|
|
|
47
48
|
readonly stderr: string;
|
|
48
49
|
readonly exitCode: number;
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
export declare function redactUrlCredentials(text: string): string;
|
|
51
|
+
export { redactUrlCredentials };
|
|
52
52
|
/**
|
|
53
53
|
* Runs one Git command through the injected executable. Rejects with the signal's reason when aborted, and with
|
|
54
54
|
* `not-a-repository` before resolving Git when the working directory lies in a root excluded from snapshots.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/git.ts"],"names":[],"mappings":"AAQA,OAAO,EACN,mBAAmB,EAKnB,MAAM,aAAa,CAAC;AAIrB,mHAAmH;AACnH,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;AAWrF;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACxC,UAAU,EAAE,aAAa,GAAG,SAAS,EACrC,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAqBxF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,qBAAqB,CAI7F;AAgBD,kHAAkH;AAClH,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAOtD,CAAC;AAEF,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,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,EAAE,CAK3D"}
|
|
@@ -6,6 +6,7 @@ import { getBinDir } from "../../config.js";
|
|
|
6
6
|
import { createChildProcessEnvironment } from "../../utils/child-process.js";
|
|
7
7
|
import { createGitEnvironment } from "../../utils/git-env.js";
|
|
8
8
|
import { isGitProvisionError } from "../../utils/git-errors.js";
|
|
9
|
+
import { redactUrlCredentials } from "../error-contract.js";
|
|
9
10
|
import { GitUnavailableError, gitInstallCommand, isGitUnavailableError, WorkspaceGitError, WorkspaceSnapshotError, } from "./errors.js";
|
|
10
11
|
import { worktreeSnapshotExcludedRoots } from "./excluded-roots.js";
|
|
11
12
|
import { canonicalizeWorktreePath } from "./paths.js";
|
|
@@ -86,11 +87,7 @@ export const NEUTRAL_CONVERSION_CONFIG = [
|
|
|
86
87
|
/** How long a non-interactive ssh waits for a connection before giving up, in seconds. */
|
|
87
88
|
export const NON_INTERACTIVE_SSH_CONNECT_TIMEOUT_SECONDS = 15;
|
|
88
89
|
function exitStatusReportsClosedInput() { }
|
|
89
|
-
|
|
90
|
-
/** Removes the user-info part of URLs, which can hold access tokens. */
|
|
91
|
-
export function redactUrlCredentials(text) {
|
|
92
|
-
return text.replace(CREDENTIALS_IN_URL, "$1");
|
|
93
|
-
}
|
|
90
|
+
export { redactUrlCredentials };
|
|
94
91
|
function gitOperation(args) {
|
|
95
92
|
for (let index = 0; index < args.length; index++) {
|
|
96
93
|
if (args[index] === "-c")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAuC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,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AE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,SAAS,CAAC,MAAuB;IAChD,MAAM,IAAI,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;QAAE,MAAM,CAAC,GAAG,EAAE,CAAC;IACvC,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { type ChildProcessWithoutNullStreams, spawn } from \"node:child_process\";\nimport { accessSync, constants, existsSync, statSync } from \"node:fs\";\nimport { isAbsolute, join, relative, sep } from \"node:path\";\nimport { getBinDir } from \"../../config.js\";\nimport { createChildProcessEnvironment } from \"../../utils/child-process.ts\";\nimport { createGitEnvironment } from \"../../utils/git-env.ts\";\nimport { isGitProvisionError } from \"../../utils/git-errors.ts\";\nimport {\n\tGitUnavailableError,\n\tgitInstallCommand,\n\tisGitUnavailableError,\n\tWorkspaceGitError,\n\tWorkspaceSnapshotError,\n} from \"./errors.ts\";\nimport { worktreeSnapshotExcludedRoots } from \"./excluded-roots.ts\";\nimport { canonicalizeWorktreePath } from \"./paths.ts\";\n\n/** The Git executable snapshot operations run, with the environment it needs (a provisioned Git may need some). */\nexport interface GitExecutable {\n\treadonly path: string;\n\treadonly env: Readonly<NodeJS.ProcessEnv>;\n}\n\nexport type GitExecutableResolver = (signal?: AbortSignal) => Promise<GitExecutable>;\n\nconst provisionedGit: GitExecutableResolver = async (signal) => {\n\tconst { resolveGit } = await import(\"../../utils/tools-manager.ts\");\n\treturn resolveGit({ signal });\n};\nlet resolveExecutable: GitExecutableResolver = provisionedGit;\n\n/** The Git every snapshot command of one scope runs instead of the resolver's, such as one restore's. */\nconst scopedExecutable = new AsyncLocalStorage<GitExecutable>();\n\n/**\n * Runs `action` with every snapshot Git command it starts on `executable`, which no resolver is asked for; other\n * operations of this process keep theirs. Undefined: `action` runs as it would without this call.\n */\nexport function withWorktreeSnapshotGit<T>(\n\texecutable: GitExecutable | undefined,\n\taction: () => Promise<T>,\n): Promise<T> {\n\treturn executable === undefined ? action() : scopedExecutable.run(executable, action);\n}\n\n/**\n * Why a snapshot cannot be recorded with the Git already on this machine, checked without downloading one: recording\n * only uses an installed or provisioned Git, so a session or workflow run that never needs Git otherwise starts no\n * download (#4322). Undefined when such a Git exists, or when an injected resolver decides.\n */\nexport async function installedGitUnavailable(): Promise<GitUnavailableError | undefined> {\n\tif (resolveExecutable !== provisionedGit) return undefined;\n\tconst { resolveGitSync } = await import(\"../../utils/tools-manager.ts\");\n\ttry {\n\t\tresolveGitSync();\n\t\treturn undefined;\n\t} catch (error) {\n\t\tif (isGitUnavailableError(error)) return error;\n\t\tif (!isGitProvisionError(error)) throw error;\n\t\t// An earlier download in this process failed another way, such as timing out: no Git is installed.\n\t\treturn new GitUnavailableError(\n\t\t\t{\n\t\t\t\tcode: \"not-installed\",\n\t\t\t\tplatform: process.platform,\n\t\t\t\tarch: process.arch,\n\t\t\t\tinstallDir: join(getBinDir(), \"git\"),\n\t\t\t\tinstallCommand: gitInstallCommand(process.platform),\n\t\t\t},\n\t\t\t{ cause: error },\n\t\t);\n\t}\n}\n\n/**\n * The single place every worktree snapshot Git invocation gets its executable from. Returns the previous resolver so\n * callers can restore it.\n */\nexport function setWorktreeSnapshotGit(resolver: GitExecutableResolver): GitExecutableResolver {\n\tconst previous = resolveExecutable;\n\tresolveExecutable = resolver;\n\treturn previous;\n}\n\nconst NULL_DEVICE = process.platform === \"win32\" ? \"NUL\" : \"/dev/null\";\n/** Settings that keep snapshot commands from running hooks, daemons, maintenance or signing in the user's repository. */\nconst BASE_CONFIG = [\n\t\"-c\",\n\t`core.hooksPath=${NULL_DEVICE}`,\n\t\"-c\",\n\t\"core.fsmonitor=false\",\n\t\"-c\",\n\t\"gc.auto=0\",\n\t\"-c\",\n\t\"maintenance.auto=false\",\n\t\"-c\",\n\t\"commit.gpgSign=false\",\n];\n/** Conversion settings that make materialization and verification independent of the host's Git configuration. */\nexport const NEUTRAL_CONVERSION_CONFIG: readonly string[] = [\n\t\"-c\",\n\t\"core.autocrlf=false\",\n\t\"-c\",\n\t\"core.eol=lf\",\n\t\"-c\",\n\t\"core.safecrlf=false\",\n];\n\nexport interface GitRunOptions {\n\treadonly cwd: string;\n\treadonly env?: Readonly<Record<string, string>>;\n\treadonly input?: string | Uint8Array;\n\treadonly signal?: AbortSignal;\n\t/** Exit codes that are results rather than failures, such as 1 from `git cat-file -e`. */\n\treadonly allowExitCodes?: readonly number[];\n\t/** Prepend {@link NEUTRAL_CONVERSION_CONFIG}. */\n\treadonly neutral?: boolean;\n\t/**\n\t * Run a command that talks to a remote so it can never wait for a person: on POSIX it starts in a new session, so\n\t * ssh and credential helpers have no terminal to prompt on and fail at once, and ssh runs in batch mode with a\n\t * bounded connect time unless the user chose their own ssh command (`GIT_SSH_COMMAND`, `GIT_SSH` or\n\t * `core.sshCommand`). A prompt is never answered, so the command fails with the usual {@link WorkspaceGitError}.\n\t */\n\treadonly nonInteractive?: boolean;\n}\n\n/** How long a non-interactive ssh waits for a connection before giving up, in seconds. */\nexport const NON_INTERACTIVE_SSH_CONNECT_TIMEOUT_SECONDS = 15;\n\nexport interface GitRunResult {\n\treadonly stdout: Buffer;\n\treadonly stderr: string;\n\treadonly exitCode: number;\n}\n\nfunction exitStatusReportsClosedInput(): void {}\n\nconst CREDENTIALS_IN_URL = /([a-z][a-z0-9+.-]*:\\/\\/)[^/@\\s]*@/gi;\n\n/** Removes the user-info part of URLs, which can hold access tokens. */\nexport function redactUrlCredentials(text: string): string {\n\treturn text.replace(CREDENTIALS_IN_URL, \"$1\");\n}\n\nfunction gitOperation(args: readonly string[]): string {\n\tfor (let index = 0; index < args.length; index++) {\n\t\tif (args[index] === \"-c\") index++;\n\t\telse if (!args[index]!.startsWith(\"-\")) return args[index]!;\n\t}\n\treturn \"\";\n}\n\nfunction firstLine(text: string): string {\n\treturn redactUrlCredentials(text.trim().split(\"\\n\", 1)[0] ?? \"\").slice(0, 300);\n}\n\n/** Whether the user's Git configuration (not the environment) names the ssh command Git runs. */\nasync function configuresSshCommand(options: GitRunOptions): Promise<boolean> {\n\tconst lookup = await runGit([\"config\", \"--get\", \"core.sshCommand\"], {\n\t\tcwd: options.cwd,\n\t\tenv: options.env,\n\t\tsignal: options.signal,\n\t\tallowExitCodes: [1],\n\t});\n\treturn lookup.exitCode === 0;\n}\n\n/** Kills `child`, and with it the ssh or helper processes it started when it leads its own session. */\nfunction killChild(child: ChildProcessWithoutNullStreams, detached: boolean): void {\n\tif (detached && child.pid !== undefined) {\n\t\ttry {\n\t\t\tprocess.kill(-child.pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// The group is already gone, or cannot be signalled: the child itself is all that is left to kill.\n\t\t\tchild.kill(\"SIGKILL\");\n\t\t}\n\t\treturn;\n\t}\n\tchild.kill(\"SIGKILL\");\n}\n\n/**\n * The `unreadable-path` error for a working directory the process cannot list or enter. Spawning in one fails with the\n * same `ENOENT` or `EACCES` as a missing or non-executable Git, so only the directory itself tells them apart.\n */\nfunction unreadableDirectory(directory: string): WorkspaceSnapshotError | undefined {\n\ttry {\n\t\taccessSync(directory, constants.R_OK | constants.X_OK);\n\t\treturn undefined;\n\t} catch (error) {\n\t\treturn new WorkspaceSnapshotError(\"unreadable-path\", directory, error as Error);\n\t}\n}\n\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/** The `not-a-repository` refusal for a working directory in a root excluded from snapshots, if it is in one. */\nfunction excludedDirectory(cwd: string): WorkspaceSnapshotError | undefined {\n\tconst roots = worktreeSnapshotExcludedRoots();\n\tif (roots.length === 0) return undefined;\n\tconst directory = canonicalizeWorktreePath(cwd);\n\tfor (const root of roots) {\n\t\tconst path = relative(canonicalizeWorktreePath(root), directory);\n\t\tif (path !== \"..\" && !path.startsWith(`..${sep}`) && !isAbsolute(path)) {\n\t\t\treturn new WorkspaceSnapshotError(\"not-a-repository\", cwd);\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Runs one Git command through the injected executable. Rejects with the signal's reason when aborted, and with\n * `not-a-repository` before resolving Git when the working directory lies in a root excluded from snapshots.\n */\nexport async function runGit(args: readonly string[], options: GitRunOptions): Promise<GitRunResult> {\n\toptions.signal?.throwIfAborted();\n\tconst excluded = excludedDirectory(options.cwd);\n\tif (excluded !== undefined) throw excluded;\n\tconst executable = scopedExecutable.getStore() ?? (await resolveExecutable(options.signal));\n\toptions.signal?.throwIfAborted();\n\tconst env = createGitEnvironment(\n\t\t{ GIT_TERMINAL_PROMPT: \"0\", GIT_OPTIONAL_LOCKS: \"0\", GCM_INTERACTIVE: \"never\" },\n\t\tcreateChildProcessEnvironment(executable.env),\n\t);\n\tObject.assign(env, options.env);\n\tif (options.nonInteractive && !env.GIT_SSH_COMMAND && !env.GIT_SSH && !(await configuresSshCommand(options))) {\n\t\tenv.GIT_SSH_COMMAND = `ssh -o BatchMode=yes -o ConnectTimeout=${NON_INTERACTIVE_SSH_CONNECT_TIMEOUT_SECONDS}`;\n\t}\n\t// A new session has no controlling terminal. Windows has no such thing, and `detached` there opens a console.\n\tconst detached = options.nonInteractive === true && process.platform !== \"win32\";\n\tconst argv = [...BASE_CONFIG, ...(options.neutral ? NEUTRAL_CONVERSION_CONFIG : []), ...args];\n\tconst spawnFailure = (error: NodeJS.ErrnoException): Error =>\n\t\t(error.code === \"ENOENT\" || error.code === \"EACCES\") && isDirectory(options.cwd)\n\t\t\t? (unreadableDirectory(options.cwd) ??\n\t\t\t\tnew GitUnavailableError(\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: \"not-installed\",\n\t\t\t\t\t\tplatform: process.platform,\n\t\t\t\t\t\tarch: process.arch,\n\t\t\t\t\t\tinstallDir: join(getBinDir(), \"git\"),\n\t\t\t\t\t\tinstallCommand: gitInstallCommand(process.platform),\n\t\t\t\t\t\tsystemGit: { path: executable.path, problem: \"probe-failed\" },\n\t\t\t\t\t},\n\t\t\t\t\t{ cause: error },\n\t\t\t\t))\n\t\t\t: new WorkspaceGitError(\n\t\t\t\t\t{\n\t\t\t\t\t\toperation: gitOperation(args),\n\t\t\t\t\t\tcwd: options.cwd,\n\t\t\t\t\t\texitCode: null,\n\t\t\t\t\t\tdetail: existsSync(options.cwd) ? firstLine(error.message) : \"the working directory does not exist\",\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\treturn new Promise<GitRunResult>((resolve, reject) => {\n\t\tlet child: ChildProcessWithoutNullStreams;\n\t\ttry {\n\t\t\tchild = spawn(executable.path, argv, { cwd: options.cwd, env, stdio: [\"pipe\", \"pipe\", \"pipe\"], detached });\n\t\t} catch (error) {\n\t\t\t// Node throws instead of emitting `error` for some failures, such as a path component that is a file.\n\t\t\treject(spawnFailure(error as NodeJS.ErrnoException));\n\t\t\treturn;\n\t\t}\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet settled = false;\n\t\tconst onAbort = () => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tkillChild(child, detached);\n\t\t\treject(options.signal?.reason);\n\t\t};\n\t\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\tconst finish = (action: () => void) => {\n\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\taction();\n\t\t};\n\t\tchild.stdout.on(\"data\", (chunk: Buffer) => stdout.push(chunk));\n\t\tchild.stderr.on(\"data\", (chunk: Buffer) => stderr.push(chunk));\n\t\tchild.on(\"error\", (error: NodeJS.ErrnoException) => finish(() => reject(spawnFailure(error))));\n\t\tchild.stdin.on(\"error\", exitStatusReportsClosedInput);\n\t\tchild.on(\"close\", (code) =>\n\t\t\tfinish(() => {\n\t\t\t\tconst result = {\n\t\t\t\t\tstdout: Buffer.concat(stdout),\n\t\t\t\t\tstderr: Buffer.concat(stderr).toString(\"utf8\"),\n\t\t\t\t\texitCode: code ?? -1,\n\t\t\t\t};\n\t\t\t\tif (code === 0 || (code !== null && options.allowExitCodes?.includes(code))) resolve(result);\n\t\t\t\telse\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew WorkspaceGitError({\n\t\t\t\t\t\t\toperation: gitOperation(args),\n\t\t\t\t\t\t\tcwd: options.cwd,\n\t\t\t\t\t\t\texitCode: code,\n\t\t\t\t\t\t\tdetail: firstLine(result.stderr),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tchild.stdin.end(options.input === undefined ? undefined : options.input);\n\t});\n}\n\n/** Runs a Git command and returns its standard output as UTF-8 text without the trailing newline. */\nexport async function gitText(args: readonly string[], options: GitRunOptions): Promise<string> {\n\tconst { stdout } = await runGit(args, options);\n\treturn stdout.toString(\"utf8\").replace(/\\n$/, \"\");\n}\n\n/** Splits NUL-terminated Git output. */\nexport function nulFields(output: Buffer | string): string[] {\n\tconst text = typeof output === \"string\" ? output : output.toString(\"utf8\");\n\tconst fields = text.split(\"\\0\");\n\tif (fields.at(-1) === \"\") fields.pop();\n\treturn fields;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAuC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChF,OA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K,UAAU,OAAO,CAAC,IAAuB,EAAE,OAAsB;IAC5E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,SAAS,CAAC,MAAuB;IAChD,MAAM,IAAI,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;QAAE,MAAM,CAAC,GAAG,EAAE,CAAC;IACvC,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { type ChildProcessWithoutNullStreams, spawn } from \"node:child_process\";\nimport { accessSync, constants, existsSync, statSync } from \"node:fs\";\nimport { isAbsolute, join, relative, sep } from \"node:path\";\nimport { getBinDir } from \"../../config.js\";\nimport { createChildProcessEnvironment } from \"../../utils/child-process.ts\";\nimport { createGitEnvironment } from \"../../utils/git-env.ts\";\nimport { isGitProvisionError } from \"../../utils/git-errors.ts\";\nimport { redactUrlCredentials } from \"../error-contract.ts\";\nimport {\n\tGitUnavailableError,\n\tgitInstallCommand,\n\tisGitUnavailableError,\n\tWorkspaceGitError,\n\tWorkspaceSnapshotError,\n} from \"./errors.ts\";\nimport { worktreeSnapshotExcludedRoots } from \"./excluded-roots.ts\";\nimport { canonicalizeWorktreePath } from \"./paths.ts\";\n\n/** The Git executable snapshot operations run, with the environment it needs (a provisioned Git may need some). */\nexport interface GitExecutable {\n\treadonly path: string;\n\treadonly env: Readonly<NodeJS.ProcessEnv>;\n}\n\nexport type GitExecutableResolver = (signal?: AbortSignal) => Promise<GitExecutable>;\n\nconst provisionedGit: GitExecutableResolver = async (signal) => {\n\tconst { resolveGit } = await import(\"../../utils/tools-manager.ts\");\n\treturn resolveGit({ signal });\n};\nlet resolveExecutable: GitExecutableResolver = provisionedGit;\n\n/** The Git every snapshot command of one scope runs instead of the resolver's, such as one restore's. */\nconst scopedExecutable = new AsyncLocalStorage<GitExecutable>();\n\n/**\n * Runs `action` with every snapshot Git command it starts on `executable`, which no resolver is asked for; other\n * operations of this process keep theirs. Undefined: `action` runs as it would without this call.\n */\nexport function withWorktreeSnapshotGit<T>(\n\texecutable: GitExecutable | undefined,\n\taction: () => Promise<T>,\n): Promise<T> {\n\treturn executable === undefined ? action() : scopedExecutable.run(executable, action);\n}\n\n/**\n * Why a snapshot cannot be recorded with the Git already on this machine, checked without downloading one: recording\n * only uses an installed or provisioned Git, so a session or workflow run that never needs Git otherwise starts no\n * download (#4322). Undefined when such a Git exists, or when an injected resolver decides.\n */\nexport async function installedGitUnavailable(): Promise<GitUnavailableError | undefined> {\n\tif (resolveExecutable !== provisionedGit) return undefined;\n\tconst { resolveGitSync } = await import(\"../../utils/tools-manager.ts\");\n\ttry {\n\t\tresolveGitSync();\n\t\treturn undefined;\n\t} catch (error) {\n\t\tif (isGitUnavailableError(error)) return error;\n\t\tif (!isGitProvisionError(error)) throw error;\n\t\t// An earlier download in this process failed another way, such as timing out: no Git is installed.\n\t\treturn new GitUnavailableError(\n\t\t\t{\n\t\t\t\tcode: \"not-installed\",\n\t\t\t\tplatform: process.platform,\n\t\t\t\tarch: process.arch,\n\t\t\t\tinstallDir: join(getBinDir(), \"git\"),\n\t\t\t\tinstallCommand: gitInstallCommand(process.platform),\n\t\t\t},\n\t\t\t{ cause: error },\n\t\t);\n\t}\n}\n\n/**\n * The single place every worktree snapshot Git invocation gets its executable from. Returns the previous resolver so\n * callers can restore it.\n */\nexport function setWorktreeSnapshotGit(resolver: GitExecutableResolver): GitExecutableResolver {\n\tconst previous = resolveExecutable;\n\tresolveExecutable = resolver;\n\treturn previous;\n}\n\nconst NULL_DEVICE = process.platform === \"win32\" ? \"NUL\" : \"/dev/null\";\n/** Settings that keep snapshot commands from running hooks, daemons, maintenance or signing in the user's repository. */\nconst BASE_CONFIG = [\n\t\"-c\",\n\t`core.hooksPath=${NULL_DEVICE}`,\n\t\"-c\",\n\t\"core.fsmonitor=false\",\n\t\"-c\",\n\t\"gc.auto=0\",\n\t\"-c\",\n\t\"maintenance.auto=false\",\n\t\"-c\",\n\t\"commit.gpgSign=false\",\n];\n/** Conversion settings that make materialization and verification independent of the host's Git configuration. */\nexport const NEUTRAL_CONVERSION_CONFIG: readonly string[] = [\n\t\"-c\",\n\t\"core.autocrlf=false\",\n\t\"-c\",\n\t\"core.eol=lf\",\n\t\"-c\",\n\t\"core.safecrlf=false\",\n];\n\nexport interface GitRunOptions {\n\treadonly cwd: string;\n\treadonly env?: Readonly<Record<string, string>>;\n\treadonly input?: string | Uint8Array;\n\treadonly signal?: AbortSignal;\n\t/** Exit codes that are results rather than failures, such as 1 from `git cat-file -e`. */\n\treadonly allowExitCodes?: readonly number[];\n\t/** Prepend {@link NEUTRAL_CONVERSION_CONFIG}. */\n\treadonly neutral?: boolean;\n\t/**\n\t * Run a command that talks to a remote so it can never wait for a person: on POSIX it starts in a new session, so\n\t * ssh and credential helpers have no terminal to prompt on and fail at once, and ssh runs in batch mode with a\n\t * bounded connect time unless the user chose their own ssh command (`GIT_SSH_COMMAND`, `GIT_SSH` or\n\t * `core.sshCommand`). A prompt is never answered, so the command fails with the usual {@link WorkspaceGitError}.\n\t */\n\treadonly nonInteractive?: boolean;\n}\n\n/** How long a non-interactive ssh waits for a connection before giving up, in seconds. */\nexport const NON_INTERACTIVE_SSH_CONNECT_TIMEOUT_SECONDS = 15;\n\nexport interface GitRunResult {\n\treadonly stdout: Buffer;\n\treadonly stderr: string;\n\treadonly exitCode: number;\n}\n\nfunction exitStatusReportsClosedInput(): void {}\n\nexport { redactUrlCredentials };\n\nfunction gitOperation(args: readonly string[]): string {\n\tfor (let index = 0; index < args.length; index++) {\n\t\tif (args[index] === \"-c\") index++;\n\t\telse if (!args[index]!.startsWith(\"-\")) return args[index]!;\n\t}\n\treturn \"\";\n}\n\nfunction firstLine(text: string): string {\n\treturn redactUrlCredentials(text.trim().split(\"\\n\", 1)[0] ?? \"\").slice(0, 300);\n}\n\n/** Whether the user's Git configuration (not the environment) names the ssh command Git runs. */\nasync function configuresSshCommand(options: GitRunOptions): Promise<boolean> {\n\tconst lookup = await runGit([\"config\", \"--get\", \"core.sshCommand\"], {\n\t\tcwd: options.cwd,\n\t\tenv: options.env,\n\t\tsignal: options.signal,\n\t\tallowExitCodes: [1],\n\t});\n\treturn lookup.exitCode === 0;\n}\n\n/** Kills `child`, and with it the ssh or helper processes it started when it leads its own session. */\nfunction killChild(child: ChildProcessWithoutNullStreams, detached: boolean): void {\n\tif (detached && child.pid !== undefined) {\n\t\ttry {\n\t\t\tprocess.kill(-child.pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// The group is already gone, or cannot be signalled: the child itself is all that is left to kill.\n\t\t\tchild.kill(\"SIGKILL\");\n\t\t}\n\t\treturn;\n\t}\n\tchild.kill(\"SIGKILL\");\n}\n\n/**\n * The `unreadable-path` error for a working directory the process cannot list or enter. Spawning in one fails with the\n * same `ENOENT` or `EACCES` as a missing or non-executable Git, so only the directory itself tells them apart.\n */\nfunction unreadableDirectory(directory: string): WorkspaceSnapshotError | undefined {\n\ttry {\n\t\taccessSync(directory, constants.R_OK | constants.X_OK);\n\t\treturn undefined;\n\t} catch (error) {\n\t\treturn new WorkspaceSnapshotError(\"unreadable-path\", directory, error as Error);\n\t}\n}\n\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/** The `not-a-repository` refusal for a working directory in a root excluded from snapshots, if it is in one. */\nfunction excludedDirectory(cwd: string): WorkspaceSnapshotError | undefined {\n\tconst roots = worktreeSnapshotExcludedRoots();\n\tif (roots.length === 0) return undefined;\n\tconst directory = canonicalizeWorktreePath(cwd);\n\tfor (const root of roots) {\n\t\tconst path = relative(canonicalizeWorktreePath(root), directory);\n\t\tif (path !== \"..\" && !path.startsWith(`..${sep}`) && !isAbsolute(path)) {\n\t\t\treturn new WorkspaceSnapshotError(\"not-a-repository\", cwd);\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Runs one Git command through the injected executable. Rejects with the signal's reason when aborted, and with\n * `not-a-repository` before resolving Git when the working directory lies in a root excluded from snapshots.\n */\nexport async function runGit(args: readonly string[], options: GitRunOptions): Promise<GitRunResult> {\n\toptions.signal?.throwIfAborted();\n\tconst excluded = excludedDirectory(options.cwd);\n\tif (excluded !== undefined) throw excluded;\n\tconst executable = scopedExecutable.getStore() ?? (await resolveExecutable(options.signal));\n\toptions.signal?.throwIfAborted();\n\tconst env = createGitEnvironment(\n\t\t{ GIT_TERMINAL_PROMPT: \"0\", GIT_OPTIONAL_LOCKS: \"0\", GCM_INTERACTIVE: \"never\" },\n\t\tcreateChildProcessEnvironment(executable.env),\n\t);\n\tObject.assign(env, options.env);\n\tif (options.nonInteractive && !env.GIT_SSH_COMMAND && !env.GIT_SSH && !(await configuresSshCommand(options))) {\n\t\tenv.GIT_SSH_COMMAND = `ssh -o BatchMode=yes -o ConnectTimeout=${NON_INTERACTIVE_SSH_CONNECT_TIMEOUT_SECONDS}`;\n\t}\n\t// A new session has no controlling terminal. Windows has no such thing, and `detached` there opens a console.\n\tconst detached = options.nonInteractive === true && process.platform !== \"win32\";\n\tconst argv = [...BASE_CONFIG, ...(options.neutral ? NEUTRAL_CONVERSION_CONFIG : []), ...args];\n\tconst spawnFailure = (error: NodeJS.ErrnoException): Error =>\n\t\t(error.code === \"ENOENT\" || error.code === \"EACCES\") && isDirectory(options.cwd)\n\t\t\t? (unreadableDirectory(options.cwd) ??\n\t\t\t\tnew GitUnavailableError(\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: \"not-installed\",\n\t\t\t\t\t\tplatform: process.platform,\n\t\t\t\t\t\tarch: process.arch,\n\t\t\t\t\t\tinstallDir: join(getBinDir(), \"git\"),\n\t\t\t\t\t\tinstallCommand: gitInstallCommand(process.platform),\n\t\t\t\t\t\tsystemGit: { path: executable.path, problem: \"probe-failed\" },\n\t\t\t\t\t},\n\t\t\t\t\t{ cause: error },\n\t\t\t\t))\n\t\t\t: new WorkspaceGitError(\n\t\t\t\t\t{\n\t\t\t\t\t\toperation: gitOperation(args),\n\t\t\t\t\t\tcwd: options.cwd,\n\t\t\t\t\t\texitCode: null,\n\t\t\t\t\t\tdetail: existsSync(options.cwd) ? firstLine(error.message) : \"the working directory does not exist\",\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\treturn new Promise<GitRunResult>((resolve, reject) => {\n\t\tlet child: ChildProcessWithoutNullStreams;\n\t\ttry {\n\t\t\tchild = spawn(executable.path, argv, { cwd: options.cwd, env, stdio: [\"pipe\", \"pipe\", \"pipe\"], detached });\n\t\t} catch (error) {\n\t\t\t// Node throws instead of emitting `error` for some failures, such as a path component that is a file.\n\t\t\treject(spawnFailure(error as NodeJS.ErrnoException));\n\t\t\treturn;\n\t\t}\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet settled = false;\n\t\tconst onAbort = () => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tkillChild(child, detached);\n\t\t\treject(options.signal?.reason);\n\t\t};\n\t\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\tconst finish = (action: () => void) => {\n\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\taction();\n\t\t};\n\t\tchild.stdout.on(\"data\", (chunk: Buffer) => stdout.push(chunk));\n\t\tchild.stderr.on(\"data\", (chunk: Buffer) => stderr.push(chunk));\n\t\tchild.on(\"error\", (error: NodeJS.ErrnoException) => finish(() => reject(spawnFailure(error))));\n\t\tchild.stdin.on(\"error\", exitStatusReportsClosedInput);\n\t\tchild.on(\"close\", (code) =>\n\t\t\tfinish(() => {\n\t\t\t\tconst result = {\n\t\t\t\t\tstdout: Buffer.concat(stdout),\n\t\t\t\t\tstderr: Buffer.concat(stderr).toString(\"utf8\"),\n\t\t\t\t\texitCode: code ?? -1,\n\t\t\t\t};\n\t\t\t\tif (code === 0 || (code !== null && options.allowExitCodes?.includes(code))) resolve(result);\n\t\t\t\telse\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew WorkspaceGitError({\n\t\t\t\t\t\t\toperation: gitOperation(args),\n\t\t\t\t\t\t\tcwd: options.cwd,\n\t\t\t\t\t\t\texitCode: code,\n\t\t\t\t\t\t\tdetail: firstLine(result.stderr),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tchild.stdin.end(options.input === undefined ? undefined : options.input);\n\t});\n}\n\n/** Runs a Git command and returns its standard output as UTF-8 text without the trailing newline. */\nexport async function gitText(args: readonly string[], options: GitRunOptions): Promise<string> {\n\tconst { stdout } = await runGit(args, options);\n\treturn stdout.toString(\"utf8\").replace(/\\n$/, \"\");\n}\n\n/** Splits NUL-terminated Git output. */\nexport function nulFields(output: Buffer | string): string[] {\n\tconst text = typeof output === \"string\" ? output : output.toString(\"utf8\");\n\tconst fields = text.split(\"\\0\");\n\tif (fields.at(-1) === \"\") fields.pop();\n\treturn fields;\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { type BestWorktreeRestore, type RestoreBestWorktreeOptions, restoreBestWorktree, unrestoredRecord, } from "./best-restore.ts";
|
|
1
2
|
export { MemorySnapshotBlobStore, SNAPSHOT_COLLECTION_BATCH, type SnapshotIndexTables, SqlSnapshotBlobStore, snapshotBlobHashes, snapshotIndexTables, } from "./blob-store.ts";
|
|
2
3
|
export { bindingOf, type CaptureWorktreeSnapshotOptions, captureWorktreeSnapshot, type WorktreeSnapshotCapture, type WorktreeSnapshotUnavailableReason, } from "./capture.ts";
|
|
3
4
|
export { computeEnvironmentHash, ENVIRONMENT_INPUT_FILES, snapshotBlob } from "./env-hash.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,SAAS,EACT,KAAK,8BAA8B,EACnC,uBAAuB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,iCAAiC,GACtC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EACN,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,uBAAuB,EAC5B,iBAAiB,EACjB,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,uBAAuB,EACvB,wBAAwB,EACxB,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EACnC,oBAAoB,EACpB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,mBAAmB,EACnB,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,iBAAiB,EACjB,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,sBAAsB,EACtB,KAAK,0BAA0B,GAC/B,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,6BAA6B,EAClC,sBAAsB,EACtB,0BAA0B,EAC1B,yBAAyB,EACzB,KAAK,iCAAiC,EACtC,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,0BAA0B,GAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,EACN,KAAK,gBAAgB,EACrB,+BAA+B,EAC/B,0BAA0B,EAC1B,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,8BAA8B,EACnC,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,cAAc,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,kCAAkC,EAClC,+BAA+B,EAC/B,KAAK,6BAA6B,GAClC,MAAM,eAAe,CAAC;AACvB,YAAY,EACX,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,8BAA8B,EAC9B,kCAAkC,EAClC,wBAAwB,EACxB,kCAAkC,EAClC,kBAAkB,GAClB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/index.ts"],"names":[],"m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BAAyB,EACzB,KAAK,iCAAiC,EACtC,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,0BAA0B,GAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,EACN,KAAK,gBAAgB,EACrB,+BAA+B,EAC/B,0BAA0B,EAC1B,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,8BAA8B,EACnC,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,cAAc,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,kCAAkC,EAClC,+BAA+B,EAC/B,KAAK,6BAA6B,GAClC,MAAM,eAAe,CAAC;AACvB,YAAY,EACX,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,8BAA8B,EAC9B,kCAAkC,EAClC,wBAAwB,EACxB,kCAAkC,EAClC,kBAAkB,GAClB,MAAM,YAAY,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { restoreBestWorktree, unrestoredRecord, } from "./best-restore.js";
|
|
1
2
|
export { MemorySnapshotBlobStore, SNAPSHOT_COLLECTION_BATCH, SqlSnapshotBlobStore, snapshotBlobHashes, snapshotIndexTables, } from "./blob-store.js";
|
|
2
3
|
export { bindingOf, captureWorktreeSnapshot, } from "./capture.js";
|
|
3
4
|
export { computeEnvironmentHash, ENVIRONMENT_INPUT_FILES, snapshotBlob } from "./env-hash.js";
|