@picassohq/cli 0.0.0-stage → 1.0.2
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/agents/browser_agent.yaml +53 -0
- package/agents/code_reviewer.yaml +49 -0
- package/agents/codebase_investigator.yaml +70 -0
- package/agents/design_auditor.yaml +50 -0
- package/agents/devex_auditor.yaml +50 -0
- package/agents/doc_writer.yaml +54 -0
- package/agents/engineering_architect.yaml +51 -0
- package/agents/generalist.yaml +55 -0
- package/agents/migration_planner.yaml +51 -0
- package/agents/product_reviewer.yaml +48 -0
- package/agents/qa_operator.yaml +52 -0
- package/agents/release_engineer.yaml +50 -0
- package/agents/security_auditor.yaml +62 -0
- package/agents/test_writer.yaml +52 -0
- package/assets/first-light-lockup.png +0 -0
- package/assets/first-light-tagline.png +0 -0
- package/assets/house/README.md +26 -0
- package/assets/house/auraone-banner.png +0 -0
- package/assets/house/auraone-logo.png +0 -0
- package/assets/house/kiro-prism-banner.png +0 -0
- package/assets/house/kiro-prism-logo.png +0 -0
- package/assets/house/picasso-banner.png +0 -0
- package/assets/house/picasso-logo.png +0 -0
- package/assets/wordmark-app.png +0 -0
- package/assets/wordmark-tight.png +0 -0
- package/assets/wordmark.png +0 -0
- package/design/styles.css +1042 -0
- package/dist/build-info.json +37 -0
- package/dist/index.js +3062 -0
- package/goals/cli-hardening.yaml +40 -0
- package/goals/repo-maintenance.yaml +40 -0
- package/package.json +49 -4
- package/runtime/dsh/picasso-ecosystem.community.amendments.yml +24 -0
- package/runtime/dsh/picasso-ecosystem.community.json +185 -0
- package/runtime/dsh/picasso-ecosystem.community.patch.yml +40 -0
- package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +143 -0
- package/runtime/dsh/picasso-isolation.patch.yml +25 -0
- package/runtime/dsh/picasso-providers.patch.yml +373 -0
- package/runtime/dsh/picasso-runtime.cordis.yml +738 -0
- package/runtime/dsh/picasso-sdk.patch.yml +204 -0
- package/runtime/engine-manifest.json +215 -0
- package/runtime/package.json +6 -0
- package/runtime/packages/picasso-cache-probe/cordis.patch.yml +5 -0
- package/runtime/packages/picasso-cache-probe/index.js +477 -0
- package/runtime/packages/picasso-cache-probe/package.json +38 -0
- package/runtime/packages/picasso-commands/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-commands/fresh-review.js +573 -0
- package/runtime/packages/picasso-commands/index.js +497 -0
- package/runtime/packages/picasso-commands/package.json +28 -0
- package/runtime/packages/picasso-instructions/conflicts.js +115 -0
- package/runtime/packages/picasso-instructions/formats.js +145 -0
- package/runtime/packages/picasso-instructions/frontmatter.js +175 -0
- package/runtime/packages/picasso-instructions/glob.js +114 -0
- package/runtime/packages/picasso-instructions/globals.js +90 -0
- package/runtime/packages/picasso-instructions/imports.js +123 -0
- package/runtime/packages/picasso-instructions/index.js +326 -0
- package/runtime/packages/picasso-instructions/modes.js +64 -0
- package/runtime/packages/picasso-instructions/package.json +30 -0
- package/runtime/packages/picasso-instructions/parse.js +134 -0
- package/runtime/packages/picasso-instructions/report.js +161 -0
- package/runtime/packages/picasso-instructions/resolve.js +939 -0
- package/runtime/packages/picasso-instructions/scan.js +181 -0
- package/runtime/packages/picasso-instructions/settings.js +150 -0
- package/runtime/packages/picasso-instructions/skills.js +345 -0
- package/runtime/packages/picasso-lean-context/cordis.patch.yml +13 -0
- package/runtime/packages/picasso-lean-context/index.js +6280 -0
- package/runtime/packages/picasso-lean-context/package.json +26 -0
- package/runtime/packages/picasso-lean-context/read-image-recovery.js +306 -0
- package/runtime/packages/picasso-lean-context/timeline.js +418 -0
- package/runtime/packages/picasso-librarian/classify.js +146 -0
- package/runtime/packages/picasso-librarian/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-librarian/index.js +878 -0
- package/runtime/packages/picasso-librarian/notes.js +159 -0
- package/runtime/packages/picasso-librarian/package.json +34 -0
- package/runtime/packages/picasso-librarian/state.js +478 -0
- package/runtime/packages/picasso-memory/index.js +1184 -0
- package/runtime/packages/picasso-memory/package.json +21 -0
- package/runtime/packages/picasso-model-router/connections.js +912 -0
- package/runtime/packages/picasso-model-router/cordis.patch.yml +17 -0
- package/runtime/packages/picasso-model-router/index.js +1083 -0
- package/runtime/packages/picasso-model-router/package.json +30 -0
- package/runtime/packages/picasso-options/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-options/index.js +263 -0
- package/runtime/packages/picasso-options/package.json +28 -0
- package/runtime/packages/picasso-progress-reports/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-progress-reports/index.js +267 -0
- package/runtime/packages/picasso-progress-reports/package.json +30 -0
- package/runtime/packages/picasso-progress-reports/report.js +235 -0
- package/runtime/packages/picasso-sdk-server/aside.js +142 -0
- package/runtime/packages/picasso-sdk-server/connections.js +38 -0
- package/runtime/packages/picasso-sdk-server/context-timeline.js +27 -0
- package/runtime/packages/picasso-sdk-server/egress-gate.js +520 -0
- package/runtime/packages/picasso-sdk-server/failure-policy.js +246 -0
- package/runtime/packages/picasso-sdk-server/file-input.js +169 -0
- package/runtime/packages/picasso-sdk-server/goal.js +131 -0
- package/runtime/packages/picasso-sdk-server/ignore-file.js +458 -0
- package/runtime/packages/picasso-sdk-server/ignore-plugin.js +12 -0
- package/runtime/packages/picasso-sdk-server/ignore-sandbox.js +122 -0
- package/runtime/packages/picasso-sdk-server/ignore-snapshot.js +131 -0
- package/runtime/packages/picasso-sdk-server/image-input.js +44 -0
- package/runtime/packages/picasso-sdk-server/index.js +891 -0
- package/runtime/packages/picasso-sdk-server/instructions.js +34 -0
- package/runtime/packages/picasso-sdk-server/jobs.js +113 -0
- package/runtime/packages/picasso-sdk-server/mcp-gate.js +51 -0
- package/runtime/packages/picasso-sdk-server/model-selection.js +162 -0
- package/runtime/packages/picasso-sdk-server/package.json +50 -0
- package/runtime/packages/picasso-sdk-server/picasso-records.js +50 -0
- package/runtime/packages/picasso-sdk-server/provider-reload.js +84 -0
- package/runtime/packages/picasso-sdk-server/queue.js +322 -0
- package/runtime/packages/picasso-sdk-server/requester.js +43 -0
- package/runtime/packages/picasso-sdk-server/rewind.js +108 -0
- package/runtime/packages/picasso-sdk-server/schedule.js +187 -0
- package/runtime/packages/picasso-sdk-server/session-grants.js +35 -0
- package/runtime/packages/picasso-sdk-server/session-state.js +118 -0
- package/runtime/packages/picasso-sdk-server/shell-paths.js +869 -0
- package/runtime/packages/picasso-sdk-server/stream-deltas.js +211 -0
- package/runtime/packages/picasso-sdk-server/team-tasks.js +451 -0
- package/runtime/packages/picasso-sdk-server/tool-output.js +128 -0
- package/runtime/packages/picasso-sdk-server/tools-list.js +51 -0
- package/runtime/packages/picasso-sdk-server/wave2-hooks.js +612 -0
- package/runtime/packages/picasso-sdk-server/workspace-archive.js +170 -0
- package/runtime/packages/picasso-sdk-server/workspace-restore.js +180 -0
- package/runtime/packages/picasso-web-search/backends.js +412 -0
- package/runtime/packages/picasso-web-search/config.js +121 -0
- package/runtime/packages/picasso-web-search/cordis.patch.yml +7 -0
- package/runtime/packages/picasso-web-search/failure.js +116 -0
- package/runtime/packages/picasso-web-search/format.js +42 -0
- package/runtime/packages/picasso-web-search/index.js +71 -0
- package/runtime/packages/picasso-web-search/package.json +38 -0
- package/runtime/packages/picasso-web-search/router.js +156 -0
- package/runtime/packages/picasso-x-reader/circle.js +324 -0
- package/runtime/packages/picasso-x-reader/command.js +169 -0
- package/runtime/packages/picasso-x-reader/cordis.patch.yml +8 -0
- package/runtime/packages/picasso-x-reader/index.js +170 -0
- package/runtime/packages/picasso-x-reader/package.json +39 -0
- package/runtime/packages/picasso-x-reader/read.js +370 -0
- package/runtime/packages/picasso-x-reader/rewrite.js +38 -0
- package/runtime/packages/picasso-x-reader/settings.js +131 -0
- package/runtime/packages/picasso-x-reader/urls.js +154 -0
- package/runtime/packages/picasso-x-reader/xmd.js +512 -0
- package/runtime/plugins/picasso-auth-bridge/index.js +380 -0
- package/runtime/plugins/picasso-auth-bridge/package.json +28 -0
- package/runtime/plugins/picasso-auto-approve/index.js +1003 -0
- package/runtime/plugins/picasso-auto-approve/package.json +28 -0
- package/runtime/plugins/picasso-browser/index.js +424 -0
- package/runtime/plugins/picasso-browser/package.json +28 -0
- package/runtime/plugins/picasso-checkpoints/evidence.js +210 -0
- package/runtime/plugins/picasso-checkpoints/index.js +885 -0
- package/runtime/plugins/picasso-checkpoints/package.json +29 -0
- package/runtime/plugins/picasso-commands/fresh-review.js +573 -0
- package/runtime/plugins/picasso-commands/index.js +497 -0
- package/runtime/plugins/picasso-commands/package.json +28 -0
- package/runtime/plugins/picasso-instructions/conflicts.js +115 -0
- package/runtime/plugins/picasso-instructions/formats.js +145 -0
- package/runtime/plugins/picasso-instructions/frontmatter.js +175 -0
- package/runtime/plugins/picasso-instructions/glob.js +114 -0
- package/runtime/plugins/picasso-instructions/globals.js +90 -0
- package/runtime/plugins/picasso-instructions/imports.js +123 -0
- package/runtime/plugins/picasso-instructions/index.js +326 -0
- package/runtime/plugins/picasso-instructions/modes.js +64 -0
- package/runtime/plugins/picasso-instructions/package.json +30 -0
- package/runtime/plugins/picasso-instructions/parse.js +134 -0
- package/runtime/plugins/picasso-instructions/report.js +161 -0
- package/runtime/plugins/picasso-instructions/resolve.js +939 -0
- package/runtime/plugins/picasso-instructions/scan.js +181 -0
- package/runtime/plugins/picasso-instructions/settings.js +150 -0
- package/runtime/plugins/picasso-instructions/skills.js +345 -0
- package/runtime/plugins/picasso-lean-context/index.js +6280 -0
- package/runtime/plugins/picasso-lean-context/package.json +26 -0
- package/runtime/plugins/picasso-lean-context/read-image-recovery.js +306 -0
- package/runtime/plugins/picasso-lean-context/timeline.js +418 -0
- package/runtime/plugins/picasso-librarian/classify.js +146 -0
- package/runtime/plugins/picasso-librarian/index.js +878 -0
- package/runtime/plugins/picasso-librarian/notes.js +159 -0
- package/runtime/plugins/picasso-librarian/package.json +34 -0
- package/runtime/plugins/picasso-librarian/state.js +478 -0
- package/runtime/plugins/picasso-lifecycle-hooks/index.js +186 -0
- package/runtime/plugins/picasso-lifecycle-hooks/package.json +25 -0
- package/runtime/plugins/picasso-mail/inbox.js +207 -0
- package/runtime/plugins/picasso-mail/index.js +293 -0
- package/runtime/plugins/picasso-mail/package.json +22 -0
- package/runtime/plugins/picasso-memory/index.js +1184 -0
- package/runtime/plugins/picasso-memory/package.json +21 -0
- package/runtime/plugins/picasso-model-router/connections.js +912 -0
- package/runtime/plugins/picasso-model-router/index.js +1083 -0
- package/runtime/plugins/picasso-model-router/package.json +30 -0
- package/runtime/plugins/picasso-options/index.js +263 -0
- package/runtime/plugins/picasso-options/package.json +28 -0
- package/runtime/plugins/picasso-progress-reports/index.js +267 -0
- package/runtime/plugins/picasso-progress-reports/package.json +30 -0
- package/runtime/plugins/picasso-progress-reports/report.js +235 -0
- package/runtime/plugins/picasso-provider-models/index.js +436 -0
- package/runtime/plugins/picasso-provider-models/package.json +28 -0
- package/runtime/plugins/picasso-repo-index/index.js +1850 -0
- package/runtime/plugins/picasso-repo-index/package.json +28 -0
- package/runtime/plugins/picasso-schedule-pause/index.js +344 -0
- package/runtime/plugins/picasso-schedule-pause/package.json +28 -0
- package/runtime/plugins/picasso-session-lifecycle/index.js +796 -0
- package/runtime/plugins/picasso-session-lifecycle/package.json +28 -0
- package/runtime/plugins/picasso-trackers/index.js +895 -0
- package/runtime/plugins/picasso-trackers/package.json +28 -0
- package/runtime/plugins/picasso-web-search/backends.js +412 -0
- package/runtime/plugins/picasso-web-search/config.js +121 -0
- package/runtime/plugins/picasso-web-search/failure.js +116 -0
- package/runtime/plugins/picasso-web-search/format.js +42 -0
- package/runtime/plugins/picasso-web-search/index.js +71 -0
- package/runtime/plugins/picasso-web-search/package.json +38 -0
- package/runtime/plugins/picasso-web-search/router.js +156 -0
- package/runtime/plugins/picasso-x-reader/circle.js +324 -0
- package/runtime/plugins/picasso-x-reader/command.js +169 -0
- package/runtime/plugins/picasso-x-reader/index.js +170 -0
- package/runtime/plugins/picasso-x-reader/package.json +39 -0
- package/runtime/plugins/picasso-x-reader/read.js +370 -0
- package/runtime/plugins/picasso-x-reader/rewrite.js +38 -0
- package/runtime/plugins/picasso-x-reader/settings.js +131 -0
- package/runtime/plugins/picasso-x-reader/urls.js +154 -0
- package/runtime/plugins/picasso-x-reader/xmd.js +512 -0
- package/runtime/relay/attachment-text.mjs +737 -0
- package/runtime/relay/companion/companion.css +126 -0
- package/runtime/relay/companion/companion.js +648 -0
- package/runtime/relay/companion/icon.svg +5 -0
- package/runtime/relay/companion/index.html +25 -0
- package/runtime/relay/companion/manifest.json +13 -0
- package/runtime/relay/companion/sw.js +41 -0
- package/runtime/relay/main.mjs +38580 -0
- package/runtime/relay/model-listing.mjs +614 -0
- package/runtime/relay/versions-routes.mjs +1400 -0
- package/runtime/verify-plugins.mjs +205 -0
- package/runtime-lock/package-lock.json +10779 -0
- package/runtime-lock/package.json +7 -0
- package/scripts/install-runtime.mjs +400 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1400 @@
|
|
|
1
|
+
import { createRequire as __picassoCreateRequire } from "node:module";
|
|
2
|
+
globalThis.require ??= __picassoCreateRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/versions-routes.ts
|
|
5
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
6
|
+
import { open as open3, readFile as readFile7, stat as stat3 } from "node:fs/promises";
|
|
7
|
+
|
|
8
|
+
// ../../packages/shared-home/dist/home.js
|
|
9
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { chmod, lstat, mkdir } from "node:fs/promises";
|
|
11
|
+
import { homedir, userInfo } from "node:os";
|
|
12
|
+
import { join, resolve } from "node:path";
|
|
13
|
+
function realHomeDir() {
|
|
14
|
+
return userInfo().homedir;
|
|
15
|
+
}
|
|
16
|
+
function picassoHome(env = process.env) {
|
|
17
|
+
return override(env["PICASSO_HOME"]) ?? join(realHomeDir(), ".picasso");
|
|
18
|
+
}
|
|
19
|
+
function dshHome(env = process.env) {
|
|
20
|
+
return override(env["DSH_HOME"]) ?? join(picassoHome(env), "dsh-home");
|
|
21
|
+
}
|
|
22
|
+
function override(value) {
|
|
23
|
+
return value !== void 0 && value.trim() !== "" ? value : void 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ../../packages/shared-home/dist/lock.js
|
|
27
|
+
import { randomUUID } from "node:crypto";
|
|
28
|
+
import { link, mkdir as mkdir2, open, readFile, rename, rm, stat } from "node:fs/promises";
|
|
29
|
+
import { hostname } from "node:os";
|
|
30
|
+
import { dirname } from "node:path";
|
|
31
|
+
|
|
32
|
+
// ../../packages/shared-home/dist/store.js
|
|
33
|
+
import { randomBytes } from "node:crypto";
|
|
34
|
+
import { constants as fsConstants } from "node:fs";
|
|
35
|
+
import { chmod as chmod2, copyFile, mkdir as mkdir3, open as open2, readFile as readFile2, rename as rename2, rm as rm2 } from "node:fs/promises";
|
|
36
|
+
import { basename, dirname as dirname2 } from "node:path";
|
|
37
|
+
|
|
38
|
+
// ../../packages/shared-home/dist/installation.js
|
|
39
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
40
|
+
import { chmod as chmod3, readFile as readFile3, stat as stat2 } from "node:fs/promises";
|
|
41
|
+
import { join as join2 } from "node:path";
|
|
42
|
+
|
|
43
|
+
// ../../packages/shared-home/dist/discovery.js
|
|
44
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
45
|
+
import { readFileSync as readFileSync2, rmSync } from "node:fs";
|
|
46
|
+
import { lstat as lstat2, readFile as readFile4, rm as rm3 } from "node:fs/promises";
|
|
47
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
48
|
+
|
|
49
|
+
// ../../packages/shared-home/dist/runner.js
|
|
50
|
+
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
51
|
+
import { readFileSync as readFileSync3, rmSync as rmSync2 } from "node:fs";
|
|
52
|
+
import { lstat as lstat3, readFile as readFile5, rm as rm4 } from "node:fs/promises";
|
|
53
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
54
|
+
var RUNNER_ENV_KEYS = Object.freeze([
|
|
55
|
+
"PICASSO_HOME",
|
|
56
|
+
"PICASSO_SETTINGS_ROOT",
|
|
57
|
+
"DSH_HOME",
|
|
58
|
+
"PICASSO_MEMORY_FILE",
|
|
59
|
+
"PICASSO_HELPER_ATTACH",
|
|
60
|
+
"PICASSO_HELPER_HOST",
|
|
61
|
+
"PICASSO_HELPER_TLS_CERT",
|
|
62
|
+
"PICASSO_HELPER_TLS_KEY",
|
|
63
|
+
"DSH_TELEMETRY_MODE",
|
|
64
|
+
// X2: the app's own `mac/<version>`, so a runner speaks to the API as the app that configured it.
|
|
65
|
+
"PICASSO_CLIENT_ID"
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
// ../../packages/shared-home/dist/attach-scope.js
|
|
69
|
+
import { timingSafeEqual } from "node:crypto";
|
|
70
|
+
import { isIP } from "node:net";
|
|
71
|
+
var LOCAL_ATTACH_PROVIDER_ROUTES = Object.freeze([
|
|
72
|
+
{ method: "GET", path: "/providers" },
|
|
73
|
+
{ method: "POST", path: "/providers/custom" },
|
|
74
|
+
{ method: "POST", path: "/providers/:id/models" },
|
|
75
|
+
{ method: "POST", path: "/providers/:id/edit" },
|
|
76
|
+
{ method: "POST", path: "/providers/:id/remove" },
|
|
77
|
+
// Active models (which models the pickers show; model-connections.json `active`): the same class as `/models`,
|
|
78
|
+
// never a key. `POST /models/refresh` reads endpoints with stored keys, so it stays refused like `/refresh`.
|
|
79
|
+
{ method: "GET", path: "/models/active" },
|
|
80
|
+
{ method: "GET", path: "/providers/:id/model-choices" },
|
|
81
|
+
{ method: "POST", path: "/providers/:id/active-models" }
|
|
82
|
+
]);
|
|
83
|
+
var LOCAL_ATTACH_ROUTES = Object.freeze([
|
|
84
|
+
{ method: "GET", path: "/health" },
|
|
85
|
+
{ method: "GET", path: "/threads" },
|
|
86
|
+
{ method: "GET", path: "/threads/:id/events" },
|
|
87
|
+
{ method: "POST", path: "/threads/:id/prompt" },
|
|
88
|
+
{ method: "POST", path: "/threads/:id/cancel" },
|
|
89
|
+
{ method: "GET", path: "/threads/:id/commands" },
|
|
90
|
+
{ method: "GET", path: "/interactions" },
|
|
91
|
+
{ method: "POST", path: "/interactions/:id" },
|
|
92
|
+
{ method: "POST", path: "/interactions/:id/hold" },
|
|
93
|
+
...LOCAL_ATTACH_PROVIDER_ROUTES
|
|
94
|
+
]);
|
|
95
|
+
var LOCAL_ATTACH_FORBIDDEN_DECISIONS = Object.freeze(["allow-always"]);
|
|
96
|
+
|
|
97
|
+
// ../../packages/shared-home/dist/account-session.js
|
|
98
|
+
import { execFile } from "node:child_process";
|
|
99
|
+
import { access, readFile as readFile6, unlink } from "node:fs/promises";
|
|
100
|
+
import { join as join5 } from "node:path";
|
|
101
|
+
var KEYCHAIN_COMMAND_TIMEOUT_MS = 1e4;
|
|
102
|
+
var KEYCHAIN_TIMEOUT_EXIT_CODE = 124;
|
|
103
|
+
function createSecurityRunner(timeoutMs = KEYCHAIN_COMMAND_TIMEOUT_MS) {
|
|
104
|
+
return (command, args, options) => new Promise((resolve6) => {
|
|
105
|
+
let timedOut = false;
|
|
106
|
+
const child = execFile(command, [...args], { encoding: "utf8", maxBuffer: 1024 * 1024, windowsHide: true }, (error, stdout, stderr) => {
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
if (timedOut) {
|
|
109
|
+
resolve6({
|
|
110
|
+
exitCode: KEYCHAIN_TIMEOUT_EXIT_CODE,
|
|
111
|
+
stdout: "",
|
|
112
|
+
stderr: `The Keychain did not answer within ${Math.ceil(timeoutMs / 1e3)} s (${command} was stopped); it may be waiting for an unlock prompt.`
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const code = error?.code;
|
|
117
|
+
resolve6({
|
|
118
|
+
exitCode: error === null ? 0 : typeof code === "number" ? code : 1,
|
|
119
|
+
stdout: String(stdout),
|
|
120
|
+
stderr: String(stderr)
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
const timer = setTimeout(() => {
|
|
124
|
+
timedOut = true;
|
|
125
|
+
child.kill("SIGKILL");
|
|
126
|
+
}, timeoutMs);
|
|
127
|
+
child.stdin?.on("error", () => void 0);
|
|
128
|
+
child.stdin?.end(options?.stdin ?? "");
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
var defaultRunner = createSecurityRunner();
|
|
132
|
+
|
|
133
|
+
// ../../packages/shared-home/dist/specs/settings.js
|
|
134
|
+
import { join as join6 } from "node:path";
|
|
135
|
+
var DEFAULT_PERMISSION_MODE = "auto";
|
|
136
|
+
var DEFAULT_SETTINGS_DIAGNOSTICS = Object.freeze({ crashReports: "off" });
|
|
137
|
+
var DEFAULT_PROGRESS_REPORT_INTERVAL_MINUTES = 10;
|
|
138
|
+
var DEFAULT_SETTINGS_PROGRESS_REPORTS = Object.freeze({
|
|
139
|
+
enabled: true,
|
|
140
|
+
intervalMinutes: DEFAULT_PROGRESS_REPORT_INTERVAL_MINUTES
|
|
141
|
+
});
|
|
142
|
+
var START_PAGE_CARDS = ["activity", "recent", "month", "contributions"];
|
|
143
|
+
var DEFAULT_START_PAGE = Object.freeze({
|
|
144
|
+
order: START_PAGE_CARDS,
|
|
145
|
+
hidden: [],
|
|
146
|
+
showsSuggestions: true,
|
|
147
|
+
sponsorPlacement: "belowComposer"
|
|
148
|
+
});
|
|
149
|
+
var DEFAULT_X_READER_BASE_URL = "https://mdfromx.com";
|
|
150
|
+
var DEFAULT_SETTINGS_X_READER = Object.freeze({
|
|
151
|
+
enabled: true,
|
|
152
|
+
baseUrl: DEFAULT_X_READER_BASE_URL,
|
|
153
|
+
format: "markdown"
|
|
154
|
+
});
|
|
155
|
+
var DEFAULT_SETTINGS_SYNC = Object.freeze({ cloudSessions: false, cloudMemory: false });
|
|
156
|
+
var DEFAULT_SHARED_SETTINGS = Object.freeze({
|
|
157
|
+
theme: "system",
|
|
158
|
+
permissionMode: DEFAULT_PERMISSION_MODE,
|
|
159
|
+
notificationsEnabled: true,
|
|
160
|
+
sync: DEFAULT_SETTINGS_SYNC
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// ../../packages/shared-home/dist/specs/projects.js
|
|
164
|
+
import { join as join7 } from "node:path";
|
|
165
|
+
|
|
166
|
+
// ../../packages/shared-home/dist/specs/mcp-servers.js
|
|
167
|
+
import { join as join8 } from "node:path";
|
|
168
|
+
|
|
169
|
+
// ../../packages/shared-home/dist/specs/hooks.js
|
|
170
|
+
import { join as join9 } from "node:path";
|
|
171
|
+
|
|
172
|
+
// ../../packages/shared-home/dist/specs/subagents.js
|
|
173
|
+
import { join as join10 } from "node:path";
|
|
174
|
+
|
|
175
|
+
// ../../packages/shared-home/dist/specs/goals.js
|
|
176
|
+
import { join as join11 } from "node:path";
|
|
177
|
+
|
|
178
|
+
// ../../packages/shared-home/dist/specs/schedules.js
|
|
179
|
+
import { join as join12 } from "node:path";
|
|
180
|
+
|
|
181
|
+
// ../../packages/shared-home/dist/themes/index.js
|
|
182
|
+
import { mkdirSync as mkdirSync2, readdirSync as readdirSync2, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
183
|
+
import { join as join13 } from "node:path";
|
|
184
|
+
|
|
185
|
+
// ../../packages/shared-home/dist/themes/presets.js
|
|
186
|
+
var BUILT_IN_THEMES = [
|
|
187
|
+
{
|
|
188
|
+
schemaVersion: 1,
|
|
189
|
+
id: "picasso",
|
|
190
|
+
name: "Picasso",
|
|
191
|
+
accent: "#79A591",
|
|
192
|
+
// Mac MacSage (light) / MacSageDark (dark) — the role values of today's palette.
|
|
193
|
+
light: {
|
|
194
|
+
canvas: "#FAFBF9",
|
|
195
|
+
sidebar: "#E6F0EA",
|
|
196
|
+
surface: "#FFFFFF",
|
|
197
|
+
raised: "#ECEFEB",
|
|
198
|
+
border: "#E8E9E7",
|
|
199
|
+
text: "#3A4931",
|
|
200
|
+
textMuted: "#586058",
|
|
201
|
+
textFaint: "#777E77",
|
|
202
|
+
accent: "#79A591",
|
|
203
|
+
accentText: "#4F7D68",
|
|
204
|
+
success: "#557A55",
|
|
205
|
+
warning: "#8C6512",
|
|
206
|
+
danger: "#B0533F",
|
|
207
|
+
info: "#4C66C9",
|
|
208
|
+
plan: "#714CA6",
|
|
209
|
+
memory: "#A4507E",
|
|
210
|
+
cost: "#8A6A33"
|
|
211
|
+
},
|
|
212
|
+
dark: {
|
|
213
|
+
canvas: "#1C1F1D",
|
|
214
|
+
sidebar: "#222824",
|
|
215
|
+
surface: "#262B28",
|
|
216
|
+
raised: "#2D3530",
|
|
217
|
+
border: "#353D38",
|
|
218
|
+
text: "#E3EAE5",
|
|
219
|
+
textMuted: "#A9B4AD",
|
|
220
|
+
textFaint: "#7C8781",
|
|
221
|
+
accent: "#79A591",
|
|
222
|
+
accentText: "#8FBCA6",
|
|
223
|
+
success: "#8FB08E",
|
|
224
|
+
warning: "#E0B062",
|
|
225
|
+
danger: "#D9826F",
|
|
226
|
+
info: "#9DB0F5",
|
|
227
|
+
plan: "#CBB0FF",
|
|
228
|
+
memory: "#F0A3CB",
|
|
229
|
+
cost: "#DDB26E"
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
schemaVersion: 1,
|
|
234
|
+
id: "catppuccin-latte",
|
|
235
|
+
name: "Catppuccin Latte",
|
|
236
|
+
accent: "#8839EF",
|
|
237
|
+
light: {
|
|
238
|
+
canvas: "#EFF1F5",
|
|
239
|
+
sidebar: "#E6E9EF",
|
|
240
|
+
surface: "#F8F9FB",
|
|
241
|
+
raised: "#DCE0E8",
|
|
242
|
+
border: "#CCD0DA",
|
|
243
|
+
text: "#4C4F69",
|
|
244
|
+
textMuted: "#5C5F77",
|
|
245
|
+
textFaint: "#6C6F85",
|
|
246
|
+
success: "#40A02B",
|
|
247
|
+
warning: "#DF8E1D",
|
|
248
|
+
danger: "#D20F39",
|
|
249
|
+
info: "#1E66F5",
|
|
250
|
+
plan: "#7287FD",
|
|
251
|
+
memory: "#EA76CB",
|
|
252
|
+
cost: "#FE640B"
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
schemaVersion: 1,
|
|
257
|
+
id: "catppuccin-mocha",
|
|
258
|
+
name: "Catppuccin Mocha",
|
|
259
|
+
accent: "#CBA6F7",
|
|
260
|
+
dark: {
|
|
261
|
+
canvas: "#1E1E2E",
|
|
262
|
+
sidebar: "#181825",
|
|
263
|
+
surface: "#24273A",
|
|
264
|
+
raised: "#313244",
|
|
265
|
+
border: "#45475A",
|
|
266
|
+
text: "#CDD6F4",
|
|
267
|
+
textMuted: "#BAC2DE",
|
|
268
|
+
textFaint: "#9399B2",
|
|
269
|
+
success: "#A6E3A1",
|
|
270
|
+
warning: "#F9E2AF",
|
|
271
|
+
danger: "#F38BA8",
|
|
272
|
+
info: "#89B4FA",
|
|
273
|
+
plan: "#B4BEFE",
|
|
274
|
+
memory: "#F5C2E7",
|
|
275
|
+
cost: "#FAB387"
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
schemaVersion: 1,
|
|
280
|
+
id: "gruvbox-light",
|
|
281
|
+
name: "Gruvbox Light",
|
|
282
|
+
accent: "#AF3A03",
|
|
283
|
+
light: {
|
|
284
|
+
canvas: "#FBF1C7",
|
|
285
|
+
sidebar: "#F2E5BC",
|
|
286
|
+
surface: "#F9F5D7",
|
|
287
|
+
raised: "#EBDBB2",
|
|
288
|
+
border: "#D5C4A1",
|
|
289
|
+
text: "#3C3836",
|
|
290
|
+
textMuted: "#504945",
|
|
291
|
+
textFaint: "#7C6F64",
|
|
292
|
+
success: "#79740E",
|
|
293
|
+
warning: "#B57614",
|
|
294
|
+
danger: "#9D0006",
|
|
295
|
+
info: "#076678",
|
|
296
|
+
plan: "#8F3F71",
|
|
297
|
+
memory: "#427B58",
|
|
298
|
+
cost: "#B57614"
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
schemaVersion: 1,
|
|
303
|
+
id: "gruvbox-dark",
|
|
304
|
+
name: "Gruvbox Dark",
|
|
305
|
+
accent: "#FABD2F",
|
|
306
|
+
dark: {
|
|
307
|
+
canvas: "#282828",
|
|
308
|
+
sidebar: "#1D2021",
|
|
309
|
+
surface: "#32302F",
|
|
310
|
+
raised: "#3C3836",
|
|
311
|
+
border: "#504945",
|
|
312
|
+
text: "#EBDBB2",
|
|
313
|
+
textMuted: "#D5C4A1",
|
|
314
|
+
textFaint: "#A89984",
|
|
315
|
+
success: "#B8BB26",
|
|
316
|
+
warning: "#FE8019",
|
|
317
|
+
danger: "#FB4934",
|
|
318
|
+
info: "#83A598",
|
|
319
|
+
plan: "#D3869B",
|
|
320
|
+
memory: "#8EC07C",
|
|
321
|
+
cost: "#FABD2F"
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
schemaVersion: 1,
|
|
326
|
+
id: "nord",
|
|
327
|
+
name: "Nord",
|
|
328
|
+
accent: "#88C0D0",
|
|
329
|
+
dark: {
|
|
330
|
+
canvas: "#2E3440",
|
|
331
|
+
sidebar: "#292E39",
|
|
332
|
+
surface: "#3B4252",
|
|
333
|
+
raised: "#434C5E",
|
|
334
|
+
border: "#4C566A",
|
|
335
|
+
text: "#ECEFF4",
|
|
336
|
+
textMuted: "#D8DEE9",
|
|
337
|
+
textFaint: "#9DA5B4",
|
|
338
|
+
success: "#A3BE8C",
|
|
339
|
+
warning: "#EBCB8B",
|
|
340
|
+
danger: "#BF616A",
|
|
341
|
+
info: "#81A1C1",
|
|
342
|
+
plan: "#B48EAD",
|
|
343
|
+
memory: "#8FBCBB",
|
|
344
|
+
cost: "#D08770"
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
schemaVersion: 1,
|
|
349
|
+
id: "solarized-light",
|
|
350
|
+
name: "Solarized Light",
|
|
351
|
+
accent: "#268BD2",
|
|
352
|
+
light: {
|
|
353
|
+
canvas: "#FDF6E3",
|
|
354
|
+
sidebar: "#EEE8D5",
|
|
355
|
+
surface: "#FFFBF0",
|
|
356
|
+
raised: "#EEE8D5",
|
|
357
|
+
border: "#DDD6C1",
|
|
358
|
+
// Solarized's base01/base00/base1 text darkened just enough for WCAG AA on base3/base2 (the originals measure
|
|
359
|
+
// 2.6–4.4:1), and a deeper blue for accent text.
|
|
360
|
+
text: "#475B62",
|
|
361
|
+
textMuted: "#52676E",
|
|
362
|
+
textFaint: "#76878A",
|
|
363
|
+
accentText: "#1F6FA8",
|
|
364
|
+
success: "#859900",
|
|
365
|
+
warning: "#B58900",
|
|
366
|
+
danger: "#DC322F",
|
|
367
|
+
info: "#2AA198",
|
|
368
|
+
plan: "#6C71C4",
|
|
369
|
+
memory: "#D33682",
|
|
370
|
+
cost: "#CB4B16"
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
schemaVersion: 1,
|
|
375
|
+
id: "solarized-dark",
|
|
376
|
+
name: "Solarized Dark",
|
|
377
|
+
accent: "#268BD2",
|
|
378
|
+
dark: {
|
|
379
|
+
canvas: "#002B36",
|
|
380
|
+
sidebar: "#00252F",
|
|
381
|
+
surface: "#073642",
|
|
382
|
+
raised: "#0D3F4C",
|
|
383
|
+
border: "#586E75",
|
|
384
|
+
// base1/base0/base00 lifted just enough for WCAG AA on base02 cards, and a lighter blue for accent text.
|
|
385
|
+
text: "#A3B0B0",
|
|
386
|
+
textMuted: "#8FA0A1",
|
|
387
|
+
textFaint: "#7A8C8E",
|
|
388
|
+
accentText: "#4FA3E0",
|
|
389
|
+
success: "#859900",
|
|
390
|
+
warning: "#B58900",
|
|
391
|
+
danger: "#DC322F",
|
|
392
|
+
info: "#2AA198",
|
|
393
|
+
plan: "#6C71C4",
|
|
394
|
+
memory: "#D33682",
|
|
395
|
+
cost: "#CB4B16"
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
schemaVersion: 1,
|
|
400
|
+
id: "tokyo-night",
|
|
401
|
+
name: "Tokyo Night",
|
|
402
|
+
accent: "#7AA2F7",
|
|
403
|
+
dark: {
|
|
404
|
+
canvas: "#1A1B26",
|
|
405
|
+
sidebar: "#16161E",
|
|
406
|
+
surface: "#1F2335",
|
|
407
|
+
raised: "#292E42",
|
|
408
|
+
border: "#3B4261",
|
|
409
|
+
text: "#C0CAF5",
|
|
410
|
+
textMuted: "#A9B1D6",
|
|
411
|
+
textFaint: "#737AA2",
|
|
412
|
+
success: "#9ECE6A",
|
|
413
|
+
warning: "#E0AF68",
|
|
414
|
+
danger: "#F7768E",
|
|
415
|
+
info: "#7DCFFF",
|
|
416
|
+
plan: "#BB9AF7",
|
|
417
|
+
memory: "#9D7CD8",
|
|
418
|
+
cost: "#FF9E64"
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
schemaVersion: 1,
|
|
423
|
+
id: "rose-pine",
|
|
424
|
+
name: "Ros\xE9 Pine",
|
|
425
|
+
accent: "#EBBCBA",
|
|
426
|
+
dark: {
|
|
427
|
+
canvas: "#191724",
|
|
428
|
+
sidebar: "#16141F",
|
|
429
|
+
surface: "#1F1D2E",
|
|
430
|
+
raised: "#26233A",
|
|
431
|
+
border: "#403D52",
|
|
432
|
+
text: "#E0DEF4",
|
|
433
|
+
textMuted: "#908CAA",
|
|
434
|
+
textFaint: "#6E6A86",
|
|
435
|
+
success: "#9CCFD8",
|
|
436
|
+
warning: "#F6C177",
|
|
437
|
+
danger: "#EB6F92",
|
|
438
|
+
info: "#C4A7E7",
|
|
439
|
+
plan: "#C4A7E7",
|
|
440
|
+
memory: "#EBBCBA",
|
|
441
|
+
cost: "#F6C177"
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
schemaVersion: 1,
|
|
446
|
+
id: "one-dark",
|
|
447
|
+
name: "One Dark",
|
|
448
|
+
accent: "#61AFEF",
|
|
449
|
+
dark: {
|
|
450
|
+
canvas: "#282C34",
|
|
451
|
+
sidebar: "#21252B",
|
|
452
|
+
surface: "#2C313A",
|
|
453
|
+
raised: "#333842",
|
|
454
|
+
border: "#3E4451",
|
|
455
|
+
text: "#DCDFE4",
|
|
456
|
+
textMuted: "#ABB2BF",
|
|
457
|
+
textFaint: "#7F848E",
|
|
458
|
+
success: "#98C379",
|
|
459
|
+
warning: "#E5C07B",
|
|
460
|
+
danger: "#E06C75",
|
|
461
|
+
info: "#56B6C2",
|
|
462
|
+
plan: "#C678DD",
|
|
463
|
+
memory: "#C678DD",
|
|
464
|
+
cost: "#D19A66"
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
schemaVersion: 1,
|
|
469
|
+
id: "github-light",
|
|
470
|
+
name: "GitHub Light",
|
|
471
|
+
accent: "#0969DA",
|
|
472
|
+
light: {
|
|
473
|
+
canvas: "#FFFFFF",
|
|
474
|
+
sidebar: "#F6F8FA",
|
|
475
|
+
surface: "#FFFFFF",
|
|
476
|
+
raised: "#F6F8FA",
|
|
477
|
+
border: "#D0D7DE",
|
|
478
|
+
text: "#1F2328",
|
|
479
|
+
textMuted: "#59636E",
|
|
480
|
+
textFaint: "#6E7781",
|
|
481
|
+
success: "#1A7F37",
|
|
482
|
+
warning: "#9A6700",
|
|
483
|
+
danger: "#D1242F",
|
|
484
|
+
info: "#0550AE",
|
|
485
|
+
plan: "#8250DF",
|
|
486
|
+
memory: "#BF3989",
|
|
487
|
+
cost: "#BC4C00"
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
schemaVersion: 1,
|
|
492
|
+
id: "github-dark",
|
|
493
|
+
name: "GitHub Dark",
|
|
494
|
+
accent: "#4493F8",
|
|
495
|
+
dark: {
|
|
496
|
+
canvas: "#0D1117",
|
|
497
|
+
sidebar: "#010409",
|
|
498
|
+
surface: "#161B22",
|
|
499
|
+
raised: "#21262D",
|
|
500
|
+
border: "#30363D",
|
|
501
|
+
text: "#E6EDF3",
|
|
502
|
+
textMuted: "#9198A1",
|
|
503
|
+
textFaint: "#7D8590",
|
|
504
|
+
success: "#3FB950",
|
|
505
|
+
warning: "#D29922",
|
|
506
|
+
danger: "#F85149",
|
|
507
|
+
info: "#58A6FF",
|
|
508
|
+
plan: "#A371F7",
|
|
509
|
+
memory: "#DB61A2",
|
|
510
|
+
cost: "#DB6D28"
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
];
|
|
514
|
+
|
|
515
|
+
// ../../packages/shared-home/dist/themes/index.js
|
|
516
|
+
var PICASSO_THEME = BUILT_IN_THEMES[0];
|
|
517
|
+
|
|
518
|
+
// ../../packages/shared-home/dist/app-connections.js
|
|
519
|
+
import { join as join14 } from "node:path";
|
|
520
|
+
|
|
521
|
+
// ../../packages/shared-home/dist/working-directory.js
|
|
522
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
523
|
+
import { existsSync as existsSync2, realpathSync, statSync } from "node:fs";
|
|
524
|
+
import { homedir as homedir2 } from "node:os";
|
|
525
|
+
import { basename as basename2, dirname as dirname5, isAbsolute, join as join15, resolve as resolve2, sep } from "node:path";
|
|
526
|
+
|
|
527
|
+
// ../../packages/shared-home/dist/memory-guard.js
|
|
528
|
+
import { appendFileSync, mkdirSync as mkdirSync3 } from "node:fs";
|
|
529
|
+
import { dirname as dirname6, join as join16 } from "node:path";
|
|
530
|
+
import { getHeapStatistics } from "node:v8";
|
|
531
|
+
var GiB = 1024 * 1024 * 1024;
|
|
532
|
+
var MEMORY_HIGH_BYTES = 6 * GiB;
|
|
533
|
+
var MEMORY_CRITICAL_BYTES = 16 * GiB;
|
|
534
|
+
|
|
535
|
+
// ../../packages/shared-home/dist/route-listings.js
|
|
536
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync5, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
537
|
+
import { dirname as dirname7, join as join17 } from "node:path";
|
|
538
|
+
|
|
539
|
+
// ../../packages/shared-home/dist/model-id-migration.js
|
|
540
|
+
import { copyFileSync, existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
541
|
+
import { join as join18 } from "node:path";
|
|
542
|
+
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
543
|
+
|
|
544
|
+
// ../../packages/shared-home/dist/active-models.js
|
|
545
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync4, readFileSync as readFileSync7, readdirSync as readdirSync3 } from "node:fs";
|
|
546
|
+
import { join as join19 } from "node:path";
|
|
547
|
+
|
|
548
|
+
// ../../packages/sessions/dist/index.js
|
|
549
|
+
import { createHash as createHash3, randomBytes as randomBytes4 } from "node:crypto";
|
|
550
|
+
import { createReadStream, readFileSync as readFileSync10, statSync as statSync4 } from "node:fs";
|
|
551
|
+
import { appendFile, chmod as chmod4, mkdir as mkdir4, readdir as readdir2, rename as rename3, rm as rm5, writeFile } from "node:fs/promises";
|
|
552
|
+
import { isAbsolute as isAbsolute3, join as join23, resolve as resolve5 } from "node:path";
|
|
553
|
+
import { createInterface } from "node:readline/promises";
|
|
554
|
+
|
|
555
|
+
// ../../packages/shared/dist/logger.js
|
|
556
|
+
var LEVEL_WEIGHT = {
|
|
557
|
+
debug: 10,
|
|
558
|
+
info: 20,
|
|
559
|
+
warn: 30,
|
|
560
|
+
error: 40,
|
|
561
|
+
silent: Number.POSITIVE_INFINITY
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
// ../../packages/shared/dist/redact-diagnostics.js
|
|
565
|
+
var REDACTED = "[redacted]";
|
|
566
|
+
var DIAGNOSTICS_LIMITS = {
|
|
567
|
+
/** Whole request body (`POST /v1/diagnostics/reports` answers 413 above this). */
|
|
568
|
+
bodyBytes: 256 * 1024,
|
|
569
|
+
messageBytes: 2 * 1024,
|
|
570
|
+
stackBytes: 16 * 1024,
|
|
571
|
+
logTailBytes: 32 * 1024,
|
|
572
|
+
/** Short fields (error name, code, command, signal, versions, os release). */
|
|
573
|
+
shortFieldBytes: 256
|
|
574
|
+
};
|
|
575
|
+
var CREDENTIAL_RULES = [
|
|
576
|
+
// JWT: three base64url segments, the first a JSON header (`eyJ`).
|
|
577
|
+
[/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/gu, REDACTED],
|
|
578
|
+
[/\b(Bearer)\s+[A-Za-z0-9._~+/=-]+/giu, `$1 ${REDACTED}`],
|
|
579
|
+
// `Authorization: Basic <x>` (any value), and a bare `Basic <b64>` whose value has a digit, `+`, `/` or `=`.
|
|
580
|
+
[/\b(Authorization\s*["']?\s*[=:]\s*["']?Basic)\s+[A-Za-z0-9._~+/=-]+/giu, `$1 ${REDACTED}`],
|
|
581
|
+
[/\b(Basic)\s+(?=[A-Za-z0-9+/]*[0-9+/=])[A-Za-z0-9+/]{12,}={0,2}/gu, `$1 ${REDACTED}`],
|
|
582
|
+
[/\b(api[_-]?key)(\s*["']?\s*[=:]\s*["']?)[^\s"'&,;]+/giu, `$1$2${REDACTED}`],
|
|
583
|
+
// JSON pairs first, so a quoted value with spaces is redacted whole: `"password": "a b"`, `"client_secret":"x"`.
|
|
584
|
+
[
|
|
585
|
+
/("(?:[A-Za-z0-9]+[_-])*(?:password|passwd|secret|token)"\s*:\s*")(?:[^"\\]|\\.)*"/giu,
|
|
586
|
+
`$1${REDACTED}"`
|
|
587
|
+
],
|
|
588
|
+
// key=value / key: value. `tokens: 12` and `max_tokens=5` do not match (the key must end in the word).
|
|
589
|
+
[
|
|
590
|
+
/\b((?:[A-Za-z0-9]+[_-])*(?:password|passwd|secret|token))(\s*["']?\s*[=:]\s*["']?)[^\s"'&,;]+/giu,
|
|
591
|
+
`$1$2${REDACTED}`
|
|
592
|
+
],
|
|
593
|
+
// AWS access key ids.
|
|
594
|
+
[/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/gu, REDACTED],
|
|
595
|
+
// URL credentials (`postgres://u:pw@localhost`). Before the email rule, which would take `pw@host.tld`.
|
|
596
|
+
[/\b([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^/\s:@]+:[^@\s/]+@/gu, `$1${REDACTED}@`],
|
|
597
|
+
[/\bsk-[A-Za-z0-9_-]{8,}/gu, REDACTED],
|
|
598
|
+
[/\bgh[pousr]_[A-Za-z0-9]{16,}/gu, REDACTED],
|
|
599
|
+
[/\bglpat-[A-Za-z0-9_-]{16,}/gu, REDACTED],
|
|
600
|
+
[/\bxox[abposr]-[A-Za-z0-9-]{8,}/gu, REDACTED]
|
|
601
|
+
];
|
|
602
|
+
var SECRET_PATTERNS = [
|
|
603
|
+
...CREDENTIAL_RULES,
|
|
604
|
+
[/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/gu, REDACTED],
|
|
605
|
+
[/\b[0-9a-fA-F]{32,}\b/gu, REDACTED]
|
|
606
|
+
];
|
|
607
|
+
var CREDENTIAL_PATTERNS = [
|
|
608
|
+
// A PEM private key block, whole (header, body and footer), also when its newlines are JSON-escaped (`\n`).
|
|
609
|
+
[/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/gu, REDACTED],
|
|
610
|
+
// Google API keys.
|
|
611
|
+
[/\bAIza[0-9A-Za-z_-]{30,}/gu, REDACTED],
|
|
612
|
+
...CREDENTIAL_RULES
|
|
613
|
+
];
|
|
614
|
+
|
|
615
|
+
// ../../packages/shared/dist/model-facts.js
|
|
616
|
+
var TOKEN_CASING = {
|
|
617
|
+
ai: "AI",
|
|
618
|
+
api: "API",
|
|
619
|
+
glm: "GLM",
|
|
620
|
+
gpt: "GPT",
|
|
621
|
+
deepseek: "DeepSeek",
|
|
622
|
+
qwen: "Qwen",
|
|
623
|
+
kimi: "Kimi",
|
|
624
|
+
minimax: "MiniMax",
|
|
625
|
+
gemini: "Gemini",
|
|
626
|
+
claude: "Claude",
|
|
627
|
+
llama: "Llama",
|
|
628
|
+
mimo: "MiMo",
|
|
629
|
+
vl: "VL",
|
|
630
|
+
oss: "OSS",
|
|
631
|
+
moe: "MoE",
|
|
632
|
+
openai: "OpenAI",
|
|
633
|
+
zai: "Z.ai",
|
|
634
|
+
xai: "xAI",
|
|
635
|
+
nvidia: "NVIDIA",
|
|
636
|
+
github: "GitHub",
|
|
637
|
+
aws: "AWS",
|
|
638
|
+
lm: "LM",
|
|
639
|
+
tts: "TTS",
|
|
640
|
+
hf: "HF"
|
|
641
|
+
};
|
|
642
|
+
var PROVIDER_NAMES = {
|
|
643
|
+
anthropic: "Anthropic",
|
|
644
|
+
openai: "OpenAI",
|
|
645
|
+
"openai-codex": "OpenAI Codex",
|
|
646
|
+
google: "Google Gemini",
|
|
647
|
+
"google-vertex": "Google Vertex AI",
|
|
648
|
+
deepseek: "DeepSeek",
|
|
649
|
+
"deepseek-official": "DeepSeek",
|
|
650
|
+
mistral: "Mistral",
|
|
651
|
+
xai: "xAI",
|
|
652
|
+
groq: "Groq",
|
|
653
|
+
openrouter: "OpenRouter",
|
|
654
|
+
"vercel-ai-gateway": "Vercel AI Gateway",
|
|
655
|
+
"cloudflare-ai-gateway": "Cloudflare AI Gateway",
|
|
656
|
+
"cloudflare-workers-ai": "Cloudflare Workers AI",
|
|
657
|
+
"amazon-bedrock": "Amazon Bedrock",
|
|
658
|
+
azure: "Azure OpenAI",
|
|
659
|
+
together: "Together AI",
|
|
660
|
+
fireworks: "Fireworks",
|
|
661
|
+
huggingface: "Hugging Face",
|
|
662
|
+
moonshotai: "Moonshot AI",
|
|
663
|
+
"moonshotai-cn": "Moonshot AI (China)",
|
|
664
|
+
opencode: "OpenCode Zen",
|
|
665
|
+
"opencode-go": "OpenCode Go",
|
|
666
|
+
"github-copilot": "GitHub Copilot",
|
|
667
|
+
cerebras: "Cerebras",
|
|
668
|
+
nvidia: "NVIDIA",
|
|
669
|
+
minimax: "MiniMax",
|
|
670
|
+
"minimax-cn": "MiniMax (China)",
|
|
671
|
+
zai: "Z.ai",
|
|
672
|
+
"kimi-coding": "Kimi Coding",
|
|
673
|
+
"qwen-token-plan": "Qwen Token Plan",
|
|
674
|
+
baseten: "Baseten",
|
|
675
|
+
meta: "Meta",
|
|
676
|
+
xiaomi: "Xiaomi",
|
|
677
|
+
ollama: "Ollama",
|
|
678
|
+
"lm-studio": "LM Studio",
|
|
679
|
+
"kiro-prism": "Kiro Prism",
|
|
680
|
+
prism: "Kiro Prism"
|
|
681
|
+
};
|
|
682
|
+
function tidyModelId(id) {
|
|
683
|
+
const last = id.split("/").filter((part) => part.length > 0).pop() ?? id;
|
|
684
|
+
return last.split(/[-_\s]+/u).filter((token) => token.length > 0).map(tidyToken).join(" ");
|
|
685
|
+
}
|
|
686
|
+
function tidyToken(token) {
|
|
687
|
+
const lower = token.toLowerCase();
|
|
688
|
+
const known = TOKEN_CASING[lower];
|
|
689
|
+
if (known !== void 0)
|
|
690
|
+
return known;
|
|
691
|
+
if (/^[vk]\d/u.test(lower))
|
|
692
|
+
return lower[0].toUpperCase() + lower.slice(1);
|
|
693
|
+
if (/^\d+(\.\d+)*[bkm]$/u.test(lower))
|
|
694
|
+
return lower.slice(0, -1) + lower.slice(-1).toUpperCase();
|
|
695
|
+
if (/^\d/u.test(lower))
|
|
696
|
+
return lower;
|
|
697
|
+
return lower[0].toUpperCase() + lower.slice(1);
|
|
698
|
+
}
|
|
699
|
+
function isNaiveName(name, id) {
|
|
700
|
+
const squash = (value) => value.toLowerCase().replace(/[-_\s]+/gu, " ").trim();
|
|
701
|
+
const last = id.split("/").filter((part) => part.length > 0).pop() ?? id;
|
|
702
|
+
if (squash(name) !== squash(id) && squash(name) !== squash(last))
|
|
703
|
+
return false;
|
|
704
|
+
return name.split(/[-_\s/]+/u).every((token) => token.slice(1) === token.slice(1).toLowerCase());
|
|
705
|
+
}
|
|
706
|
+
function displayProviderName(id, name) {
|
|
707
|
+
const given = name?.trim();
|
|
708
|
+
if (given && !isNaiveName(given, id))
|
|
709
|
+
return given;
|
|
710
|
+
return PROVIDER_NAMES[id] ?? tidyModelId(id);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// ../../packages/shared/dist/engine-errors.js
|
|
714
|
+
function addModelHint(surface, route, model) {
|
|
715
|
+
switch (surface) {
|
|
716
|
+
case "tui":
|
|
717
|
+
return "/provider to add it";
|
|
718
|
+
case "cli":
|
|
719
|
+
return `add it with: picasso provider models ${route} --add ${model}`;
|
|
720
|
+
case "mac":
|
|
721
|
+
return "add it in Settings \u203A Providers";
|
|
722
|
+
case "any":
|
|
723
|
+
return "add it to the connection's models";
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
function connectHint(surface, route) {
|
|
727
|
+
switch (surface) {
|
|
728
|
+
case "tui":
|
|
729
|
+
return "/provider to set it up";
|
|
730
|
+
case "cli":
|
|
731
|
+
return `set it up with: picasso provider set ${route}`;
|
|
732
|
+
case "mac":
|
|
733
|
+
return "set it up in Settings \u203A Providers";
|
|
734
|
+
case "any":
|
|
735
|
+
return "set up the connection first";
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
var connection = (route) => `The ${displayProviderName(route)} connection`;
|
|
739
|
+
var RULES = [
|
|
740
|
+
{
|
|
741
|
+
pattern: /pi-ai provider "([^"]+)" has no configured model "([^"]+)"/u,
|
|
742
|
+
plain: (m, surface) => `${connection(m[1])} doesn't have ${m[2]} set up \xB7 ${addModelHint(surface, m[1], m[2])}`
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
// Kept as "does not support reasoning effort" so the refusal is still recognised (model-reasoning.json).
|
|
746
|
+
pattern: /pi-ai provider "([^"]+)" model "([^"]+)" does not support reasoning effort "([^"]+)"/u,
|
|
747
|
+
plain: (m) => `${m[2]} on ${displayProviderName(m[1])} does not support reasoning effort "${m[3]}"`
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
pattern: /pi-ai adapter does not own provider "([^"]+)"/u,
|
|
751
|
+
plain: (m, surface) => `${connection(m[1])} isn't set up \xB7 ${connectHint(surface, m[1])}`
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
pattern: /no adapter registered for provider "([^"]+)"/u,
|
|
755
|
+
plain: (m, surface) => `${connection(m[1])} isn't set up \xB7 ${connectHint(surface, m[1])}`
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
pattern: /pi-ai request header preparation failed for provider "([^"]+)":\s*/u,
|
|
759
|
+
plain: (m) => `Couldn't prepare the request for ${displayProviderName(m[1])}: `
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
pattern: /pi-ai model "([^"]+)" does not support image input/u,
|
|
763
|
+
plain: (m) => `${m[1]} doesn't take images`
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
pattern: /pi-ai stream idle timeout after (\d+)ms/u,
|
|
767
|
+
plain: (m) => `The model sent nothing for ${Math.max(1, Math.round(Number(m[1]) / 1e3))} s`
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
pattern: /pi-ai detected context overflow for model "([^"]+)"/u,
|
|
771
|
+
plain: (m) => `The conversation is too long for ${m[1]}`
|
|
772
|
+
},
|
|
773
|
+
{
|
|
774
|
+
pattern: /pi-ai stream for model "([^"]+)" ended pending/u,
|
|
775
|
+
plain: (m) => `${m[1]} stopped before it finished the reply`
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
pattern: /pi-ai deferred response for model "([^"]+)" is not supported/u,
|
|
779
|
+
plain: (m) => `${m[1]} answered with a deferred response, which Picasso can't read`
|
|
780
|
+
}
|
|
781
|
+
];
|
|
782
|
+
function plainEngineError(raw, surface = "tui") {
|
|
783
|
+
if (typeof raw !== "string" || raw.length === 0)
|
|
784
|
+
return raw;
|
|
785
|
+
let text = raw;
|
|
786
|
+
for (const rule of RULES) {
|
|
787
|
+
const match = rule.pattern.exec(text);
|
|
788
|
+
if (match !== null)
|
|
789
|
+
text = text.slice(0, match.index) + rule.plain(match, surface) + text.slice(match.index + match[0].length);
|
|
790
|
+
}
|
|
791
|
+
if (!namesEngineLibrary(text))
|
|
792
|
+
return text;
|
|
793
|
+
return text.replace(/(^|[^-\w])\[?pi-ai\]?:?\s*/giu, (_whole, lead) => lead).replace(/\s{2,}/gu, " ").trim();
|
|
794
|
+
}
|
|
795
|
+
function namesEngineLibrary(text) {
|
|
796
|
+
return /(^|[^-\w])pi-ai\b/iu.test(text);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// ../../packages/sessions/dist/dsh-log.js
|
|
800
|
+
import { existsSync as existsSync5, readdirSync as readdirSync4, readFileSync as readFileSync8, statSync as statSync2 } from "node:fs";
|
|
801
|
+
import { homedir as homedir3 } from "node:os";
|
|
802
|
+
import { join as join20 } from "node:path";
|
|
803
|
+
import * as zlib from "node:zlib";
|
|
804
|
+
var LOG_FILE = /^session\.v(\d+)\.jsonl(\.zstd)?$/u;
|
|
805
|
+
var ZSTD_MAGIC = Buffer.from([40, 181, 47, 253]);
|
|
806
|
+
var MEMORY_PREAMBLE = "Background memory recalled from EARLIER";
|
|
807
|
+
var MEMORY_REQUEST_MARKER = "\n\nUser request:\n";
|
|
808
|
+
var PROMPT_SOURCES = ["user", "goal", "agent-message", "subagent-settled"];
|
|
809
|
+
function defaultDshHome() {
|
|
810
|
+
return process.env.DSH_HOME ?? join20(homedir3(), ".dsh");
|
|
811
|
+
}
|
|
812
|
+
function dshSessionsRoot(dshHome2 = defaultDshHome()) {
|
|
813
|
+
return join20(dshHome2, "sessions");
|
|
814
|
+
}
|
|
815
|
+
function safeReaddir(path) {
|
|
816
|
+
try {
|
|
817
|
+
return readdirSync4(path, { withFileTypes: true });
|
|
818
|
+
} catch {
|
|
819
|
+
return [];
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
function logInSessionDir(sessionDir, sessionId, projectDir) {
|
|
823
|
+
let best;
|
|
824
|
+
for (const entry of safeReaddir(sessionDir)) {
|
|
825
|
+
if (!entry.isFile())
|
|
826
|
+
continue;
|
|
827
|
+
const match = LOG_FILE.exec(entry.name);
|
|
828
|
+
if (match === null)
|
|
829
|
+
continue;
|
|
830
|
+
const path = join20(sessionDir, entry.name);
|
|
831
|
+
let stats;
|
|
832
|
+
try {
|
|
833
|
+
stats = statSync2(path);
|
|
834
|
+
} catch {
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
const candidate = {
|
|
838
|
+
sessionId,
|
|
839
|
+
path,
|
|
840
|
+
projectDir,
|
|
841
|
+
version: Number(match[1]),
|
|
842
|
+
updatedAtMs: stats.mtimeMs,
|
|
843
|
+
sizeBytes: stats.size
|
|
844
|
+
};
|
|
845
|
+
if (best === void 0 || candidate.version > best.version || candidate.version === best.version && candidate.updatedAtMs > best.updatedAtMs) {
|
|
846
|
+
best = candidate;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return best;
|
|
850
|
+
}
|
|
851
|
+
function indexDshSessionLogs(dshHome2) {
|
|
852
|
+
const root = dshSessionsRoot(dshHome2);
|
|
853
|
+
const index = /* @__PURE__ */ new Map();
|
|
854
|
+
for (const project of safeReaddir(root)) {
|
|
855
|
+
if (!project.isDirectory())
|
|
856
|
+
continue;
|
|
857
|
+
const projectDir = join20(root, project.name);
|
|
858
|
+
for (const session of safeReaddir(projectDir)) {
|
|
859
|
+
if (!session.isDirectory())
|
|
860
|
+
continue;
|
|
861
|
+
const found = logInSessionDir(join20(projectDir, session.name), session.name, projectDir);
|
|
862
|
+
if (found === void 0)
|
|
863
|
+
continue;
|
|
864
|
+
const existing = index.get(found.sessionId);
|
|
865
|
+
if (existing === void 0 || found.updatedAtMs > existing.updatedAtMs)
|
|
866
|
+
index.set(found.sessionId, found);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return index;
|
|
870
|
+
}
|
|
871
|
+
function zstdDecompressor() {
|
|
872
|
+
const decompress = zlib.zstdDecompressSync;
|
|
873
|
+
if (decompress === void 0) {
|
|
874
|
+
throw new Error("Reading dsh's zstd session log needs Node.js with zlib zstd support (>= 22.15).");
|
|
875
|
+
}
|
|
876
|
+
return decompress;
|
|
877
|
+
}
|
|
878
|
+
function zstdFrameLength(buffer, offset) {
|
|
879
|
+
if (offset + 5 > buffer.length || buffer.readUInt32LE(offset) !== ZSTD_MAGIC.readUInt32LE(0))
|
|
880
|
+
return void 0;
|
|
881
|
+
const descriptor = buffer[offset + 4];
|
|
882
|
+
const singleSegment = (descriptor & 32) !== 0;
|
|
883
|
+
const contentSizeBytes = [singleSegment ? 1 : 0, 2, 4, 8][descriptor >> 6];
|
|
884
|
+
const dictionaryBytes = [0, 1, 2, 4][descriptor & 3];
|
|
885
|
+
let at = offset + 5 + (singleSegment ? 0 : 1) + dictionaryBytes + contentSizeBytes;
|
|
886
|
+
for (; ; ) {
|
|
887
|
+
if (at + 3 > buffer.length)
|
|
888
|
+
return void 0;
|
|
889
|
+
const header = buffer[at] | buffer[at + 1] << 8 | buffer[at + 2] << 16;
|
|
890
|
+
const type = header >> 1 & 3;
|
|
891
|
+
if (type === 3)
|
|
892
|
+
return void 0;
|
|
893
|
+
at += 3 + (type === 1 ? 1 : header >> 3);
|
|
894
|
+
if (at > buffer.length)
|
|
895
|
+
return void 0;
|
|
896
|
+
if ((header & 1) !== 0)
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
if ((descriptor & 4) !== 0)
|
|
900
|
+
at += 4;
|
|
901
|
+
return at <= buffer.length ? at - offset : void 0;
|
|
902
|
+
}
|
|
903
|
+
function decodeDshZstdFrames(buffer) {
|
|
904
|
+
const decompress = zstdDecompressor();
|
|
905
|
+
if (buffer.indexOf(ZSTD_MAGIC) !== 0) {
|
|
906
|
+
return { text: decompress(buffer).toString("utf8"), frames: 1, decodedBytes: buffer.length, trailingBytes: 0 };
|
|
907
|
+
}
|
|
908
|
+
const parts = [];
|
|
909
|
+
let start = 0;
|
|
910
|
+
while (start < buffer.length) {
|
|
911
|
+
const length = zstdFrameLength(buffer, start);
|
|
912
|
+
if (length === void 0)
|
|
913
|
+
break;
|
|
914
|
+
try {
|
|
915
|
+
parts.push(decompress(buffer.subarray(start, start + length)));
|
|
916
|
+
} catch {
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
start += length;
|
|
920
|
+
}
|
|
921
|
+
if (parts.length === 0)
|
|
922
|
+
throw new Error("dsh session log has no complete zstd frame");
|
|
923
|
+
return { text: Buffer.concat(parts).toString("utf8"), frames: parts.length, decodedBytes: start, trailingBytes: buffer.length - start };
|
|
924
|
+
}
|
|
925
|
+
function parseDshLog(text) {
|
|
926
|
+
const records = [];
|
|
927
|
+
for (const line of text.split("\n")) {
|
|
928
|
+
const trimmed = line.trim();
|
|
929
|
+
if (trimmed.length === 0)
|
|
930
|
+
continue;
|
|
931
|
+
let parsed;
|
|
932
|
+
try {
|
|
933
|
+
parsed = JSON.parse(trimmed);
|
|
934
|
+
} catch {
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
if (isRecord(parsed) && typeof parsed.type === "string")
|
|
938
|
+
records.push(parsed);
|
|
939
|
+
}
|
|
940
|
+
return records;
|
|
941
|
+
}
|
|
942
|
+
function isRecord(value) {
|
|
943
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
944
|
+
}
|
|
945
|
+
function str(value) {
|
|
946
|
+
return typeof value === "string" ? value : void 0;
|
|
947
|
+
}
|
|
948
|
+
function num(value) {
|
|
949
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
950
|
+
}
|
|
951
|
+
function dataOf(record) {
|
|
952
|
+
return isRecord(record.data) ? record.data : {};
|
|
953
|
+
}
|
|
954
|
+
function messageText(message) {
|
|
955
|
+
if (!isRecord(message) || !Array.isArray(message.content))
|
|
956
|
+
return "";
|
|
957
|
+
return message.content.filter((block) => isRecord(block) && block.type === "text").map((block) => str(block.text) ?? "").join("").trim();
|
|
958
|
+
}
|
|
959
|
+
function sourceKind(message) {
|
|
960
|
+
return isRecord(message.source) ? str(message.source.kind) : void 0;
|
|
961
|
+
}
|
|
962
|
+
function stripRecalledMemory(text) {
|
|
963
|
+
if (!text.startsWith(MEMORY_PREAMBLE))
|
|
964
|
+
return text;
|
|
965
|
+
const marker = text.lastIndexOf(MEMORY_REQUEST_MARKER);
|
|
966
|
+
return marker < 0 ? text : text.slice(marker + MEMORY_REQUEST_MARKER.length).trim();
|
|
967
|
+
}
|
|
968
|
+
function addUsage(totals, usage) {
|
|
969
|
+
if (!isRecord(usage))
|
|
970
|
+
return totals;
|
|
971
|
+
return {
|
|
972
|
+
inputTokens: totals.inputTokens + (num(usage.inputTokens) ?? 0),
|
|
973
|
+
outputTokens: totals.outputTokens + (num(usage.outputTokens) ?? 0),
|
|
974
|
+
cacheReadTokens: totals.cacheReadTokens + (num(usage.cacheReadTokens) ?? num(usage.cacheReadInputTokens) ?? 0),
|
|
975
|
+
cacheWriteTokens: totals.cacheWriteTokens + (num(usage.cacheWriteTokens) ?? 0)
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
var ZERO_USAGE = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
979
|
+
function finishTurn(draft) {
|
|
980
|
+
const rank = (source) => {
|
|
981
|
+
const index = PROMPT_SOURCES.indexOf(source);
|
|
982
|
+
return index < 0 ? PROMPT_SOURCES.length : index;
|
|
983
|
+
};
|
|
984
|
+
const primary = draft.prompts.filter((prompt) => prompt.steer !== true).sort((left, right) => rank(left.source) - rank(right.source))[0];
|
|
985
|
+
if (primary === void 0 && draft.lastText.length === 0 && draft.toolCalls === 0)
|
|
986
|
+
return void 0;
|
|
987
|
+
const steers = draft.prompts.filter((prompt) => prompt !== primary && (prompt.steer === true || prompt.source === "user")).map((prompt) => prompt.text);
|
|
988
|
+
const result = draft.lastText.length > 0 ? draft.lastText : draft.status === "error" ? `Error: ${draft.error ?? "the turn failed"}` : draft.status === "cancelled" ? "Turn cancelled." : draft.status === "running" ? "Still running." : draft.toolCalls > 0 ? `Completed (${draft.toolCalls} tool call${draft.toolCalls === 1 ? "" : "s"}).` : "Completed.";
|
|
989
|
+
return {
|
|
990
|
+
turn: draft.turn,
|
|
991
|
+
prompt: primary?.text ?? `Turn ${draft.turn}`,
|
|
992
|
+
steers,
|
|
993
|
+
result: draft.status === "error" && draft.lastText.length > 0 && draft.error !== void 0 ? `${draft.lastText}
|
|
994
|
+
Error: ${draft.error}` : result,
|
|
995
|
+
status: draft.status,
|
|
996
|
+
promptSource: primary?.source ?? "none",
|
|
997
|
+
messageIds: draft.prompts.flatMap((prompt) => prompt.id === void 0 ? [] : [prompt.id]),
|
|
998
|
+
...draft.startedAtMs === void 0 ? {} : { startedAtMs: draft.startedAtMs },
|
|
999
|
+
...draft.endedAtMs === void 0 ? {} : { endedAtMs: draft.endedAtMs },
|
|
1000
|
+
toolCalls: draft.toolCalls,
|
|
1001
|
+
usage: draft.usage,
|
|
1002
|
+
...draft.events === void 0 ? {} : { events: draft.events }
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
function projectDshTranscript(records, options = {}) {
|
|
1006
|
+
const turns = [];
|
|
1007
|
+
const project = options.projector;
|
|
1008
|
+
let draft;
|
|
1009
|
+
let leading = [];
|
|
1010
|
+
let trailing;
|
|
1011
|
+
const open4 = (turn, time) => {
|
|
1012
|
+
const opened = {
|
|
1013
|
+
turn,
|
|
1014
|
+
prompts: [],
|
|
1015
|
+
lastText: "",
|
|
1016
|
+
status: "running",
|
|
1017
|
+
toolCalls: 0,
|
|
1018
|
+
usage: ZERO_USAGE,
|
|
1019
|
+
...time === void 0 ? {} : { startedAtMs: time }
|
|
1020
|
+
};
|
|
1021
|
+
if (project !== void 0) {
|
|
1022
|
+
opened.events = turns.length === 0 && trailing === void 0 ? [] : leading;
|
|
1023
|
+
leading = [];
|
|
1024
|
+
}
|
|
1025
|
+
return opened;
|
|
1026
|
+
};
|
|
1027
|
+
const close = () => {
|
|
1028
|
+
if (draft === void 0)
|
|
1029
|
+
return;
|
|
1030
|
+
const finished = finishTurn(draft);
|
|
1031
|
+
if (finished !== void 0) {
|
|
1032
|
+
turns.push(finished);
|
|
1033
|
+
if (draft.events !== void 0)
|
|
1034
|
+
trailing = draft.events;
|
|
1035
|
+
} else if (draft.events !== void 0) {
|
|
1036
|
+
(trailing ?? leading).push(...draft.events);
|
|
1037
|
+
}
|
|
1038
|
+
draft = void 0;
|
|
1039
|
+
};
|
|
1040
|
+
const deliver = (events) => {
|
|
1041
|
+
if (events.length === 0)
|
|
1042
|
+
return;
|
|
1043
|
+
if (draft?.events !== void 0)
|
|
1044
|
+
draft.events.push(...events);
|
|
1045
|
+
else
|
|
1046
|
+
(trailing ?? leading).push(...events);
|
|
1047
|
+
};
|
|
1048
|
+
for (const record of records) {
|
|
1049
|
+
const data = dataOf(record);
|
|
1050
|
+
let projected = [];
|
|
1051
|
+
if (project !== void 0) {
|
|
1052
|
+
try {
|
|
1053
|
+
projected = project(record);
|
|
1054
|
+
} catch {
|
|
1055
|
+
projected = [];
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
if (record.type === "turn/end")
|
|
1059
|
+
deliver(projected);
|
|
1060
|
+
switch (record.type) {
|
|
1061
|
+
case "turn/start": {
|
|
1062
|
+
close();
|
|
1063
|
+
draft = open4(num(data.turn) ?? turns.length + 1, num(record.time));
|
|
1064
|
+
break;
|
|
1065
|
+
}
|
|
1066
|
+
case "user/message": {
|
|
1067
|
+
const kind = sourceKind(data);
|
|
1068
|
+
if (kind === void 0 || !PROMPT_SOURCES.includes(kind))
|
|
1069
|
+
break;
|
|
1070
|
+
const raw = messageText(data);
|
|
1071
|
+
const summary = isRecord(data.source) ? str(data.source.summary) : void 0;
|
|
1072
|
+
const text = kind === "user" ? stripRecalledMemory(raw) : raw || summary || "";
|
|
1073
|
+
if (text.length === 0)
|
|
1074
|
+
break;
|
|
1075
|
+
draft ??= open4(turns.length + 1, num(record.time));
|
|
1076
|
+
const id = str(data.id);
|
|
1077
|
+
const delivers = kind === "user" && (draft.steerInserts ?? []).some((item) => id !== void 0 && item.id !== void 0 ? item.id === id : item.text.length > 0 && item.text === text);
|
|
1078
|
+
draft.prompts.push({ text, source: kind, ...id === void 0 ? {} : { id }, ...delivers ? { steer: true } : {} });
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
case "agent/inbox/spliced": {
|
|
1082
|
+
if (draft === void 0 || data.target !== "next-step" || !Array.isArray(data.inserted))
|
|
1083
|
+
break;
|
|
1084
|
+
for (const inserted of data.inserted) {
|
|
1085
|
+
if (!isRecord(inserted))
|
|
1086
|
+
continue;
|
|
1087
|
+
const text = stripRecalledMemory(messageText(inserted));
|
|
1088
|
+
const id = str(inserted.id);
|
|
1089
|
+
if (text.length > 0 || id !== void 0)
|
|
1090
|
+
(draft.steerInserts ??= []).push({ text, ...id === void 0 ? {} : { id } });
|
|
1091
|
+
}
|
|
1092
|
+
break;
|
|
1093
|
+
}
|
|
1094
|
+
case "assistant/message": {
|
|
1095
|
+
if (draft === void 0)
|
|
1096
|
+
break;
|
|
1097
|
+
const text = messageText(data.message);
|
|
1098
|
+
if (text.length > 0)
|
|
1099
|
+
draft.lastText = text;
|
|
1100
|
+
draft.usage = addUsage(draft.usage, data.usage);
|
|
1101
|
+
break;
|
|
1102
|
+
}
|
|
1103
|
+
case "tool/call": {
|
|
1104
|
+
if (draft !== void 0)
|
|
1105
|
+
draft.toolCalls += 1;
|
|
1106
|
+
break;
|
|
1107
|
+
}
|
|
1108
|
+
case "turn/end": {
|
|
1109
|
+
if (draft === void 0)
|
|
1110
|
+
break;
|
|
1111
|
+
const reason = isRecord(data.reason) ? data.reason : {};
|
|
1112
|
+
const kind = str(reason.kind);
|
|
1113
|
+
draft.status = kind === "error" ? "error" : kind === "cancelled" || kind === "canceled" || kind === "aborted" ? "cancelled" : "completed";
|
|
1114
|
+
if (kind === "error") {
|
|
1115
|
+
const error = isRecord(reason.error) ? str(reason.error.message) : str(reason.message);
|
|
1116
|
+
if (error !== void 0)
|
|
1117
|
+
draft.error = plainEngineError(error, "any");
|
|
1118
|
+
}
|
|
1119
|
+
const time = num(record.time);
|
|
1120
|
+
if (time !== void 0)
|
|
1121
|
+
draft.endedAtMs = time;
|
|
1122
|
+
close();
|
|
1123
|
+
break;
|
|
1124
|
+
}
|
|
1125
|
+
default:
|
|
1126
|
+
break;
|
|
1127
|
+
}
|
|
1128
|
+
if (record.type !== "turn/end")
|
|
1129
|
+
deliver(projected);
|
|
1130
|
+
}
|
|
1131
|
+
close();
|
|
1132
|
+
if (project !== void 0 && leading.length > 0 && turns.length > 0) {
|
|
1133
|
+
const last = turns[turns.length - 1];
|
|
1134
|
+
turns[turns.length - 1] = { ...last, events: [...last.events ?? [], ...leading] };
|
|
1135
|
+
}
|
|
1136
|
+
return turns;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// ../../packages/sessions/dist/last-session.js
|
|
1140
|
+
import { realpathSync as realpathSync2 } from "node:fs";
|
|
1141
|
+
import { resolve as resolve3 } from "node:path";
|
|
1142
|
+
|
|
1143
|
+
// ../../packages/sessions/dist/dsh-log-diagnostics.js
|
|
1144
|
+
import { createHash } from "node:crypto";
|
|
1145
|
+
import { existsSync as existsSync6, readFileSync as readFileSync9, statSync as statSync3 } from "node:fs";
|
|
1146
|
+
import { basename as basename3, dirname as dirname8, join as join21 } from "node:path";
|
|
1147
|
+
|
|
1148
|
+
// ../../packages/sessions/dist/sharing.js
|
|
1149
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1150
|
+
|
|
1151
|
+
// ../../packages/sessions/dist/lease.js
|
|
1152
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
1153
|
+
import { existsSync as existsSync7, readdirSync as readdirSync5 } from "node:fs";
|
|
1154
|
+
import { readdir, readlink, realpath } from "node:fs/promises";
|
|
1155
|
+
import { join as join22, resolve as resolve4 } from "node:path";
|
|
1156
|
+
|
|
1157
|
+
// ../../packages/sessions/dist/work-artifacts.js
|
|
1158
|
+
import { isAbsolute as isAbsolute2, posix } from "node:path";
|
|
1159
|
+
|
|
1160
|
+
// src/versions-routes.ts
|
|
1161
|
+
var IMPORTED_VERSIONS_REASON = "Imported threads are read-only, so their versions cannot be switched.";
|
|
1162
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1163
|
+
var str2 = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
1164
|
+
var num2 = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
1165
|
+
var strings = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
1166
|
+
var digest = (text) => createHash4("sha1").update(text).digest("hex");
|
|
1167
|
+
var HEAD_EVENTS = 3;
|
|
1168
|
+
var HEAD_READ_START = 64 * 1024;
|
|
1169
|
+
var HEAD_READ_MAX = 4 * 1024 * 1024;
|
|
1170
|
+
var PROMPT_CLIP = 4e3;
|
|
1171
|
+
var DETAIL_CACHE_LIMIT = 24;
|
|
1172
|
+
var eventSig = (record) => digest(JSON.stringify([record.type, record.seq, record.time, record.data ?? null])).slice(0, 12);
|
|
1173
|
+
function decodeChunk(path, buffer) {
|
|
1174
|
+
const text = path.endsWith(".zstd") ? decodeDshZstdFrames(buffer).text : buffer.toString("utf8");
|
|
1175
|
+
return parseDshLog(text);
|
|
1176
|
+
}
|
|
1177
|
+
async function readHeadRecords(location) {
|
|
1178
|
+
const handle = await open3(location.path, "r");
|
|
1179
|
+
try {
|
|
1180
|
+
for (let want = HEAD_READ_START; ; want *= 4) {
|
|
1181
|
+
const buffer = Buffer.alloc(want);
|
|
1182
|
+
const { bytesRead } = await handle.read(buffer, 0, want, 0);
|
|
1183
|
+
const whole = bytesRead < want;
|
|
1184
|
+
let records;
|
|
1185
|
+
try {
|
|
1186
|
+
records = decodeChunk(location.path, buffer.subarray(0, bytesRead));
|
|
1187
|
+
if (!location.path.endsWith(".zstd") && !whole) records = records.slice(0, -1);
|
|
1188
|
+
} catch {
|
|
1189
|
+
records = void 0;
|
|
1190
|
+
}
|
|
1191
|
+
if (whole || records !== void 0 && records.length > HEAD_EVENTS) return records;
|
|
1192
|
+
if (want * 4 > HEAD_READ_MAX) return records;
|
|
1193
|
+
}
|
|
1194
|
+
} finally {
|
|
1195
|
+
await handle.close();
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
function headOf(location, records) {
|
|
1199
|
+
const header = records.find((record) => record.type === "session");
|
|
1200
|
+
if (header === void 0) return void 0;
|
|
1201
|
+
const events = records.filter((record) => record.type !== "session" && num2(record.seq) !== void 0);
|
|
1202
|
+
if (events.length < HEAD_EVENTS) return void 0;
|
|
1203
|
+
return {
|
|
1204
|
+
id: str2(header["id"]) ?? location.sessionId,
|
|
1205
|
+
createdAt: num2(header["createdAt"]) ?? location.updatedAtMs,
|
|
1206
|
+
origin: str2(header["origin"]),
|
|
1207
|
+
rootKey: digest(JSON.stringify(events.slice(0, HEAD_EVENTS).map((record) => [record.type, record.seq, record.time, record.data ?? null])))
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
function detailOf(records) {
|
|
1211
|
+
const sigs = /* @__PURE__ */ new Map();
|
|
1212
|
+
let marker;
|
|
1213
|
+
const starts = [];
|
|
1214
|
+
for (const record of records) {
|
|
1215
|
+
const seq = num2(record.seq);
|
|
1216
|
+
if (record.type === "session" || seq === void 0) continue;
|
|
1217
|
+
sigs.set(seq, eventSig(record));
|
|
1218
|
+
if (record.type === "session/end-seed" && record.data?.["inherited"] === true && (marker === void 0 || seq > marker)) marker = seq;
|
|
1219
|
+
if (record.type === "turn/start") starts.push({ seq, time: num2(record.time) });
|
|
1220
|
+
}
|
|
1221
|
+
const prompts = projectDshTranscript(records);
|
|
1222
|
+
const turns = starts.map((start) => {
|
|
1223
|
+
const turn = prompts.find((candidate) => candidate.startedAtMs !== void 0 && candidate.startedAtMs === start.time);
|
|
1224
|
+
return { seq: start.seq, prompt: (turn?.prompt ?? "").trim().slice(0, PROMPT_CLIP) };
|
|
1225
|
+
});
|
|
1226
|
+
return { cut: marker === void 0 ? void 0 : marker - 1, sigs, turns };
|
|
1227
|
+
}
|
|
1228
|
+
var LineageIndex = class {
|
|
1229
|
+
heads = /* @__PURE__ */ new Map();
|
|
1230
|
+
details = /* @__PURE__ */ new Map();
|
|
1231
|
+
/** Every session on disk with its head; a log that cannot be read is skipped (it joins no family). */
|
|
1232
|
+
async loadHeads(home) {
|
|
1233
|
+
const found = [...indexDshSessionLogs(home).values()];
|
|
1234
|
+
const out = [];
|
|
1235
|
+
let reads = 0;
|
|
1236
|
+
for (const location of found) {
|
|
1237
|
+
let head = this.heads.get(location.path);
|
|
1238
|
+
if (head === void 0) {
|
|
1239
|
+
if (++reads % 32 === 0) await new Promise((resolve6) => setImmediate(resolve6));
|
|
1240
|
+
try {
|
|
1241
|
+
const records = await readHeadRecords(location);
|
|
1242
|
+
head = records === void 0 ? void 0 : headOf(location, records);
|
|
1243
|
+
} catch {
|
|
1244
|
+
head = void 0;
|
|
1245
|
+
}
|
|
1246
|
+
if (head === void 0) continue;
|
|
1247
|
+
this.heads.set(location.path, head);
|
|
1248
|
+
}
|
|
1249
|
+
out.push({ location, head });
|
|
1250
|
+
}
|
|
1251
|
+
return out;
|
|
1252
|
+
}
|
|
1253
|
+
async detail(location) {
|
|
1254
|
+
let stamp;
|
|
1255
|
+
try {
|
|
1256
|
+
const info = await stat3(location.path);
|
|
1257
|
+
stamp = `${location.path}:${info.size}:${info.mtimeMs}`;
|
|
1258
|
+
} catch {
|
|
1259
|
+
return void 0;
|
|
1260
|
+
}
|
|
1261
|
+
const cached = this.details.get(stamp);
|
|
1262
|
+
if (cached !== void 0) {
|
|
1263
|
+
this.details.delete(stamp);
|
|
1264
|
+
this.details.set(stamp, cached);
|
|
1265
|
+
return cached;
|
|
1266
|
+
}
|
|
1267
|
+
let detail;
|
|
1268
|
+
try {
|
|
1269
|
+
detail = detailOf(decodeChunk(location.path, await readFile7(location.path)));
|
|
1270
|
+
} catch {
|
|
1271
|
+
return void 0;
|
|
1272
|
+
}
|
|
1273
|
+
this.details.set(stamp, detail);
|
|
1274
|
+
while (this.details.size > DETAIL_CACHE_LIMIT) this.details.delete(this.details.keys().next().value);
|
|
1275
|
+
return detail;
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
var byCreated = (a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
1279
|
+
function promptAfter(member, after) {
|
|
1280
|
+
return member.detail.turns.find((turn) => turn.seq > after)?.prompt;
|
|
1281
|
+
}
|
|
1282
|
+
function deriveFamilies(rootKey, targetId, tree, facts) {
|
|
1283
|
+
const sorted = [...tree].sort(byCreated);
|
|
1284
|
+
const target = sorted.find((member) => member.id === targetId);
|
|
1285
|
+
if (target === void 0) return [];
|
|
1286
|
+
const points = /* @__PURE__ */ new Map();
|
|
1287
|
+
for (const member of sorted) {
|
|
1288
|
+
const cut = member.detail.cut;
|
|
1289
|
+
const sig = cut === void 0 ? void 0 : member.detail.sigs.get(cut);
|
|
1290
|
+
if (cut === void 0 || sig === void 0) continue;
|
|
1291
|
+
const key = `${cut}:${sig}`;
|
|
1292
|
+
const point = points.get(key) ?? { cut, sig, children: [] };
|
|
1293
|
+
point.children.push(member);
|
|
1294
|
+
points.set(key, point);
|
|
1295
|
+
}
|
|
1296
|
+
const families = [];
|
|
1297
|
+
for (const point of [...points.values()].sort((a, b) => a.cut - b.cut)) {
|
|
1298
|
+
const owner = sorted.find((member) => (member.detail.cut === void 0 || member.detail.cut < point.cut) && member.detail.sigs.get(point.cut) === point.sig && member.detail.sigs.has(point.cut + 1));
|
|
1299
|
+
const members = [...owner === void 0 ? [] : [owner], ...point.children.filter((child) => child !== owner)];
|
|
1300
|
+
if (!members.some((member) => member.id === targetId)) continue;
|
|
1301
|
+
const originalPrompt = owner === void 0 ? void 0 : promptAfter(owner, point.cut);
|
|
1302
|
+
const listed = members.filter((member) => member.id === targetId || !facts.archived.has(member.id) && !facts.trashed.has(member.id) && !facts.side.has(member.id));
|
|
1303
|
+
const versions = listed.map((member, index) => {
|
|
1304
|
+
let kind;
|
|
1305
|
+
if (member === owner) kind = "original";
|
|
1306
|
+
else if (originalPrompt !== void 0) {
|
|
1307
|
+
const prompt = promptAfter(member, point.cut + 1);
|
|
1308
|
+
if (prompt !== void 0) kind = prompt === originalPrompt ? "regenerated" : "edited";
|
|
1309
|
+
}
|
|
1310
|
+
return {
|
|
1311
|
+
threadId: member.id,
|
|
1312
|
+
label: `Version ${index + 1}${kind === void 0 ? "" : ` \xB7 ${kind}`}`,
|
|
1313
|
+
...kind === void 0 ? {} : { kind },
|
|
1314
|
+
createdAt: member.createdAt,
|
|
1315
|
+
isCurrent: member.id === targetId,
|
|
1316
|
+
...facts.running.has(member.id) ? { running: true } : {}
|
|
1317
|
+
};
|
|
1318
|
+
});
|
|
1319
|
+
families.push({ familyId: `v-${digest(`${rootKey}:${point.cut}:${point.sig}`).slice(0, 16)}`, parentThreadId: owner?.id ?? null, forkSeq: point.cut, versions });
|
|
1320
|
+
}
|
|
1321
|
+
return families;
|
|
1322
|
+
}
|
|
1323
|
+
function primaryFamily(targetId, families, tree) {
|
|
1324
|
+
const target = tree.find((member) => member.id === targetId);
|
|
1325
|
+
const cut = target?.detail.cut;
|
|
1326
|
+
const own = cut === void 0 ? void 0 : families.find((family) => family.forkSeq === cut && family.parentThreadId !== targetId);
|
|
1327
|
+
if (own !== void 0) return own;
|
|
1328
|
+
return [...families].sort((a, b) => b.forkSeq - a.forkSeq)[0];
|
|
1329
|
+
}
|
|
1330
|
+
var lineage = new LineageIndex();
|
|
1331
|
+
function reply(res, status, body) {
|
|
1332
|
+
if (res.headersSent) return;
|
|
1333
|
+
res.writeHead(status, { "content-type": "application/json" }).end(JSON.stringify(body));
|
|
1334
|
+
}
|
|
1335
|
+
async function threadVersions(threadId, ctx, index = lineage) {
|
|
1336
|
+
const [listed, lifecycle] = await Promise.all([ctx.call("session/list", { _request: {} }), ctx.call("sessionLifecycle/list", {})]);
|
|
1337
|
+
if (!listed.ok) return { status: 422, body: { error: listed.error } };
|
|
1338
|
+
const rows = (isRecord2(listed.value) && Array.isArray(listed.value["items"]) ? listed.value["items"] : []).filter(isRecord2);
|
|
1339
|
+
const row = rows.find((candidate) => candidate["sessionId"] === threadId);
|
|
1340
|
+
if (row !== void 0) await ctx.markImported([row]).catch(() => void 0);
|
|
1341
|
+
const state = lifecycle.ok && isRecord2(lifecycle.value) ? lifecycle.value : {};
|
|
1342
|
+
const facts = {
|
|
1343
|
+
archived: new Set(strings(state["archived"])),
|
|
1344
|
+
trashed: new Set(strings(state["trashed"])),
|
|
1345
|
+
side: new Set(strings(state["side"])),
|
|
1346
|
+
running: new Set(rows.filter((candidate) => candidate["running"] === true).map((candidate) => str2(candidate["sessionId"])).filter((id) => id !== void 0))
|
|
1347
|
+
};
|
|
1348
|
+
const disabledReason = row !== void 0 && row["imported"] !== void 0 && row["imported"] !== null ? IMPORTED_VERSIONS_REASON : void 0;
|
|
1349
|
+
const superseded = new Set(strings(state["superseded"]));
|
|
1350
|
+
const thread = row === void 0 ? void 0 : {
|
|
1351
|
+
...ctx.shapeRow?.(row) ?? row,
|
|
1352
|
+
...facts.archived.has(threadId) ? { archived: true } : {},
|
|
1353
|
+
...superseded.has(threadId) ? { superseded: true } : {}
|
|
1354
|
+
};
|
|
1355
|
+
const extras = { ...disabledReason === void 0 ? {} : { disabledReason }, ...thread === void 0 ? {} : { thread } };
|
|
1356
|
+
const none = () => ({ threadId, familyId: null, parentThreadId: null, forkSeq: null, versions: [], families: [], ...extras });
|
|
1357
|
+
const all = await index.loadHeads(dshHome(ctx.env));
|
|
1358
|
+
const self = all.find((entry) => entry.head.id === threadId);
|
|
1359
|
+
if (self === void 0) {
|
|
1360
|
+
if (row === void 0) return { status: 404, body: { error: { code: "session/not-found", message: `Thread ${threadId} was not found.` } } };
|
|
1361
|
+
return { status: 200, body: none() };
|
|
1362
|
+
}
|
|
1363
|
+
const tree = [];
|
|
1364
|
+
for (const entry of all) {
|
|
1365
|
+
if (entry.head.rootKey !== self.head.rootKey || entry.head.origin === "subagent") continue;
|
|
1366
|
+
if (entry.head.id !== threadId && (facts.side.has(entry.head.id) || facts.trashed.has(entry.head.id))) continue;
|
|
1367
|
+
const detail = await index.detail(entry.location);
|
|
1368
|
+
if (detail !== void 0) tree.push({ id: entry.head.id, createdAt: entry.head.createdAt, detail });
|
|
1369
|
+
}
|
|
1370
|
+
const families = deriveFamilies(self.head.rootKey, threadId, tree, facts).filter((family) => family.versions.length > 1);
|
|
1371
|
+
const primary = primaryFamily(threadId, families, tree);
|
|
1372
|
+
if (primary === void 0) return { status: 200, body: none() };
|
|
1373
|
+
const body = {
|
|
1374
|
+
threadId,
|
|
1375
|
+
familyId: primary.familyId,
|
|
1376
|
+
parentThreadId: primary.parentThreadId,
|
|
1377
|
+
forkSeq: primary.forkSeq,
|
|
1378
|
+
versions: primary.versions,
|
|
1379
|
+
families,
|
|
1380
|
+
...extras
|
|
1381
|
+
};
|
|
1382
|
+
return { status: 200, body };
|
|
1383
|
+
}
|
|
1384
|
+
async function handleVersionsRoute(res, scope, threadId, ctx) {
|
|
1385
|
+
if (scope !== "owner") return reply(res, 403, { error: { code: "scope_denied", message: "Message versions need the owner bearer." } });
|
|
1386
|
+
try {
|
|
1387
|
+
const result = await threadVersions(threadId, ctx);
|
|
1388
|
+
return reply(res, result.status, result.body);
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
return reply(res, 500, { error: { code: "versions/failed", message: error instanceof Error ? error.message : String(error) } });
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
export {
|
|
1394
|
+
IMPORTED_VERSIONS_REASON,
|
|
1395
|
+
LineageIndex,
|
|
1396
|
+
deriveFamilies,
|
|
1397
|
+
handleVersionsRoute,
|
|
1398
|
+
primaryFamily,
|
|
1399
|
+
threadVersions
|
|
1400
|
+
};
|