@elie-laloum/outpost 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +9 -5
- package/SECURITY.md +2 -0
- package/dist/adapters/models/openai-compatible.constants.d.ts +4 -0
- package/dist/adapters/models/openai-compatible.constants.js +10 -0
- package/dist/adapters/models/openai-compatible.constants.js.map +1 -0
- package/dist/adapters/models/openai-compatible.d.ts +3 -0
- package/dist/adapters/models/openai-compatible.js +78 -0
- package/dist/adapters/models/openai-compatible.js.map +1 -0
- package/dist/adapters/models/openai-compatible.types.d.ts +14 -0
- package/dist/adapters/models/openai-compatible.types.js +2 -0
- package/dist/adapters/models/openai-compatible.types.js.map +1 -0
- package/dist/adapters/models/openai-http.d.ts +1 -0
- package/dist/adapters/models/openai-http.js +30 -0
- package/dist/adapters/models/openai-http.js.map +1 -0
- package/dist/adapters/models/openai-request.d.ts +4 -0
- package/dist/adapters/models/openai-request.js +46 -0
- package/dist/adapters/models/openai-request.js.map +1 -0
- package/dist/adapters/models/openai-response.d.ts +3 -0
- package/dist/adapters/models/openai-response.js +65 -0
- package/dist/adapters/models/openai-response.js.map +1 -0
- package/dist/application/execution.types.d.ts +2 -0
- package/dist/application/execution.types.js.map +1 -1
- package/dist/application/outpost.types.d.ts +5 -0
- package/dist/application/outpost.types.js.map +1 -1
- package/dist/application/recovery-archive.d.ts +4 -0
- package/dist/application/recovery-archive.js +29 -0
- package/dist/application/recovery-archive.js.map +1 -0
- package/dist/application/recovery-archive.types.d.ts +10 -0
- package/dist/application/recovery-archive.types.js +2 -0
- package/dist/application/recovery-archive.types.js.map +1 -0
- package/dist/application/recovery-inspection.js +3 -0
- package/dist/application/recovery-inspection.js.map +1 -1
- package/dist/application/recovery-inspection.types.d.ts +2 -0
- package/dist/application/recovery-inspection.types.js.map +1 -1
- package/dist/application/recovery-retention.d.ts +2 -1
- package/dist/application/recovery-retention.js +9 -1
- package/dist/application/recovery-retention.js.map +1 -1
- package/dist/application/recovery-retention.types.d.ts +6 -0
- package/dist/application/recovery-retention.types.js.map +1 -1
- package/dist/application/remote-backup.js +8 -0
- package/dist/application/remote-backup.js.map +1 -1
- package/dist/application/remote-workspace.types.d.ts +2 -0
- package/dist/application/remote-workspace.types.js.map +1 -1
- package/dist/application/sandbox-agents.js +2 -1
- package/dist/application/sandbox-agents.js.map +1 -1
- package/dist/application/sandbox-dispatch.js +9 -0
- package/dist/application/sandbox-dispatch.js.map +1 -1
- package/dist/application/sandbox-provision.js +6 -0
- package/dist/application/sandbox-provision.js.map +1 -1
- package/dist/application/storage-reservation.js +3 -0
- package/dist/application/storage-reservation.js.map +1 -1
- package/dist/application/transport-inspection.constants.d.ts +2 -0
- package/dist/application/transport-inspection.constants.js +10 -0
- package/dist/application/transport-inspection.constants.js.map +1 -0
- package/dist/application/transport-inspection.d.ts +2 -0
- package/dist/application/transport-inspection.js +103 -0
- package/dist/application/transport-inspection.js.map +1 -0
- package/dist/application/transport-retention.d.ts +4 -0
- package/dist/application/transport-retention.js +153 -0
- package/dist/application/transport-retention.js.map +1 -0
- package/dist/domain/conversation.types.d.ts +2 -0
- package/dist/domain/conversation.types.js.map +1 -1
- package/dist/domain/model.types.d.ts +15 -0
- package/dist/domain/model.types.js +2 -0
- package/dist/domain/model.types.js.map +1 -0
- package/dist/domain/transport.constants.d.ts +2 -0
- package/dist/domain/transport.constants.js +3 -0
- package/dist/domain/transport.constants.js.map +1 -0
- package/dist/domain/transport.d.ts +6 -0
- package/dist/domain/transport.js +21 -0
- package/dist/domain/transport.js.map +1 -0
- package/dist/domain/transport.types.d.ts +31 -0
- package/dist/domain/transport.types.js +2 -0
- package/dist/domain/transport.types.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/artifact-store.js +10 -0
- package/dist/infrastructure/artifact-store.js.map +1 -1
- package/dist/infrastructure/artifact-store.types.d.ts +3 -1
- package/dist/infrastructure/artifact-store.types.js.map +1 -1
- package/dist/infrastructure/conversations/capture.js +1 -1
- package/dist/infrastructure/conversations/capture.js.map +1 -1
- package/dist/infrastructure/conversations.d.ts +2 -0
- package/dist/infrastructure/conversations.js +2 -0
- package/dist/infrastructure/conversations.js.map +1 -1
- package/dist/infrastructure/inspection-file.js +3 -3
- package/dist/infrastructure/inspection-file.js.map +1 -1
- package/dist/infrastructure/inspection-hash.js +4 -3
- package/dist/infrastructure/inspection-hash.js.map +1 -1
- package/dist/infrastructure/inspection-path.d.ts +1 -0
- package/dist/infrastructure/inspection-path.js +18 -0
- package/dist/infrastructure/inspection-path.js.map +1 -0
- package/dist/infrastructure/journal.js +6 -0
- package/dist/infrastructure/journal.js.map +1 -1
- package/dist/infrastructure/journal.types.d.ts +3 -0
- package/dist/infrastructure/journal.types.js.map +1 -1
- package/dist/infrastructure/local-transport.d.ts +3 -0
- package/dist/infrastructure/local-transport.js +146 -0
- package/dist/infrastructure/local-transport.js.map +1 -0
- package/dist/infrastructure/local-transport.types.d.ts +3 -0
- package/dist/infrastructure/local-transport.types.js +2 -0
- package/dist/infrastructure/local-transport.types.js.map +1 -0
- package/dist/infrastructure/resource-activity-inspection.d.ts +2 -1
- package/dist/infrastructure/resource-activity-inspection.js +2 -2
- package/dist/infrastructure/resource-activity-inspection.js.map +1 -1
- package/dist/infrastructure/resource-activity.js +42 -14
- package/dist/infrastructure/resource-activity.js.map +1 -1
- package/dist/infrastructure/resource-activity.types.d.ts +2 -0
- package/dist/infrastructure/resource-activity.types.js.map +1 -1
- package/dist/infrastructure/s3-transport.d.ts +4 -0
- package/dist/infrastructure/s3-transport.js +144 -0
- package/dist/infrastructure/s3-transport.js.map +1 -0
- package/dist/infrastructure/s3-transport.types.d.ts +6 -0
- package/dist/infrastructure/s3-transport.types.js +2 -0
- package/dist/infrastructure/s3-transport.types.js.map +1 -0
- package/dist/infrastructure/storage-inventory.types.d.ts +2 -1
- package/dist/infrastructure/storage-inventory.types.js.map +1 -1
- package/dist/infrastructure/storage-reservations.types.d.ts +2 -0
- package/dist/infrastructure/storage-reservations.types.js.map +1 -1
- package/dist/infrastructure/task-queue-bullmq-resources.d.ts +13 -0
- package/dist/infrastructure/task-queue-bullmq-resources.js +118 -0
- package/dist/infrastructure/task-queue-bullmq-resources.js.map +1 -0
- package/dist/infrastructure/task-queue-bullmq-state.d.ts +5 -0
- package/dist/infrastructure/task-queue-bullmq-state.js +26 -0
- package/dist/infrastructure/task-queue-bullmq-state.js.map +1 -0
- package/dist/infrastructure/task-queue-bullmq.constants.d.ts +7 -0
- package/dist/infrastructure/task-queue-bullmq.constants.js +79 -0
- package/dist/infrastructure/task-queue-bullmq.constants.js.map +1 -0
- package/dist/infrastructure/task-queue-bullmq.d.ts +3 -0
- package/dist/infrastructure/task-queue-bullmq.js +124 -0
- package/dist/infrastructure/task-queue-bullmq.js.map +1 -0
- package/dist/infrastructure/task-queue-bullmq.types.d.ts +17 -0
- package/dist/infrastructure/task-queue-bullmq.types.js +2 -0
- package/dist/infrastructure/task-queue-bullmq.types.js.map +1 -0
- package/dist/infrastructure/transport-archive.constants.d.ts +6 -0
- package/dist/infrastructure/transport-archive.constants.js +7 -0
- package/dist/infrastructure/transport-archive.constants.js.map +1 -0
- package/dist/infrastructure/transport-archive.d.ts +5 -0
- package/dist/infrastructure/transport-archive.js +157 -0
- package/dist/infrastructure/transport-archive.js.map +1 -0
- package/dist/infrastructure/transport-archive.types.d.ts +17 -0
- package/dist/infrastructure/transport-archive.types.js +2 -0
- package/dist/infrastructure/transport-archive.types.js.map +1 -0
- package/dist/infrastructure/transport-artifact-store.d.ts +3 -0
- package/dist/infrastructure/transport-artifact-store.js +31 -0
- package/dist/infrastructure/transport-artifact-store.js.map +1 -0
- package/dist/infrastructure/transport-artifact-store.types.d.ts +4 -0
- package/dist/infrastructure/transport-artifact-store.types.js +2 -0
- package/dist/infrastructure/transport-artifact-store.types.js.map +1 -0
- package/dist/infrastructure/transport-checkpoint.d.ts +5 -0
- package/dist/infrastructure/transport-checkpoint.js +105 -0
- package/dist/infrastructure/transport-checkpoint.js.map +1 -0
- package/dist/infrastructure/transport-checkpoint.types.d.ts +9 -0
- package/dist/infrastructure/transport-checkpoint.types.js +2 -0
- package/dist/infrastructure/transport-checkpoint.types.js.map +1 -0
- package/dist/infrastructure/transport-conversations.d.ts +4 -0
- package/dist/infrastructure/transport-conversations.js +69 -0
- package/dist/infrastructure/transport-conversations.js.map +1 -0
- package/dist/infrastructure/transport-conversations.types.d.ts +4 -0
- package/dist/infrastructure/transport-conversations.types.js +2 -0
- package/dist/infrastructure/transport-conversations.types.js.map +1 -0
- package/dist/infrastructure/transport-envelope.d.ts +7 -0
- package/dist/infrastructure/transport-envelope.js +47 -0
- package/dist/infrastructure/transport-envelope.js.map +1 -0
- package/dist/infrastructure/transport-journal.d.ts +6 -0
- package/dist/infrastructure/transport-journal.js +93 -0
- package/dist/infrastructure/transport-journal.js.map +1 -0
- package/dist/infrastructure/transport-journal.types.d.ts +10 -0
- package/dist/infrastructure/transport-journal.types.js +2 -0
- package/dist/infrastructure/transport-journal.types.js.map +1 -0
- package/dist/infrastructure/transport-json.d.ts +6 -0
- package/dist/infrastructure/transport-json.js +46 -0
- package/dist/infrastructure/transport-json.js.map +1 -0
- package/dist/infrastructure/transport-reservations.d.ts +5 -0
- package/dist/infrastructure/transport-reservations.js +89 -0
- package/dist/infrastructure/transport-reservations.js.map +1 -0
- package/dist/infrastructure/transport-reservations.types.d.ts +4 -0
- package/dist/infrastructure/transport-reservations.types.js +2 -0
- package/dist/infrastructure/transport-reservations.types.js.map +1 -0
- package/dist/infrastructure/transport.constants.d.ts +8 -0
- package/dist/infrastructure/transport.constants.js +9 -0
- package/dist/infrastructure/transport.constants.js.map +1 -0
- package/dist/infrastructure/workflow-checkpoint.js +7 -0
- package/dist/infrastructure/workflow-checkpoint.js.map +1 -1
- package/dist/infrastructure/workflow-checkpoint.types.d.ts +3 -1
- package/dist/infrastructure/workflow-checkpoint.types.js.map +1 -1
- package/package.json +26 -5
|
@@ -42,7 +42,7 @@ export async function captureConversation(format, id, repository, lease, staging
|
|
|
42
42
|
await rm(temporary, { force: true });
|
|
43
43
|
}
|
|
44
44
|
if (layout.sidecars) {
|
|
45
|
-
const remoteSidecars = posix.join(posix.dirname(remote), id, "subagents");
|
|
45
|
+
const remoteSidecars = posix.join(posix.dirname(remote.replaceAll("\\", "/")), id, "subagents");
|
|
46
46
|
const listed = options.local
|
|
47
47
|
? {
|
|
48
48
|
status: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../../../src/infrastructure/conversations/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAMtD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAA0B,EAC1B,EAAU,EACV,UAAkB,EAClB,KAAmB,EACnB,OAAe,EACf,UAA0B,EA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EAAE,CAAC,CAAC;oBACrC,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,IAAI,EAAE,CACZ,uCAAuC,MAAM,CAAC,KAAK,CAAC,EAAE,CACvD,CAAC;gBACJ,CAAC;YACH,CAAC;IACL,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, join, posix, resolve } from \"node:path\";\nimport { OutpostError } from \"../../domain/errors.ts\";\nimport type { SandboxLease } from \"../../domain/sandbox.types.ts\";\nimport type {\n ConversationFormat,\n ConversationLocation,\n} from \"../conversations.types.ts\";\nimport { safeDestination } from \"../files.ts\";\nimport type { CaptureOptions } from \"./capture.types.ts\";\nimport { transcriptSearchBytes } from \"./conversation.constants.ts\";\nimport { files } from \"./files.ts\";\nimport { conversationLayout } from \"./layout.ts\";\nimport { locateConversation } from \"./locate.ts\";\nimport { validId } from \"./paths.ts\";\nimport { relocateTranscript } from \"./relocate.ts\";\n\nexport async function captureConversation(\n format: ConversationFormat,\n id: string,\n repository: string,\n lease: SandboxLease,\n staging: string,\n options: CaptureOptions = {},\n): Promise<ConversationLocation> {\n validId(id);\n const home = options.home ?? homedir();\n const layout = conversationLayout(format);\n const search = layout.remoteSearchRoot(lease.home);\n const pattern = layout.pattern(id);\n const result = options.local\n ? {\n status: 0,\n stdout: (await locateConversation(format, id, lease.root, lease.home))\n .file,\n }\n : await lease.invoke({\n executable: \"find\",\n arguments: [search, \"-type\", \"f\", \"-name\", pattern],\n retain: transcriptSearchBytes,\n });\n const remote = result.stdout.trim().split(\"\\n\").filter(Boolean)[0];\n if (result.status !== 0 || !remote)\n throw new OutpostError(\n \"session\",\n `Agent emitted conversation ${id} but its transcript is unavailable`,\n { id, search },\n );\n const file = layout.capturePath(id, repository, home, remote);\n await mkdir(staging, { recursive: true });\n const temporary = join(staging, `${randomUUID()}.jsonl`);\n await lease.download(remote, temporary);\n await mkdir(dirname(file), { recursive: true });\n try {\n await writeFile(\n file,\n relocateTranscript(\n await readFile(temporary, \"utf8\"),\n resolve(repository),\n ),\n { mode: 0o600 },\n );\n } finally {\n await rm(temporary, { force: true });\n }\n if (layout.sidecars) {\n const remoteSidecars = posix.join(\n posix.dirname(remote.replaceAll(\"\\\\\", \"/\")),\n id,\n \"subagents\",\n );\n const listed = options.local\n ? {\n status: 0,\n stdout: (await files(join(dirname(remote), id, \"subagents\"))).join(\n \"\\n\",\n ),\n }\n : await lease.invoke({\n executable: \"find\",\n arguments: [remoteSidecars, \"-type\", \"f\", \"-name\", \"*.jsonl\"],\n retain: transcriptSearchBytes,\n });\n if (listed.status === 0)\n for (const child of listed.stdout.split(\"\\n\").filter(Boolean)) {\n try {\n const scratch = join(staging, `${randomUUID()}.jsonl`);\n await lease.download(child, scratch);\n const destination = await safeDestination(\n join(dirname(file), id, \"subagents\"),\n posix.relative(\n remoteSidecars.replaceAll(\"\\\\\", \"/\"),\n child.replaceAll(\"\\\\\", \"/\"),\n ),\n );\n await mkdir(dirname(destination), { recursive: true });\n try {\n await writeFile(\n destination,\n relocateTranscript(\n await readFile(scratch, \"utf8\"),\n resolve(repository),\n ),\n { mode: 0o600 },\n );\n } finally {\n await rm(scratch, { force: true });\n }\n } catch (cause) {\n options.warn?.(\n `Could not capture child transcript: ${String(cause)}`,\n );\n }\n }\n }\n return { id, file, format };\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transportConversations } from "./transport-conversations.ts";
|
|
1
2
|
import type { ConversationFormat } from "./conversations.types.ts";
|
|
2
3
|
import { captureConversation } from "./conversations/capture.ts";
|
|
3
4
|
import { locateConversation } from "./conversations/locate.ts";
|
|
@@ -13,6 +14,7 @@ export { projectKey } from "./conversations/paths.ts";
|
|
|
13
14
|
export { relocateTranscript } from "./conversations/relocate.ts";
|
|
14
15
|
export { restoreConversation } from "./conversations/restore.ts";
|
|
15
16
|
export declare const conversations: {
|
|
17
|
+
transported: typeof transportConversations;
|
|
16
18
|
native: typeof nativeConversations;
|
|
17
19
|
locate: typeof locateConversation;
|
|
18
20
|
capture: typeof captureConversation;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transportConversations } from "./transport-conversations.js";
|
|
1
2
|
import { homedir } from "node:os";
|
|
2
3
|
import { join, resolve } from "node:path";
|
|
3
4
|
import { captureConversation } from "./conversations/capture.js";
|
|
@@ -14,6 +15,7 @@ export { projectKey } from "./conversations/paths.js";
|
|
|
14
15
|
export { relocateTranscript } from "./conversations/relocate.js";
|
|
15
16
|
export { restoreConversation } from "./conversations/restore.js";
|
|
16
17
|
export const conversations = {
|
|
18
|
+
transported: transportConversations,
|
|
17
19
|
native: nativeConversations,
|
|
18
20
|
locate: locateConversation,
|
|
19
21
|
capture: captureConversation,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../src/infrastructure/conversations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,kBAAkB;IAC1B,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,kBAAkB;IAC3B,UAAU;IACV,UAAU,CAAC,EAAU,EAAE,UAAkB,EAAE,IAAI,GAAG,OAAO,EAAE;QACzD,OAAO,CAAC,EAAE,CAAC,CAAC;QACZ,OAAO,IAAI,CACT,IAAI,EACJ,SAAS,EACT,UAAU,EACV,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,EAC/B,GAAG,EAAE,QAAQ,CACd,CAAC;IACJ,CAAC;IACD,SAAS,CACP,MAA0B,EAC1B,UAAkB,EAClB,IAAI,GAAG,OAAO,EAAE;QAEhB,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAChE,CAAC;IACD,WAAW,EAAE,UAAU;CACxB,CAAC","sourcesContent":["import { homedir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport type { ConversationFormat } from \"./conversations.types.ts\";\nimport { captureConversation } from \"./conversations/capture.ts\";\nimport { conversationLayout } from \"./conversations/layout.ts\";\nimport { locateConversation } from \"./conversations/locate.ts\";\nimport { nativeConversations } from \"./conversations/native-store.ts\";\nimport { projectKey, remotePath, validId } from \"./conversations/paths.ts\";\nimport { relocateTranscript } from \"./conversations/relocate.ts\";\nimport { restoreConversation } from \"./conversations/restore.ts\";\n\nexport type {\n ConversationFormat,\n ConversationLocation,\n} from \"./conversations.types.ts\";\nexport { captureConversation } from \"./conversations/capture.ts\";\nexport { locateConversation } from \"./conversations/locate.ts\";\nexport { nativeConversations } from \"./conversations/native-store.ts\";\nexport { projectKey } from \"./conversations/paths.ts\";\nexport { relocateTranscript } from \"./conversations/relocate.ts\";\nexport { restoreConversation } from \"./conversations/restore.ts\";\n\nexport const conversations = {\n native: nativeConversations,\n locate: locateConversation,\n capture: captureConversation,\n restore: restoreConversation,\n rewrite: relocateTranscript,\n projectKey,\n claudePath(id: string, repository: string, home = homedir()): string {\n validId(id);\n return join(\n home,\n \".claude\",\n \"projects\",\n projectKey(resolve(repository)),\n `${id}.jsonl`,\n );\n },\n directory(\n format: ConversationFormat,\n repository: string,\n home = homedir(),\n ): string {\n return conversationLayout(format).directory(repository, home);\n },\n destination: remotePath,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../src/infrastructure/conversations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,WAAW,EAAE,sBAAsB;IACnC,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,kBAAkB;IAC1B,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,kBAAkB;IAC3B,UAAU;IACV,UAAU,CAAC,EAAU,EAAE,UAAkB,EAAE,IAAI,GAAG,OAAO,EAAE;QACzD,OAAO,CAAC,EAAE,CAAC,CAAC;QACZ,OAAO,IAAI,CACT,IAAI,EACJ,SAAS,EACT,UAAU,EACV,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,EAC/B,GAAG,EAAE,QAAQ,CACd,CAAC;IACJ,CAAC;IACD,SAAS,CACP,MAA0B,EAC1B,UAAkB,EAClB,IAAI,GAAG,OAAO,EAAE;QAEhB,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAChE,CAAC;IACD,WAAW,EAAE,UAAU;CACxB,CAAC","sourcesContent":["import { transportConversations } from \"./transport-conversations.ts\";\nimport { homedir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport type { ConversationFormat } from \"./conversations.types.ts\";\nimport { captureConversation } from \"./conversations/capture.ts\";\nimport { conversationLayout } from \"./conversations/layout.ts\";\nimport { locateConversation } from \"./conversations/locate.ts\";\nimport { nativeConversations } from \"./conversations/native-store.ts\";\nimport { projectKey, remotePath, validId } from \"./conversations/paths.ts\";\nimport { relocateTranscript } from \"./conversations/relocate.ts\";\nimport { restoreConversation } from \"./conversations/restore.ts\";\n\nexport type {\n ConversationFormat,\n ConversationLocation,\n} from \"./conversations.types.ts\";\nexport { captureConversation } from \"./conversations/capture.ts\";\nexport { locateConversation } from \"./conversations/locate.ts\";\nexport { nativeConversations } from \"./conversations/native-store.ts\";\nexport { projectKey } from \"./conversations/paths.ts\";\nexport { relocateTranscript } from \"./conversations/relocate.ts\";\nexport { restoreConversation } from \"./conversations/restore.ts\";\n\nexport const conversations = {\n transported: transportConversations,\n native: nativeConversations,\n locate: locateConversation,\n capture: captureConversation,\n restore: restoreConversation,\n rewrite: relocateTranscript,\n projectKey,\n claudePath(id: string, repository: string, home = homedir()): string {\n validId(id);\n return join(\n home,\n \".claude\",\n \"projects\",\n projectKey(resolve(repository)),\n `${id}.jsonl`,\n );\n },\n directory(\n format: ConversationFormat,\n repository: string,\n home = homedir(),\n ): string {\n return conversationLayout(format).directory(repository, home);\n },\n destination: remotePath,\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { lstat, open
|
|
2
|
-
import { resolve } from "node:path";
|
|
1
|
+
import { lstat, open } from "node:fs/promises";
|
|
3
2
|
import { positive } from "../domain/errors.js";
|
|
4
3
|
import { inspectionFileFlags } from "./inspection-file.constants.js";
|
|
4
|
+
import { isDirectInspectionPath } from "./inspection-path.js";
|
|
5
5
|
function unchanged(before, after) {
|
|
6
6
|
return (before.dev === after.dev &&
|
|
7
7
|
before.ino === after.ino &&
|
|
@@ -12,7 +12,7 @@ function unchanged(before, after) {
|
|
|
12
12
|
export async function readInspectionFile(path, maxBytes) {
|
|
13
13
|
positive(maxBytes, "maxBytes");
|
|
14
14
|
const before = await lstat(path);
|
|
15
|
-
if (!before.isFile() || (await
|
|
15
|
+
if (!before.isFile() || !(await isDirectInspectionPath(path)))
|
|
16
16
|
throw new Error("Inspection path changed");
|
|
17
17
|
if (before.size > maxBytes)
|
|
18
18
|
throw new Error("Inspection file is too large");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspection-file.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"inspection-file.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,SAAS,SAAS,CAAC,MAAa,EAAE,KAAY;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;QACxB,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;QACxB,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;QAC1B,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;QAChC,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CACjC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAY,EACZ,QAAgB;IAEhB,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,MAAM,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,IAAI,MAAM,CAAC,IAAI,GAAG,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC5E,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACnD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QAC1C,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,OAAO,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YAC9B,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CACnC,MAAM,EACN,MAAM,EACN,MAAM,CAAC,MAAM,GAAG,MAAM,EACtB,MAAM,CACP,CAAC;YACF,IAAI,CAAC,SAAS;gBAAE,MAAM;YACtB,MAAM,IAAI,SAAS,CAAC;QACtB,CAAC;QACD,IAAI,MAAM,GAAG,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACvE,IACE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YACrC,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;YAErC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["import { lstat, open } from \"node:fs/promises\";\nimport type { Stats } from \"node:fs\";\nimport { positive } from \"../domain/errors.ts\";\nimport { inspectionFileFlags } from \"./inspection-file.constants.ts\";\nimport { isDirectInspectionPath } from \"./inspection-path.ts\";\n\nfunction unchanged(before: Stats, after: Stats): boolean {\n return (\n before.dev === after.dev &&\n before.ino === after.ino &&\n before.size === after.size &&\n before.mtimeMs === after.mtimeMs &&\n before.ctimeMs === after.ctimeMs\n );\n}\n\nexport async function readInspectionFile(\n path: string,\n maxBytes: number,\n): Promise<Buffer> {\n positive(maxBytes, \"maxBytes\");\n const before = await lstat(path);\n if (!before.isFile() || !(await isDirectInspectionPath(path)))\n throw new Error(\"Inspection path changed\");\n if (before.size > maxBytes) throw new Error(\"Inspection file is too large\");\n const file = await open(path, inspectionFileFlags);\n try {\n const opened = await file.stat();\n if (!opened.isFile() || !unchanged(before, opened))\n throw new Error(\"Inspection file changed\");\n const buffer = Buffer.alloc(maxBytes + 1);\n let length = 0;\n while (length < buffer.length) {\n const { bytesRead } = await file.read(\n buffer,\n length,\n buffer.length - length,\n length,\n );\n if (!bytesRead) break;\n length += bytesRead;\n }\n if (length > maxBytes) throw new Error(\"Inspection file is too large\");\n if (\n !unchanged(opened, await file.stat()) ||\n !unchanged(opened, await lstat(path))\n )\n throw new Error(\"Inspection file changed\");\n return buffer.subarray(0, length);\n } finally {\n await file.close();\n }\n}\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { lstat, open, readlink
|
|
3
|
-
import { dirname
|
|
2
|
+
import { lstat, open, readlink } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
4
|
import { OutpostError } from "../domain/errors.js";
|
|
5
5
|
import { inspectionFileFlags } from "./inspection-file.constants.js";
|
|
6
6
|
import { inspectionHashChunkBytes } from "./inspection-hash.constants.js";
|
|
7
|
+
import { isDirectInspectionPath } from "./inspection-path.js";
|
|
7
8
|
function unchanged(before, after) {
|
|
8
9
|
return (before.dev === after.dev &&
|
|
9
10
|
before.ino === after.ino &&
|
|
@@ -13,7 +14,7 @@ function unchanged(before, after) {
|
|
|
13
14
|
}
|
|
14
15
|
export async function hashInspectionEntry(path, maxBytes = Number.MAX_SAFE_INTEGER) {
|
|
15
16
|
const before = await lstat(path);
|
|
16
|
-
if ((await
|
|
17
|
+
if (!(await isDirectInspectionPath(dirname(path))))
|
|
17
18
|
throw new Error("Hash path traverses a symlink");
|
|
18
19
|
const hash = createHash("sha256");
|
|
19
20
|
if (before.isSymbolicLink()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspection-hash.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"inspection-hash.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,SAAS,SAAS,CAAC,MAAa,EAAE,KAAY;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;QACxB,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;QACxB,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;QAC1B,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;QAChC,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CACj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AAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { lstat, open, readlink } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { Stats } from \"node:fs\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport { inspectionFileFlags } from \"./inspection-file.constants.ts\";\nimport { inspectionHashChunkBytes } from \"./inspection-hash.constants.ts\";\nimport { isDirectInspectionPath } from \"./inspection-path.ts\";\nimport type { InspectionHash } from \"./inspection-hash.types.ts\";\n\nfunction unchanged(before: Stats, after: Stats): boolean {\n return (\n before.dev === after.dev &&\n before.ino === after.ino &&\n before.size === after.size &&\n before.mtimeMs === after.mtimeMs &&\n before.ctimeMs === after.ctimeMs\n );\n}\n\nexport async function hashInspectionEntry(\n path: string,\n maxBytes = Number.MAX_SAFE_INTEGER,\n): Promise<InspectionHash> {\n const before = await lstat(path);\n if (!(await isDirectInspectionPath(dirname(path))))\n throw new Error(\"Hash path traverses a symlink\");\n const hash = createHash(\"sha256\");\n if (before.isSymbolicLink()) {\n const target = await readlink(path, { encoding: \"buffer\" });\n if (target.length > maxBytes)\n throw new OutpostError(\"workspace\", \"Checksum byte limit exceeded\", {\n reason: \"CHECKSUM_LIMIT\",\n });\n if (!unchanged(before, await lstat(path)))\n throw new Error(\"Hash source changed\");\n return {\n kind: \"symlink\",\n bytes: target.length,\n sha256: hash.update(target).digest(\"hex\"),\n };\n }\n if (!before.isFile()) throw new Error(\"Hash source is not a regular file\");\n if (before.size > maxBytes)\n throw new OutpostError(\"workspace\", \"Checksum byte limit exceeded\", {\n reason: \"CHECKSUM_LIMIT\",\n });\n const file = await open(path, inspectionFileFlags);\n try {\n const opened = await file.stat();\n if (!opened.isFile() || !unchanged(before, opened))\n throw new Error(\"Hash source changed\");\n const buffer = Buffer.alloc(inspectionHashChunkBytes);\n let bytes = 0;\n while (bytes < opened.size) {\n const result = await file.read(\n buffer,\n 0,\n Math.min(buffer.length, opened.size - bytes),\n bytes,\n );\n if (!result.bytesRead) throw new Error(\"Hash source truncated\");\n bytes += result.bytesRead;\n hash.update(buffer.subarray(0, result.bytesRead));\n }\n if (\n !unchanged(opened, await file.stat()) ||\n !unchanged(opened, await lstat(path))\n )\n throw new Error(\"Hash source changed\");\n return { kind: \"file\", bytes, sha256: hash.digest(\"hex\") };\n } finally {\n await file.close();\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isDirectInspectionPath(path: string): Promise<boolean>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
export async function isDirectInspectionPath(path) {
|
|
4
|
+
let current = resolve(path);
|
|
5
|
+
if ((await realpath(current)) === current)
|
|
6
|
+
return true;
|
|
7
|
+
if (process.platform !== "win32")
|
|
8
|
+
return false;
|
|
9
|
+
while (true) {
|
|
10
|
+
if ((await lstat(current)).isSymbolicLink())
|
|
11
|
+
return false;
|
|
12
|
+
const parent = dirname(current);
|
|
13
|
+
if (parent === current)
|
|
14
|
+
return true;
|
|
15
|
+
current = parent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=inspection-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection-path.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAY;IACvD,IAAI,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IACvD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAC/C,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,EAAE;YAAE,OAAO,KAAK,CAAC;QAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAChC,IAAI,MAAM,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC;QACpC,OAAO,GAAG,MAAM,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { lstat, realpath } from \"node:fs/promises\";\nimport { dirname, resolve } from \"node:path\";\n\nexport async function isDirectInspectionPath(path: string): Promise<boolean> {\n let current = resolve(path);\n if ((await realpath(current)) === current) return true;\n if (process.platform !== \"win32\") return false;\n while (true) {\n if ((await lstat(current)).isSymbolicLink()) return false;\n const parent = dirname(current);\n if (parent === current) return true;\n current = parent;\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transportJournal } from "./transport-journal.js";
|
|
1
2
|
import { lock } from "./git/lock.js";
|
|
2
3
|
import { markJournalClosed } from "./journal-retention.js";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
@@ -5,6 +6,11 @@ import { mkdir, open, rm } from "node:fs/promises";
|
|
|
5
6
|
import { dirname, join, resolve } from "node:path";
|
|
6
7
|
import { reporter } from "./reporter.js";
|
|
7
8
|
export async function journal(repository, logging = {}, label) {
|
|
9
|
+
if (logging && logging !== "stdout" && logging.transporter) {
|
|
10
|
+
if (logging.file !== undefined)
|
|
11
|
+
throw new Error("Provide a journal file or transporter, not both");
|
|
12
|
+
return transportJournal(logging.transporter, logging.verbose ?? false, label);
|
|
13
|
+
}
|
|
8
14
|
const file = logging && logging !== "stdout"
|
|
9
15
|
? resolve(repository, logging.file ??
|
|
10
16
|
join(".outpost", "logs", `${label ? label.replace(/[^A-Za-z0-9_-]/g, "-").slice(0, 64) + "-" : ""}${new Date().toISOString().replaceAll(":", "-")}-${randomUUID()}.js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AAO;YACT,MAAM,IAAI,GACR,IAAI,CAAC,SAAS,CAAC;gBACb,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBAC5B,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3B,GAAG,KAAK;aACT,CAAC,GAAG,IAAI,CAAC;YACZ,IAAI,OAAO,KAAK,QAAQ;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC;;gBAEvC,OAAO,GAAG,OAAO;qBACd,IAAI,CAAC,KAAK,IAAI,EAAE;oBACf,MAAM,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC5B,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;oBACf,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC,CAAC,CAAC;QACT,CAAC;QACD,KAAK;YACH,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE;gBACtB,IAAI,CAAC;oBACH,MAAM,OAAO,CAAC;oBACd,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC;oBACtB,IAAI,OAAO;wBAAE,MAAM,OAAO,CAAC;oBAC3B,IAAI,IAAI,IAAI,OAAO;wBAAE,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC;wBAAS,CAAC;oBACT,MAAM,OAAO,EAAE,EAAE,CAAC;gBACpB,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { lock } from \"./git/lock.ts\";\nimport { markJournalClosed } from \"./journal-retention.ts\";\nimport { randomUUID } from \"node:crypto\";\nimport type { FileHandle } from \"node:fs/promises\";\nimport { mkdir, open, rm } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport type { Journal, Logging } from \"./journal.types.ts\";\nimport { reporter } from \"./reporter.ts\";\n\nexport type { Logging } from \"./journal.types.ts\";\n\nexport async function journal(\n repository: string,\n logging: Logging = {},\n label?: string,\n): Promise<Journal> {\n const file =\n logging && logging !== \"stdout\"\n ? resolve(\n repository,\n logging.file ??\n join(\n \".outpost\",\n \"logs\",\n `${label ? label.replace(/[^A-Za-z0-9_-]/g, \"-\").slice(0, 64) + \"-\" : \"\"}${new Date().toISOString().replaceAll(\":\", \"-\")}-${randomUUID()}.jsonl`,\n ),\n )\n : undefined;\n let handle: FileHandle | undefined,\n pending = Promise.resolve();\n let failure: unknown;\n let release: (() => Promise<void>) | undefined;\n let closing: Promise<void> | undefined;\n const managed =\n !!logging && logging !== \"stdout\" && logging.file === undefined;\n const display = reporter({ ...(label ? { label } : {}) });\n if (file) {\n await mkdir(dirname(file), { recursive: true });\n release = await lock(repository, `journal:${file}`);\n try {\n await rm(`${file}.closed.json`, { force: true });\n handle = await open(file, managed ? \"wx\" : \"a\", 0o600);\n await handle.write(\n JSON.stringify({\n kind: \"dispatch-start\",\n at: new Date().toISOString(),\n label,\n }) + \"\\n\",\n );\n } catch (error) {\n await handle?.close();\n await release();\n throw error;\n }\n }\n return {\n ...(file ? { file } : {}),\n record(event) {\n if (!logging || closing) return;\n if (event.kind === \"raw\" && logging !== \"stdout\" && !logging.verbose)\n return;\n const line =\n JSON.stringify({\n at: new Date().toISOString(),\n ...(label ? { label } : {}),\n ...event,\n }) + \"\\n\";\n if (logging === \"stdout\") display(event);\n else\n pending = pending\n .then(async () => {\n await handle?.write(line);\n })\n .catch((error) => {\n failure = error;\n });\n },\n close() {\n closing ??= (async () => {\n try {\n await pending;\n await handle?.close();\n if (failure) throw failure;\n if (file && managed) await markJournalClosed(file);\n } finally {\n await release?.();\n }\n })();\n return closing;\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"journal.js","sourceRoot":"","sources":["../../src/infrastructure/journal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EA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,CAAC,KAAK;YACV,IAAI,CAAC,OAAO,IAAI,OAAO;gBAAE,OAAO;YAChC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,OAAO,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO;gBAClE,OAAO;YACT,MAAM,IAAI,GACR,IAAI,CAAC,SAAS,CAAC;gBACb,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBAC5B,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3B,GAAG,KAAK;aACT,CAAC,GAAG,IAAI,CAAC;YACZ,IAAI,OAAO,KAAK,QAAQ;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC;;gBAEvC,OAAO,GAAG,OAAO;qBACd,IAAI,CAAC,KAAK,IAAI,EAAE;oBACf,MAAM,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC5B,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;oBACf,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC,CAAC,CAAC;QACT,CAAC;QACD,KAAK;YACH,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE;gBACtB,IAAI,CAAC;oBACH,MAAM,OAAO,CAAC;oBACd,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC;oBACtB,IAAI,OAAO;wBAAE,MAAM,OAAO,CAAC;oBAC3B,IAAI,IAAI,IAAI,OAAO;wBAAE,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC;wBAAS,CAAC;oBACT,MAAM,OAAO,EAAE,EAAE,CAAC;gBACpB,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { transportJournal } from \"./transport-journal.ts\";\nimport { lock } from \"./git/lock.ts\";\nimport { markJournalClosed } from \"./journal-retention.ts\";\nimport { randomUUID } from \"node:crypto\";\nimport type { FileHandle } from \"node:fs/promises\";\nimport { mkdir, open, rm } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport type { Journal, Logging } from \"./journal.types.ts\";\nimport { reporter } from \"./reporter.ts\";\n\nexport type { Logging } from \"./journal.types.ts\";\n\nexport async function journal(\n repository: string,\n logging: Logging = {},\n label?: string,\n): Promise<Journal> {\n if (logging && logging !== \"stdout\" && logging.transporter) {\n if (logging.file !== undefined)\n throw new Error(\"Provide a journal file or transporter, not both\");\n return transportJournal(\n logging.transporter,\n logging.verbose ?? false,\n label,\n );\n }\n const file =\n logging && logging !== \"stdout\"\n ? resolve(\n repository,\n logging.file ??\n join(\n \".outpost\",\n \"logs\",\n `${label ? label.replace(/[^A-Za-z0-9_-]/g, \"-\").slice(0, 64) + \"-\" : \"\"}${new Date().toISOString().replaceAll(\":\", \"-\")}-${randomUUID()}.jsonl`,\n ),\n )\n : undefined;\n let handle: FileHandle | undefined,\n pending = Promise.resolve();\n let failure: unknown;\n let release: (() => Promise<void>) | undefined;\n let closing: Promise<void> | undefined;\n const managed =\n !!logging && logging !== \"stdout\" && logging.file === undefined;\n const display = reporter({ ...(label ? { label } : {}) });\n if (file) {\n await mkdir(dirname(file), { recursive: true });\n release = await lock(repository, `journal:${file}`);\n try {\n await rm(`${file}.closed.json`, { force: true });\n handle = await open(file, managed ? \"wx\" : \"a\", 0o600);\n await handle.write(\n JSON.stringify({\n kind: \"dispatch-start\",\n at: new Date().toISOString(),\n label,\n }) + \"\\n\",\n );\n } catch (error) {\n await handle?.close();\n await release();\n throw error;\n }\n }\n return {\n ...(file ? { file } : {}),\n record(event) {\n if (!logging || closing) return;\n if (event.kind === \"raw\" && logging !== \"stdout\" && !logging.verbose)\n return;\n const line =\n JSON.stringify({\n at: new Date().toISOString(),\n ...(label ? { label } : {}),\n ...event,\n }) + \"\\n\";\n if (logging === \"stdout\") display(event);\n else\n pending = pending\n .then(async () => {\n await handle?.write(line);\n })\n .catch((error) => {\n failure = error;\n });\n },\n close() {\n closing ??= (async () => {\n try {\n await pending;\n await handle?.close();\n if (failure) throw failure;\n if (file && managed) await markJournalClosed(file);\n } finally {\n await release?.();\n }\n })();\n return closing;\n },\n };\n}\n"]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import type { Transport, TransportReference } from "../domain/transport.types.ts";
|
|
1
2
|
import type { AgentEvent } from "../domain/agent.types.ts";
|
|
2
3
|
export type Logging = false | "stdout" | {
|
|
3
4
|
readonly file?: string;
|
|
5
|
+
readonly transporter?: Transport;
|
|
4
6
|
readonly verbose?: boolean;
|
|
5
7
|
};
|
|
6
8
|
export type Journal = {
|
|
7
9
|
file?: string;
|
|
10
|
+
reference?: TransportReference;
|
|
8
11
|
record(event: AgentEvent): void;
|
|
9
12
|
close(): Promise<void>;
|
|
10
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"journal.types.js","sourceRoot":"","sources":["../../src/infrastructure/journal.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentEvent } from \"../domain/agent.types.ts\";\n\nexport type Logging =\n false
|
|
1
|
+
{"version":3,"file":"journal.types.js","sourceRoot":"","sources":["../../src/infrastructure/journal.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Transport,\n TransportReference,\n} from \"../domain/transport.types.ts\";\nimport type { AgentEvent } from \"../domain/agent.types.ts\";\n\nexport type Logging =\n | false\n | \"stdout\"\n | {\n readonly file?: string;\n readonly transporter?: Transport;\n readonly verbose?: boolean;\n };\n\nexport type Journal = {\n file?: string;\n reference?: TransportReference;\n record(event: AgentEvent): void;\n close(): Promise<void>;\n};\n"]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { mkdir, lstat, open, rename, rm, readdir } from "node:fs/promises";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { setTimeout } from "node:timers/promises";
|
|
5
|
+
import { TransportConflict, transportKey, transportCondition, } from "../domain/transport.js";
|
|
6
|
+
import { lock } from "./git/lock.js";
|
|
7
|
+
import { OutpostError } from "../domain/errors.js";
|
|
8
|
+
import { readInspectionFile } from "./inspection-file.js";
|
|
9
|
+
import { decodeObject, encodeObject, readLimit } from "./transport-envelope.js";
|
|
10
|
+
import { transportDefaults } from "./transport.constants.js";
|
|
11
|
+
async function privateDirectory(path) {
|
|
12
|
+
const parent = dirname(path);
|
|
13
|
+
if (parent !== path) {
|
|
14
|
+
await privateDirectory(parent);
|
|
15
|
+
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
16
|
+
}
|
|
17
|
+
if (!(await lstat(path)).isDirectory())
|
|
18
|
+
throw new Error("Transport directories must not be symlinks");
|
|
19
|
+
}
|
|
20
|
+
export function localTransport(options) {
|
|
21
|
+
const root = resolve(options.directory), objects = join(root, "objects");
|
|
22
|
+
const path = (key) => join(objects, `${transportKey(key)}.object`);
|
|
23
|
+
const read = async (key, options = {}) => {
|
|
24
|
+
options.signal?.throwIfAborted();
|
|
25
|
+
const limit = readLimit(options.maxBytes);
|
|
26
|
+
try {
|
|
27
|
+
const target = path(key);
|
|
28
|
+
const info = await lstat(target);
|
|
29
|
+
const data = await readInspectionFile(target, Math.min(info.size, limit + transportDefaults.headerBytes) || 1);
|
|
30
|
+
options.signal?.throwIfAborted();
|
|
31
|
+
return decodeObject(data, key, limit);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error &&
|
|
35
|
+
typeof error === "object" &&
|
|
36
|
+
"code" in error &&
|
|
37
|
+
error.code === "ENOENT")
|
|
38
|
+
return undefined;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
async function mutate(key, options, action) {
|
|
43
|
+
transportKey(key);
|
|
44
|
+
transportCondition(options.ifRevision);
|
|
45
|
+
await privateDirectory(root);
|
|
46
|
+
const signal = AbortSignal.any([
|
|
47
|
+
AbortSignal.timeout(transportDefaults.lockMs),
|
|
48
|
+
...(options.signal ? [options.signal] : []),
|
|
49
|
+
]);
|
|
50
|
+
let release;
|
|
51
|
+
while (!release) {
|
|
52
|
+
signal.throwIfAborted();
|
|
53
|
+
try {
|
|
54
|
+
release = await lock(root, key);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (!(error instanceof OutpostError) || error.code !== "conflict")
|
|
58
|
+
throw error;
|
|
59
|
+
await setTimeout(transportDefaults.retryMs, undefined, { signal });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
if ((await read(key))?.revision !== (options.ifRevision ?? undefined))
|
|
64
|
+
throw new TransportConflict(key);
|
|
65
|
+
options.signal?.throwIfAborted();
|
|
66
|
+
return await action();
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
await release();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
name: "local",
|
|
74
|
+
read,
|
|
75
|
+
write(key, input, options) {
|
|
76
|
+
const bytes = Buffer.from(input);
|
|
77
|
+
return mutate(key, options, async () => {
|
|
78
|
+
const target = path(key);
|
|
79
|
+
await privateDirectory(dirname(target));
|
|
80
|
+
const { entry, data } = encodeObject(key, bytes);
|
|
81
|
+
const temporary = `${target}.${randomUUID()}.tmp`;
|
|
82
|
+
try {
|
|
83
|
+
const file = await open(temporary, "wx", 0o600);
|
|
84
|
+
try {
|
|
85
|
+
await file.writeFile(data, { signal: options.signal });
|
|
86
|
+
await file.sync();
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await file.close();
|
|
90
|
+
}
|
|
91
|
+
options.signal?.throwIfAborted();
|
|
92
|
+
await rename(temporary, target);
|
|
93
|
+
if (process.platform !== "win32") {
|
|
94
|
+
const parent = await open(dirname(target), "r");
|
|
95
|
+
try {
|
|
96
|
+
await parent.sync();
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
await parent.close();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return entry;
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
await rm(temporary, { force: true });
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
remove(key, options) {
|
|
110
|
+
if (options.ifRevision === null)
|
|
111
|
+
return Promise.reject(new Error("Transport removal requires an existing revision"));
|
|
112
|
+
return mutate(key, options, () => rm(path(key), { force: true }));
|
|
113
|
+
},
|
|
114
|
+
async *list(prefix = "", options = {}) {
|
|
115
|
+
if (prefix)
|
|
116
|
+
transportKey(prefix.replace(/\/$/, ""));
|
|
117
|
+
async function* scan(directory, base) {
|
|
118
|
+
const entries = await readdir(directory, { withFileTypes: true }).catch((error) => {
|
|
119
|
+
if (error.code === "ENOENT")
|
|
120
|
+
return [];
|
|
121
|
+
throw error;
|
|
122
|
+
});
|
|
123
|
+
for (const entry of entries) {
|
|
124
|
+
options.signal?.throwIfAborted();
|
|
125
|
+
const name = `${base}${entry.name}`;
|
|
126
|
+
if (entry.isDirectory())
|
|
127
|
+
yield* scan(join(directory, entry.name), `${name}/`);
|
|
128
|
+
if (entry.isFile() && name.endsWith(".object"))
|
|
129
|
+
yield name.slice(0, -7);
|
|
130
|
+
if (entry.isSymbolicLink())
|
|
131
|
+
throw new Error("Transport objects must not be symlinks");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for await (const key of scan(objects, "")) {
|
|
135
|
+
if (!key.startsWith(prefix))
|
|
136
|
+
continue;
|
|
137
|
+
const object = await read(key, options.signal ? { signal: options.signal } : {});
|
|
138
|
+
if (object) {
|
|
139
|
+
const { bytes: _bytes, ...entry } = object;
|
|
140
|
+
yield entry;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=local-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-transport.js","sourceRoot":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AC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;oBAC1B,IAAI,KAAK,CAAC,cAAc,EAAE;wBACxB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;gBAC9D,CAAC;YACH,CAAC;YACD,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC;gBAC1C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;oBAAE,SAAS;gBACtC,MAAM,MAAM,GAAG,MAAM,IAAI,CACvB,GAAG,EACH,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CACjD,CAAC;gBACF,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC;oBAC3C,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { mkdir, lstat, open, rename, rm, readdir } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { setTimeout } from \"node:timers/promises\";\nimport {\n TransportConflict,\n transportKey,\n transportCondition,\n} from \"../domain/transport.ts\";\nimport type {\n Transport,\n TransportWriteOptions,\n} from \"../domain/transport.types.ts\";\nimport type { LocalTransportOptions } from \"./local-transport.types.ts\";\nimport { lock } from \"./git/lock.ts\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport { readInspectionFile } from \"./inspection-file.ts\";\nimport { decodeObject, encodeObject, readLimit } from \"./transport-envelope.ts\";\nimport { transportDefaults } from \"./transport.constants.ts\";\n\nasync function privateDirectory(path: string): Promise<void> {\n const parent = dirname(path);\n if (parent !== path) {\n await privateDirectory(parent);\n await mkdir(path, { recursive: true, mode: 0o700 });\n }\n if (!(await lstat(path)).isDirectory())\n throw new Error(\"Transport directories must not be symlinks\");\n}\n\nexport function localTransport(options: LocalTransportOptions): Transport {\n const root = resolve(options.directory),\n objects = join(root, \"objects\");\n const path = (key: string) => join(objects, `${transportKey(key)}.object`);\n const read: Transport[\"read\"] = async (key, options = {}) => {\n options.signal?.throwIfAborted();\n const limit = readLimit(options.maxBytes);\n try {\n const target = path(key);\n const info = await lstat(target);\n const data = await readInspectionFile(\n target,\n Math.min(info.size, limit + transportDefaults.headerBytes) || 1,\n );\n options.signal?.throwIfAborted();\n return decodeObject(data, key, limit);\n } catch (error) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n )\n return undefined;\n throw error;\n }\n };\n async function mutate<T>(\n key: string,\n options: TransportWriteOptions,\n action: () => Promise<T>,\n ): Promise<T> {\n transportKey(key);\n transportCondition(options.ifRevision);\n await privateDirectory(root);\n const signal = AbortSignal.any([\n AbortSignal.timeout(transportDefaults.lockMs),\n ...(options.signal ? [options.signal] : []),\n ]);\n let release: (() => Promise<void>) | undefined;\n while (!release) {\n signal.throwIfAborted();\n try {\n release = await lock(root, key);\n } catch (error) {\n if (!(error instanceof OutpostError) || error.code !== \"conflict\")\n throw error;\n await setTimeout(transportDefaults.retryMs, undefined, { signal });\n }\n }\n try {\n if ((await read(key))?.revision !== (options.ifRevision ?? undefined))\n throw new TransportConflict(key);\n options.signal?.throwIfAborted();\n return await action();\n } finally {\n await release();\n }\n }\n return {\n name: \"local\",\n read,\n write(key, input, options) {\n const bytes = Buffer.from(input);\n return mutate(key, options, async () => {\n const target = path(key);\n await privateDirectory(dirname(target));\n const { entry, data } = encodeObject(key, bytes);\n const temporary = `${target}.${randomUUID()}.tmp`;\n try {\n const file = await open(temporary, \"wx\", 0o600);\n try {\n await file.writeFile(data, { signal: options.signal });\n await file.sync();\n } finally {\n await file.close();\n }\n options.signal?.throwIfAborted();\n await rename(temporary, target);\n if (process.platform !== \"win32\") {\n const parent = await open(dirname(target), \"r\");\n try {\n await parent.sync();\n } finally {\n await parent.close();\n }\n }\n return entry;\n } finally {\n await rm(temporary, { force: true });\n }\n });\n },\n remove(key, options) {\n if (options.ifRevision === null)\n return Promise.reject(\n new Error(\"Transport removal requires an existing revision\"),\n );\n return mutate(key, options, () => rm(path(key), { force: true }));\n },\n async *list(prefix = \"\", options = {}) {\n if (prefix) transportKey(prefix.replace(/\\/$/, \"\"));\n async function* scan(\n directory: string,\n base: string,\n ): AsyncIterable<string> {\n const entries = await readdir(directory, { withFileTypes: true }).catch(\n (error) => {\n if (error.code === \"ENOENT\") return [];\n throw error;\n },\n );\n for (const entry of entries) {\n options.signal?.throwIfAborted();\n const name = `${base}${entry.name}`;\n if (entry.isDirectory())\n yield* scan(join(directory, entry.name), `${name}/`);\n if (entry.isFile() && name.endsWith(\".object\"))\n yield name.slice(0, -7);\n if (entry.isSymbolicLink())\n throw new Error(\"Transport objects must not be symlinks\");\n }\n }\n for await (const key of scan(objects, \"\")) {\n if (!key.startsWith(prefix)) continue;\n const object = await read(\n key,\n options.signal ? { signal: options.signal } : {},\n );\n if (object) {\n const { bytes: _bytes, ...entry } = object;\n yield entry;\n }\n }\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-transport.types.js","sourceRoot":"","sources":["../../src/infrastructure/local-transport.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface LocalTransportOptions {\n readonly directory: string;\n}\n"]}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { ResourceInspection } from "./resource-activity.types.ts";
|
|
1
|
+
import type { ResourceActivityRecord, ResourceInspection } from "./resource-activity.types.ts";
|
|
2
|
+
export declare function resourceRecord(value: unknown): ResourceActivityRecord;
|
|
2
3
|
export declare function inspectResourceActivity(repository: string, maxEntries?: number): Promise<ResourceInspection>;
|
|
@@ -54,7 +54,7 @@ function identity(value) {
|
|
|
54
54
|
started: value.started,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
export function resourceRecord(value) {
|
|
58
58
|
object(value);
|
|
59
59
|
invariant(value.version === 1, "Unknown activity version");
|
|
60
60
|
text(value.id);
|
|
@@ -114,7 +114,7 @@ export async function inspectResourceActivity(repository, maxEntries = defaults.
|
|
|
114
114
|
break;
|
|
115
115
|
}
|
|
116
116
|
try {
|
|
117
|
-
const value =
|
|
117
|
+
const value = resourceRecord(JSON.parse((await readInspectionFile(file, defaults.maxRecordBytes)).toString("utf8")));
|
|
118
118
|
invariant(entry.name === `${value.id}.json`, "Activity identity mismatch");
|
|
119
119
|
entries.push({
|
|
120
120
|
path: file,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-activity-inspection.js","sourceRoot":"","sources":["../../src/infrastructure/resource-activity-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,wBAAwB,IAAI,QAAQ,EACpC,sBAAsB,EACtB,cAAc,GACf,MAAM,kCAAkC,CAAC;AAU1C,SAAS,MAAM,CAAC,KAAc;IAC5B,SAAS,CACP,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAC7D,yBAAyB,CAC1B,CAAC;AACJ,CAAC;AACD,SAAS,IAAI,CAAC,KAAc;IAC1B,SAAS,CACP,OAAO,KAAK,KAAK,QAAQ;QACvB,KAAK,CAAC,MAAM,GAAG,CAAC;QAChB,KAAK,CAAC,MA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:fs/promises\";\nimport { join } from \"node:path\";\nimport { invariant, positive } from \"../domain/errors.ts\";\nimport { observeOwnership } from \"./git/process-identity.ts\";\nimport type { LocalProcessIdentity } from \"./git/process-identity.types.ts\";\nimport { readInspectionFile } from \"./inspection-file.ts\";\nimport {\n resourceActivityDefaults as defaults,\n resourceOperationKinds,\n resourcePhases,\n} from \"./resource-activity.constants.ts\";\nimport type {\n ResourceActivityRecord,\n ResourceInspection,\n ResourceInspectionEntry,\n ResourceOperation,\n ResourceOperationResult,\n} from \"./resource-activity.types.ts\";\nimport type { StorageIssue } from \"./storage-inventory.types.ts\";\n\nfunction object(value: unknown): asserts value is Record<string, unknown> {\n invariant(\n !!value && typeof value === \"object\" && !Array.isArray(value),\n \"Invalid activity object\",\n );\n}\nfunction text(value: unknown): asserts value is string {\n invariant(\n typeof value === \"string\" &&\n value.length > 0 &&\n value.length <= defaults.maxText,\n \"Invalid activity text\",\n );\n}\nfunction date(value: unknown): asserts value is string {\n text(value);\n invariant(Number.isFinite(Date.parse(value)), \"Invalid activity time\");\n}\nfunction operation(value: unknown): ResourceOperation {\n object(value);\n invariant(\n typeof value.count === \"number\" &&\n Number.isSafeInteger(value.count) &&\n value.count > 0,\n \"Invalid activity count\",\n );\n date(value.startedAt);\n const kind = resourceOperationKinds.find((kind) => kind === value.kind);\n invariant(kind, \"Invalid activity operation\");\n return { count: value.count, startedAt: value.startedAt, kind };\n}\nfunction result(value: unknown): ResourceOperationResult {\n const base = operation(value);\n object(value);\n text(value.id);\n date(value.finishedAt);\n invariant(\n value.outcome === \"completed\" || value.outcome === \"failed\",\n \"Invalid activity outcome\",\n );\n return {\n ...base,\n id: value.id,\n finishedAt: value.finishedAt,\n outcome: value.outcome,\n };\n}\nfunction identity(value: unknown): LocalProcessIdentity | undefined {\n if (value === undefined) return undefined;\n object(value);\n text(value.host);\n text(value.boot);\n text(value.namespace);\n text(value.started);\n return {\n host: value.host,\n boot: value.boot,\n namespace: value.namespace,\n started: value.started,\n };\n}\nfunction record(value: unknown): ResourceActivityRecord {\n object(value);\n invariant(value.version === 1, \"Unknown activity version\");\n text(value.id);\n text(value.provider);\n text(value.workspace);\n date(value.createdAt);\n date(value.updatedAt);\n invariant(\n typeof value.pid === \"number\" &&\n Number.isSafeInteger(value.pid) &&\n value.pid > 0 &&\n value.pid <= 2_147_483_647,\n \"Invalid activity owner\",\n );\n invariant(\n value.placement === \"host\" ||\n value.placement === \"mounted\" ||\n value.placement === \"remote\",\n \"Invalid activity placement\",\n );\n const phase = resourcePhases.find((phase) => phase === value.phase);\n invariant(phase, \"Invalid activity phase\");\n invariant(\n Array.isArray(value.operations) &&\n value.operations.length <= resourceOperationKinds.length,\n \"Invalid activity operations\",\n );\n const owner = identity(value.identity);\n return {\n version: 1,\n id: value.id,\n pid: value.pid,\n ...(owner ? { identity: owner } : {}),\n provider: value.provider,\n placement: value.placement,\n workspace: value.workspace,\n createdAt: value.createdAt,\n updatedAt: value.updatedAt,\n phase,\n operations: value.operations.map(operation),\n ...(value.lastOperation === undefined\n ? {}\n : { lastOperation: result(value.lastOperation) }),\n ...(value.lastFailure === undefined\n ? {}\n : { lastFailure: result(value.lastFailure) }),\n };\n}\n\nexport async function inspectResourceActivity(\n repository: string,\n maxEntries: number = defaults.maxRecords,\n): Promise<ResourceInspection> {\n positive(maxEntries, \"maxEntries\");\n const entries: ResourceInspectionEntry[] = [];\n const issues: StorageIssue[] = [];\n let path = repository;\n try {\n for (const part of [\".outpost\", \"locks\", defaults.directory]) {\n path = join(path, part);\n const info = await lstat(path);\n invariant(\n info.isDirectory() &&\n !info.isSymbolicLink() &&\n (await realpath(path)) === path,\n \"Unsafe activity directory\",\n );\n }\n for await (const entry of await opendir(path)) {\n const file = join(path, entry.name);\n if (entries.length >= Math.min(maxEntries, defaults.maxRecords)) {\n issues.push({ path, code: \"RESOURCE_ENTRY_LIMIT\" });\n break;\n }\n try {\n const value = record(\n JSON.parse(\n (await readInspectionFile(file, defaults.maxRecordBytes)).toString(\n \"utf8\",\n ),\n ),\n );\n invariant(\n entry.name === `${value.id}.json`,\n \"Activity identity mismatch\",\n );\n entries.push({\n path: file,\n record: value,\n ownership: await observeOwnership(value.pid, value.identity),\n });\n } catch {\n entries.push({\n path: file,\n ownership: {\n status: \"unknown\",\n reason: \"RESOURCE_RECORD_UNREADABLE\",\n },\n });\n issues.push({ path: file, code: \"RESOURCE_RECORD_UNREADABLE\" });\n }\n }\n } catch (cause) {\n if (!(\n cause &&\n typeof cause === \"object\" &&\n \"code\" in cause &&\n cause.code === \"ENOENT\"\n ))\n issues.push({ path, code: \"RESOURCE_DIRECTORY_UNAVAILABLE\" });\n }\n entries.sort((left, right) => left.path.localeCompare(right.path));\n return {\n scope: \"recorded-sandboxes\",\n complete: issues.length === 0,\n entries,\n issues,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resource-activity-inspection.js","sourceRoot":"","sources":["../../src/infrastructure/resource-activity-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,wBAAwB,IAAI,QAAQ,EACpC,sBAAsB,EACtB,cAAc,GACf,MAAM,kCAAkC,CAAC;AAU1C,SAAS,MAAM,CAAC,KAAc;IAC5B,SAAS,CACP,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAC7D,yBAAyB,CAC1B,CAAC;AACJ,CAAC;AACD,SAAS,IAAI,CAAC,KAAc;IAC1B,SAAS,CACP,OAAO,KAAK,KAAK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,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import { lstat, opendir, realpath } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { invariant, positive } from \"../domain/errors.ts\";\nimport { observeOwnership } from \"./git/process-identity.ts\";\nimport type { LocalProcessIdentity } from \"./git/process-identity.types.ts\";\nimport { readInspectionFile } from \"./inspection-file.ts\";\nimport {\n resourceActivityDefaults as defaults,\n resourceOperationKinds,\n resourcePhases,\n} from \"./resource-activity.constants.ts\";\nimport type {\n ResourceActivityRecord,\n ResourceInspection,\n ResourceInspectionEntry,\n ResourceOperation,\n ResourceOperationResult,\n} from \"./resource-activity.types.ts\";\nimport type { StorageIssue } from \"./storage-inventory.types.ts\";\n\nfunction object(value: unknown): asserts value is Record<string, unknown> {\n invariant(\n !!value && typeof value === \"object\" && !Array.isArray(value),\n \"Invalid activity object\",\n );\n}\nfunction text(value: unknown): asserts value is string {\n invariant(\n typeof value === \"string\" &&\n value.length > 0 &&\n value.length <= defaults.maxText,\n \"Invalid activity text\",\n );\n}\nfunction date(value: unknown): asserts value is string {\n text(value);\n invariant(Number.isFinite(Date.parse(value)), \"Invalid activity time\");\n}\nfunction operation(value: unknown): ResourceOperation {\n object(value);\n invariant(\n typeof value.count === \"number\" &&\n Number.isSafeInteger(value.count) &&\n value.count > 0,\n \"Invalid activity count\",\n );\n date(value.startedAt);\n const kind = resourceOperationKinds.find((kind) => kind === value.kind);\n invariant(kind, \"Invalid activity operation\");\n return { count: value.count, startedAt: value.startedAt, kind };\n}\nfunction result(value: unknown): ResourceOperationResult {\n const base = operation(value);\n object(value);\n text(value.id);\n date(value.finishedAt);\n invariant(\n value.outcome === \"completed\" || value.outcome === \"failed\",\n \"Invalid activity outcome\",\n );\n return {\n ...base,\n id: value.id,\n finishedAt: value.finishedAt,\n outcome: value.outcome,\n };\n}\nfunction identity(value: unknown): LocalProcessIdentity | undefined {\n if (value === undefined) return undefined;\n object(value);\n text(value.host);\n text(value.boot);\n text(value.namespace);\n text(value.started);\n return {\n host: value.host,\n boot: value.boot,\n namespace: value.namespace,\n started: value.started,\n };\n}\nexport function resourceRecord(value: unknown): ResourceActivityRecord {\n object(value);\n invariant(value.version === 1, \"Unknown activity version\");\n text(value.id);\n text(value.provider);\n text(value.workspace);\n date(value.createdAt);\n date(value.updatedAt);\n invariant(\n typeof value.pid === \"number\" &&\n Number.isSafeInteger(value.pid) &&\n value.pid > 0 &&\n value.pid <= 2_147_483_647,\n \"Invalid activity owner\",\n );\n invariant(\n value.placement === \"host\" ||\n value.placement === \"mounted\" ||\n value.placement === \"remote\",\n \"Invalid activity placement\",\n );\n const phase = resourcePhases.find((phase) => phase === value.phase);\n invariant(phase, \"Invalid activity phase\");\n invariant(\n Array.isArray(value.operations) &&\n value.operations.length <= resourceOperationKinds.length,\n \"Invalid activity operations\",\n );\n const owner = identity(value.identity);\n return {\n version: 1,\n id: value.id,\n pid: value.pid,\n ...(owner ? { identity: owner } : {}),\n provider: value.provider,\n placement: value.placement,\n workspace: value.workspace,\n createdAt: value.createdAt,\n updatedAt: value.updatedAt,\n phase,\n operations: value.operations.map(operation),\n ...(value.lastOperation === undefined\n ? {}\n : { lastOperation: result(value.lastOperation) }),\n ...(value.lastFailure === undefined\n ? {}\n : { lastFailure: result(value.lastFailure) }),\n };\n}\n\nexport async function inspectResourceActivity(\n repository: string,\n maxEntries: number = defaults.maxRecords,\n): Promise<ResourceInspection> {\n positive(maxEntries, \"maxEntries\");\n const entries: ResourceInspectionEntry[] = [];\n const issues: StorageIssue[] = [];\n let path = repository;\n try {\n for (const part of [\".outpost\", \"locks\", defaults.directory]) {\n path = join(path, part);\n const info = await lstat(path);\n invariant(\n info.isDirectory() &&\n !info.isSymbolicLink() &&\n (await realpath(path)) === path,\n \"Unsafe activity directory\",\n );\n }\n for await (const entry of await opendir(path)) {\n const file = join(path, entry.name);\n if (entries.length >= Math.min(maxEntries, defaults.maxRecords)) {\n issues.push({ path, code: \"RESOURCE_ENTRY_LIMIT\" });\n break;\n }\n try {\n const value = resourceRecord(\n JSON.parse(\n (await readInspectionFile(file, defaults.maxRecordBytes)).toString(\n \"utf8\",\n ),\n ),\n );\n invariant(\n entry.name === `${value.id}.json`,\n \"Activity identity mismatch\",\n );\n entries.push({\n path: file,\n record: value,\n ownership: await observeOwnership(value.pid, value.identity),\n });\n } catch {\n entries.push({\n path: file,\n ownership: {\n status: \"unknown\",\n reason: \"RESOURCE_RECORD_UNREADABLE\",\n },\n });\n issues.push({ path: file, code: \"RESOURCE_RECORD_UNREADABLE\" });\n }\n }\n } catch (cause) {\n if (!(\n cause &&\n typeof cause === \"object\" &&\n \"code\" in cause &&\n cause.code === \"ENOENT\"\n ))\n issues.push({ path, code: \"RESOURCE_DIRECTORY_UNAVAILABLE\" });\n }\n entries.sort((left, right) => left.path.localeCompare(right.path));\n return {\n scope: \"recorded-sandboxes\",\n complete: issues.length === 0,\n entries,\n issues,\n };\n}\n"]}
|