@surething/cockpit 1.1.8 → 1.1.9
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/.next-prod/BUILD_ID +1 -1
- package/.next-prod/app-path-routes-manifest.json +9 -5
- package/.next-prod/build-manifest.json +2 -2
- package/.next-prod/cockpit-build.json +1 -1
- package/.next-prod/prerender-manifest.json +3 -3
- package/.next-prod/routes-manifest.json +24 -0
- package/.next-prod/server/app/_global-error/page.js +2 -2
- package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_global-error.html +1 -1
- package/.next-prod/server/app/_global-error.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found/page.js +1 -1
- package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/api/agent/test/route.js +1 -1
- package/.next-prod/server/app/api/bash/route.js +1 -1
- package/.next-prod/server/app/api/bots/[id]/route.js +1 -1
- package/.next-prod/server/app/api/bots/files/route.js +1 -1
- package/.next-prod/server/app/api/bots/route.js +1 -1
- package/.next-prod/server/app/api/chat/codex/route.js +1 -1
- package/.next-prod/server/app/api/chat/deepseek/route.js +1 -1
- package/.next-prod/server/app/api/chat/glm/route.js +1 -1
- package/.next-prod/server/app/api/chat/grok/route.js +1 -1
- package/.next-prod/server/app/api/chat/kimi/route.js +1 -1
- package/.next-prod/server/app/api/chat/ollama/route.js +1 -1
- package/.next-prod/server/app/api/chat/route.js +1 -1
- package/.next-prod/server/app/api/chat/stop/route.js +1 -1
- package/.next-prod/server/app/api/claude-stats/route.js +1 -1
- package/.next-prod/server/app/api/commands/route.js +1 -1
- package/.next-prod/server/app/api/comments/route.js +1 -1
- package/.next-prod/server/app/api/db/columns/route.js +1 -1
- package/.next-prod/server/app/api/db/connect/route.js +1 -1
- package/.next-prod/server/app/api/db/disconnect/route.js +1 -1
- package/.next-prod/server/app/api/db/export/route.js +1 -1
- package/.next-prod/server/app/api/db/query/route.js +1 -1
- package/.next-prod/server/app/api/db/schemas/route.js +2 -2
- package/.next-prod/server/app/api/deepseek/balance/route.js +1 -1
- package/.next-prod/server/app/api/deepseek/credentials/route.js +1 -1
- package/.next-prod/server/app/api/deepseek/models/route.js +1 -1
- package/.next-prod/server/app/api/dev/spans/route.js +1 -1
- package/.next-prod/server/app/api/extension/version/route.js +1 -1
- package/.next-prod/server/app/api/file/route.js +1 -1
- package/.next-prod/server/app/api/files/blame/route.js +1 -1
- package/.next-prod/server/app/api/files/clipboard/route.js +1 -1
- package/.next-prod/server/app/api/files/copy/route.js +1 -1
- package/.next-prod/server/app/api/files/delete/route.js +1 -1
- package/.next-prod/server/app/api/files/expanded/route.js +1 -1
- package/.next-prod/server/app/api/files/index/route.js +1 -1
- package/.next-prod/server/app/api/files/init/route.js +1 -1
- package/.next-prod/server/app/api/files/paste/route.js +1 -1
- package/.next-prod/server/app/api/files/read/route.js +1 -1
- package/.next-prod/server/app/api/files/readdir/route.js +1 -1
- package/.next-prod/server/app/api/files/recent/route.js +1 -1
- package/.next-prod/server/app/api/files/save/route.js +1 -1
- package/.next-prod/server/app/api/files/search/route.js +1 -1
- package/.next-prod/server/app/api/files/stat/route.js +1 -1
- package/.next-prod/server/app/api/files/text/route.js +1 -1
- package/.next-prod/server/app/api/fs/dirs/route.js +1 -1
- package/.next-prod/server/app/api/git/blob/route.js +1 -1
- package/.next-prod/server/app/api/git/branch-diff/route.js +1 -1
- package/.next-prod/server/app/api/git/branches/route.js +1 -1
- package/.next-prod/server/app/api/git/commit-diff/route.js +1 -1
- package/.next-prod/server/app/api/git/commits/route.js +1 -1
- package/.next-prod/server/app/api/git/current-branch/route.js +1 -1
- package/.next-prod/server/app/api/git/diff/route.js +1 -1
- package/.next-prod/server/app/api/git/discard/route.js +1 -1
- package/.next-prod/server/app/api/git/stage/route.js +1 -1
- package/.next-prod/server/app/api/git/status/route.js +1 -1
- package/.next-prod/server/app/api/git/unstage/route.js +1 -1
- package/.next-prod/server/app/api/git/worktree/route.js +1 -1
- package/.next-prod/server/app/api/glm/credentials/route.js +1 -1
- package/.next-prod/server/app/api/glm/models/route.js +1 -1
- package/.next-prod/server/app/api/glm/usage/route.js +1 -1
- package/.next-prod/server/app/api/global-state/route.js +2 -2
- package/.next-prod/server/app/api/grok/models/route.js +1 -1
- package/.next-prod/server/app/api/health/route.js +1 -1
- package/.next-prod/server/app/api/html-apps/[id]/route.js +1 -1
- package/.next-prod/server/app/api/html-apps/files/route.js +1 -1
- package/.next-prod/server/app/api/html-apps/route.js +1 -1
- package/.next-prod/server/app/api/instructions/config/route.js +1 -1
- package/.next-prod/server/app/api/kimi/credentials/route.js +1 -1
- package/.next-prod/server/app/api/kimi/models/route.js +1 -1
- package/.next-prod/server/app/api/kimi/usage/route.js +1 -1
- package/.next-prod/server/app/api/lsp/definition/route.js +1 -1
- package/.next-prod/server/app/api/lsp/hover/route.js +1 -1
- package/.next-prod/server/app/api/lsp/references/route.js +1 -1
- package/.next-prod/server/app/api/lsp/status/route.js +1 -1
- package/.next-prod/server/app/api/lsp/warmup/route.js +1 -1
- package/.next-prod/server/app/api/mobile-link/route.js +1 -1
- package/.next-prod/server/app/api/mysql/columns/route.js +2 -2
- package/.next-prod/server/app/api/mysql/connect/route.js +1 -1
- package/.next-prod/server/app/api/mysql/disconnect/route.js +1 -1
- package/.next-prod/server/app/api/mysql/export/route.js +1 -1
- package/.next-prod/server/app/api/mysql/query/route.js +1 -1
- package/.next-prod/server/app/api/mysql/schemas/route.js +2 -2
- package/.next-prod/server/app/api/neo4j/connect/route.js +1 -1
- package/.next-prod/server/app/api/neo4j/disconnect/route.js +1 -1
- package/.next-prod/server/app/api/neo4j/query/route.js +1 -1
- package/.next-prod/server/app/api/neo4j/schema/route.js +1 -1
- package/.next-prod/server/app/api/note/list/route.js +1 -1
- package/.next-prod/server/app/api/note/route.js +1 -1
- package/.next-prod/server/app/api/ollama/config/route.js +1 -1
- package/.next-prod/server/app/api/ollama/default-model/route.js +1 -1
- package/.next-prod/server/app/api/ollama/models/route.js +1 -1
- package/.next-prod/server/app/api/ollama/start/route.js +1 -1
- package/.next-prod/server/app/api/open-cursor/route.js +1 -1
- package/.next-prod/server/app/api/open-vscode/route.js +1 -1
- package/.next-prod/server/app/api/pi/thinking/route.js +1 -1
- package/.next-prod/server/app/api/pinned-sessions/route.js +1 -1
- package/.next-prod/server/app/api/project-settings/route.js +1 -1
- package/.next-prod/server/app/api/project-state/route.js +2 -2
- package/.next-prod/server/app/api/projectGraph/affected/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/callees/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/callers/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/coedit/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/edges/route.js +1 -0
- package/.next-prod/server/app/api/projectGraph/edges/route.js.nft.json +1 -0
- package/.next-prod/server/app/api/projectGraph/edges/route_client-reference-manifest.js +1 -0
- package/.next-prod/server/app/api/projectGraph/file/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/file-functions/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/impact/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/maps/route.js +1 -0
- package/.next-prod/server/app/api/projectGraph/maps/route.js.nft.json +1 -0
- package/.next-prod/server/app/api/projectGraph/maps/route_client-reference-manifest.js +1 -0
- package/.next-prod/server/app/api/projectGraph/related/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/search/route.js +1 -1
- package/.next-prod/server/app/api/projectGraph/symbols/route.js +1 -1
- package/.next-prod/server/app/api/projects/route.js +1 -1
- package/.next-prod/server/app/api/push/public-key/route.js +1 -1
- package/.next-prod/server/app/api/push/subscribe/route.js +1 -1
- package/.next-prod/server/app/api/push/unsubscribe/route.js +1 -1
- package/.next-prod/server/app/api/redis/command/route.js +1 -1
- package/.next-prod/server/app/api/redis/connect/route.js +1 -1
- package/.next-prod/server/app/api/redis/delete/route.js +1 -1
- package/.next-prod/server/app/api/redis/disconnect/route.js +1 -1
- package/.next-prod/server/app/api/redis/get/route.js +1 -1
- package/.next-prod/server/app/api/redis/keys/route.js +1 -1
- package/.next-prod/server/app/api/redis/set/route.js +1 -1
- package/.next-prod/server/app/api/restart/route.js +1 -1
- package/.next-prod/server/app/api/scheduled-tasks/route.js +2 -2
- package/.next-prod/server/app/api/services/config/route.js +1 -1
- package/.next-prod/server/app/api/services/scripts/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/turn/route.js +2 -2
- package/.next-prod/server/app/api/session/image/route.js +1 -1
- package/.next-prod/server/app/api/session/user-messages/route.js +1 -1
- package/.next-prod/server/app/api/session-bots/route.js +1 -1
- package/.next-prod/server/app/api/session-by-path/route.js +1 -1
- package/.next-prod/server/app/api/session-context/route.js +2 -2
- package/.next-prod/server/app/api/session-title/route.js +1 -1
- package/.next-prod/server/app/api/session-title/suggest/route.js +1 -1
- package/.next-prod/server/app/api/sessions/delegate/route.js +1 -1
- package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
- package/.next-prod/server/app/api/sessions/projects/route.js +1 -1
- package/.next-prod/server/app/api/sessions/search/route.js +1 -1
- package/.next-prod/server/app/api/sessions/status/route.js +1 -1
- package/.next-prod/server/app/api/settings/route.js +1 -1
- package/.next-prod/server/app/api/shutdown/route.js +1 -1
- package/.next-prod/server/app/api/skills/[id]/route.js +1 -1
- package/.next-prod/server/app/api/skills/builtin/route.js +1 -1
- package/.next-prod/server/app/api/skills/content/route.js +1 -1
- package/.next-prod/server/app/api/skills/files/route.js +1 -1
- package/.next-prod/server/app/api/skills/route.js +1 -1
- package/.next-prod/server/app/api/snapshots/blob/route.js +1 -1
- package/.next-prod/server/app/api/snapshots/diff/route.js +1 -1
- package/.next-prod/server/app/api/snapshots/mark/route.js +1 -0
- package/.next-prod/server/app/api/snapshots/mark/route.js.nft.json +1 -0
- package/.next-prod/server/app/api/snapshots/mark/route_client-reference-manifest.js +1 -0
- package/.next-prod/server/app/api/snapshots/range-diff/route.js +1 -1
- package/.next-prod/server/app/api/snapshots/restore/route.js +1 -0
- package/.next-prod/server/app/api/snapshots/restore/route.js.nft.json +1 -0
- package/.next-prod/server/app/api/snapshots/restore/route_client-reference-manifest.js +1 -0
- package/.next-prod/server/app/api/snapshots/route.js +1 -1
- package/.next-prod/server/app/api/terminal/aliases/route.js +1 -1
- package/.next-prod/server/app/api/terminal/autocomplete/route.js +1 -1
- package/.next-prod/server/app/api/terminal/bubble-order/route.js +1 -1
- package/.next-prod/server/app/api/terminal/env/route.js +1 -1
- package/.next-prod/server/app/api/terminal/history/route.js +1 -1
- package/.next-prod/server/app/api/terminal/running/route.js +1 -1
- package/.next-prod/server/app/api/update/route.js +1 -1
- package/.next-prod/server/app/api/update-state/route.js +1 -1
- package/.next-prod/server/app/api/version/route.js +1 -1
- package/.next-prod/server/app/apps/[...path]/route.js +1 -1
- package/.next-prod/server/app/favicon.ico/route.js +1 -1
- package/.next-prod/server/app/m/page.js +2 -1
- package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/manifest.webmanifest/route.js +1 -1
- package/.next-prod/server/app/page.js +1 -1
- package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/project/page.js +1 -1
- package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app-paths-manifest.json +9 -5
- package/.next-prod/server/chunks/2493.js +13 -13
- package/.next-prod/server/chunks/4949.js +1 -1
- package/.next-prod/server/chunks/6610.js +34 -34
- package/.next-prod/server/chunks/7270.js +1 -1
- package/.next-prod/server/chunks/9830.js +2 -2
- package/.next-prod/server/chunks/9998.js +1 -1
- package/.next-prod/server/middleware-build-manifest.js +1 -1
- package/.next-prod/server/next-font-manifest.js +1 -1
- package/.next-prod/server/next-font-manifest.json +1 -1
- package/.next-prod/server/pages/500.html +1 -1
- package/.next-prod/server/server-reference-manifest.json +1 -1
- package/.next-prod/static/LwAYWBEgXwTIkuj7U9BpE/_buildManifest.js +1 -0
- package/.next-prod/static/chunks/{50189-b59a96372658a46a.js → 55541-994b26deaa23f4e6.js} +2 -2
- package/.next-prod/static/chunks/{731-fd4b8bcd1d40dfe9.js → 6837-78c0d1a8165d46f7.js} +21 -21
- package/.next-prod/static/chunks/92000-46024df89fb50e16.js +41 -0
- package/.next-prod/static/chunks/98596-4ca2d2544138aefd.js +733 -0
- package/.next-prod/static/chunks/app/_global-error/page-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/agent/test/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/bash/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/bots/[id]/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/bots/files/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/bots/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/chat/codex/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/chat/deepseek/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/chat/glm/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/chat/grok/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/chat/kimi/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/chat/ollama/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/chat/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/chat/stop/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/claude-stats/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/commands/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/comments/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/db/columns/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/db/connect/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/db/disconnect/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/db/export/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/db/query/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/db/schemas/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/deepseek/balance/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/deepseek/credentials/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/deepseek/models/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/dev/spans/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/extension/version/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/file/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/blame/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/clipboard/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/copy/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/delete/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/expanded/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/index/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/init/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/paste/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/read/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/readdir/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/recent/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/save/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/search/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/stat/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/files/text/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/fs/dirs/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/blob/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/branch-diff/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/branches/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/commit-diff/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/commits/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/current-branch/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/diff/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/discard/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/stage/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/status/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/unstage/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/git/worktree/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/glm/credentials/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/glm/models/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/glm/usage/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/global-state/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/grok/models/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/health/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/html-apps/[id]/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/html-apps/files/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/html-apps/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/instructions/config/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/kimi/credentials/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/kimi/models/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/kimi/usage/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/lsp/definition/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/lsp/hover/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/lsp/references/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/lsp/status/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/lsp/warmup/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/mobile-link/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/mysql/columns/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/mysql/connect/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/mysql/disconnect/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/mysql/export/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/mysql/query/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/mysql/schemas/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/neo4j/connect/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/neo4j/disconnect/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/neo4j/query/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/neo4j/schema/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/note/list/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/note/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/ollama/config/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/ollama/default-model/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/ollama/models/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/ollama/start/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/open-cursor/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/open-vscode/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/pi/thinking/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/pinned-sessions/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/project-settings/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/project-state/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/affected/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/callees/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/callers/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/coedit/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/edges/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/file/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/file-functions/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/impact/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/maps/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/related/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/search/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projectGraph/symbols/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/projects/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/push/public-key/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/push/subscribe/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/push/unsubscribe/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/redis/command/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/redis/connect/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/redis/delete/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/redis/disconnect/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/redis/get/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/redis/keys/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/redis/set/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/restart/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/scheduled-tasks/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/services/config/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/services/scripts/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session/[sessionId]/fork/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session/[sessionId]/history/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session/[sessionId]/turn/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session/image/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session/user-messages/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session-bots/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session-by-path/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session-context/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session-title/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/session-title/suggest/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/sessions/delegate/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/sessions/projects/[encodedPath]/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/sessions/projects/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/sessions/search/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/sessions/status/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/settings/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/shutdown/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/skills/[id]/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/skills/builtin/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/skills/content/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/skills/files/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/skills/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/snapshots/blob/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/snapshots/diff/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/snapshots/mark/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/snapshots/range-diff/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/snapshots/restore/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/snapshots/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/terminal/aliases/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/terminal/autocomplete/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/terminal/bubble-order/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/terminal/env/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/terminal/history/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/terminal/running/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/update/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/update-state/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/api/version/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/apps/[...path]/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/{layout-f0ff0ab277c84dc6.js → layout-7107ed4eeac1f693.js} +1 -1
- package/.next-prod/static/chunks/app/m/page-0c8e79e2f753aecb.js +2 -0
- package/.next-prod/static/chunks/app/manifest.webmanifest/route-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/app/{page-d2ccfc2cb47ac4af.js → page-338a2c84319778b1.js} +1 -1
- package/.next-prod/static/chunks/app/project/{page-d2ccfc2cb47ac4af.js → page-338a2c84319778b1.js} +1 -1
- package/.next-prod/static/chunks/next/dist/client/components/builtin/app-error-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/next/dist/client/components/builtin/forbidden-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/next/dist/client/components/builtin/not-found-6af5bc188af96106.js +1 -0
- package/.next-prod/static/chunks/next/dist/client/components/builtin/unauthorized-6af5bc188af96106.js +1 -0
- package/.next-prod/static/css/fa34d3b1412ca27a.css +1 -0
- package/.next-prod/trace +86 -15
- package/.next-prod/trace-build +1 -1
- package/.next-prod/types/app/api/projectGraph/edges/route.ts +353 -0
- package/.next-prod/types/app/api/projectGraph/maps/route.ts +353 -0
- package/.next-prod/types/app/api/snapshots/mark/route.ts +353 -0
- package/.next-prod/types/app/api/snapshots/restore/route.ts +353 -0
- package/.next-prod/types/routes.d.ts +5 -1
- package/.next-prod/types/validator.ts +36 -0
- package/README.md +6 -0
- package/bin/rotateLog.mjs +6 -5
- package/desktop-checksums.json +4 -4
- package/dist/{anthropicCompat-PQWSZ3O7.mjs → anthropicCompat-4HZVLIFE.mjs} +3 -2
- package/dist/auth.mjs +19 -3
- package/dist/authAudit.mjs +79 -0
- package/dist/{chunk-6QDJ3QAX.mjs → chunk-6QHHEA3D.mjs} +11 -9
- package/dist/{chunk-2PDNZOMA.mjs → chunk-HJT5ZRYY.mjs} +2 -2
- package/dist/{chunk-S7FDWHAF.mjs → chunk-LSFNZJMR.mjs} +26825 -29730
- package/dist/{chunk-3S5JGONK.mjs → chunk-N3DTLFZE.mjs} +14 -12
- package/dist/{chunk-AKBWZB3V.mjs → chunk-QPFJKR3B.mjs} +2 -2
- package/dist/{chunk-LQISLDJ5.mjs → chunk-SI632CNY.mjs} +1 -1
- package/dist/{chunk-G747UZSS.mjs → chunk-T4M6CNFO.mjs} +132 -34
- package/dist/chunk-WSSVELJX.mjs +2920 -0
- package/dist/{chunk-2O6IH2TF.mjs → chunk-X4R5HO25.mjs} +2 -2
- package/dist/deepseek-YEPNQ2GX.mjs +13 -0
- package/dist/glm-SGT2LTOS.mjs +15 -0
- package/dist/httpApi.mjs +9 -8
- package/dist/kimi-FDXILCYU.mjs +15 -0
- package/dist/scheduledTasks.mjs +41 -15
- package/dist/{sessionStore-FF2VHKXM.mjs → sessionStore-WJGMZM4A.mjs} +2 -1
- package/dist/wsServer.mjs +63 -26
- package/package.json +3 -3
- package/public/html-lib/markdown.js +1 -1
- package/server.mjs +6 -1
- package/skills/cr/SKILL.md +184 -11
- package/skills/dl/SKILL.md +5 -0
- package/skills/rf/SKILL.md +124 -0
- package/skills/rf/axes.md +87 -0
- package/skills/rf/converge.md +50 -0
- package/skills/rf/fix.md +138 -0
- package/skills/rf/lenses.md +76 -0
- package/skills/rf/report.md +133 -0
- package/skills/rf/sources.md +129 -0
- package/.next-prod/static/AO-RPvB4uxOb6-XZ_0YXg/_buildManifest.js +0 -1
- package/.next-prod/static/chunks/17220-89a26ee102272095.js +0 -732
- package/.next-prod/static/chunks/45590-d1a8b4e539cc8dda.js +0 -42
- package/.next-prod/static/chunks/app/_global-error/page-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/agent/test/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/bash/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/bots/[id]/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/bots/files/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/bots/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/chat/codex/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/chat/deepseek/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/chat/glm/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/chat/grok/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/chat/kimi/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/chat/ollama/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/chat/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/chat/stop/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/claude-stats/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/commands/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/comments/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/db/columns/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/db/connect/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/db/disconnect/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/db/export/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/db/query/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/db/schemas/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/deepseek/balance/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/deepseek/credentials/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/deepseek/models/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/dev/spans/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/extension/version/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/file/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/blame/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/clipboard/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/copy/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/delete/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/expanded/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/index/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/init/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/paste/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/read/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/readdir/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/recent/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/save/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/search/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/stat/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/files/text/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/fs/dirs/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/blob/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/branch-diff/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/branches/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/commit-diff/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/commits/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/current-branch/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/diff/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/discard/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/stage/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/status/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/unstage/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/git/worktree/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/glm/credentials/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/glm/models/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/glm/usage/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/global-state/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/grok/models/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/health/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/html-apps/[id]/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/html-apps/files/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/html-apps/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/instructions/config/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/kimi/credentials/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/kimi/models/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/kimi/usage/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/lsp/definition/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/lsp/hover/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/lsp/references/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/lsp/status/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/lsp/warmup/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/mobile-link/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/mysql/columns/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/mysql/connect/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/mysql/disconnect/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/mysql/export/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/mysql/query/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/mysql/schemas/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/neo4j/connect/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/neo4j/disconnect/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/neo4j/query/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/neo4j/schema/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/note/list/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/note/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/ollama/config/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/ollama/default-model/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/ollama/models/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/ollama/start/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/open-cursor/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/open-vscode/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/pi/thinking/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/pinned-sessions/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/project-settings/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/project-state/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/affected/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/callees/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/callers/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/coedit/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/file/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/file-functions/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/impact/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/related/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/search/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projectGraph/symbols/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/projects/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/push/public-key/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/push/subscribe/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/push/unsubscribe/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/redis/command/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/redis/connect/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/redis/delete/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/redis/disconnect/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/redis/get/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/redis/keys/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/redis/set/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/restart/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/scheduled-tasks/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/services/config/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/services/scripts/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session/[sessionId]/fork/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session/[sessionId]/history/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session/[sessionId]/turn/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session/image/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session/user-messages/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session-bots/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session-by-path/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session-context/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session-title/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/session-title/suggest/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/sessions/delegate/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/sessions/projects/[encodedPath]/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/sessions/projects/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/sessions/search/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/sessions/status/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/settings/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/shutdown/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/skills/[id]/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/skills/builtin/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/skills/content/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/skills/files/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/skills/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/snapshots/blob/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/snapshots/diff/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/snapshots/range-diff/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/snapshots/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/terminal/aliases/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/terminal/autocomplete/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/terminal/bubble-order/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/terminal/env/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/terminal/history/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/terminal/running/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/update/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/update-state/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/api/version/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/apps/[...path]/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/app/m/page-50e48b4ba0942454.js +0 -1
- package/.next-prod/static/chunks/app/manifest.webmanifest/route-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/next/dist/client/components/builtin/app-error-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/next/dist/client/components/builtin/forbidden-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/next/dist/client/components/builtin/not-found-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/chunks/next/dist/client/components/builtin/unauthorized-42efcb4fd08c5099.js +0 -1
- package/.next-prod/static/css/74144fec62c7ff43.css +0 -1
- package/dist/deepseek-5QJ2IWS3.mjs +0 -12
- package/dist/glm-SIOUQCWL.mjs +0 -14
- package/dist/kimi-NKL4WBNS.mjs +0 -14
- /package/.next-prod/static/{AO-RPvB4uxOb6-XZ_0YXg → LwAYWBEgXwTIkuj7U9BpE}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,2920 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError,
|
|
3
|
+
Config_exports,
|
|
4
|
+
Context_exports,
|
|
5
|
+
Effect_exports,
|
|
6
|
+
Either_exports,
|
|
7
|
+
FSError,
|
|
8
|
+
Layer_exports
|
|
9
|
+
} from "./chunk-LSFNZJMR.mjs";
|
|
10
|
+
|
|
11
|
+
// packages/feature/agent/src/effect/grokSessionLive.ts
|
|
12
|
+
import { appendFile, mkdir as mkdir2, readdir, open } from "fs/promises";
|
|
13
|
+
import { join as join4 } from "path";
|
|
14
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
15
|
+
|
|
16
|
+
// packages/shared/effect-core/src/config.ts
|
|
17
|
+
var envConfig = Config_exports.literal("dev", "prod")("COCKPIT_ENV").pipe(
|
|
18
|
+
Config_exports.withDefault("prod")
|
|
19
|
+
);
|
|
20
|
+
var hostConfig = Config_exports.string("COCKPIT_HOST").pipe(
|
|
21
|
+
Config_exports.withDefault("127.0.0.1")
|
|
22
|
+
);
|
|
23
|
+
var portConfig = Config_exports.integer("COCKPIT_PORT").pipe(
|
|
24
|
+
Config_exports.orElse(() => Config_exports.integer("PORT")),
|
|
25
|
+
Config_exports.withDefault(3457)
|
|
26
|
+
);
|
|
27
|
+
var openProjectConfig = Config_exports.option(
|
|
28
|
+
Config_exports.string("COCKPIT_OPEN_PROJECT")
|
|
29
|
+
).pipe(
|
|
30
|
+
Config_exports.map((opt) => opt._tag === "Some" ? opt.value : void 0)
|
|
31
|
+
);
|
|
32
|
+
var noOpenConfig = Config_exports.boolean("COCKPIT_NO_OPEN").pipe(
|
|
33
|
+
Config_exports.withDefault(false)
|
|
34
|
+
);
|
|
35
|
+
var logLevelConfig = Config_exports.string("COCKPIT_LOG_LEVEL").pipe(
|
|
36
|
+
Config_exports.withDefault("info")
|
|
37
|
+
);
|
|
38
|
+
var snapshotKeepDaysConfig = Config_exports.integer("COCKPIT_SNAPSHOT_KEEP_DAYS").pipe(
|
|
39
|
+
Config_exports.withDefault(7)
|
|
40
|
+
);
|
|
41
|
+
var snapshotRepoTtlDaysConfig = Config_exports.integer(
|
|
42
|
+
"COCKPIT_SNAPSHOT_REPO_TTL_DAYS"
|
|
43
|
+
).pipe(Config_exports.withDefault(30));
|
|
44
|
+
var snapshotMaxFileKbConfig = Config_exports.integer(
|
|
45
|
+
"COCKPIT_SNAPSHOT_MAX_FILE_KB"
|
|
46
|
+
).pipe(Config_exports.withDefault(2048));
|
|
47
|
+
var sessionKeepDaysConfig = Config_exports.integer("COCKPIT_SESSION_KEEP_DAYS").pipe(
|
|
48
|
+
Config_exports.withDefault(30)
|
|
49
|
+
);
|
|
50
|
+
var delegateMaxConcurrentConfig = Config_exports.integer("COCKPIT_DELEGATE_MAX").pipe(
|
|
51
|
+
Config_exports.validate({ message: "COCKPIT_DELEGATE_MAX must be >= 1", validation: (n) => n >= 1 }),
|
|
52
|
+
Config_exports.withDefault(10)
|
|
53
|
+
);
|
|
54
|
+
var CockpitConfig = Effect_exports.gen(
|
|
55
|
+
function* () {
|
|
56
|
+
const env = yield* envConfig;
|
|
57
|
+
const host = yield* hostConfig;
|
|
58
|
+
const port = yield* portConfig;
|
|
59
|
+
const openProject = yield* openProjectConfig;
|
|
60
|
+
const noOpen = yield* noOpenConfig;
|
|
61
|
+
const logLevel = yield* logLevelConfig;
|
|
62
|
+
const snapshotKeepDays = yield* snapshotKeepDaysConfig;
|
|
63
|
+
const snapshotRepoTtlDays = yield* snapshotRepoTtlDaysConfig;
|
|
64
|
+
const snapshotMaxFileKb = yield* snapshotMaxFileKbConfig;
|
|
65
|
+
const sessionKeepDays = yield* sessionKeepDaysConfig;
|
|
66
|
+
const delegateMaxConcurrent = yield* delegateMaxConcurrentConfig;
|
|
67
|
+
const cockpitDir = yield* Effect_exports.sync(() => {
|
|
68
|
+
const env2 = typeof process !== "undefined" ? process.env : void 0;
|
|
69
|
+
const home = env2?.HOME || env2?.USERPROFILE || ".";
|
|
70
|
+
const homeOverride = env2?.COCKPIT_HOME;
|
|
71
|
+
if (homeOverride) return homeOverride.replace(/^~(?=$|\/)/, home);
|
|
72
|
+
return home + "/.cockpit";
|
|
73
|
+
});
|
|
74
|
+
const logFile = cockpitDir + "/logs/cockpit.log";
|
|
75
|
+
return {
|
|
76
|
+
env,
|
|
77
|
+
host,
|
|
78
|
+
port: port === 3457 && env === "dev" ? 3456 : port,
|
|
79
|
+
// dev defaults to 3456
|
|
80
|
+
cockpitDir,
|
|
81
|
+
openProject,
|
|
82
|
+
openBrowser: !noOpen,
|
|
83
|
+
logLevel,
|
|
84
|
+
logFile,
|
|
85
|
+
snapshotKeepDays,
|
|
86
|
+
snapshotRepoTtlDays,
|
|
87
|
+
snapshotMaxFileKb,
|
|
88
|
+
sessionKeepDays,
|
|
89
|
+
delegateMaxConcurrent
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
).pipe(Effect_exports.orDie);
|
|
93
|
+
var ConfigLive = Layer_exports.empty;
|
|
94
|
+
|
|
95
|
+
// packages/shared/utils/src/homePath.ts
|
|
96
|
+
function isHomeRelativePath(p) {
|
|
97
|
+
return /^~(?=$|[/\\])/.test(p.trim());
|
|
98
|
+
}
|
|
99
|
+
function expandHomePath(p, home) {
|
|
100
|
+
if (!home || !isHomeRelativePath(p)) return p;
|
|
101
|
+
return home.replace(/[/\\]+$/, "") + p.trim().slice(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// packages/shared/utils/src/paths.ts
|
|
105
|
+
import { homedir } from "os";
|
|
106
|
+
import { join, resolve } from "path";
|
|
107
|
+
import { chmod, mkdir, readFile, rename, unlink, writeFile } from "fs/promises";
|
|
108
|
+
import { randomUUID } from "crypto";
|
|
109
|
+
import { existsSync, renameSync } from "fs";
|
|
110
|
+
|
|
111
|
+
// packages/shared/utils/src/encodePath.ts
|
|
112
|
+
var CLAUDE_ENCODED_MAX_LEN = 200;
|
|
113
|
+
function claudePathHash(path) {
|
|
114
|
+
let h = 0;
|
|
115
|
+
for (let i = 0; i < path.length; i++) h = (h << 5) - h + path.charCodeAt(i) | 0;
|
|
116
|
+
return Math.abs(h).toString(36);
|
|
117
|
+
}
|
|
118
|
+
function encodePath(path) {
|
|
119
|
+
const encoded = path.replace(/[^a-zA-Z0-9]/g, "-");
|
|
120
|
+
return encoded.length <= CLAUDE_ENCODED_MAX_LEN ? encoded : `${encoded.slice(0, CLAUDE_ENCODED_MAX_LEN)}-${claudePathHash(path)}`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// packages/shared/utils/src/paths.ts
|
|
124
|
+
var HOME_DIR = homedir();
|
|
125
|
+
var COCKPIT_DIR = process.env.COCKPIT_HOME ? resolve(expandHomePath(process.env.COCKPIT_HOME, HOME_DIR)) : join(HOME_DIR, ".cockpit");
|
|
126
|
+
var GROK_SESSIONS_DIR = join(COCKPIT_DIR, "grok", "sessions");
|
|
127
|
+
var COCKPIT_PROJECTS_DIR = join(COCKPIT_DIR, "projects");
|
|
128
|
+
var GLOBAL_STATE_FILE = join(COCKPIT_DIR, "state.json");
|
|
129
|
+
var PINNED_SESSIONS_FILE = join(COCKPIT_DIR, "pinned-sessions.json");
|
|
130
|
+
var PUSH_SUBSCRIPTIONS_FILE = join(COCKPIT_DIR, "push-subscriptions.json");
|
|
131
|
+
var PUSH_VAPID_FILE = join(COCKPIT_DIR, "push-vapid.json");
|
|
132
|
+
var NOTE_FILE = join(COCKPIT_DIR, "note.md");
|
|
133
|
+
var SCHEDULED_TASKS_FILE = join(COCKPIT_DIR, "scheduled-tasks.json");
|
|
134
|
+
var SETTINGS_FILE = join(COCKPIT_DIR, "settings.json");
|
|
135
|
+
var SKILLS_FILE = join(COCKPIT_DIR, "skills.json");
|
|
136
|
+
var BOTS_FILE = join(COCKPIT_DIR, "bot.json");
|
|
137
|
+
var SESSION_BOTS_FILE = join(COCKPIT_DIR, "session-bots.json");
|
|
138
|
+
var BOTS_DIR = join(COCKPIT_DIR, "bots");
|
|
139
|
+
var HTML_APPS_FILE = join(COCKPIT_DIR, "html.json");
|
|
140
|
+
var APPS_DIR = join(process.env.COCKPIT_ROOT || process.cwd(), "apps");
|
|
141
|
+
var BUILTIN_SKILLS_SRC_DIR = join(process.env.COCKPIT_ROOT || process.cwd(), "skills");
|
|
142
|
+
var BUILTIN_BOTS_SRC_DIR = join(process.env.COCKPIT_ROOT || process.cwd(), "bots");
|
|
143
|
+
var CLAUDE_DIR = join(HOME_DIR, ".claude");
|
|
144
|
+
var CLAUDE_PROJECTS_DIR = join(CLAUDE_DIR, "projects");
|
|
145
|
+
var DEEPSEEK_DIR = join(COCKPIT_DIR, "deepseek");
|
|
146
|
+
var DEEPSEEK_CREDENTIALS_FILE = join(DEEPSEEK_DIR, "credentials.json");
|
|
147
|
+
var KIMI_DIR = join(COCKPIT_DIR, "kimi");
|
|
148
|
+
var KIMI_CREDENTIALS_FILE = join(KIMI_DIR, "credentials.json");
|
|
149
|
+
var GLM_DIR = join(COCKPIT_DIR, "glm");
|
|
150
|
+
var GLM_CREDENTIALS_FILE = join(GLM_DIR, "credentials.json");
|
|
151
|
+
var OLLAMA_DIR = join(COCKPIT_DIR, "ollama");
|
|
152
|
+
var OLLAMA_CONFIG_FILE = join(OLLAMA_DIR, "config.json");
|
|
153
|
+
var SECRET_FILES = [
|
|
154
|
+
DEEPSEEK_CREDENTIALS_FILE,
|
|
155
|
+
KIMI_CREDENTIALS_FILE,
|
|
156
|
+
GLM_CREDENTIALS_FILE,
|
|
157
|
+
OLLAMA_CONFIG_FILE,
|
|
158
|
+
PUSH_VAPID_FILE
|
|
159
|
+
];
|
|
160
|
+
var SECRET_FILE_SET = new Set(SECRET_FILES);
|
|
161
|
+
var OWNER_ONLY = 384;
|
|
162
|
+
async function tightenSecretFiles() {
|
|
163
|
+
for (const file of SECRET_FILES) {
|
|
164
|
+
await chmod(file, OWNER_ONLY).catch((err) => {
|
|
165
|
+
if (err.code !== "ENOENT") console.warn(`[paths] could not restrict permissions of ${file}: ${err.message}`);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
var PRIVATE_DIR_MODE = 448;
|
|
170
|
+
async function tightenPrivateData() {
|
|
171
|
+
await chmod(COCKPIT_DIR, PRIVATE_DIR_MODE).catch((err) => {
|
|
172
|
+
if (err.code !== "ENOENT") console.warn(`[paths] could not restrict permissions of ${COCKPIT_DIR}: ${err.message}`);
|
|
173
|
+
});
|
|
174
|
+
await tightenSecretFiles();
|
|
175
|
+
}
|
|
176
|
+
function getCockpitProjectDir(cwd) {
|
|
177
|
+
return join(COCKPIT_PROJECTS_DIR, encodePath(cwd));
|
|
178
|
+
}
|
|
179
|
+
function getSessionFilePath(cwd) {
|
|
180
|
+
return join(getCockpitProjectDir(cwd), "session.json");
|
|
181
|
+
}
|
|
182
|
+
function getTerminalHistoryPath(cwd, tabId) {
|
|
183
|
+
return join(getCockpitProjectDir(cwd), `terminal-history-${tabId}.jsonl`);
|
|
184
|
+
}
|
|
185
|
+
function getTerminalOutputPath(cwd, commandId) {
|
|
186
|
+
return join(getCockpitProjectDir(cwd), `terminal-output-${commandId}.txt`);
|
|
187
|
+
}
|
|
188
|
+
function getBubbleOrderPath(cwd, tabId) {
|
|
189
|
+
return join(getCockpitProjectDir(cwd), `terminal-bubble-order-${tabId}.json`);
|
|
190
|
+
}
|
|
191
|
+
function getClaudeProjectDir(cwd) {
|
|
192
|
+
return join(CLAUDE_PROJECTS_DIR, encodePath(cwd));
|
|
193
|
+
}
|
|
194
|
+
function getClaudeSessionPath(cwd, sessionId) {
|
|
195
|
+
return join(getClaudeProjectDir(cwd), `${sessionId}.jsonl`);
|
|
196
|
+
}
|
|
197
|
+
var CODEX_SESSIONS_DIR = join(HOME_DIR, ".codex", "sessions");
|
|
198
|
+
var CODEX_THREAD_ID_RE = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:\.jsonl)?$/i;
|
|
199
|
+
function normalizeCodexSessionId(sessionIdOrPath) {
|
|
200
|
+
const match = sessionIdOrPath.match(CODEX_THREAD_ID_RE);
|
|
201
|
+
return match?.[1] ?? sessionIdOrPath;
|
|
202
|
+
}
|
|
203
|
+
async function ensureDir(dirPath) {
|
|
204
|
+
if (!existsSync(dirPath)) {
|
|
205
|
+
await mkdir(dirPath, { recursive: true });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function ensureParentDir(filePath) {
|
|
209
|
+
const dir = join(filePath, "..");
|
|
210
|
+
await ensureDir(dir);
|
|
211
|
+
}
|
|
212
|
+
async function readJsonFile(filePath, defaultValue) {
|
|
213
|
+
try {
|
|
214
|
+
const content = await readFile(filePath, "utf-8");
|
|
215
|
+
return JSON.parse(content);
|
|
216
|
+
} catch {
|
|
217
|
+
return defaultValue;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function readJsonFileForUpdate(filePath, defaultValue) {
|
|
221
|
+
let content;
|
|
222
|
+
try {
|
|
223
|
+
content = await readFile(filePath, "utf-8");
|
|
224
|
+
} catch (err) {
|
|
225
|
+
if (err?.code === "ENOENT") return defaultValue;
|
|
226
|
+
throw err;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
return JSON.parse(content);
|
|
230
|
+
} catch (err) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
`${filePath} is not valid JSON, refusing to overwrite it: ${err instanceof Error ? err.message : String(err)}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
var isRenameBlocked = (err) => {
|
|
237
|
+
const code = err?.code;
|
|
238
|
+
return code === "EPERM" || code === "EACCES" || code === "EBUSY";
|
|
239
|
+
};
|
|
240
|
+
async function renameOver(from, to) {
|
|
241
|
+
if (process.platform !== "win32") return rename(from, to);
|
|
242
|
+
for (let attempt = 0; ; attempt++) {
|
|
243
|
+
try {
|
|
244
|
+
return renameSync(from, to);
|
|
245
|
+
} catch (err) {
|
|
246
|
+
if (attempt >= 12 || !isRenameBlocked(err)) throw err;
|
|
247
|
+
await new Promise((r) => setTimeout(r, Math.min(10 * (attempt + 1), 150)));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async function writeJsonFile(filePath, data) {
|
|
252
|
+
await ensureParentDir(filePath);
|
|
253
|
+
const body = JSON.stringify(data, null, 2);
|
|
254
|
+
const secret = SECRET_FILE_SET.has(filePath);
|
|
255
|
+
const tmp = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
256
|
+
try {
|
|
257
|
+
await writeFile(tmp, body, secret ? { encoding: "utf-8", mode: OWNER_ONLY } : "utf-8");
|
|
258
|
+
if (secret) await chmod(tmp, OWNER_ONLY);
|
|
259
|
+
await renameOver(tmp, filePath);
|
|
260
|
+
} catch (err) {
|
|
261
|
+
await unlink(tmp).catch(() => {
|
|
262
|
+
});
|
|
263
|
+
if (!isRenameBlocked(err)) throw err;
|
|
264
|
+
await writeFile(filePath, body, secret ? { encoding: "utf-8", mode: OWNER_ONLY } : "utf-8");
|
|
265
|
+
if (secret) await chmod(filePath, OWNER_ONLY);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
var g_fileLocks = globalThis;
|
|
269
|
+
var fileLocks = g_fileLocks.__cockpitFileLocks ?? (g_fileLocks.__cockpitFileLocks = /* @__PURE__ */ new Map());
|
|
270
|
+
function withFileLock(filePath, fn) {
|
|
271
|
+
const prev = fileLocks.get(filePath) ?? Promise.resolve();
|
|
272
|
+
const run = prev.then(fn);
|
|
273
|
+
const chain = run.then(() => {
|
|
274
|
+
}, () => {
|
|
275
|
+
});
|
|
276
|
+
fileLocks.set(filePath, chain);
|
|
277
|
+
chain.then(() => {
|
|
278
|
+
if (fileLocks.get(filePath) === chain) {
|
|
279
|
+
fileLocks.delete(filePath);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
return run;
|
|
283
|
+
}
|
|
284
|
+
function mutateJsonFile(filePath, defaultValue, mutate) {
|
|
285
|
+
return withFileLock(filePath, async () => {
|
|
286
|
+
const current = await readJsonFileForUpdate(filePath, defaultValue);
|
|
287
|
+
const next = await mutate(current);
|
|
288
|
+
await writeJsonFile(filePath, next);
|
|
289
|
+
return next;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// packages/shared/utils/src/piPaths.ts
|
|
294
|
+
import { join as join2, resolve as resolve2, sep } from "path";
|
|
295
|
+
|
|
296
|
+
// packages/shared/utils/src/piEngines.ts
|
|
297
|
+
var PI_ENGINES = ["ollama", "deepseek", "kimi", "glm"];
|
|
298
|
+
function isPiEngine(engine) {
|
|
299
|
+
return PI_ENGINES.some((candidate) => candidate === engine);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// packages/shared/utils/src/piPaths.ts
|
|
303
|
+
var PI_AGENT_DIR = join2(COCKPIT_DIR, "pi");
|
|
304
|
+
var PI_SESSIONS_DIR = join2(PI_AGENT_DIR, "sessions");
|
|
305
|
+
function getPiSessionsDir(cwd) {
|
|
306
|
+
return join2(PI_SESSIONS_DIR, `--${resolve2(cwd).replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`);
|
|
307
|
+
}
|
|
308
|
+
function isPiSessionPath(file) {
|
|
309
|
+
return resolve2(file).startsWith(`${resolve2(PI_SESSIONS_DIR)}${sep}`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// packages/feature/agent/src/server/engines/grokAcp/client.ts
|
|
313
|
+
import { spawn } from "child_process";
|
|
314
|
+
import { createInterface } from "readline";
|
|
315
|
+
|
|
316
|
+
// packages/feature/agent/src/server/engines/grokAcp/binary.ts
|
|
317
|
+
import { statSync } from "fs";
|
|
318
|
+
import { join as join3 } from "path";
|
|
319
|
+
var isFile = (path) => {
|
|
320
|
+
try {
|
|
321
|
+
return statSync(path).isFile();
|
|
322
|
+
} catch {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
function resolveGrokBinary(root = process.env.COCKPIT_ROOT || process.cwd(), platform = process.platform, arch = process.arch) {
|
|
327
|
+
if (!["darwin", "linux", "win32"].includes(platform) || !["x64", "arm64"].includes(arch)) {
|
|
328
|
+
throw new Error(`Grok: unsupported platform ${platform} (${arch})`);
|
|
329
|
+
}
|
|
330
|
+
const packageName = `@xai-official/grok-${platform}-${arch}`;
|
|
331
|
+
const cliRoot = join3(root, "node_modules", "@xai-official", "grok");
|
|
332
|
+
const suffix = platform === "win32" ? ".exe" : "";
|
|
333
|
+
const candidates = [
|
|
334
|
+
join3(cliRoot, "bin", `grok-native${suffix}`),
|
|
335
|
+
join3(root, "node_modules", packageName, "bin", `grok${suffix}`),
|
|
336
|
+
join3(cliRoot, "node_modules", packageName, "bin", `grok${suffix}`)
|
|
337
|
+
];
|
|
338
|
+
for (const candidate of candidates) if (isFile(candidate)) return candidate;
|
|
339
|
+
throw new Error(`Grok: cannot locate bundled ${packageName} under ${root}. Reinstall Cockpit with optional dependencies, or run: cockpit update`);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// packages/feature/agent/src/server/engines/grokAcp/client.ts
|
|
343
|
+
var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
344
|
+
var GrokRpcError = class extends Error {
|
|
345
|
+
constructor(message, code) {
|
|
346
|
+
super(message);
|
|
347
|
+
this.code = code;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
var GrokAcpClient = class {
|
|
351
|
+
constructor(options) {
|
|
352
|
+
this.options = options;
|
|
353
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
354
|
+
this.nextId = 1;
|
|
355
|
+
this.child = spawn(options.binary ?? resolveGrokBinary(), options.args ?? ["--no-auto-update", "agent", "--always-approve", "stdio"], {
|
|
356
|
+
cwd: options.cwd,
|
|
357
|
+
env: options.env,
|
|
358
|
+
stdio: "pipe",
|
|
359
|
+
detached: process.platform !== "win32"
|
|
360
|
+
});
|
|
361
|
+
this.exited = new Promise((resolve6) => {
|
|
362
|
+
this.child.once("exit", () => resolve6());
|
|
363
|
+
this.child.once("error", () => resolve6());
|
|
364
|
+
});
|
|
365
|
+
const stdout = createInterface({ input: this.child.stdout, crlfDelay: Infinity });
|
|
366
|
+
const stderr = createInterface({ input: this.child.stderr, crlfDelay: Infinity });
|
|
367
|
+
let diagnostic = "";
|
|
368
|
+
stderr.on("line", (line) => {
|
|
369
|
+
diagnostic = `${diagnostic}
|
|
370
|
+
${line}`.slice(-4096);
|
|
371
|
+
});
|
|
372
|
+
stdout.on("line", (line) => {
|
|
373
|
+
try {
|
|
374
|
+
this.receive(JSON.parse(line));
|
|
375
|
+
} catch (cause) {
|
|
376
|
+
this.fail(cause instanceof Error ? cause : new Error(String(cause)));
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
this.child.on("error", (error) => this.fail(new Error(`Cannot start Grok CLI. Check the configured CLI path or reinstall Cockpit. ${error.message}`)));
|
|
380
|
+
this.child.on("exit", (code, signal) => {
|
|
381
|
+
stdout.close();
|
|
382
|
+
stderr.close();
|
|
383
|
+
this.fail(new Error(`Grok CLI exited (${signal ?? code}).${diagnostic}`));
|
|
384
|
+
});
|
|
385
|
+
for (const pipe of [this.child.stdin, this.child.stdout, this.child.stderr]) pipe.on("error", (error) => this.fail(error));
|
|
386
|
+
}
|
|
387
|
+
fail(error) {
|
|
388
|
+
if (this.failure) return;
|
|
389
|
+
this.failure = error;
|
|
390
|
+
for (const pending of this.pending.values()) pending.reject(error);
|
|
391
|
+
this.pending.clear();
|
|
392
|
+
this.options.onClosed(error);
|
|
393
|
+
}
|
|
394
|
+
write(message) {
|
|
395
|
+
if (this.failure) throw this.failure;
|
|
396
|
+
this.child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}
|
|
397
|
+
`);
|
|
398
|
+
}
|
|
399
|
+
receive(value) {
|
|
400
|
+
const message = object(value);
|
|
401
|
+
if (message.jsonrpc !== "2.0") throw new Error("Invalid Grok ACP JSON-RPC frame");
|
|
402
|
+
if (typeof message.method === "string") {
|
|
403
|
+
const params = object(message.params);
|
|
404
|
+
if (typeof message.id === "string" || typeof message.id === "number") {
|
|
405
|
+
try {
|
|
406
|
+
this.write({ id: message.id, result: this.options.onRequest(message.method, params) });
|
|
407
|
+
} catch (cause) {
|
|
408
|
+
this.write({ id: message.id, error: { code: -32601, message: String(cause) } });
|
|
409
|
+
}
|
|
410
|
+
} else this.options.onNotification({ method: message.method, params });
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (typeof message.id !== "number") return;
|
|
414
|
+
const pending = this.pending.get(message.id);
|
|
415
|
+
if (!pending) return;
|
|
416
|
+
this.pending.delete(message.id);
|
|
417
|
+
if (message.error) {
|
|
418
|
+
const error = object(message.error);
|
|
419
|
+
pending.reject(new GrokRpcError(String(error.message ?? "Grok ACP request failed"), typeof error.code === "number" ? error.code : void 0));
|
|
420
|
+
} else pending.resolve(object(message.result));
|
|
421
|
+
}
|
|
422
|
+
request(method, params) {
|
|
423
|
+
if (this.failure) return Promise.reject(this.failure);
|
|
424
|
+
const id = this.nextId++;
|
|
425
|
+
return new Promise((resolve6, reject) => {
|
|
426
|
+
this.pending.set(id, { resolve: resolve6, reject });
|
|
427
|
+
try {
|
|
428
|
+
this.write({ id, method, params });
|
|
429
|
+
} catch (cause) {
|
|
430
|
+
this.pending.delete(id);
|
|
431
|
+
reject(cause);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
notify(method, params) {
|
|
436
|
+
this.write({ method, params });
|
|
437
|
+
}
|
|
438
|
+
dispose(force = false) {
|
|
439
|
+
this.fail(new Error("Grok ACP connection closed"));
|
|
440
|
+
if (!this.child.pid || this.child.exitCode !== null || this.child.signalCode !== null) return;
|
|
441
|
+
try {
|
|
442
|
+
if (process.platform === "win32") {
|
|
443
|
+
const killer = spawn("taskkill", ["/pid", String(this.child.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
444
|
+
const fallback = () => {
|
|
445
|
+
if (this.child.exitCode === null && this.child.signalCode === null) this.child.kill();
|
|
446
|
+
};
|
|
447
|
+
killer.on("error", fallback);
|
|
448
|
+
killer.on("exit", (code) => {
|
|
449
|
+
if (code !== 0) fallback();
|
|
450
|
+
});
|
|
451
|
+
} else process.kill(-this.child.pid, force ? "SIGKILL" : "SIGTERM");
|
|
452
|
+
} catch {
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// packages/feature/agent/src/effect/grokSessionLive.ts
|
|
458
|
+
function grokSessionPath(cwd, sessionId) {
|
|
459
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(sessionId)) throw new Error("Invalid Grok session id");
|
|
460
|
+
return join4(GROK_SESSIONS_DIR, encodePath(cwd), `${sessionId}.jsonl`);
|
|
461
|
+
}
|
|
462
|
+
function appendGrokTranscript(cwd, sessionId, entry) {
|
|
463
|
+
return Effect_exports.tryPromise({
|
|
464
|
+
try: async () => {
|
|
465
|
+
const dir = join4(GROK_SESSIONS_DIR, encodePath(cwd));
|
|
466
|
+
await mkdir2(dir, { recursive: true });
|
|
467
|
+
const uuid = randomUUID2();
|
|
468
|
+
await appendFile(grokSessionPath(cwd, sessionId), `${JSON.stringify({
|
|
469
|
+
...entry,
|
|
470
|
+
uuid,
|
|
471
|
+
sessionId,
|
|
472
|
+
cwd,
|
|
473
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
474
|
+
})}
|
|
475
|
+
`, { mode: 384 });
|
|
476
|
+
return uuid;
|
|
477
|
+
},
|
|
478
|
+
catch: (cause) => new FSError({ path: GROK_SESSIONS_DIR, op: "write", cause })
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
var describeProject = (encodedPath) => Effect_exports.gen(function* () {
|
|
482
|
+
const dir = join4(GROK_SESSIONS_DIR, encodedPath);
|
|
483
|
+
const files = yield* Effect_exports.tryPromise({
|
|
484
|
+
try: async () => (await readdir(dir)).filter((file) => file.endsWith(".jsonl")),
|
|
485
|
+
catch: (cause) => new FSError({ path: dir, op: "read", cause })
|
|
486
|
+
});
|
|
487
|
+
if (!files.length) return [];
|
|
488
|
+
const filePath = join4(dir, files[0]);
|
|
489
|
+
const first = yield* Effect_exports.acquireUseRelease(
|
|
490
|
+
Effect_exports.tryPromise({ try: () => open(filePath, "r"), catch: (cause) => new FSError({ path: filePath, op: "read", cause }) }),
|
|
491
|
+
(file) => Effect_exports.tryPromise({
|
|
492
|
+
try: async () => {
|
|
493
|
+
const buffer = Buffer.alloc(8192);
|
|
494
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
|
|
495
|
+
return object(JSON.parse(buffer.toString("utf8", 0, bytesRead).split("\n")[0])).cwd;
|
|
496
|
+
},
|
|
497
|
+
catch: (cause) => new FSError({ path: filePath, op: "read", cause })
|
|
498
|
+
}),
|
|
499
|
+
(file) => Effect_exports.promise(() => file.close())
|
|
500
|
+
);
|
|
501
|
+
return typeof first === "string" ? [{ encodedPath, cwd: first, count: files.length }] : [];
|
|
502
|
+
});
|
|
503
|
+
var listGrokProjects = Effect_exports.gen(function* () {
|
|
504
|
+
const dirs = yield* Effect_exports.tryPromise({
|
|
505
|
+
try: () => readdir(GROK_SESSIONS_DIR, { withFileTypes: true }).catch((cause) => {
|
|
506
|
+
if (cause.code === "ENOENT") return [];
|
|
507
|
+
throw cause;
|
|
508
|
+
}),
|
|
509
|
+
catch: (cause) => new FSError({ path: GROK_SESSIONS_DIR, op: "read", cause })
|
|
510
|
+
});
|
|
511
|
+
const projects = yield* Effect_exports.forEach(
|
|
512
|
+
dirs.filter((dir) => dir.isDirectory()),
|
|
513
|
+
(dir) => describeProject(dir.name).pipe(Effect_exports.catchAll((error) => Effect_exports.logWarning("Cannot read Grok project header", error).pipe(Effect_exports.as([])))),
|
|
514
|
+
{ concurrency: 8 }
|
|
515
|
+
);
|
|
516
|
+
return projects.flat();
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// packages/feature/agent/src/effect/piSessionLive.ts
|
|
520
|
+
import { open as open2, readFile as readFile2, readdir as readdir2, stat } from "fs/promises";
|
|
521
|
+
|
|
522
|
+
// packages/feature/agent/src/effect/piSessionIdentity.ts
|
|
523
|
+
import { createHash } from "crypto";
|
|
524
|
+
var canonical = (value) => Array.isArray(value) ? value.map(canonical) : value && typeof value === "object" ? Object.fromEntries(Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, canonical(item)])) : value;
|
|
525
|
+
var payloadOf = (entry) => canonical(Object.fromEntries(Object.entries(entry).filter(([key]) => !["id", "parentId", "firstKeptEntryId", "fromId", "targetId"].includes(key))));
|
|
526
|
+
var digest = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 32);
|
|
527
|
+
function legacyPiSnapshot(sessionId, entries) {
|
|
528
|
+
return { count: entries.length, digest: digest([sessionId, entries.map(payloadOf)]) };
|
|
529
|
+
}
|
|
530
|
+
function legacyPiEntryId(sessionId, index, entry, snapshot) {
|
|
531
|
+
return `pi-v1-${index}-${snapshot.count}-${snapshot.digest}-${digest([sessionId, payloadOf(entry)])}`;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// packages/feature/agent/src/effect/piSessionLive.ts
|
|
535
|
+
import { join as join6, resolve as resolve4 } from "path";
|
|
536
|
+
|
|
537
|
+
// packages/feature/agent/src/server/engines/piEvents.ts
|
|
538
|
+
import { join as join5, resolve as resolve3 } from "path";
|
|
539
|
+
import { homedir as homedir2 } from "os";
|
|
540
|
+
import { fileURLToPath } from "url";
|
|
541
|
+
function piToolPath(input, cwd) {
|
|
542
|
+
const normalize = (value, toolPath = false) => {
|
|
543
|
+
let path = toolPath ? value.replace(/[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g, " ").replace(/^@/, "") : value;
|
|
544
|
+
if (process.platform === "win32" && path.startsWith("/") && !path.startsWith("//") && !path.includes("\\")) {
|
|
545
|
+
const match = path.match(/^\/(?:mnt\/|cygdrive\/)?([a-z])(?:\/(.*))?$/i);
|
|
546
|
+
if (match) path = `${match[1].toUpperCase()}:\\${match[2]?.replaceAll("/", "\\") ?? ""}`;
|
|
547
|
+
}
|
|
548
|
+
if (path === "~") return homedir2();
|
|
549
|
+
if (path.startsWith("~/") || process.platform === "win32" && path.startsWith("~\\")) return join5(homedir2(), path.slice(2));
|
|
550
|
+
return path.startsWith("file://") ? fileURLToPath(path) : path;
|
|
551
|
+
};
|
|
552
|
+
return resolve3(normalize(cwd), normalize(input, true));
|
|
553
|
+
}
|
|
554
|
+
function piTool(name, args, cwd) {
|
|
555
|
+
const names = { read: "Read", write: "Write", edit: "Edit", bash: "Bash", grep: "Grep", find: "Glob", ls: "LS" };
|
|
556
|
+
return { name: names[name] ?? name, input: {
|
|
557
|
+
...args,
|
|
558
|
+
...typeof args.path === "string" ? { file_path: cwd ? piToolPath(args.path, cwd) : args.path } : {},
|
|
559
|
+
...typeof args.oldText === "string" ? { old_string: args.oldText } : {},
|
|
560
|
+
...typeof args.newText === "string" ? { new_string: args.newText } : {}
|
|
561
|
+
} };
|
|
562
|
+
}
|
|
563
|
+
function piUsage(usage) {
|
|
564
|
+
return { input_tokens: usage.input, output_tokens: usage.output, cache_read_input_tokens: usage.cacheRead, cache_creation_input_tokens: usage.cacheWrite };
|
|
565
|
+
}
|
|
566
|
+
function createPiRunUsage() {
|
|
567
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
568
|
+
const totals = { input_tokens: 0, output_tokens: 0, cache_read_input_tokens: 0, cache_creation_input_tokens: 0 };
|
|
569
|
+
let cost = 0;
|
|
570
|
+
return {
|
|
571
|
+
record(message) {
|
|
572
|
+
if (seen.has(message)) return void 0;
|
|
573
|
+
seen.add(message);
|
|
574
|
+
totals.input_tokens += message.usage.input;
|
|
575
|
+
totals.output_tokens += message.usage.output;
|
|
576
|
+
totals.cache_read_input_tokens += message.usage.cacheRead;
|
|
577
|
+
totals.cache_creation_input_tokens += message.usage.cacheWrite;
|
|
578
|
+
cost += message.usage.cost.total;
|
|
579
|
+
return { type: "usage_update", ...totals };
|
|
580
|
+
},
|
|
581
|
+
snapshot: () => ({ ...totals }),
|
|
582
|
+
cost: () => cost
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function piMessage(message, id, timestamp, cwd) {
|
|
586
|
+
const base = { uuid: id, timestamp };
|
|
587
|
+
if (message.role === "system") return [];
|
|
588
|
+
if (message.role === "toolResult") return [{ ...base, type: "user", message: { role: "user", content: [{ type: "tool_result", tool_use_id: message.toolCallId, content: message.content.filter((b) => b.type === "text").map((b) => b.text).join("\n"), is_error: message.isError }] } }];
|
|
589
|
+
if (message.role === "user") return [{ ...base, type: "user", message: { role: "user", content: typeof message.content === "string" ? message.content : message.content.map((b) => b.type === "image" ? { type: "image", source: { type: "base64", media_type: b.mimeType, data: b.data } } : { type: "text", text: b.text }) } }];
|
|
590
|
+
const result = message.content.flatMap((block) => {
|
|
591
|
+
if (block.type === "text") return [{ ...base, type: "assistant", message: { content: [{ type: "text", text: block.text }] } }];
|
|
592
|
+
if (block.type === "toolCall") {
|
|
593
|
+
const tool = piTool(block.name, block.arguments, cwd);
|
|
594
|
+
return [{ ...base, type: "assistant", message: { content: [{ type: "tool_use", id: block.id, ...tool }] } }];
|
|
595
|
+
}
|
|
596
|
+
return [];
|
|
597
|
+
});
|
|
598
|
+
if (message.errorMessage) result.push({ ...base, type: "assistant", message: { errorMessage: message.errorMessage, content: [{ type: "text", text: `\u26A0\uFE0F ${message.errorMessage}` }] } });
|
|
599
|
+
if (!result.length) result.push({ ...base, type: "assistant", message: { content: [] } });
|
|
600
|
+
const last = result[result.length - 1];
|
|
601
|
+
last.message = { ...last.message, model: message.model, usage: piUsage(message.usage) };
|
|
602
|
+
return result;
|
|
603
|
+
}
|
|
604
|
+
function piBranchMessages(entries, cwd) {
|
|
605
|
+
const latestEdits = new Map(entries.flatMap((e) => e.type === "context_edit" ? [[e.targetId, e.replacement]] : []));
|
|
606
|
+
return entries.flatMap((entry) => {
|
|
607
|
+
if (entry.type === "custom_message" && ["cockpit.execution-notice", "cockpit.execution-stop"].includes(entry.customType)) {
|
|
608
|
+
return [{ type: "user", uuid: entry.id, timestamp: entry.timestamp, isMeta: true, message: { role: "user", content: entry.content } }];
|
|
609
|
+
}
|
|
610
|
+
if (entry.type === "custom" && ["cockpit.undelivered-input", "cockpit.subagent-instructions", "cockpit.subagent-interrupted-output", "cockpit.subagent-snapshot", "cockpit.execution-stop"].includes(entry.customType)) {
|
|
611
|
+
const data = entry.data;
|
|
612
|
+
if (typeof data?.text !== "string") return [];
|
|
613
|
+
return [{ type: "user", uuid: entry.id, timestamp: entry.timestamp, isMeta: true, message: { role: "user", content: data.text } }];
|
|
614
|
+
}
|
|
615
|
+
if (entry.type !== "message") return [];
|
|
616
|
+
const message = entry.message;
|
|
617
|
+
const rows = message.role === "user" || message.role === "assistant" || message.role === "toolResult" ? piMessage(message, entry.id, entry.timestamp, cwd) : [];
|
|
618
|
+
if (message.role === "assistant" && ["length", "error", "aborted"].includes(message.stopReason)) {
|
|
619
|
+
const excluded = latestEdits.has(entry.id) && latestEdits.get(entry.id) === null;
|
|
620
|
+
const text = `Response incomplete (stopReason=${message.stopReason}).${message.stopReason === "length" ? " Output was truncated." : ""}${excluded ? " Pi excluded this response from subsequent model context." : ""} Partial output is retained above.`;
|
|
621
|
+
rows.push({ type: "user", uuid: `${entry.id}-outcome`, timestamp: entry.timestamp, isMeta: true, message: { role: "user", content: text } });
|
|
622
|
+
}
|
|
623
|
+
return rows;
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
function piRunEvents(event, cwd) {
|
|
627
|
+
if (event.type === "entry_appended" && event.entry.type === "custom_message" && ["cockpit.execution-notice", "cockpit.execution-stop"].includes(event.entry.customType)) {
|
|
628
|
+
return [{ type: "user", isMeta: true, message: { role: "user", content: event.entry.content } }];
|
|
629
|
+
}
|
|
630
|
+
if (event.type === "entry_appended" && event.entry.type === "custom" && event.entry.customType === "cockpit.execution-stop") {
|
|
631
|
+
const data = event.entry.data;
|
|
632
|
+
return typeof data?.text === "string" ? [{ type: "user", isMeta: true, message: { role: "user", content: data.text } }] : [];
|
|
633
|
+
}
|
|
634
|
+
if (event.type === "message_start" && event.message.role === "assistant") return [{ type: "stream_event", event: { type: "message_start" } }];
|
|
635
|
+
if (event.type === "message_update") {
|
|
636
|
+
const delta = event.assistantMessageEvent;
|
|
637
|
+
if (delta.type === "text_delta") return [{ type: "stream_event", event: { type: "content_block_delta", delta: { type: "text_delta", text: delta.delta } } }];
|
|
638
|
+
if (delta.type === "thinking_delta") return [{ type: "stream_event", event: { type: "content_block_delta", delta: { type: "thinking_delta", thinking: delta.delta } } }];
|
|
639
|
+
}
|
|
640
|
+
if (event.type === "tool_execution_start") {
|
|
641
|
+
const tool = piTool(event.toolName, event.args, cwd);
|
|
642
|
+
return [{ type: "assistant", message: { content: [{ type: "tool_use", id: event.toolCallId, ...tool }] } }];
|
|
643
|
+
}
|
|
644
|
+
if (event.type === "tool_execution_update" && event.toolName === "subagent") {
|
|
645
|
+
return [{
|
|
646
|
+
type: "tool_progress",
|
|
647
|
+
tool_call_id: event.toolCallId,
|
|
648
|
+
progress_text: event.partialResult.content.filter((block) => block.type === "text").map((block) => block.text ?? "").join("\n")
|
|
649
|
+
}];
|
|
650
|
+
}
|
|
651
|
+
if (event.type === "tool_execution_end") return [{ type: "user", message: { content: [{ type: "tool_result", tool_use_id: event.toolCallId, content: event.result.content.filter((b) => b.type === "text").map((b) => b.text ?? "").join("\n"), is_error: event.isError }] } }];
|
|
652
|
+
if (event.type === "auto_retry_start") return [{ type: "system", subtype: "api_retry", attempt: event.attempt, max_retries: event.maxAttempts, retry_delay_ms: event.delayMs, error: event.errorMessage }];
|
|
653
|
+
if (event.type === "compaction_start") return [{ type: "system", subtype: "status", status: "compacting" }];
|
|
654
|
+
if (event.type === "compaction_end") return [{ type: "system", subtype: "status", status: null }];
|
|
655
|
+
return [];
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// packages/feature/agent/src/effect/piSessionLive.ts
|
|
659
|
+
var readPiEntries = (path) => Effect_exports.tryPromise({
|
|
660
|
+
try: async () => {
|
|
661
|
+
const { parseSessionEntries, migrateSessionEntries } = await import("@earendil-works/pi-coding-agent");
|
|
662
|
+
const entries = parseSessionEntries(await readFile2(path, "utf8")).filter((entry) => entry && typeof entry === "object");
|
|
663
|
+
const header = entries[0];
|
|
664
|
+
if (header?.type !== "session" || typeof header.id !== "string" || typeof header.cwd !== "string") throw new Error("Invalid Pi session header");
|
|
665
|
+
const legacyIds = (header.version ?? 1) < 2;
|
|
666
|
+
migrateSessionEntries(entries);
|
|
667
|
+
if (legacyIds) {
|
|
668
|
+
const nativeEntries = entries.filter((entry) => entry.type !== "session");
|
|
669
|
+
const snapshot = legacyPiSnapshot(header.id, nativeEntries);
|
|
670
|
+
const ids = new Map(nativeEntries.map(
|
|
671
|
+
(entry, i) => [entry.id, legacyPiEntryId(header.id, i, entry, snapshot)]
|
|
672
|
+
));
|
|
673
|
+
for (const entry of entries) {
|
|
674
|
+
if (entry.type === "session") continue;
|
|
675
|
+
entry.id = ids.get(entry.id);
|
|
676
|
+
entry.parentId = entry.parentId === null ? null : ids.get(entry.parentId) ?? entry.parentId;
|
|
677
|
+
if (entry.type === "compaction") entry.firstKeptEntryId = ids.get(entry.firstKeptEntryId) ?? entry.firstKeptEntryId;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return { entries, header, legacyIds };
|
|
681
|
+
},
|
|
682
|
+
catch: (cause) => new AppError({ message: `Cannot read Pi session ${path}`, cause })
|
|
683
|
+
});
|
|
684
|
+
var readPiManager = (path) => readPiEntries(path).pipe(
|
|
685
|
+
Effect_exports.flatMap(({ entries, header }) => Effect_exports.tryPromise({
|
|
686
|
+
try: async () => {
|
|
687
|
+
const { SessionManager } = await import("@earendil-works/pi-coding-agent");
|
|
688
|
+
return SessionManager.inMemory(header.cwd, void 0, entries);
|
|
689
|
+
},
|
|
690
|
+
catch: (cause) => new AppError({ message: `Cannot load Pi session ${path}`, cause })
|
|
691
|
+
}))
|
|
692
|
+
);
|
|
693
|
+
function piSelection(entries) {
|
|
694
|
+
for (const entry of entries.toReversed()) {
|
|
695
|
+
if (entry.type === "model_change" && isPiEngine(entry.provider)) return { engine: entry.provider, model: entry.modelId };
|
|
696
|
+
if (entry.type === "message" && entry.message.role === "assistant" && isPiEngine(entry.message.provider)) return { engine: entry.message.provider, model: entry.message.model };
|
|
697
|
+
}
|
|
698
|
+
return { engine: "ollama" };
|
|
699
|
+
}
|
|
700
|
+
var describePiSession = (path) => Effect_exports.gen(function* () {
|
|
701
|
+
const manager = yield* readPiManager(path);
|
|
702
|
+
const modifiedAt = yield* Effect_exports.tryPromise({ try: async () => (await stat(path)).mtimeMs, catch: (cause) => new AppError({ message: `Cannot stat Pi session ${path}`, cause }) });
|
|
703
|
+
return { id: manager.getSessionId(), path, cwd: manager.getCwd(), ...piSelection(manager.getBranch()), modifiedAt };
|
|
704
|
+
});
|
|
705
|
+
var piSessionPaths = (cwd) => Effect_exports.tryPromise({
|
|
706
|
+
try: async () => {
|
|
707
|
+
const readDir = (dir) => readdir2(dir, { withFileTypes: true }).catch((cause) => {
|
|
708
|
+
if (cause.code === "ENOENT") return [];
|
|
709
|
+
throw cause;
|
|
710
|
+
});
|
|
711
|
+
const dirs = cwd ? [getPiSessionsDir(cwd)] : (await readDir(PI_SESSIONS_DIR)).filter((entry) => entry.isDirectory()).map((entry) => join6(PI_SESSIONS_DIR, entry.name));
|
|
712
|
+
const paths = [];
|
|
713
|
+
for (const dir of dirs) for (const file of await readDir(dir)) if (file.isFile() && file.name.endsWith(".jsonl")) paths.push(join6(dir, file.name));
|
|
714
|
+
return paths;
|
|
715
|
+
},
|
|
716
|
+
catch: (cause) => new AppError({ message: "Cannot list Pi sessions", cause })
|
|
717
|
+
});
|
|
718
|
+
var missingPiFile = (error) => error.cause?.code === "ENOENT";
|
|
719
|
+
var readPiHeader = (path) => Effect_exports.tryPromise({
|
|
720
|
+
try: async () => {
|
|
721
|
+
const { parseSessionEntries } = await import("@earendil-works/pi-coding-agent");
|
|
722
|
+
const handle = await open2(path, "r");
|
|
723
|
+
try {
|
|
724
|
+
let pending = Buffer.alloc(0);
|
|
725
|
+
const chunk = Buffer.alloc(4096);
|
|
726
|
+
for (; ; ) {
|
|
727
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, null);
|
|
728
|
+
pending = Buffer.concat([pending, chunk.subarray(0, bytesRead)]);
|
|
729
|
+
for (; ; ) {
|
|
730
|
+
const end = pending.indexOf(10);
|
|
731
|
+
if (end < 0 && bytesRead > 0) break;
|
|
732
|
+
const text = (end < 0 ? pending : pending.subarray(0, end)).toString("utf8");
|
|
733
|
+
pending = end < 0 ? Buffer.alloc(0) : pending.subarray(end + 1);
|
|
734
|
+
const entry = parseSessionEntries(text).find((value) => value && typeof value === "object");
|
|
735
|
+
if (entry) {
|
|
736
|
+
if (entry.type !== "session" || typeof entry.id !== "string" || typeof entry.cwd !== "string") throw new Error("Invalid Pi session header");
|
|
737
|
+
return entry;
|
|
738
|
+
}
|
|
739
|
+
if (end < 0) throw new Error("Missing Pi session header");
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
} finally {
|
|
743
|
+
await handle.close();
|
|
744
|
+
}
|
|
745
|
+
},
|
|
746
|
+
catch: (cause) => new AppError({ message: `Cannot discover Pi session ${path}`, cause })
|
|
747
|
+
});
|
|
748
|
+
var findPiSession = (cwd, id) => Effect_exports.gen(function* () {
|
|
749
|
+
for (const path of yield* piSessionPaths(cwd)) {
|
|
750
|
+
const header = yield* readPiHeader(path).pipe(Effect_exports.catchAll((error) => missingPiFile(error) ? Effect_exports.succeed(void 0) : Effect_exports.fail(error)));
|
|
751
|
+
if (header?.id !== id || resolve4(header.cwd) !== resolve4(cwd)) continue;
|
|
752
|
+
return yield* describePiSession(path).pipe(Effect_exports.catchAll((error) => missingPiFile(error) ? Effect_exports.succeed(void 0) : Effect_exports.fail(error)));
|
|
753
|
+
}
|
|
754
|
+
return void 0;
|
|
755
|
+
});
|
|
756
|
+
var readPiSession = (path) => readPiManager(path).pipe(Effect_exports.map((manager) => {
|
|
757
|
+
const entries = manager.getBranch();
|
|
758
|
+
return { manager, entries, messages: piBranchMessages(entries, manager.getCwd()), name: manager.getSessionName() };
|
|
759
|
+
}));
|
|
760
|
+
var readPiModel = (cwd, id, engine) => !cwd || !id ? Promise.resolve(void 0) : Effect_exports.runPromise(findPiSession(cwd, id).pipe(Effect_exports.map((s) => s?.engine === engine ? s.model : void 0)));
|
|
761
|
+
|
|
762
|
+
// packages/feature/agent/src/server/api/session/sessionStore.ts
|
|
763
|
+
import { join as join9 } from "path";
|
|
764
|
+
|
|
765
|
+
// packages/feature/agent/src/effect/transcriptPresence.ts
|
|
766
|
+
import { stat as stat2 } from "fs/promises";
|
|
767
|
+
|
|
768
|
+
// packages/feature/agent/src/server/transcriptLayout.ts
|
|
769
|
+
import { join as join7 } from "path";
|
|
770
|
+
var noHistoryStashPath = (path) => join7(path.replace(/\.jsonl$/, ""), "nohistory-backup.jsonl");
|
|
771
|
+
var CODEX_NO_HISTORY_SUFFIX = ".nohistory-backup";
|
|
772
|
+
var codexNoHistoryStashPath = (path) => `${path}${CODEX_NO_HISTORY_SUFFIX}`;
|
|
773
|
+
var transcriptFormat = (engine) => engine === "codex" ? "codex" : ["pi", "ollama", "kimi", "deepseek", "glm"].includes(engine) ? "pi" : "claude";
|
|
774
|
+
var transcriptStashPath = (path, engine) => engine === "claude" ? noHistoryStashPath(path) : engine === "codex" ? codexNoHistoryStashPath(path) : null;
|
|
775
|
+
|
|
776
|
+
// packages/feature/agent/src/server/transcriptRevision.ts
|
|
777
|
+
var shared = globalThis;
|
|
778
|
+
var generations = shared.__cockpitTranscriptGenerations ?? (shared.__cockpitTranscriptGenerations = /* @__PURE__ */ new Map());
|
|
779
|
+
var transcriptGeneration = (path) => generations.get(path) ?? 0;
|
|
780
|
+
var advanceTranscriptGeneration = (path) => {
|
|
781
|
+
generations.set(path, transcriptGeneration(path) + 1);
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
// packages/feature/agent/src/effect/transcriptPresence.ts
|
|
785
|
+
var identifyTranscriptFile = (path) => Effect_exports.tryPromise({
|
|
786
|
+
try: () => stat2(path).then((s) => ({ ino: s.ino, size: s.size, mtimeMs: s.mtimeMs }), (cause) => {
|
|
787
|
+
if (cause.code === "ENOENT") return null;
|
|
788
|
+
throw cause;
|
|
789
|
+
}),
|
|
790
|
+
catch: (cause) => new FSError({ path, op: "stat", cause })
|
|
791
|
+
});
|
|
792
|
+
var sameTranscriptFile = (a, b, allowAppend = false) => a === null || b === null ? a === b : a.ino === b.ino && (a.size === b.size && a.mtimeMs === b.mtimeMs || allowAppend && b.size > a.size);
|
|
793
|
+
var withTranscriptLayout = (path, engine, read) => Effect_exports.gen(function* () {
|
|
794
|
+
const stash = transcriptStashPath(path, engine);
|
|
795
|
+
const probe = () => Effect_exports.gen(function* () {
|
|
796
|
+
const generation = transcriptGeneration(path);
|
|
797
|
+
const current = yield* identifyTranscriptFile(path);
|
|
798
|
+
const history = stash ? yield* identifyTranscriptFile(stash) : null;
|
|
799
|
+
return { current, history, generation };
|
|
800
|
+
});
|
|
801
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
802
|
+
const before = yield* probe();
|
|
803
|
+
if (before.generation !== transcriptGeneration(path)) continue;
|
|
804
|
+
const result = yield* Effect_exports.either(read(before));
|
|
805
|
+
const after = yield* probe();
|
|
806
|
+
if (before.generation !== transcriptGeneration(path) || after.generation !== before.generation || !sameTranscriptFile(before.history, after.history) || !sameTranscriptFile(before.current, after.current, true)) continue;
|
|
807
|
+
if (Either_exports.isLeft(result)) return yield* Effect_exports.fail(result.left);
|
|
808
|
+
return result.right;
|
|
809
|
+
}
|
|
810
|
+
return yield* Effect_exports.fail(new FSError({ path, op: "read", cause: new Error("Transcript layout changed repeatedly") }));
|
|
811
|
+
});
|
|
812
|
+
var transcriptExists = (path, engine) => withTranscriptLayout(path, engine, (layout) => Effect_exports.succeed(Boolean(layout.current || layout.history)));
|
|
813
|
+
|
|
814
|
+
// packages/feature/agent/src/effect/transcriptIndexLive.ts
|
|
815
|
+
import { createHash as createHash2 } from "crypto";
|
|
816
|
+
import { open as open3, readFile as readFile4, readdir as readdir3, realpath, rm as rm2, stat as stat3 } from "fs/promises";
|
|
817
|
+
import { basename, dirname as dirname2, join as join8, resolve as resolve5 } from "path";
|
|
818
|
+
|
|
819
|
+
// packages/shared/effect-services/src/transcriptIndex.ts
|
|
820
|
+
var TranscriptIndex = Context_exports.GenericTag("@cockpit/TranscriptIndex");
|
|
821
|
+
|
|
822
|
+
// packages/feature/agent/src/server/api/session/codexTools.ts
|
|
823
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
824
|
+
|
|
825
|
+
// packages/feature/agent/src/shared/codexPrompt.ts
|
|
826
|
+
var CODEX_IMAGE_ONLY_TEXT = "[Image]";
|
|
827
|
+
var CONTEXT_KINDS = /* @__PURE__ */ new Set([
|
|
828
|
+
"agents_md.instructions",
|
|
829
|
+
"plugins.recommendations",
|
|
830
|
+
"environments.environment_context",
|
|
831
|
+
"generic.turn_aborted"
|
|
832
|
+
]);
|
|
833
|
+
function isRecord(value) {
|
|
834
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
835
|
+
}
|
|
836
|
+
function notificationBody(text) {
|
|
837
|
+
return text.trim().match(/^<subagent_notification>\s*([\s\S]*?)\s*<\/subagent_notification>$/)?.[1];
|
|
838
|
+
}
|
|
839
|
+
function isContextText(text) {
|
|
840
|
+
return /^# AGENTS\.md instructions(?:\s|$)/.test(text) || /^<(?:environment_context|turn_aborted|user_instructions)(?:\s|>)/.test(text) || /^<recommended_plugins>[\s\S]*<\/recommended_plugins>$/.test(text.trim());
|
|
841
|
+
}
|
|
842
|
+
function notificationData(text) {
|
|
843
|
+
const body = notificationBody(text);
|
|
844
|
+
if (body === void 0) return void 0;
|
|
845
|
+
try {
|
|
846
|
+
const data = JSON.parse(body);
|
|
847
|
+
return isRecord(data) && typeof data.agent_path === "string" && isRecord(data.status) ? data : void 0;
|
|
848
|
+
} catch {
|
|
849
|
+
return void 0;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function subagentNotice(raw, data = notificationData(raw)) {
|
|
853
|
+
const state = data && isRecord(data.status) ? Object.entries(data.status)[0] : void 0;
|
|
854
|
+
const text = state && typeof state[1] === "string" ? state[1].trim() : "";
|
|
855
|
+
const status = state?.[0] === "errored" ? "failed" : state?.[0] === "shutdown" ? "stopped" : state?.[0];
|
|
856
|
+
return {
|
|
857
|
+
summary: text.split("\n").find((line) => line.trim()) || "Sub-agent notification",
|
|
858
|
+
detail: text ? `${text}
|
|
859
|
+
|
|
860
|
+
Raw notification:
|
|
861
|
+
${raw}` : raw,
|
|
862
|
+
...status ? { status } : {}
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
function projectCodexUserMessage(payload) {
|
|
866
|
+
const content = payload.content || [];
|
|
867
|
+
const meta = isRecord(payload.internal_chat_message_metadata_passthrough) ? payload.internal_chat_message_metadata_passthrough : void 0;
|
|
868
|
+
const kinds = Array.isArray(meta?.content_item_kinds) && meta.content_item_kinds.length === content.length ? meta.content_item_kinds : void 0;
|
|
869
|
+
const items = Array.isArray(meta?.content_item_metadata) && meta.content_item_metadata.length === content.length ? meta.content_item_metadata : void 0;
|
|
870
|
+
const hasSources = meta ? "content_item_kinds" in meta || "content_item_metadata" in meta : payload.internal_chat_message_metadata_passthrough != null;
|
|
871
|
+
const events = [];
|
|
872
|
+
let prompt;
|
|
873
|
+
const appendPrompt = (block) => {
|
|
874
|
+
if (!prompt) {
|
|
875
|
+
prompt = { kind: "prompt", blocks: [] };
|
|
876
|
+
events.push(prompt);
|
|
877
|
+
}
|
|
878
|
+
prompt.blocks.push(block);
|
|
879
|
+
};
|
|
880
|
+
content.forEach((block, index) => {
|
|
881
|
+
if (!isRecord(block)) return;
|
|
882
|
+
const rawKind = kinds?.[index];
|
|
883
|
+
const kind = typeof rawKind === "string" ? rawKind : void 0;
|
|
884
|
+
const item = items?.[index];
|
|
885
|
+
const provenance = isRecord(item) && isRecord(item.provenance) ? item.provenance : void 0;
|
|
886
|
+
if (kind?.startsWith("user.") || provenance?.type === "user") {
|
|
887
|
+
appendPrompt(block);
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
const text = typeof block.text === "string" ? block.text : "";
|
|
891
|
+
if (kind === "multi_agent.subagent_notification") {
|
|
892
|
+
events.push({ kind: "notice", notice: subagentNotice(text) });
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
if (kind && CONTEXT_KINDS.has(kind) || provenance?.type === "agents_md") return;
|
|
896
|
+
if (provenance?.type === "harness" || provenance?.type === "tool") {
|
|
897
|
+
if (/^<subagent_notification(?:\s|>)/.test(text.trim())) {
|
|
898
|
+
events.push({ kind: "notice", notice: subagentNotice(text) });
|
|
899
|
+
} else if (!isContextText(text)) {
|
|
900
|
+
events.push({ kind: "meta", detail: text.trim() || JSON.stringify(block) });
|
|
901
|
+
}
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
if (hasSources) {
|
|
905
|
+
appendPrompt(block);
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
const data = notificationData(text);
|
|
909
|
+
if (data) {
|
|
910
|
+
events.push({ kind: "notice", notice: subagentNotice(text, data) });
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
if (isContextText(text)) return;
|
|
914
|
+
appendPrompt(block);
|
|
915
|
+
});
|
|
916
|
+
return events;
|
|
917
|
+
}
|
|
918
|
+
function codexPromptText(text, images = 0) {
|
|
919
|
+
return text || (images ? CODEX_IMAGE_ONLY_TEXT : null);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// packages/feature/agent/src/server/engines/shared/codexUsage.ts
|
|
923
|
+
function codexUsageToClaude({ input, cached, cacheWrite, output }) {
|
|
924
|
+
if (input <= 0 && output <= 0) return null;
|
|
925
|
+
return {
|
|
926
|
+
input_tokens: Math.max(0, input - cached - cacheWrite),
|
|
927
|
+
cache_read_input_tokens: cached,
|
|
928
|
+
cache_creation_input_tokens: cacheWrite,
|
|
929
|
+
output_tokens: output
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// packages/feature/agent/src/server/api/session/codexTools.ts
|
|
934
|
+
var CODEX_TOOL_NAMES = {
|
|
935
|
+
bash: "Bash",
|
|
936
|
+
applyPatch: "ApplyPatch",
|
|
937
|
+
/** `view_image` → claude's Read: it opens a file, and Read is in READ_ONLY_TOOLS. */
|
|
938
|
+
read: "Read",
|
|
939
|
+
/** `spawn_agent` → claude's Task, so one bubble == one sub-agent. */
|
|
940
|
+
task: "Task",
|
|
941
|
+
/** `update_plan` / live `todo_list` → the checklist MessageBubble already renders. */
|
|
942
|
+
todo: "TodoWrite",
|
|
943
|
+
webSearch: "WebSearch",
|
|
944
|
+
webFetch: "WebFetch",
|
|
945
|
+
/** `image_generation` writes a file, so it reads as a Write in the timeline. */
|
|
946
|
+
imageGeneration: "Write"
|
|
947
|
+
};
|
|
948
|
+
var CODEX_MCP_NAMESPACE_PREFIX = "mcp__";
|
|
949
|
+
var codexMcpToolName = (server, tool) => `${CODEX_MCP_NAMESPACE_PREFIX}${server}__${tool}`;
|
|
950
|
+
var CODEX_SPAWN_FN_NAME = "spawn_agent";
|
|
951
|
+
var CODEX_WAIT_FN_NAME = "wait_agent";
|
|
952
|
+
var CODEX_SUB_AGENT_ACTIVITY_TYPE = "sub_agent_activity";
|
|
953
|
+
var CODEX_SUB_AGENT_ACTIVITY_ITEM_TYPE = "SubAgentActivity";
|
|
954
|
+
var CODEX_AGENT_MESSAGE_TYPE = "agent_message";
|
|
955
|
+
var CODEX_PLAN_FN_NAME = "update_plan";
|
|
956
|
+
var CODEX_VIEW_IMAGE_FN_NAME = "view_image";
|
|
957
|
+
var CODEX_PATCH_FN_NAME = "apply_patch";
|
|
958
|
+
var CODEX_EXEC_SCRIPT_FN_NAME = "exec";
|
|
959
|
+
var CODEX_CUSTOM_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
960
|
+
CODEX_PATCH_FN_NAME,
|
|
961
|
+
CODEX_EXEC_SCRIPT_FN_NAME
|
|
962
|
+
]);
|
|
963
|
+
function normalizeCodexToolName(name, namespace) {
|
|
964
|
+
if (namespace?.startsWith(CODEX_MCP_NAMESPACE_PREFIX)) return `${namespace}__${name}`;
|
|
965
|
+
if (name === "shell_command" || name === "exec_command") return CODEX_TOOL_NAMES.bash;
|
|
966
|
+
if (name === "apply_patch") return CODEX_TOOL_NAMES.applyPatch;
|
|
967
|
+
if (name === CODEX_SPAWN_FN_NAME) return CODEX_TOOL_NAMES.task;
|
|
968
|
+
if (name === CODEX_PLAN_FN_NAME) return CODEX_TOOL_NAMES.todo;
|
|
969
|
+
if (name === CODEX_VIEW_IMAGE_FN_NAME) return CODEX_TOOL_NAMES.read;
|
|
970
|
+
return name;
|
|
971
|
+
}
|
|
972
|
+
function parseCodexPlanInput(args) {
|
|
973
|
+
const plan = Array.isArray(args.plan) ? args.plan : [];
|
|
974
|
+
return {
|
|
975
|
+
todos: plan.flatMap((raw) => {
|
|
976
|
+
const step = raw;
|
|
977
|
+
if (typeof step?.step !== "string") return [];
|
|
978
|
+
return [{
|
|
979
|
+
content: step.step,
|
|
980
|
+
status: typeof step.status === "string" ? step.status : "pending"
|
|
981
|
+
}];
|
|
982
|
+
})
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
function codexTodoInput(items) {
|
|
986
|
+
return {
|
|
987
|
+
todos: (items ?? []).flatMap(
|
|
988
|
+
(i) => typeof i?.text === "string" ? [{ content: i.text, status: i.status || (i.completed ? "completed" : "pending") }] : []
|
|
989
|
+
)
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
function codexTodoResultText(todos) {
|
|
993
|
+
const done = todos.filter((t) => t.status === "completed").length;
|
|
994
|
+
return `${done}/${todos.length} completed`;
|
|
995
|
+
}
|
|
996
|
+
function codexWebSearchCall(query, action) {
|
|
997
|
+
if (action?.type === "open_page" && action.url) {
|
|
998
|
+
return { name: CODEX_TOOL_NAMES.webFetch, input: { url: action.url }, result: action.url };
|
|
999
|
+
}
|
|
1000
|
+
const q = action?.query || query || "";
|
|
1001
|
+
const queries = action?.queries?.length ? action.queries : q ? [q] : [];
|
|
1002
|
+
return {
|
|
1003
|
+
name: CODEX_TOOL_NAMES.webSearch,
|
|
1004
|
+
input: { query: q },
|
|
1005
|
+
/**
|
|
1006
|
+
* The queries, not the hits — deliberately.
|
|
1007
|
+
*
|
|
1008
|
+
* A web_search item does carry `results`, but the protocol types it as
|
|
1009
|
+
* `Array<Unknown>` and says why: "These stay as opaque JSON at the
|
|
1010
|
+
* extension/app-server boundary so new result fields and result types can
|
|
1011
|
+
* pass through without a Codex release." Rendering it would mean inventing
|
|
1012
|
+
* a shape upstream has explicitly refused to fix, and finding out it moved
|
|
1013
|
+
* the way every other spelling mismatch here has been found — by a bubble
|
|
1014
|
+
* silently going blank.
|
|
1015
|
+
*
|
|
1016
|
+
* Showing the queries beats an empty result, which reads as unfinished.
|
|
1017
|
+
*/
|
|
1018
|
+
result: queries.join("\n")
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
function codexMcpResultText(item) {
|
|
1022
|
+
if (item.error?.message) return item.error.message;
|
|
1023
|
+
if (item.result === null || item.result === void 0) return "";
|
|
1024
|
+
if (typeof item.result === "string") return item.result;
|
|
1025
|
+
const content = item.result.content;
|
|
1026
|
+
if (Array.isArray(content)) {
|
|
1027
|
+
const text = content.filter((b) => !!b && typeof b === "object").filter((b) => typeof b.text === "string").map((b) => b.text).join("");
|
|
1028
|
+
if (text) return text;
|
|
1029
|
+
}
|
|
1030
|
+
return JSON.stringify(item.result, null, 2);
|
|
1031
|
+
}
|
|
1032
|
+
function parseCodexPatchInput(input) {
|
|
1033
|
+
const changes = [];
|
|
1034
|
+
const re = /^\*\*\* (Add|Update|Delete) File: (.+)$/gm;
|
|
1035
|
+
let m;
|
|
1036
|
+
while (m = re.exec(input)) {
|
|
1037
|
+
changes.push({ path: m[2].trim(), kind: m[1].toLowerCase() });
|
|
1038
|
+
}
|
|
1039
|
+
return { changes };
|
|
1040
|
+
}
|
|
1041
|
+
var JS_STRING_LITERAL_RE = /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`/g;
|
|
1042
|
+
var JS_SIMPLE_ESCAPES = {
|
|
1043
|
+
n: "\n",
|
|
1044
|
+
r: "\r",
|
|
1045
|
+
t: " ",
|
|
1046
|
+
b: "\b",
|
|
1047
|
+
f: "\f",
|
|
1048
|
+
v: "\v",
|
|
1049
|
+
"0": "\0"
|
|
1050
|
+
};
|
|
1051
|
+
function decodeJsStringLiteral(literal) {
|
|
1052
|
+
if (literal.startsWith('"')) {
|
|
1053
|
+
try {
|
|
1054
|
+
return JSON.parse(literal);
|
|
1055
|
+
} catch {
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return literal.slice(1, -1).replace(
|
|
1059
|
+
/\\(u\{[0-9a-fA-F]+\}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|[\s\S])/g,
|
|
1060
|
+
(_full, esc) => {
|
|
1061
|
+
if (esc.startsWith("u{")) return String.fromCodePoint(parseInt(esc.slice(2, -1), 16));
|
|
1062
|
+
if (esc.startsWith("u") || esc.startsWith("x")) return String.fromCharCode(parseInt(esc.slice(1), 16));
|
|
1063
|
+
return JS_SIMPLE_ESCAPES[esc] ?? esc;
|
|
1064
|
+
}
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
function extractPatchLiteral(script) {
|
|
1068
|
+
JS_STRING_LITERAL_RE.lastIndex = 0;
|
|
1069
|
+
let m;
|
|
1070
|
+
while (m = JS_STRING_LITERAL_RE.exec(script)) {
|
|
1071
|
+
const value = decodeJsStringLiteral(m[0]);
|
|
1072
|
+
if (value.includes("*** Begin Patch")) return value;
|
|
1073
|
+
}
|
|
1074
|
+
return null;
|
|
1075
|
+
}
|
|
1076
|
+
var JS_IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*/;
|
|
1077
|
+
var JS_SCALAR_RE = /^(-?\d[\d_]*(?:\.\d*)?(?:[eE][+-]?\d+)?|true|false|null|undefined)/;
|
|
1078
|
+
var skipJsWs = (c) => {
|
|
1079
|
+
while (c.i < c.s.length && /\s/.test(c.s[c.i])) c.i++;
|
|
1080
|
+
};
|
|
1081
|
+
function readJsString(c) {
|
|
1082
|
+
const q = c.s[c.i];
|
|
1083
|
+
if (q !== '"' && q !== "'" && q !== "`") return null;
|
|
1084
|
+
const start = c.i;
|
|
1085
|
+
c.i++;
|
|
1086
|
+
while (c.i < c.s.length) {
|
|
1087
|
+
const ch = c.s[c.i];
|
|
1088
|
+
if (ch === "\\") {
|
|
1089
|
+
c.i += 2;
|
|
1090
|
+
continue;
|
|
1091
|
+
}
|
|
1092
|
+
if (ch === q) {
|
|
1093
|
+
c.i++;
|
|
1094
|
+
return decodeJsStringLiteral(c.s.slice(start, c.i));
|
|
1095
|
+
}
|
|
1096
|
+
c.i++;
|
|
1097
|
+
}
|
|
1098
|
+
return null;
|
|
1099
|
+
}
|
|
1100
|
+
function readJsValue(c) {
|
|
1101
|
+
skipJsWs(c);
|
|
1102
|
+
const ch = c.s[c.i];
|
|
1103
|
+
if (ch === void 0) return null;
|
|
1104
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
1105
|
+
const str2 = readJsString(c);
|
|
1106
|
+
return str2 === null ? null : { v: str2 };
|
|
1107
|
+
}
|
|
1108
|
+
if (ch === "{") return readJsObject(c);
|
|
1109
|
+
if (ch === "[") return readJsArray(c);
|
|
1110
|
+
const m = JS_SCALAR_RE.exec(c.s.slice(c.i));
|
|
1111
|
+
if (!m) return null;
|
|
1112
|
+
c.i += m[0].length;
|
|
1113
|
+
const raw = m[0];
|
|
1114
|
+
if (raw === "true") return { v: true };
|
|
1115
|
+
if (raw === "false") return { v: false };
|
|
1116
|
+
if (raw === "null" || raw === "undefined") return { v: null };
|
|
1117
|
+
const n = Number(raw.replace(/_/g, ""));
|
|
1118
|
+
return Number.isNaN(n) ? null : { v: n };
|
|
1119
|
+
}
|
|
1120
|
+
function readJsArray(c) {
|
|
1121
|
+
if (c.s[c.i] !== "[") return null;
|
|
1122
|
+
c.i++;
|
|
1123
|
+
const out = [];
|
|
1124
|
+
for (; ; ) {
|
|
1125
|
+
skipJsWs(c);
|
|
1126
|
+
if (c.s[c.i] === "]") {
|
|
1127
|
+
c.i++;
|
|
1128
|
+
return { v: out };
|
|
1129
|
+
}
|
|
1130
|
+
if (c.i >= c.s.length) return null;
|
|
1131
|
+
const item = readJsValue(c);
|
|
1132
|
+
if (!item) return null;
|
|
1133
|
+
out.push(item.v);
|
|
1134
|
+
skipJsWs(c);
|
|
1135
|
+
if (c.s[c.i] === ",") {
|
|
1136
|
+
c.i++;
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
if (c.s[c.i] === "]") {
|
|
1140
|
+
c.i++;
|
|
1141
|
+
return { v: out };
|
|
1142
|
+
}
|
|
1143
|
+
return null;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
function readJsObject(c) {
|
|
1147
|
+
if (c.s[c.i] !== "{") return null;
|
|
1148
|
+
c.i++;
|
|
1149
|
+
const out = {};
|
|
1150
|
+
for (; ; ) {
|
|
1151
|
+
skipJsWs(c);
|
|
1152
|
+
if (c.s[c.i] === "}") {
|
|
1153
|
+
c.i++;
|
|
1154
|
+
return { v: out };
|
|
1155
|
+
}
|
|
1156
|
+
if (c.i >= c.s.length) return null;
|
|
1157
|
+
let key = null;
|
|
1158
|
+
const ch = c.s[c.i];
|
|
1159
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
1160
|
+
key = readJsString(c);
|
|
1161
|
+
} else {
|
|
1162
|
+
const m = JS_IDENT_RE.exec(c.s.slice(c.i));
|
|
1163
|
+
if (m) {
|
|
1164
|
+
key = m[0];
|
|
1165
|
+
c.i += m[0].length;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
if (key === null) return null;
|
|
1169
|
+
skipJsWs(c);
|
|
1170
|
+
if (c.s[c.i] !== ":") return null;
|
|
1171
|
+
c.i++;
|
|
1172
|
+
const val = readJsValue(c);
|
|
1173
|
+
if (!val) return null;
|
|
1174
|
+
out[key] = val.v;
|
|
1175
|
+
skipJsWs(c);
|
|
1176
|
+
if (c.s[c.i] === ",") {
|
|
1177
|
+
c.i++;
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
if (c.s[c.i] === "}") {
|
|
1181
|
+
c.i++;
|
|
1182
|
+
return { v: out };
|
|
1183
|
+
}
|
|
1184
|
+
return null;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
function readToolArgsAt(script, from) {
|
|
1188
|
+
const open4 = script.indexOf("{", from);
|
|
1189
|
+
if (open4 === -1) return null;
|
|
1190
|
+
const read = readJsObject({ s: script, i: open4 });
|
|
1191
|
+
if (!read || !read.v || typeof read.v !== "object") return null;
|
|
1192
|
+
return read.v;
|
|
1193
|
+
}
|
|
1194
|
+
function extractExecArgs(script) {
|
|
1195
|
+
const call = script.indexOf("tools.exec_command(");
|
|
1196
|
+
if (call === -1) return null;
|
|
1197
|
+
return readToolArgsAt(script, call);
|
|
1198
|
+
}
|
|
1199
|
+
var TOOL_CALL_RE = /tools\.([A-Za-z_$][A-Za-z0-9_$]*)\s*\(/g;
|
|
1200
|
+
function extractOtherToolCall(script) {
|
|
1201
|
+
TOOL_CALL_RE.lastIndex = 0;
|
|
1202
|
+
let m;
|
|
1203
|
+
while (m = TOOL_CALL_RE.exec(script)) {
|
|
1204
|
+
const tool = m[1];
|
|
1205
|
+
if (tool === "exec_command" || tool === "apply_patch") continue;
|
|
1206
|
+
const args = readToolArgsAt(script, m.index);
|
|
1207
|
+
if (args) return { tool, args };
|
|
1208
|
+
}
|
|
1209
|
+
return null;
|
|
1210
|
+
}
|
|
1211
|
+
function parseCodexExecScript(script) {
|
|
1212
|
+
const patch = extractPatchLiteral(script);
|
|
1213
|
+
if (patch) return { kind: "patch", patch };
|
|
1214
|
+
const args = extractExecArgs(script);
|
|
1215
|
+
if (args) {
|
|
1216
|
+
return { kind: "exec", command: typeof args.cmd === "string" ? args.cmd : "", args };
|
|
1217
|
+
}
|
|
1218
|
+
const other = extractOtherToolCall(script);
|
|
1219
|
+
if (other) return { kind: "other", tool: other.tool, args: other.args };
|
|
1220
|
+
return { kind: "unknown" };
|
|
1221
|
+
}
|
|
1222
|
+
function codexExecScriptCall(script) {
|
|
1223
|
+
const parsed = parseCodexExecScript(script);
|
|
1224
|
+
if (parsed.kind === "patch") {
|
|
1225
|
+
return { name: CODEX_TOOL_NAMES.applyPatch, input: parseCodexPatchInput(parsed.patch) };
|
|
1226
|
+
}
|
|
1227
|
+
if (parsed.kind === "exec") {
|
|
1228
|
+
return {
|
|
1229
|
+
name: CODEX_TOOL_NAMES.bash,
|
|
1230
|
+
input: normalizeCodexToolInput("exec_command", parsed.args)
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
if (parsed.kind === "other") {
|
|
1234
|
+
return {
|
|
1235
|
+
name: normalizeCodexToolName(parsed.tool),
|
|
1236
|
+
input: normalizeCodexToolInput(parsed.tool, parsed.args)
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
return { name: CODEX_TOOL_NAMES.bash, input: { command: script } };
|
|
1240
|
+
}
|
|
1241
|
+
function isCodexImageBlock(block) {
|
|
1242
|
+
const { type, image_url: url } = block;
|
|
1243
|
+
return typeof url === "string" || type === "input_image" || type === "output_image";
|
|
1244
|
+
}
|
|
1245
|
+
var CODEX_OUTPUT_STRINGIFY_LIMIT = 4e3;
|
|
1246
|
+
function stringifyBounded(value) {
|
|
1247
|
+
const json = JSON.stringify(value) ?? "";
|
|
1248
|
+
if (json.length <= CODEX_OUTPUT_STRINGIFY_LIMIT) return json;
|
|
1249
|
+
return `${json.slice(0, CODEX_OUTPUT_STRINGIFY_LIMIT)}\u2026 (${json.length} chars truncated)`;
|
|
1250
|
+
}
|
|
1251
|
+
function codexToolOutputText(output) {
|
|
1252
|
+
if (output === null || output === void 0) return "";
|
|
1253
|
+
if (typeof output === "string") return output;
|
|
1254
|
+
if (Array.isArray(output)) return output.map(codexToolOutputText).join("");
|
|
1255
|
+
if (typeof output === "object") {
|
|
1256
|
+
const text = output.text;
|
|
1257
|
+
if (typeof text === "string") return text;
|
|
1258
|
+
if (isCodexImageBlock(output)) return CODEX_IMAGE_ONLY_TEXT;
|
|
1259
|
+
return stringifyBounded(output);
|
|
1260
|
+
}
|
|
1261
|
+
return String(output);
|
|
1262
|
+
}
|
|
1263
|
+
function parseCodexTokenUsage(payload) {
|
|
1264
|
+
if (!payload || payload.type !== "token_count") return null;
|
|
1265
|
+
const info = payload.info;
|
|
1266
|
+
if (!info || typeof info !== "object") return null;
|
|
1267
|
+
const last = info.last_token_usage;
|
|
1268
|
+
if (!last || typeof last !== "object") return null;
|
|
1269
|
+
const raw = last;
|
|
1270
|
+
const num2 = (key) => typeof raw[key] === "number" ? raw[key] : 0;
|
|
1271
|
+
return codexUsageToClaude({
|
|
1272
|
+
input: num2("input_tokens"),
|
|
1273
|
+
cached: num2("cached_input_tokens"),
|
|
1274
|
+
cacheWrite: num2("cache_write_input_tokens"),
|
|
1275
|
+
output: num2("output_tokens")
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
var CODEX_KNOWN_CALL_TYPES = /* @__PURE__ */ new Set([
|
|
1279
|
+
"function_call",
|
|
1280
|
+
"function_call_output",
|
|
1281
|
+
"custom_tool_call",
|
|
1282
|
+
"custom_tool_call_output"
|
|
1283
|
+
]);
|
|
1284
|
+
function parseCodexUnknownCall(payload) {
|
|
1285
|
+
if (!payload || typeof payload.type !== "string") return null;
|
|
1286
|
+
if (CODEX_KNOWN_CALL_TYPES.has(payload.type)) return null;
|
|
1287
|
+
const callId = typeof payload.call_id === "string" ? payload.call_id : "";
|
|
1288
|
+
if (!callId) return null;
|
|
1289
|
+
return {
|
|
1290
|
+
callId,
|
|
1291
|
+
name: typeof payload.name === "string" && payload.name ? payload.name : payload.type,
|
|
1292
|
+
input: unknownCallInput(payload)
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
function unknownCallInput(payload) {
|
|
1296
|
+
const args = payload.arguments;
|
|
1297
|
+
if (args && typeof args === "object" && !Array.isArray(args)) {
|
|
1298
|
+
return args;
|
|
1299
|
+
}
|
|
1300
|
+
if (typeof args === "string" && args.trim()) {
|
|
1301
|
+
try {
|
|
1302
|
+
const parsed = JSON.parse(args);
|
|
1303
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1304
|
+
return parsed;
|
|
1305
|
+
}
|
|
1306
|
+
} catch {
|
|
1307
|
+
}
|
|
1308
|
+
return { arguments: args };
|
|
1309
|
+
}
|
|
1310
|
+
if (typeof payload.input === "string" && payload.input) return { input: payload.input };
|
|
1311
|
+
return {};
|
|
1312
|
+
}
|
|
1313
|
+
function codexUnknownCallResult(payload) {
|
|
1314
|
+
if (payload.output !== void 0) return codexToolOutputText(payload.output);
|
|
1315
|
+
const { type: _t, id: _i, call_id: _c, ...rest } = payload;
|
|
1316
|
+
return Object.keys(rest).length > 0 ? stringifyBounded(rest) : "";
|
|
1317
|
+
}
|
|
1318
|
+
var CODEX_AGENT_DONE = /* @__PURE__ */ new Set(["completed", "errored", "interrupted", "not_found", "failed"]);
|
|
1319
|
+
function parseCodexSpawnInput(args, extra) {
|
|
1320
|
+
const message = typeof args.message === "string" ? args.message : "";
|
|
1321
|
+
const encrypted = isCodexEncryptedPayload(message);
|
|
1322
|
+
const prompt = encrypted ? "" : message;
|
|
1323
|
+
const agentType = typeof args.agent_type === "string" ? args.agent_type : typeof args.task_name === "string" ? codexAgentPathName(args.task_name) : void 0;
|
|
1324
|
+
return {
|
|
1325
|
+
...agentType ? { subagent_type: agentType } : {},
|
|
1326
|
+
description: codexSpawnDescription(extra?.nickname, agentType, prompt),
|
|
1327
|
+
...encrypted ? { message_encrypted: true } : { prompt },
|
|
1328
|
+
...extra?.agentId ? { agent_id: extra.agentId } : {}
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
var CODEX_FERNET_TOKEN_RE = /^gAAAAA[A-Za-z0-9_-]{32,}={0,2}$/;
|
|
1332
|
+
function isCodexEncryptedPayload(text) {
|
|
1333
|
+
return CODEX_FERNET_TOKEN_RE.test(text.trim());
|
|
1334
|
+
}
|
|
1335
|
+
function codexAgentPathName(agentPath) {
|
|
1336
|
+
const segments = agentPath.split("/").filter(Boolean);
|
|
1337
|
+
return segments[segments.length - 1] || agentPath;
|
|
1338
|
+
}
|
|
1339
|
+
function parseCodexSubAgentActivity(payload) {
|
|
1340
|
+
if (!payload) return null;
|
|
1341
|
+
const item = payload.item;
|
|
1342
|
+
const src = payload.type === CODEX_SUB_AGENT_ACTIVITY_TYPE ? { ...payload, callId: payload.event_id } : item && item.type === CODEX_SUB_AGENT_ACTIVITY_ITEM_TYPE ? { ...item, callId: item.id } : null;
|
|
1343
|
+
if (!src) return null;
|
|
1344
|
+
const { callId, agent_thread_id: agentThreadId } = src;
|
|
1345
|
+
if (typeof callId !== "string" || !callId) return null;
|
|
1346
|
+
if (typeof agentThreadId !== "string" || !agentThreadId) return null;
|
|
1347
|
+
return {
|
|
1348
|
+
callId,
|
|
1349
|
+
agentThreadId,
|
|
1350
|
+
...typeof src.agent_path === "string" ? { agentPath: src.agent_path } : {},
|
|
1351
|
+
...typeof src.kind === "string" ? { kind: src.kind } : {}
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
function parseCodexAgentMessage(payload) {
|
|
1355
|
+
if (!payload || payload.type !== CODEX_AGENT_MESSAGE_TYPE) return null;
|
|
1356
|
+
const author = typeof payload.author === "string" ? payload.author : "";
|
|
1357
|
+
if (!author) return null;
|
|
1358
|
+
const raw = Array.isArray(payload.content) ? payload.content.map((c) => typeof c?.text === "string" ? c.text : "").join("") : typeof payload.content === "string" ? payload.content : "";
|
|
1359
|
+
const messageType = raw.match(/^Message Type:\s*(\S+)/m)?.[1];
|
|
1360
|
+
const payloadHeader = raw.match(/^Payload:[ \t]*$/m);
|
|
1361
|
+
let body = raw;
|
|
1362
|
+
if (payloadHeader?.index !== void 0) {
|
|
1363
|
+
const nl = raw.indexOf("\n", payloadHeader.index);
|
|
1364
|
+
if (nl !== -1) body = raw.slice(nl + 1);
|
|
1365
|
+
}
|
|
1366
|
+
return {
|
|
1367
|
+
author,
|
|
1368
|
+
...typeof payload.recipient === "string" ? { recipient: payload.recipient } : {},
|
|
1369
|
+
text: body.trim() || raw.trim(),
|
|
1370
|
+
final: !messageType || messageType === "FINAL_ANSWER"
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
function codexSpawnDescription(nickname, agentType, prompt) {
|
|
1374
|
+
if (nickname) return agentType ? `${nickname} (${agentType})` : nickname;
|
|
1375
|
+
const firstLine = prompt.split("\n", 1)[0]?.trim() || "";
|
|
1376
|
+
if (firstLine) return firstLine.slice(0, 80);
|
|
1377
|
+
return agentType || "subagent";
|
|
1378
|
+
}
|
|
1379
|
+
function parseCodexSpawnOutput(output) {
|
|
1380
|
+
try {
|
|
1381
|
+
const parsed = JSON.parse(output);
|
|
1382
|
+
if (typeof parsed?.agent_id !== "string" || !parsed.agent_id) return null;
|
|
1383
|
+
return {
|
|
1384
|
+
agentId: parsed.agent_id,
|
|
1385
|
+
...typeof parsed.nickname === "string" ? { nickname: parsed.nickname } : {}
|
|
1386
|
+
};
|
|
1387
|
+
} catch {
|
|
1388
|
+
return null;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
function parseCodexWaitOutput(output) {
|
|
1392
|
+
let parsed;
|
|
1393
|
+
try {
|
|
1394
|
+
parsed = JSON.parse(output);
|
|
1395
|
+
} catch {
|
|
1396
|
+
return [];
|
|
1397
|
+
}
|
|
1398
|
+
const status = parsed?.status;
|
|
1399
|
+
if (!status || typeof status !== "object") return [];
|
|
1400
|
+
const out = [];
|
|
1401
|
+
for (const [agentId, raw] of Object.entries(status)) {
|
|
1402
|
+
if (!raw || typeof raw !== "object") continue;
|
|
1403
|
+
const [tag, value] = Object.entries(raw)[0] ?? [];
|
|
1404
|
+
if (!tag) continue;
|
|
1405
|
+
out.push({
|
|
1406
|
+
agentId,
|
|
1407
|
+
status: tag,
|
|
1408
|
+
message: typeof value === "string" ? value : "",
|
|
1409
|
+
done: CODEX_AGENT_DONE.has(tag)
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
return out;
|
|
1413
|
+
}
|
|
1414
|
+
function parseCodexAgentsStates(states2) {
|
|
1415
|
+
if (!states2 || typeof states2 !== "object") return [];
|
|
1416
|
+
return Object.entries(states2).flatMap(([agentId, raw]) => {
|
|
1417
|
+
const status = typeof raw?.status === "string" ? raw.status : "";
|
|
1418
|
+
if (!status) return [];
|
|
1419
|
+
return [{
|
|
1420
|
+
agentId,
|
|
1421
|
+
status,
|
|
1422
|
+
message: typeof raw?.message === "string" ? raw.message : "",
|
|
1423
|
+
done: CODEX_AGENT_DONE.has(status)
|
|
1424
|
+
}];
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
function codexAgentResultText(state) {
|
|
1428
|
+
return state.message || `(agent ${state.status})`;
|
|
1429
|
+
}
|
|
1430
|
+
function codexFilePath(path) {
|
|
1431
|
+
if (!/^file:/i.test(path)) return path;
|
|
1432
|
+
try {
|
|
1433
|
+
return fileURLToPath2(path);
|
|
1434
|
+
} catch {
|
|
1435
|
+
return path;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
function normalizeCodexToolInput(name, input) {
|
|
1439
|
+
if (name === CODEX_SPAWN_FN_NAME) return parseCodexSpawnInput(input);
|
|
1440
|
+
if (name === CODEX_PLAN_FN_NAME) return parseCodexPlanInput(input);
|
|
1441
|
+
if (name === CODEX_VIEW_IMAGE_FN_NAME && typeof input.path === "string") {
|
|
1442
|
+
const { path: _path, ...rest2 } = input;
|
|
1443
|
+
return { ...rest2, file_path: codexFilePath(input.path) };
|
|
1444
|
+
}
|
|
1445
|
+
if (normalizeCodexToolName(name) !== CODEX_TOOL_NAMES.bash) return input;
|
|
1446
|
+
if (typeof input.command === "string") return input;
|
|
1447
|
+
if (typeof input.cmd !== "string") return input;
|
|
1448
|
+
const { cmd: _cmd, ...rest } = input;
|
|
1449
|
+
return { ...rest, command: input.cmd };
|
|
1450
|
+
}
|
|
1451
|
+
var CODEX_IMAGE_TAG_RE = /^<image\b[^>]*>$/i;
|
|
1452
|
+
var CODEX_IMAGE_MARKUP_RE = /<\/?image\b[^>]*>/gi;
|
|
1453
|
+
var DATA_IMAGE_URL_RE = /^data:(image\/(?:png|jpeg|webp|gif));base64,([\s\S]*)$/;
|
|
1454
|
+
function parseCodexImageUrl(imageUrl) {
|
|
1455
|
+
const match = imageUrl.match(DATA_IMAGE_URL_RE);
|
|
1456
|
+
if (!match) return null;
|
|
1457
|
+
return {
|
|
1458
|
+
type: "base64",
|
|
1459
|
+
media_type: match[1],
|
|
1460
|
+
data: match[2]
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
function extractCodexImageAttachments(content) {
|
|
1464
|
+
const attachments = [];
|
|
1465
|
+
let depth = 0;
|
|
1466
|
+
let pending;
|
|
1467
|
+
for (const block of content || []) {
|
|
1468
|
+
if (!block || typeof block !== "object") {
|
|
1469
|
+
if (pending) pending.invalid = true;
|
|
1470
|
+
continue;
|
|
1471
|
+
}
|
|
1472
|
+
if (block.type === "input_image") {
|
|
1473
|
+
const image = typeof block.image_url === "string" ? parseCodexImageUrl(block.image_url) : null;
|
|
1474
|
+
const attachment = image ? { image } : void 0;
|
|
1475
|
+
if (attachment) attachments.push(attachment);
|
|
1476
|
+
if (pending) {
|
|
1477
|
+
if (depth !== 1 || pending.attachment || !attachment) pending.invalid = true;
|
|
1478
|
+
pending.attachment = attachment;
|
|
1479
|
+
}
|
|
1480
|
+
} else if (block.type === "input_text" && typeof block.text === "string") {
|
|
1481
|
+
const tags = block.text.matchAll(/<\/?image\b[^>]*>/gi);
|
|
1482
|
+
let end = 0;
|
|
1483
|
+
for (const tag of tags) {
|
|
1484
|
+
if (pending && block.text.slice(end, tag.index).trim()) pending.invalid = true;
|
|
1485
|
+
if (/^<\/image\s*>$/i.test(tag[0])) {
|
|
1486
|
+
if (depth === 1 && pending && !pending.invalid && pending.path && pending.attachment) {
|
|
1487
|
+
pending.attachment.path = pending.path;
|
|
1488
|
+
}
|
|
1489
|
+
depth = Math.max(0, depth - 1);
|
|
1490
|
+
if (depth === 0) pending = void 0;
|
|
1491
|
+
} else {
|
|
1492
|
+
if (pending) pending.invalid = true;
|
|
1493
|
+
if (depth === 0) {
|
|
1494
|
+
const path = tag[0].match(/\bpath\s*=\s*(["'])(.*?)\1/i)?.[2];
|
|
1495
|
+
pending = { path: path ? codexFilePath(path) : void 0, invalid: false };
|
|
1496
|
+
}
|
|
1497
|
+
depth++;
|
|
1498
|
+
}
|
|
1499
|
+
end = tag.index + tag[0].length;
|
|
1500
|
+
}
|
|
1501
|
+
if (pending && block.text.slice(end).trim()) pending.invalid = true;
|
|
1502
|
+
} else if (pending) {
|
|
1503
|
+
pending.invalid = true;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
return attachments;
|
|
1507
|
+
}
|
|
1508
|
+
function extractCodexUserContent(content) {
|
|
1509
|
+
const text = (content?.filter((c) => c.type === "input_text" && c.text && !CODEX_IMAGE_TAG_RE.test(c.text.trim())).map((c) => c.text).join("") || "").replace(CODEX_IMAGE_MARKUP_RE, "");
|
|
1510
|
+
const images = extractCodexImageAttachments(content).map(({ image }) => image);
|
|
1511
|
+
return { text, images };
|
|
1512
|
+
}
|
|
1513
|
+
function codexItemToolUseId(item) {
|
|
1514
|
+
return item.call_id || item.id || "";
|
|
1515
|
+
}
|
|
1516
|
+
function codexItemKind(type) {
|
|
1517
|
+
if (!type) return "";
|
|
1518
|
+
return type.replace(/^([A-Z])/, (c) => c.toLowerCase()).replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
1519
|
+
}
|
|
1520
|
+
function codexCommandText(command) {
|
|
1521
|
+
if (typeof command === "string") return command;
|
|
1522
|
+
if (!Array.isArray(command)) return "";
|
|
1523
|
+
return command.map((a) => {
|
|
1524
|
+
const arg = String(a);
|
|
1525
|
+
return /[\s"'$`\\|&;<>()]/.test(arg) ? `'${arg.replace(/'/g, `'\\''`)}'` : arg;
|
|
1526
|
+
}).join(" ");
|
|
1527
|
+
}
|
|
1528
|
+
var patchChanges = (item) => {
|
|
1529
|
+
const raw = item.changes;
|
|
1530
|
+
if (!raw) return [];
|
|
1531
|
+
const kindOf = (v) => {
|
|
1532
|
+
if (typeof v === "string") return v;
|
|
1533
|
+
const o = v;
|
|
1534
|
+
const tag = (o?.kind && typeof o.kind === "object" ? o.kind.type : o?.kind) ?? o?.type;
|
|
1535
|
+
return typeof tag === "string" ? tag : "update";
|
|
1536
|
+
};
|
|
1537
|
+
if (Array.isArray(raw)) {
|
|
1538
|
+
return raw.map((c) => ({ path: c?.path || "", kind: kindOf(c) }));
|
|
1539
|
+
}
|
|
1540
|
+
return Object.entries(raw).map(([path, v]) => ({ path, kind: kindOf(v) }));
|
|
1541
|
+
};
|
|
1542
|
+
var patchResultText = (item) => {
|
|
1543
|
+
const cs = patchChanges(item);
|
|
1544
|
+
if (cs.length === 0) return "apply_patch";
|
|
1545
|
+
return cs.map((c) => `${c.kind} ${c.path}`.trim()).join("\n");
|
|
1546
|
+
};
|
|
1547
|
+
function codexItemBubble(item) {
|
|
1548
|
+
const id = codexItemToolUseId(item);
|
|
1549
|
+
if (!id) return null;
|
|
1550
|
+
switch (codexItemKind(item.type)) {
|
|
1551
|
+
case "command_execution":
|
|
1552
|
+
return {
|
|
1553
|
+
id,
|
|
1554
|
+
name: CODEX_TOOL_NAMES.bash,
|
|
1555
|
+
input: { command: codexCommandText(item.command) },
|
|
1556
|
+
// An empty result spins forever in the UI, so a bare exit code stands
|
|
1557
|
+
// in for a command that printed nothing.
|
|
1558
|
+
result: item.aggregated_output || `(exit code: ${item.exit_code ?? "unknown"})`,
|
|
1559
|
+
exitCode: typeof item.exit_code === "number" ? item.exit_code : null
|
|
1560
|
+
};
|
|
1561
|
+
case "file_change":
|
|
1562
|
+
return {
|
|
1563
|
+
id,
|
|
1564
|
+
name: CODEX_TOOL_NAMES.applyPatch,
|
|
1565
|
+
input: { changes: patchChanges(item) },
|
|
1566
|
+
result: patchResultText(item)
|
|
1567
|
+
};
|
|
1568
|
+
case "mcp_tool_call":
|
|
1569
|
+
return {
|
|
1570
|
+
id,
|
|
1571
|
+
name: codexMcpToolName(item.server || "mcp", item.tool || "tool"),
|
|
1572
|
+
input: item.arguments || {},
|
|
1573
|
+
result: codexMcpResultText(item) || `(${item.status || "completed"})`
|
|
1574
|
+
};
|
|
1575
|
+
case "web_search": {
|
|
1576
|
+
const { name, input, result } = codexWebSearchCall(item.query, item.action);
|
|
1577
|
+
return { id, name, input, result };
|
|
1578
|
+
}
|
|
1579
|
+
case "todo_list": {
|
|
1580
|
+
const input = codexTodoInput(item.items);
|
|
1581
|
+
return { id, name: CODEX_TOOL_NAMES.todo, input, result: codexTodoResultText(input.todos) };
|
|
1582
|
+
}
|
|
1583
|
+
// Reading an image back. The result is deliberately the placeholder and not
|
|
1584
|
+
// the image: inlining a screenshot's data URL used to push ~600KB of base64
|
|
1585
|
+
// through the API, React state and the DOM for one bubble.
|
|
1586
|
+
case "image_view":
|
|
1587
|
+
return {
|
|
1588
|
+
id,
|
|
1589
|
+
name: CODEX_TOOL_NAMES.read,
|
|
1590
|
+
input: { file_path: codexFilePath(item.path || "") },
|
|
1591
|
+
result: CODEX_IMAGE_ONLY_TEXT
|
|
1592
|
+
};
|
|
1593
|
+
/**
|
|
1594
|
+
* Generating an image. It writes a file, so it belongs in the timeline like
|
|
1595
|
+
* any other write — it was grouped with `sleep` and the review-mode markers
|
|
1596
|
+
* by mistake, which left a generated image invisible on both sides.
|
|
1597
|
+
*/
|
|
1598
|
+
case "image_generation":
|
|
1599
|
+
return {
|
|
1600
|
+
id,
|
|
1601
|
+
name: CODEX_TOOL_NAMES.imageGeneration,
|
|
1602
|
+
input: { file_path: codexFilePath(item.savedPath || ""), ...item.revisedPrompt ? { prompt: item.revisedPrompt } : {} },
|
|
1603
|
+
result: item.savedPath || `(${item.status || "completed"})`
|
|
1604
|
+
};
|
|
1605
|
+
// A tool reached through codex's dynamic namespace rather than a fixed one.
|
|
1606
|
+
// Named like an MCP call because that is what it is from the reader's side.
|
|
1607
|
+
case "dynamic_tool_call":
|
|
1608
|
+
return {
|
|
1609
|
+
id,
|
|
1610
|
+
name: codexMcpToolName(item.namespace || "tool", item.tool || "call"),
|
|
1611
|
+
input: item.arguments || {},
|
|
1612
|
+
result: codexMcpResultText(item) || `(${item.status || "completed"})`
|
|
1613
|
+
};
|
|
1614
|
+
default:
|
|
1615
|
+
return null;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
// packages/feature/agent/src/shared/decisionContext.ts
|
|
1620
|
+
var BLOCK = /^\s*<cockpit-decisions>\n?([\s\S]*?)<\/cockpit-decisions>\s*/;
|
|
1621
|
+
var ITEM = /^- \[(dec-[a-z0-9]+-[a-z0-9]+) r(\d+)\] (.*)$/gm;
|
|
1622
|
+
function splitDecisionContext(text) {
|
|
1623
|
+
const m = BLOCK.exec(text);
|
|
1624
|
+
if (!m) return { items: [], body: text };
|
|
1625
|
+
const items = [];
|
|
1626
|
+
for (const it of m[1].matchAll(ITEM)) items.push({ key: `${it[1]}@${it[2]}`, text: it[3] });
|
|
1627
|
+
return { items, body: text.slice(m[0].length) };
|
|
1628
|
+
}
|
|
1629
|
+
var stripDecisionContext = (text) => splitDecisionContext(text).body;
|
|
1630
|
+
|
|
1631
|
+
// packages/feature/agent/src/shared/messageOrigin.ts
|
|
1632
|
+
function sentOriginLine(link, project, inputId) {
|
|
1633
|
+
const id = inputId ? ` \xB7 input ${inputId}` : "";
|
|
1634
|
+
return link ? `[Sent from Cockpit session ${link} (${project}) via @mention${id}]` : `[Sent via @mention from another Cockpit session${id}]`;
|
|
1635
|
+
}
|
|
1636
|
+
function delegatedOriginLine(link, project) {
|
|
1637
|
+
return `[Delegated from Cockpit session ${link} (${project})]`;
|
|
1638
|
+
}
|
|
1639
|
+
var SENT = /^\[Sent from Cockpit session (\/project\?\S+) \((.*)\) via @mention(?: · input ([\w-]+))?\]$/;
|
|
1640
|
+
var SENT_ANONYMOUS = /^\[Sent via @mention from another Cockpit session(?: · input ([\w-]+))?\]$/;
|
|
1641
|
+
var DELEGATED = /^\[Delegated from Cockpit session (\/project\?\S+) \((.*)\)\]$/;
|
|
1642
|
+
function parseMessageOrigin(text) {
|
|
1643
|
+
const lines = text.split("\n");
|
|
1644
|
+
const first = lines[0] ?? "";
|
|
1645
|
+
const sent = first.match(SENT);
|
|
1646
|
+
const anonymous = sent ? null : first.match(SENT_ANONYMOUS);
|
|
1647
|
+
if (sent || anonymous) {
|
|
1648
|
+
const inputId = sent?.[3] ?? anonymous?.[1];
|
|
1649
|
+
return {
|
|
1650
|
+
kind: "sent",
|
|
1651
|
+
link: sent?.[1] ?? null,
|
|
1652
|
+
project: sent?.[2] ?? null,
|
|
1653
|
+
body: lines.slice(1).join("\n").replace(/^\n+/, ""),
|
|
1654
|
+
...inputId && { inputId }
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
const index = lines.findIndex((line, i) => i <= 1 && DELEGATED.test(line));
|
|
1658
|
+
if (index === -1) return null;
|
|
1659
|
+
const delegated = lines[index].match(DELEGATED);
|
|
1660
|
+
return {
|
|
1661
|
+
kind: "delegated",
|
|
1662
|
+
link: delegated[1],
|
|
1663
|
+
project: delegated[2],
|
|
1664
|
+
body: [...lines.slice(0, index), ...lines.slice(index + 1)].join("\n").replace(/^\n+/, "")
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
// packages/feature/agent/src/shared/commandPrompt.ts
|
|
1669
|
+
var FOOTER_HEADERS = {
|
|
1670
|
+
read: {
|
|
1671
|
+
zh: "\u8BF7\u5148\u8BFB\u53D6\u4EE5\u4E0B skill \u6587\u4EF6\uFF0C\u518D\u636E\u6B64\u6267\u884C\uFF1A",
|
|
1672
|
+
en: "Read these skill files first, then act accordingly:"
|
|
1673
|
+
},
|
|
1674
|
+
/** Handoff list when every Bot line is delegated. */
|
|
1675
|
+
handoff: {
|
|
1676
|
+
zh: "\u4EE5\u4E0B\u6587\u4EF6\u4EA4\u7ED9\u4F60\u6D3E\u53D1\u7684\u5B50\u4F1A\u8BDD\u53BB\u8BFB\uFF0C\u4F60\u53EA\u8F6C\u4EA4\u8DEF\u5F84\uFF0C\u4E0D\u8981\u81EA\u5DF1\u6253\u5F00\uFF1A",
|
|
1677
|
+
en: "These files are for the session you delegate to. Pass the paths along; do not open them yourself:"
|
|
1678
|
+
},
|
|
1679
|
+
/** Handoff list when a Bot also runs here (bot-turn is then in both lists). */
|
|
1680
|
+
handoffMixed: {
|
|
1681
|
+
zh: "\u4EE5\u4E0B\u8DEF\u5F84\u539F\u6837\u8F6C\u4EA4\u7ED9\u4F60\u6D3E\u53D1\u7684\u5B50\u4F1A\u8BDD\uFF1B\u9664\u4E0A\u9762\u8BFB\u53D6\u5217\u8868\u5DF2\u5217\u51FA\u7684\u4EE5\u5916\uFF0C\u4E0D\u8981\u81EA\u5DF1\u6253\u5F00\uFF1A",
|
|
1682
|
+
en: "Pass these paths verbatim to the session you delegate to; do not open any that the read list above does not already list:"
|
|
1683
|
+
},
|
|
1684
|
+
targets: {
|
|
1685
|
+
zh: "\u4EE5\u4E0A [session\xB7@\u2026] \u884C\u6307\u5411\u7684\u4F1A\u8BDD\uFF08cwd \u4E0E sessionId \u539F\u6837\u4F7F\u7528\uFF09\uFF1A",
|
|
1686
|
+
en: "Sessions the [session\xB7@\u2026] lines above address (use cwd and sessionId verbatim):"
|
|
1687
|
+
},
|
|
1688
|
+
unresolved: {
|
|
1689
|
+
zh: "\u4EE5\u4E0B @ \u5F00\u5934\u7684\u884C\u6CA1\u6709\u88AB\u8BC6\u522B\uFF0C\u5DF2\u6309\u666E\u901A\u6587\u672C\u5904\u7406\uFF0C\u8BF7\u544A\u77E5\u7528\u6237\uFF1A",
|
|
1690
|
+
en: "These @ lines were not recognised and were left as plain text. Tell the user:"
|
|
1691
|
+
}
|
|
1692
|
+
};
|
|
1693
|
+
var footerHeader = (kind, lang) => FOOTER_HEADERS[kind][lang];
|
|
1694
|
+
var HEADER_KIND = new Map(
|
|
1695
|
+
Object.entries(FOOTER_HEADERS).flatMap(([kind, byLang]) => [[byLang.zh, kind], [byLang.en, kind]])
|
|
1696
|
+
);
|
|
1697
|
+
var INLINE_SKILL = /^---\nname:\s*([^\n]+)/;
|
|
1698
|
+
var TAG_LINE = /^\[(?:(main|subagent|session)·)?(.+?)\](?: (.*))?$/;
|
|
1699
|
+
var isHeaderBlock = (block) => {
|
|
1700
|
+
const [first, ...rest] = block.split("\n");
|
|
1701
|
+
return HEADER_KIND.has(first) && rest.length > 0 && rest.every((line) => line.startsWith("- "));
|
|
1702
|
+
};
|
|
1703
|
+
function footerStart(text) {
|
|
1704
|
+
const blocks = text.split("\n\n");
|
|
1705
|
+
let i = blocks.length - 1;
|
|
1706
|
+
let found = false;
|
|
1707
|
+
while (i >= 0) {
|
|
1708
|
+
if (isHeaderBlock(blocks[i])) {
|
|
1709
|
+
found = true;
|
|
1710
|
+
i--;
|
|
1711
|
+
continue;
|
|
1712
|
+
}
|
|
1713
|
+
let j = i;
|
|
1714
|
+
while (j > 0 && !INLINE_SKILL.test(blocks[j])) j--;
|
|
1715
|
+
if (j > 0 && INLINE_SKILL.test(blocks[j]) && isHeaderBlock(blocks[j - 1])) {
|
|
1716
|
+
found = true;
|
|
1717
|
+
i = j - 1;
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1720
|
+
break;
|
|
1721
|
+
}
|
|
1722
|
+
if (!found) return -1;
|
|
1723
|
+
let offset = 0;
|
|
1724
|
+
for (let k = 0; k <= i; k++) offset += blocks[k].length + 2;
|
|
1725
|
+
return i < 0 ? 0 : offset - 2;
|
|
1726
|
+
}
|
|
1727
|
+
var listItem = (line, kind) => {
|
|
1728
|
+
const m = kind === "targets" ? line.match(/^- (.+)(?::|: )(\{.*\})$/) : line.match(/^- (.+?)(?::|: )(.*)$/);
|
|
1729
|
+
return m ? { name: m[1], detail: m[2] } : null;
|
|
1730
|
+
};
|
|
1731
|
+
function typedCommand(locus, name) {
|
|
1732
|
+
if (name.startsWith("@")) return name;
|
|
1733
|
+
return locus === "subagent" ? `/@${name}` : `/${name}`;
|
|
1734
|
+
}
|
|
1735
|
+
function parseCommandPrompt(text) {
|
|
1736
|
+
const start = footerStart(text);
|
|
1737
|
+
if (start === -1) return null;
|
|
1738
|
+
const body = text.slice(0, start);
|
|
1739
|
+
const footer = text.slice(start).replace(/^\n+/, "");
|
|
1740
|
+
const references = [];
|
|
1741
|
+
const notes = [];
|
|
1742
|
+
let kind = null;
|
|
1743
|
+
for (const block of footer.split(/\n\n(?=\S)/)) {
|
|
1744
|
+
const [first, ...rest] = block.split("\n");
|
|
1745
|
+
const headerKind = HEADER_KIND.get(first);
|
|
1746
|
+
const inline = kind !== null ? block.match(INLINE_SKILL) : null;
|
|
1747
|
+
if (headerKind) kind = headerKind;
|
|
1748
|
+
else if (inline) {
|
|
1749
|
+
references.push({ kind: "inline", name: inline[1].trim().replace(/^["']|["']$/g, ""), detail: "" });
|
|
1750
|
+
kind = "inline";
|
|
1751
|
+
continue;
|
|
1752
|
+
} else if (kind === "inline") continue;
|
|
1753
|
+
for (const line of headerKind ? rest : [first, ...rest]) {
|
|
1754
|
+
if (kind === "unresolved") {
|
|
1755
|
+
if (line.startsWith("- ")) notes.push(line.slice(2));
|
|
1756
|
+
continue;
|
|
1757
|
+
}
|
|
1758
|
+
const item = kind ? listItem(line, kind) : null;
|
|
1759
|
+
if (item && kind) references.push({ kind, ...item });
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
const listed = new Set(references.map((r) => r.name));
|
|
1763
|
+
const targets = references.filter((r) => r.kind === "targets").map((r) => r.name).sort((a, b) => b.length - a.length);
|
|
1764
|
+
const parseLine2 = (line) => {
|
|
1765
|
+
if (line.startsWith("[session\xB7")) {
|
|
1766
|
+
for (const name2 of targets) {
|
|
1767
|
+
const tag = `[session\xB7${name2}]`;
|
|
1768
|
+
if (line.startsWith(tag) && (line.length === tag.length || line[tag.length] === " ")) {
|
|
1769
|
+
return { command: name2, text: line.slice(tag.length + 1) };
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
const m = line.match(TAG_LINE);
|
|
1774
|
+
if (!m) return { command: null, text: line };
|
|
1775
|
+
const [, locus, name, rest = ""] = m;
|
|
1776
|
+
if (!locus && !listed.has(name)) return { command: null, text: line };
|
|
1777
|
+
return { command: typedCommand(locus, name), text: rest };
|
|
1778
|
+
};
|
|
1779
|
+
const lines = (body ? body.split("\n") : []).map(parseLine2);
|
|
1780
|
+
const notesOnly = references.length === 0 && notes.length > 0;
|
|
1781
|
+
if (!notesOnly && !lines.some((l) => l.command)) return null;
|
|
1782
|
+
while (lines.length && lines[lines.length - 1].command === null && !lines[lines.length - 1].text.trim()) lines.pop();
|
|
1783
|
+
return { lines, references, notes };
|
|
1784
|
+
}
|
|
1785
|
+
function typedPromptText(text) {
|
|
1786
|
+
const parsed = parseCommandPrompt(text);
|
|
1787
|
+
if (!parsed) return text;
|
|
1788
|
+
return parsed.lines.map((l) => l.command ? l.text ? `${l.command} ${l.text}` : l.command : l.text).join("\n");
|
|
1789
|
+
}
|
|
1790
|
+
function humanUserText(text) {
|
|
1791
|
+
const origin = parseMessageOrigin(text);
|
|
1792
|
+
return typedPromptText(origin ? origin.body : text);
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
// packages/feature/agent/src/server/sessionTitle.ts
|
|
1796
|
+
function filterCommandTags(rawText) {
|
|
1797
|
+
const text = humanUserText(stripDecisionContext(rawText));
|
|
1798
|
+
const argsMatch = text.match(/<command-args>([^<]*)<\/command-args>/);
|
|
1799
|
+
if (argsMatch && argsMatch[1].trim()) {
|
|
1800
|
+
return argsMatch[1].trim();
|
|
1801
|
+
}
|
|
1802
|
+
const nameMatch = text.match(/<command-name>([^<]*)<\/command-name>/);
|
|
1803
|
+
if (nameMatch && nameMatch[1].trim()) {
|
|
1804
|
+
return nameMatch[1].trim();
|
|
1805
|
+
}
|
|
1806
|
+
let filtered = text.replace(/<command-message>[^<]*<\/command-message>/g, "");
|
|
1807
|
+
filtered = filtered.replace(/<command-name>[^<]*<\/command-name>/g, "");
|
|
1808
|
+
filtered = filtered.replace(/<command-args>[^<]*<\/command-args>/g, "");
|
|
1809
|
+
filtered = filtered.replace(/<local-command-stdout>[\s\S]*?<\/local-command-stdout>/g, "");
|
|
1810
|
+
filtered = filtered.replace(/<local-command-caveat>[\s\S]*?<\/local-command-caveat>/g, "");
|
|
1811
|
+
return filtered.trim();
|
|
1812
|
+
}
|
|
1813
|
+
function generateTitle(aiTitle, summary, userMessages) {
|
|
1814
|
+
if (aiTitle) return aiTitle;
|
|
1815
|
+
if (summary) return summary;
|
|
1816
|
+
let commandName = "";
|
|
1817
|
+
for (const msg of userMessages) {
|
|
1818
|
+
const filtered = filterCommandTags(msg);
|
|
1819
|
+
if (!filtered) continue;
|
|
1820
|
+
if (/^\/\S+$/.test(filtered) && !commandName) {
|
|
1821
|
+
commandName = filtered;
|
|
1822
|
+
continue;
|
|
1823
|
+
}
|
|
1824
|
+
if (commandName) {
|
|
1825
|
+
return `${commandName} ${filtered}`;
|
|
1826
|
+
}
|
|
1827
|
+
return filtered;
|
|
1828
|
+
}
|
|
1829
|
+
if (commandName) return commandName;
|
|
1830
|
+
return "Untitled Session";
|
|
1831
|
+
}
|
|
1832
|
+
function generateCodexTitle(firstPrompt) {
|
|
1833
|
+
const text = firstPrompt ? humanUserText(firstPrompt).trim() : "";
|
|
1834
|
+
return (text || "Untitled Session").slice(0, 80);
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
// packages/feature/agent/src/server/transcriptViews.ts
|
|
1838
|
+
function getOwn(dict, key) {
|
|
1839
|
+
return Object.prototype.hasOwnProperty.call(dict, key) ? dict[key] : void 0;
|
|
1840
|
+
}
|
|
1841
|
+
function setOwn(dict, key, value) {
|
|
1842
|
+
Object.defineProperty(dict, key, { value, writable: true, enumerable: true, configurable: true });
|
|
1843
|
+
return value;
|
|
1844
|
+
}
|
|
1845
|
+
function isCodexSubagent(entry) {
|
|
1846
|
+
return entry.parentThreadId !== void 0;
|
|
1847
|
+
}
|
|
1848
|
+
function filterCommandTags2(text) {
|
|
1849
|
+
let filtered = humanUserText(stripDecisionContext(text)).replace(/<command-[^>]*>[\s\S]*?<\/command-[^>]*>/g, "");
|
|
1850
|
+
filtered = filtered.replace(/<local-command-[^>]*>[\s\S]*?<\/local-command-[^>]*>/g, "");
|
|
1851
|
+
return filtered.trim();
|
|
1852
|
+
}
|
|
1853
|
+
function isValidUserMessage(text) {
|
|
1854
|
+
if (text.startsWith("This session is being continued")) return false;
|
|
1855
|
+
if (text.startsWith("Caveat: The messages below")) return false;
|
|
1856
|
+
if (!text.trim()) return false;
|
|
1857
|
+
return true;
|
|
1858
|
+
}
|
|
1859
|
+
function previewMessages(snap) {
|
|
1860
|
+
const out = [];
|
|
1861
|
+
for (const turn of snap.userTurns) {
|
|
1862
|
+
if (turn.isMeta) continue;
|
|
1863
|
+
let text;
|
|
1864
|
+
if (snap.format === "codex") {
|
|
1865
|
+
const prompt = codexPromptText(turn.listText ?? turn.blocks.join(""), turn.images);
|
|
1866
|
+
if (prompt === null) continue;
|
|
1867
|
+
const shown = humanUserText(prompt).trim();
|
|
1868
|
+
if (shown) out.push(shown);
|
|
1869
|
+
continue;
|
|
1870
|
+
} else {
|
|
1871
|
+
text = turn.blocks.find((b) => b) ?? "";
|
|
1872
|
+
if (!text) continue;
|
|
1873
|
+
}
|
|
1874
|
+
const filtered = filterCommandTags2(text);
|
|
1875
|
+
if (filtered && isValidUserMessage(filtered)) out.push(filtered);
|
|
1876
|
+
}
|
|
1877
|
+
return out;
|
|
1878
|
+
}
|
|
1879
|
+
function titleMessages(snap) {
|
|
1880
|
+
return snap.userTurns.filter((turn) => !turn.isMeta).flatMap((turn) => turn.blocks.filter((b) => b));
|
|
1881
|
+
}
|
|
1882
|
+
function codexTitle(snap) {
|
|
1883
|
+
for (const turn of snap.userTurns) {
|
|
1884
|
+
const text = codexPromptText(turn.listText ?? turn.blocks.join(""), turn.images);
|
|
1885
|
+
if (text === null) continue;
|
|
1886
|
+
return generateCodexTitle(text);
|
|
1887
|
+
}
|
|
1888
|
+
return void 0;
|
|
1889
|
+
}
|
|
1890
|
+
function defaultSessionTitle(snap) {
|
|
1891
|
+
return snap.format === "codex" ? codexTitle(snap) || "Untitled Session" : generateTitle(snap.aiTitle, snap.summary, titleMessages(snap));
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
// packages/feature/agent/src/shared/transcriptTurns.ts
|
|
1895
|
+
function injectionKind(msg) {
|
|
1896
|
+
if (msg.isMeta && msg.sourceToolUseID) return "skill";
|
|
1897
|
+
if (msg.origin?.kind === "task-notification") return "task-notification";
|
|
1898
|
+
if (msg.origin?.kind && msg.origin.kind !== "human") return "meta";
|
|
1899
|
+
if (msg.isMeta) return "meta";
|
|
1900
|
+
if (msg.isCompactSummary) return "meta";
|
|
1901
|
+
return null;
|
|
1902
|
+
}
|
|
1903
|
+
function isHumanTurnStart(entry) {
|
|
1904
|
+
entry = queuedPromptAsUserEntry(entry) ?? entry;
|
|
1905
|
+
if (entry.type !== "user") return false;
|
|
1906
|
+
if (injectionKind(entry) !== null) return false;
|
|
1907
|
+
const content = entry.message?.content;
|
|
1908
|
+
if (typeof content === "string") return content.length > 0;
|
|
1909
|
+
if (!Array.isArray(content)) return false;
|
|
1910
|
+
return content.some((block) => block?.type === "text" || block?.type === "image" && block.source);
|
|
1911
|
+
}
|
|
1912
|
+
function queuedPromptAsUserEntry(entry) {
|
|
1913
|
+
const a = entry.attachment;
|
|
1914
|
+
if (entry.type !== "attachment" || a?.type !== "queued_command" || a.commandMode !== "prompt") return null;
|
|
1915
|
+
if (!(typeof a.prompt === "string" || Array.isArray(a.prompt)) || a.prompt.length === 0) return null;
|
|
1916
|
+
return {
|
|
1917
|
+
type: "user",
|
|
1918
|
+
uuid: entry.uuid,
|
|
1919
|
+
// Keep the journal wrapper for edit targets, and the original input for live binding.
|
|
1920
|
+
...a.source_uuid ? { sourceId: a.source_uuid } : {},
|
|
1921
|
+
timestamp: entry.timestamp ?? a.timestamp,
|
|
1922
|
+
sessionId: entry.sessionId,
|
|
1923
|
+
message: { role: "user", content: a.prompt }
|
|
1924
|
+
};
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
// packages/feature/agent/src/shared/pullRequests.ts
|
|
1928
|
+
var CREATE_COMMAND = /\bgh\s+pr\s+create\b/;
|
|
1929
|
+
var VIEW_COMMAND = /\bgh\s+pr\s+view\b/;
|
|
1930
|
+
var LIST_HEAD_COMMAND = /\bgh\s+pr\s+list\b[^\n;&|]*\s(?:--head|-H)(?:=|\s)/;
|
|
1931
|
+
var PR_URL = /https:\/\/github\.com\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\/pull\/(\d+)/;
|
|
1932
|
+
var TITLE_FLAG = /(?:^|\s)(?:--title|-t)(?:=|\s+)(?:'([^']*)'|"((?:[^"\\]|\\.)*)"|([^\s'"]+))/;
|
|
1933
|
+
function isPullRequestCreateCommand(command) {
|
|
1934
|
+
return CREATE_COMMAND.test(command);
|
|
1935
|
+
}
|
|
1936
|
+
function isPullRequestLookupCommand(command) {
|
|
1937
|
+
return CREATE_COMMAND.test(command) || VIEW_COMMAND.test(command) || LIST_HEAD_COMMAND.test(command);
|
|
1938
|
+
}
|
|
1939
|
+
function findPullRequestUrl(text) {
|
|
1940
|
+
const m = PR_URL.exec(text);
|
|
1941
|
+
if (!m) return null;
|
|
1942
|
+
const repo = `${m[1]}/${m[2]}`;
|
|
1943
|
+
const number = Number(m[3]);
|
|
1944
|
+
return { url: `https://github.com/${repo}/pull/${number}`, repo, number };
|
|
1945
|
+
}
|
|
1946
|
+
function pullRequestTitleOf(command) {
|
|
1947
|
+
const m = TITLE_FLAG.exec(command);
|
|
1948
|
+
if (!m) return void 0;
|
|
1949
|
+
const raw = m[1] ?? m[2]?.replace(/\\(.)/g, "$1") ?? m[3];
|
|
1950
|
+
const title = raw?.trim();
|
|
1951
|
+
return title || void 0;
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
// packages/shared/effect-runtime/src/server/fs.ts
|
|
1955
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
1956
|
+
import { mkdir as mkdir3, readFile as readFile3, rename as rename2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
1957
|
+
import { dirname } from "path";
|
|
1958
|
+
var readJsonOr = (file, fallback, guard = (_value) => true) => Effect_exports.tryPromise({
|
|
1959
|
+
try: () => readFile3(file, "utf8"),
|
|
1960
|
+
catch: (cause) => new FSError({ path: file, op: "read", cause })
|
|
1961
|
+
}).pipe(
|
|
1962
|
+
Effect_exports.flatMap((raw) => Effect_exports.try(() => JSON.parse(raw))),
|
|
1963
|
+
Effect_exports.map((value) => guard(value) ? value : fallback),
|
|
1964
|
+
Effect_exports.orElseSucceed(() => fallback)
|
|
1965
|
+
);
|
|
1966
|
+
var nodeAtomicWriteOps = {
|
|
1967
|
+
mkdir: (dir, opts) => mkdir3(dir, { ...opts, mode: 448 }),
|
|
1968
|
+
writeFile: (file, text) => writeFile2(file, text, { mode: 384 }),
|
|
1969
|
+
rename: rename2,
|
|
1970
|
+
rm
|
|
1971
|
+
};
|
|
1972
|
+
var writeAtomically = async (file, text, ops = nodeAtomicWriteOps) => {
|
|
1973
|
+
await ops.mkdir(dirname(file), { recursive: true });
|
|
1974
|
+
const tmp = `${file}.${randomUUID3()}.tmp`;
|
|
1975
|
+
await ops.writeFile(tmp, text).then(() => ops.rename(tmp, file)).catch(async (err) => {
|
|
1976
|
+
await ops.rm(tmp, { force: true }).catch(() => void 0);
|
|
1977
|
+
throw err;
|
|
1978
|
+
});
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
// packages/feature/agent/src/effect/transcriptIndexLive.ts
|
|
1982
|
+
var TRANSCRIPT_INDEX_VERSION = 13;
|
|
1983
|
+
var READ_CONCURRENCY = 4;
|
|
1984
|
+
var ANCHOR_BYTES = 64;
|
|
1985
|
+
var CHUNK_BYTES = 1024 * 1024;
|
|
1986
|
+
var FLUSH_DELAY = "3 seconds";
|
|
1987
|
+
var CACHE_MAX_FILES = 64;
|
|
1988
|
+
var CACHE_MAX_BYTES = 16 * 1024 * 1024;
|
|
1989
|
+
var emptyStats = () => ({
|
|
1990
|
+
messages: 0,
|
|
1991
|
+
firstDate: "",
|
|
1992
|
+
sessionIds: {},
|
|
1993
|
+
sessionTimes: {},
|
|
1994
|
+
hourCounts: {},
|
|
1995
|
+
daily: {},
|
|
1996
|
+
dailyTokens: {},
|
|
1997
|
+
modelUsage: {}
|
|
1998
|
+
});
|
|
1999
|
+
var emptyFoldState = () => ({
|
|
2000
|
+
aiTitle: "",
|
|
2001
|
+
summary: "",
|
|
2002
|
+
cwd: null,
|
|
2003
|
+
userTurns: [],
|
|
2004
|
+
corpus: [],
|
|
2005
|
+
pullRequests: [],
|
|
2006
|
+
pendingPrCreates: {},
|
|
2007
|
+
unresolvedPrCreate: null,
|
|
2008
|
+
stats: emptyStats()
|
|
2009
|
+
});
|
|
2010
|
+
var emptyEntry = (path, format, ino) => ({
|
|
2011
|
+
v: TRANSCRIPT_INDEX_VERSION,
|
|
2012
|
+
path,
|
|
2013
|
+
format,
|
|
2014
|
+
ino,
|
|
2015
|
+
size: 0,
|
|
2016
|
+
mtimeMs: 0,
|
|
2017
|
+
offset: 0,
|
|
2018
|
+
anchor: "",
|
|
2019
|
+
skippedLines: 0,
|
|
2020
|
+
...emptyFoldState()
|
|
2021
|
+
});
|
|
2022
|
+
var cloneEntry = (e) => ({
|
|
2023
|
+
...e,
|
|
2024
|
+
userTurns: [...e.userTurns],
|
|
2025
|
+
corpus: [...e.corpus],
|
|
2026
|
+
pullRequests: [...e.pullRequests],
|
|
2027
|
+
pendingPrCreates: { ...e.pendingPrCreates },
|
|
2028
|
+
stats: structuredClone(e.stats)
|
|
2029
|
+
});
|
|
2030
|
+
var toSnapshot = (e) => ({
|
|
2031
|
+
path: e.path,
|
|
2032
|
+
format: e.format,
|
|
2033
|
+
size: e.size,
|
|
2034
|
+
mtimeMs: e.mtimeMs,
|
|
2035
|
+
aiTitle: e.aiTitle,
|
|
2036
|
+
summary: e.summary,
|
|
2037
|
+
cwd: e.cwd,
|
|
2038
|
+
userTurns: e.userTurns,
|
|
2039
|
+
corpus: e.corpus,
|
|
2040
|
+
pullRequests: e.pullRequests,
|
|
2041
|
+
stats: e.stats
|
|
2042
|
+
});
|
|
2043
|
+
var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2044
|
+
var str = (v) => typeof v === "string" ? v : void 0;
|
|
2045
|
+
var num = (v) => typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
2046
|
+
var parseLine = (line) => {
|
|
2047
|
+
try {
|
|
2048
|
+
const v = JSON.parse(line);
|
|
2049
|
+
return isRecord2(v) ? v : null;
|
|
2050
|
+
} catch {
|
|
2051
|
+
return null;
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
var decodeClaudeLine = (line) => {
|
|
2055
|
+
const parsed = parseLine(line);
|
|
2056
|
+
if (!parsed) return null;
|
|
2057
|
+
const queued = queuedPromptAsUserEntry(parsed);
|
|
2058
|
+
const d = queued ? { ...parsed, ...queued } : parsed;
|
|
2059
|
+
const type = str(d.type) ?? "";
|
|
2060
|
+
const message = isRecord2(d.message) ? d.message : void 0;
|
|
2061
|
+
const content = message?.content;
|
|
2062
|
+
const blocks = Array.isArray(content) ? content.filter(isRecord2) : [];
|
|
2063
|
+
let userTurn;
|
|
2064
|
+
if (type === "user" && content) {
|
|
2065
|
+
const texts = typeof content === "string" ? [content] : blocks.filter((b) => b.type === "text").map((b) => str(b.text) ?? "");
|
|
2066
|
+
if (texts.length > 0) {
|
|
2067
|
+
const injected = injectionKind({
|
|
2068
|
+
isMeta: d.isMeta === true,
|
|
2069
|
+
isCompactSummary: d.isCompactSummary === true,
|
|
2070
|
+
origin: isRecord2(d.origin) ? { kind: str(d.origin.kind) } : void 0,
|
|
2071
|
+
sourceToolUseID: str(d.sourceToolUseID)
|
|
2072
|
+
}) !== null;
|
|
2073
|
+
userTurn = injected ? { blocks: texts, isMeta: true } : { blocks: texts };
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
let assistant;
|
|
2077
|
+
let assistantText = "";
|
|
2078
|
+
if (type === "assistant" && message) {
|
|
2079
|
+
const usage = isRecord2(message.usage) ? message.usage : void 0;
|
|
2080
|
+
assistant = {
|
|
2081
|
+
model: str(message.model),
|
|
2082
|
+
usage: usage && {
|
|
2083
|
+
input: num(usage.input_tokens),
|
|
2084
|
+
output: num(usage.output_tokens),
|
|
2085
|
+
cacheRead: num(usage.cache_read_input_tokens),
|
|
2086
|
+
cacheCreation: num(usage.cache_creation_input_tokens)
|
|
2087
|
+
},
|
|
2088
|
+
toolUses: blocks.filter((b) => b.type === "tool_use").length
|
|
2089
|
+
};
|
|
2090
|
+
assistantText = blocks.filter((b) => b.type === "text").map((b) => str(b.text) ?? "").join("\n");
|
|
2091
|
+
}
|
|
2092
|
+
const corpusText = userTurn && !userTurn.isMeta ? userTurn.blocks.join("\n") : assistantText;
|
|
2093
|
+
let prCreateCalls;
|
|
2094
|
+
let prLookupCalls;
|
|
2095
|
+
let toolResults;
|
|
2096
|
+
for (const b of blocks) {
|
|
2097
|
+
if (type === "assistant" && b.type === "tool_use") {
|
|
2098
|
+
const id = str(b.id);
|
|
2099
|
+
const command = isRecord2(b.input) ? str(b.input.command) : void 0;
|
|
2100
|
+
if (!id || !command) continue;
|
|
2101
|
+
if (isPullRequestCreateCommand(command)) (prCreateCalls ??= []).push({ id, title: pullRequestTitleOf(command) });
|
|
2102
|
+
else if (isPullRequestLookupCommand(command)) (prLookupCalls ??= []).push(id);
|
|
2103
|
+
} else if (type === "user" && b.type === "tool_result") {
|
|
2104
|
+
const id = str(b.tool_use_id);
|
|
2105
|
+
const text = typeof b.content === "string" ? b.content : Array.isArray(b.content) ? b.content.filter(isRecord2).map((c) => str(c.text) ?? "").join("\n") : "";
|
|
2106
|
+
if (id && text) (toolResults ??= []).push({ id, text });
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
return {
|
|
2110
|
+
type,
|
|
2111
|
+
sessionId: str(d.sessionId) || void 0,
|
|
2112
|
+
timestamp: str(d.timestamp) || void 0,
|
|
2113
|
+
cwd: str(d.cwd) || void 0,
|
|
2114
|
+
aiTitle: type === "ai-title" ? str(d.aiTitle) || void 0 : void 0,
|
|
2115
|
+
summary: type === "summary" ? str(d.summary) || void 0 : void 0,
|
|
2116
|
+
userTurn,
|
|
2117
|
+
assistant,
|
|
2118
|
+
corpusText: corpusText.trim() ? corpusText : void 0,
|
|
2119
|
+
prCreateCalls,
|
|
2120
|
+
prLookupCalls,
|
|
2121
|
+
toolResults
|
|
2122
|
+
};
|
|
2123
|
+
};
|
|
2124
|
+
var decodeCodexLine = (line) => {
|
|
2125
|
+
if (!line.trim()) return null;
|
|
2126
|
+
const d = parseLine(line);
|
|
2127
|
+
if (!d || !isRecord2(d.payload)) return null;
|
|
2128
|
+
const payload = d.payload;
|
|
2129
|
+
if (d.type === "event_msg" && payload.type === "task_complete") {
|
|
2130
|
+
const message = isRecord2(payload.error) ? str(payload.error.message) : void 0;
|
|
2131
|
+
return message ? { type: "assistant", corpusText: `\u26A0\uFE0F ${message}` } : null;
|
|
2132
|
+
}
|
|
2133
|
+
if (d.type === "event_msg" && payload.type === "item_completed" && isRecord2(payload.item) && payload.item.type === "CommandExecution") {
|
|
2134
|
+
const item = payload.item;
|
|
2135
|
+
const command = Array.isArray(item.command) ? item.command.filter((c) => typeof c === "string").join(" ") : str(item.command) ?? "";
|
|
2136
|
+
const output = str(item.aggregated_output) ?? "";
|
|
2137
|
+
if (isPullRequestCreateCommand(command)) {
|
|
2138
|
+
return { type: "tool", prCreateResult: { output, title: pullRequestTitleOf(command), timestamp: str(d.timestamp) || void 0 } };
|
|
2139
|
+
}
|
|
2140
|
+
return isPullRequestLookupCommand(command) && output ? { type: "tool", prLookupResult: { output } } : null;
|
|
2141
|
+
}
|
|
2142
|
+
if (d.type !== "response_item") return null;
|
|
2143
|
+
if (payload.type !== "message" || !Array.isArray(payload.content)) return null;
|
|
2144
|
+
const source = payload.role === "user" ? projectCodexUserMessage({
|
|
2145
|
+
content: payload.content,
|
|
2146
|
+
internal_chat_message_metadata_passthrough: payload.internal_chat_message_metadata_passthrough
|
|
2147
|
+
}).flatMap((event) => event.kind === "prompt" ? event.blocks : []) : payload.content;
|
|
2148
|
+
const content = source.filter(isRecord2).filter((c) => {
|
|
2149
|
+
if (c.type === "input_text" || c.type === "output_text") return typeof c.text === "string";
|
|
2150
|
+
if (c.type === "input_image") return typeof c.image_url === "string";
|
|
2151
|
+
return true;
|
|
2152
|
+
});
|
|
2153
|
+
if (payload.role === "assistant") {
|
|
2154
|
+
const text2 = content.filter((c) => c.type === "output_text").map((c) => str(c.text) ?? "").join("\n");
|
|
2155
|
+
return text2.trim() ? { type: "assistant", corpusText: text2 } : null;
|
|
2156
|
+
}
|
|
2157
|
+
if (payload.role !== "user") return null;
|
|
2158
|
+
const blocks = content.filter((c) => c.type === "input_text" && str(c.text)).map((c) => c.text);
|
|
2159
|
+
const { text, images } = extractCodexUserContent(content);
|
|
2160
|
+
if (codexPromptText(text, images.length) === null) return null;
|
|
2161
|
+
return {
|
|
2162
|
+
type: "user",
|
|
2163
|
+
userTurn: { blocks, listText: text, images: images.length },
|
|
2164
|
+
corpusText: text || void 0
|
|
2165
|
+
};
|
|
2166
|
+
};
|
|
2167
|
+
var DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
2168
|
+
var applyStats = (s, r) => {
|
|
2169
|
+
const { type, sessionId, timestamp } = r;
|
|
2170
|
+
if (sessionId) setOwn(s.sessionIds, sessionId, 1);
|
|
2171
|
+
if (sessionId && timestamp) {
|
|
2172
|
+
const ts = new Date(timestamp).getTime();
|
|
2173
|
+
if (!isNaN(ts)) {
|
|
2174
|
+
const t = getOwn(s.sessionTimes, sessionId);
|
|
2175
|
+
if (!t) setOwn(s.sessionTimes, sessionId, { start: ts, end: ts });
|
|
2176
|
+
else {
|
|
2177
|
+
if (ts < t.start) t.start = ts;
|
|
2178
|
+
if (ts > t.end) t.end = ts;
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
const prefix = timestamp?.slice(0, 10);
|
|
2183
|
+
const date = prefix && DATE.test(prefix) ? prefix : void 0;
|
|
2184
|
+
if (date && (!s.firstDate || date < s.firstDate)) s.firstDate = date;
|
|
2185
|
+
if (timestamp && type === "user") {
|
|
2186
|
+
const hour = new Date(timestamp).getHours();
|
|
2187
|
+
if (!isNaN(hour)) setOwn(s.hourCounts, String(hour), (getOwn(s.hourCounts, String(hour)) || 0) + 1);
|
|
2188
|
+
}
|
|
2189
|
+
const dayOf = (day) => getOwn(s.daily, day) ?? setOwn(s.daily, day, { messages: 0, sessions: {}, toolCalls: 0 });
|
|
2190
|
+
if (type === "user") {
|
|
2191
|
+
s.messages++;
|
|
2192
|
+
if (date && sessionId) {
|
|
2193
|
+
const daily = dayOf(date);
|
|
2194
|
+
daily.messages++;
|
|
2195
|
+
setOwn(daily.sessions, sessionId, 1);
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
if (type === "assistant") {
|
|
2199
|
+
s.messages++;
|
|
2200
|
+
const a = r.assistant;
|
|
2201
|
+
if (!a) return;
|
|
2202
|
+
if (a.model && a.usage) {
|
|
2203
|
+
const mu = getOwn(s.modelUsage, a.model) ?? setOwn(s.modelUsage, a.model, {
|
|
2204
|
+
inputTokens: 0,
|
|
2205
|
+
outputTokens: 0,
|
|
2206
|
+
cacheReadInputTokens: 0,
|
|
2207
|
+
cacheCreationInputTokens: 0,
|
|
2208
|
+
webSearchRequests: 0
|
|
2209
|
+
});
|
|
2210
|
+
mu.inputTokens += a.usage.input;
|
|
2211
|
+
mu.outputTokens += a.usage.output;
|
|
2212
|
+
mu.cacheReadInputTokens += a.usage.cacheRead;
|
|
2213
|
+
mu.cacheCreationInputTokens += a.usage.cacheCreation;
|
|
2214
|
+
if (date) {
|
|
2215
|
+
const dtm = getOwn(s.dailyTokens, date) ?? setOwn(s.dailyTokens, date, {});
|
|
2216
|
+
const total = a.usage.input + a.usage.output + a.usage.cacheRead + a.usage.cacheCreation;
|
|
2217
|
+
setOwn(dtm, a.model, (getOwn(dtm, a.model) || 0) + total);
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
if (date && a.toolUses > 0) dayOf(date).toolCalls += a.toolUses;
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
var applyRecord = (state, format, r) => {
|
|
2224
|
+
if (format === "claude") {
|
|
2225
|
+
applyStats(state.stats, r);
|
|
2226
|
+
if (state.cwd === null && r.cwd) state.cwd = r.cwd;
|
|
2227
|
+
if (r.aiTitle) state.aiTitle = r.aiTitle;
|
|
2228
|
+
if (r.summary) state.summary = r.summary;
|
|
2229
|
+
}
|
|
2230
|
+
if (r.userTurn) state.userTurns.push(r.userTurn);
|
|
2231
|
+
if (r.userTurn && !r.userTurn.isMeta) state.unresolvedPrCreate = null;
|
|
2232
|
+
if (r.corpusText) state.corpus.push({ role: r.type === "assistant" ? "assistant" : "user", text: r.corpusText });
|
|
2233
|
+
for (const call of r.prCreateCalls ?? []) setOwn(state.pendingPrCreates, call.id, call.title ? { title: call.title } : {});
|
|
2234
|
+
if (state.unresolvedPrCreate) for (const id of r.prLookupCalls ?? []) setOwn(state.pendingPrCreates, id, { lookup: true });
|
|
2235
|
+
for (const result of r.toolResults ?? []) {
|
|
2236
|
+
const call = getOwn(state.pendingPrCreates, result.id);
|
|
2237
|
+
if (!call) continue;
|
|
2238
|
+
delete state.pendingPrCreates[result.id];
|
|
2239
|
+
if (call.lookup) resolvePullRequestCreate(state, result.text);
|
|
2240
|
+
else settlePullRequestCreate(state, result.text, call.title, r.timestamp);
|
|
2241
|
+
}
|
|
2242
|
+
if (r.prCreateResult) settlePullRequestCreate(state, r.prCreateResult.output, r.prCreateResult.title, r.prCreateResult.timestamp);
|
|
2243
|
+
if (r.prLookupResult) resolvePullRequestCreate(state, r.prLookupResult.output);
|
|
2244
|
+
};
|
|
2245
|
+
var settlePullRequestCreate = (state, output, title, createdAt) => {
|
|
2246
|
+
state.unresolvedPrCreate = addPullRequest(state, output, title, createdAt) ? null : { ...title ? { title } : {}, ...createdAt ? { createdAt } : {} };
|
|
2247
|
+
};
|
|
2248
|
+
var resolvePullRequestCreate = (state, output) => {
|
|
2249
|
+
const pending = state.unresolvedPrCreate;
|
|
2250
|
+
if (pending && addPullRequest(state, output, pending.title, pending.createdAt)) state.unresolvedPrCreate = null;
|
|
2251
|
+
};
|
|
2252
|
+
var addPullRequest = (state, output, title, createdAt) => {
|
|
2253
|
+
const ref = findPullRequestUrl(output);
|
|
2254
|
+
if (!ref) return false;
|
|
2255
|
+
if (state.pullRequests.some((pr) => pr.url === ref.url)) return true;
|
|
2256
|
+
state.pullRequests.push({ ...ref, ...title ? { title } : {}, ...createdAt ? { createdAt } : {} });
|
|
2257
|
+
return true;
|
|
2258
|
+
};
|
|
2259
|
+
var DECODERS = {
|
|
2260
|
+
claude: decodeClaudeLine,
|
|
2261
|
+
codex: decodeCodexLine,
|
|
2262
|
+
pi: () => null
|
|
2263
|
+
// Native Pi branches are projected by piSnapshot, never folded incrementally.
|
|
2264
|
+
};
|
|
2265
|
+
var foldLine = (state, format, line) => {
|
|
2266
|
+
try {
|
|
2267
|
+
const record = DECODERS[format](line);
|
|
2268
|
+
if (!record) return false;
|
|
2269
|
+
applyRecord(state, format, record);
|
|
2270
|
+
return true;
|
|
2271
|
+
} catch {
|
|
2272
|
+
return false;
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
var foldClaudeLine = (state, line) => void foldLine(state, "claude", line);
|
|
2276
|
+
var forEachLine = async (fh, from, to, onLine) => {
|
|
2277
|
+
let pos = from;
|
|
2278
|
+
let carry = Buffer.alloc(0);
|
|
2279
|
+
let consumed = 0;
|
|
2280
|
+
while (pos < to) {
|
|
2281
|
+
const want = Math.min(CHUNK_BYTES, to - pos);
|
|
2282
|
+
const chunk = Buffer.alloc(want);
|
|
2283
|
+
const { bytesRead } = await fh.read(chunk, 0, want, pos);
|
|
2284
|
+
if (bytesRead <= 0) break;
|
|
2285
|
+
pos += bytesRead;
|
|
2286
|
+
const buf = carry.length ? Buffer.concat([carry, chunk.subarray(0, bytesRead)]) : chunk.subarray(0, bytesRead);
|
|
2287
|
+
const lastNl = buf.lastIndexOf(10);
|
|
2288
|
+
if (lastNl < 0) {
|
|
2289
|
+
carry = buf;
|
|
2290
|
+
continue;
|
|
2291
|
+
}
|
|
2292
|
+
let start = 0;
|
|
2293
|
+
while (start <= lastNl) {
|
|
2294
|
+
const nl = buf.indexOf(10, start);
|
|
2295
|
+
let end = nl;
|
|
2296
|
+
if (end > start && buf[end - 1] === 13) end--;
|
|
2297
|
+
if (end > start) onLine(buf.toString("utf8", start, end));
|
|
2298
|
+
start = nl + 1;
|
|
2299
|
+
}
|
|
2300
|
+
consumed += lastNl + 1;
|
|
2301
|
+
carry = buf.subarray(lastNl + 1);
|
|
2302
|
+
}
|
|
2303
|
+
return consumed;
|
|
2304
|
+
};
|
|
2305
|
+
var readAnchor = async (fh, offset) => {
|
|
2306
|
+
if (offset <= 0) return "";
|
|
2307
|
+
const start = Math.max(0, offset - ANCHOR_BYTES);
|
|
2308
|
+
const buf = Buffer.alloc(offset - start);
|
|
2309
|
+
const { bytesRead } = await fh.read(buf, 0, buf.length, start);
|
|
2310
|
+
return buf.subarray(0, bytesRead).toString("base64");
|
|
2311
|
+
};
|
|
2312
|
+
var gIndex = globalThis;
|
|
2313
|
+
var states = gIndex.__cockpitTranscriptIndex ?? (gIndex.__cockpitTranscriptIndex = /* @__PURE__ */ new Map());
|
|
2314
|
+
var stateFor = (shardDir) => {
|
|
2315
|
+
let s = states.get(shardDir);
|
|
2316
|
+
if (!s) {
|
|
2317
|
+
s = {
|
|
2318
|
+
entries: /* @__PURE__ */ new Map(),
|
|
2319
|
+
blockedShards: /* @__PURE__ */ new Set(),
|
|
2320
|
+
pendingRemovals: /* @__PURE__ */ new Set(),
|
|
2321
|
+
removalsScheduled: false,
|
|
2322
|
+
pathLocks: /* @__PURE__ */ new Map(),
|
|
2323
|
+
lockUsers: /* @__PURE__ */ new WeakMap(),
|
|
2324
|
+
unpersistedEntries: /* @__PURE__ */ new WeakSet(),
|
|
2325
|
+
readSem: Effect_exports.unsafeMakeSemaphore(READ_CONCURRENCY),
|
|
2326
|
+
bytesParsed: 0,
|
|
2327
|
+
rebuilds: 0,
|
|
2328
|
+
codexHeads: /* @__PURE__ */ new Map(),
|
|
2329
|
+
codexHeadsLoad: null,
|
|
2330
|
+
codexHeadsDirty: false,
|
|
2331
|
+
codexHeadsFlushScheduled: false,
|
|
2332
|
+
codexDirs: /* @__PURE__ */ new Map(),
|
|
2333
|
+
codexById: null,
|
|
2334
|
+
codexHeadReads: 0,
|
|
2335
|
+
codexHeadInflight: /* @__PURE__ */ new Map(),
|
|
2336
|
+
codexWalkInflight: null
|
|
2337
|
+
};
|
|
2338
|
+
states.set(shardDir, s);
|
|
2339
|
+
}
|
|
2340
|
+
return s;
|
|
2341
|
+
};
|
|
2342
|
+
var shardPath = (shardDir, path) => join8(shardDir, `${createHash2("sha1").update(path).digest("hex").slice(0, 24)}.json`);
|
|
2343
|
+
var entrySizes = /* @__PURE__ */ new WeakMap();
|
|
2344
|
+
var entryBytes = (e) => {
|
|
2345
|
+
const known = entrySizes.get(e);
|
|
2346
|
+
if (known !== void 0) return known;
|
|
2347
|
+
let bytes = 512 + 2 * (e.path.length + (e.cwd?.length ?? 0) + e.aiTitle.length + e.summary.length + e.anchor.length + JSON.stringify(e.stats).length);
|
|
2348
|
+
for (const turn of e.userTurns) {
|
|
2349
|
+
bytes += 96 + 2 * (turn.listText?.length ?? 0);
|
|
2350
|
+
for (const text of turn.blocks) bytes += 16 + 2 * text.length;
|
|
2351
|
+
}
|
|
2352
|
+
for (const line of e.corpus) bytes += 64 + 2 * line.text.length;
|
|
2353
|
+
for (const pr of e.pullRequests) bytes += 128 + 2 * (pr.url.length + (pr.title?.length ?? 0));
|
|
2354
|
+
entrySizes.set(e, bytes);
|
|
2355
|
+
return bytes;
|
|
2356
|
+
};
|
|
2357
|
+
var cacheBytes = (s) => [...s.entries.values()].reduce((sum, entry) => sum + entryBytes(entry), 0);
|
|
2358
|
+
var retainEntry = (s, entry, cache) => {
|
|
2359
|
+
if (cache === "scan" && !s.entries.has(entry.path)) return;
|
|
2360
|
+
if (entryBytes(entry) > CACHE_MAX_BYTES) {
|
|
2361
|
+
s.entries.delete(entry.path);
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
if (cache === "retain") s.entries.delete(entry.path);
|
|
2365
|
+
s.entries.set(entry.path, entry);
|
|
2366
|
+
let bytes = cacheBytes(s);
|
|
2367
|
+
while (s.entries.size > CACHE_MAX_FILES || bytes > CACHE_MAX_BYTES) {
|
|
2368
|
+
const [path, oldest] = s.entries.entries().next().value;
|
|
2369
|
+
s.entries.delete(path);
|
|
2370
|
+
bytes -= entryBytes(oldest);
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
var withPathLock = (s, path, eff) => Effect_exports.suspend(() => {
|
|
2374
|
+
let sem = s.pathLocks.get(path);
|
|
2375
|
+
if (!sem) {
|
|
2376
|
+
sem = Effect_exports.unsafeMakeSemaphore(1);
|
|
2377
|
+
s.pathLocks.set(path, sem);
|
|
2378
|
+
}
|
|
2379
|
+
const lock = sem;
|
|
2380
|
+
s.lockUsers.set(lock, (s.lockUsers.get(lock) ?? 0) + 1);
|
|
2381
|
+
return lock.withPermits(1)(eff).pipe(Effect_exports.ensuring(Effect_exports.sync(() => {
|
|
2382
|
+
const remaining = s.lockUsers.get(lock) - 1;
|
|
2383
|
+
s.lockUsers.set(lock, remaining);
|
|
2384
|
+
if (remaining === 0 && s.pathLocks.get(path) === lock) s.pathLocks.delete(path);
|
|
2385
|
+
})));
|
|
2386
|
+
});
|
|
2387
|
+
var loadShard = async (shardDir, path) => {
|
|
2388
|
+
try {
|
|
2389
|
+
const e = JSON.parse(await readFile4(shardPath(shardDir, path), "utf8"));
|
|
2390
|
+
return e.v === TRANSCRIPT_INDEX_VERSION && e.path === path ? e : null;
|
|
2391
|
+
} catch {
|
|
2392
|
+
return null;
|
|
2393
|
+
}
|
|
2394
|
+
};
|
|
2395
|
+
var flushRemovals = (shardDir, s) => Effect_exports.gen(function* () {
|
|
2396
|
+
s.removalsScheduled = false;
|
|
2397
|
+
const paths = [...s.pendingRemovals];
|
|
2398
|
+
s.pendingRemovals.clear();
|
|
2399
|
+
yield* Effect_exports.forEach(
|
|
2400
|
+
paths,
|
|
2401
|
+
(p) => withPathLock(s, p, Effect_exports.suspend(() => {
|
|
2402
|
+
if (!s.blockedShards.has(p)) return Effect_exports.void;
|
|
2403
|
+
const file = shardPath(shardDir, p);
|
|
2404
|
+
return Effect_exports.tryPromise({
|
|
2405
|
+
try: () => rm2(file, { force: true }),
|
|
2406
|
+
catch: (cause) => new FSError({ path: file, op: "rm", cause })
|
|
2407
|
+
}).pipe(
|
|
2408
|
+
Effect_exports.tap(() => Effect_exports.sync(() => s.blockedShards.delete(p))),
|
|
2409
|
+
// Keep it pending: the next cleanup retries.
|
|
2410
|
+
Effect_exports.catchAll(
|
|
2411
|
+
(err) => Effect_exports.sync(() => s.pendingRemovals.add(p)).pipe(
|
|
2412
|
+
Effect_exports.zipRight(Effect_exports.logWarning("transcript index: shard removal failed").pipe(Effect_exports.annotateLogs({ path: err.path })))
|
|
2413
|
+
)
|
|
2414
|
+
)
|
|
2415
|
+
);
|
|
2416
|
+
})),
|
|
2417
|
+
{ concurrency: 4, discard: true }
|
|
2418
|
+
);
|
|
2419
|
+
});
|
|
2420
|
+
var scheduleShardRemoval = (shardDir, s, path) => {
|
|
2421
|
+
s.pendingRemovals.add(path);
|
|
2422
|
+
if (s.removalsScheduled) return;
|
|
2423
|
+
s.removalsScheduled = true;
|
|
2424
|
+
Effect_exports.runFork(Effect_exports.sleep(FLUSH_DELAY).pipe(Effect_exports.zipRight(flushRemovals(shardDir, s))));
|
|
2425
|
+
};
|
|
2426
|
+
var refreshFile = async (shardDir, s, path, format) => {
|
|
2427
|
+
const generation = transcriptGeneration(path);
|
|
2428
|
+
let st;
|
|
2429
|
+
try {
|
|
2430
|
+
st = await stat3(path);
|
|
2431
|
+
} catch {
|
|
2432
|
+
if (s.entries.delete(path)) {
|
|
2433
|
+
s.blockedShards.add(path);
|
|
2434
|
+
scheduleShardRemoval(shardDir, s, path);
|
|
2435
|
+
}
|
|
2436
|
+
return null;
|
|
2437
|
+
}
|
|
2438
|
+
const found = s.entries.get(path) ?? (!s.blockedShards.has(path) ? await loadShard(shardDir, path) : null);
|
|
2439
|
+
const prev = found && found.format === format && found.v === TRANSCRIPT_INDEX_VERSION && found.ino === st.ino ? found : void 0;
|
|
2440
|
+
if (prev && prev.size === st.size && prev.mtimeMs === st.mtimeMs) return { entry: prev, changed: false, generation };
|
|
2441
|
+
const fh = await open3(path, "r");
|
|
2442
|
+
try {
|
|
2443
|
+
let rebuild = !prev || st.size < prev.offset || st.size === prev.size;
|
|
2444
|
+
if (prev && !rebuild && prev.offset > 0 && await readAnchor(fh, prev.offset) !== prev.anchor) rebuild = true;
|
|
2445
|
+
const next = !prev || rebuild ? emptyEntry(path, format, st.ino) : cloneEntry(prev);
|
|
2446
|
+
if (rebuild) s.rebuilds++;
|
|
2447
|
+
const consumed = await forEachLine(fh, next.offset, st.size, (line) => {
|
|
2448
|
+
if (!foldLine(next, format, line)) next.skippedLines++;
|
|
2449
|
+
});
|
|
2450
|
+
s.bytesParsed += consumed;
|
|
2451
|
+
next.offset += consumed;
|
|
2452
|
+
next.size = st.size;
|
|
2453
|
+
next.mtimeMs = st.mtimeMs;
|
|
2454
|
+
next.anchor = await readAnchor(fh, next.offset);
|
|
2455
|
+
return { entry: next, changed: true, generation };
|
|
2456
|
+
} finally {
|
|
2457
|
+
await fh.close();
|
|
2458
|
+
}
|
|
2459
|
+
};
|
|
2460
|
+
var piSnapshot = (path) => Effect_exports.gen(function* () {
|
|
2461
|
+
const native = yield* readPiSession(path);
|
|
2462
|
+
const info = yield* Effect_exports.tryPromise({ try: () => stat3(path), catch: (cause) => new FSError({ path, op: "stat", cause }) });
|
|
2463
|
+
const state = emptyFoldState();
|
|
2464
|
+
state.cwd = native.manager.getCwd();
|
|
2465
|
+
state.aiTitle = native.name ?? "";
|
|
2466
|
+
for (const message of native.messages) foldClaudeLine(state, JSON.stringify({ ...message, sessionId: native.manager.getSessionId() }));
|
|
2467
|
+
return { ...state, engine: piSelection(native.entries).engine, path, format: "pi", size: info.size, mtimeMs: info.mtimeMs };
|
|
2468
|
+
}).pipe(Effect_exports.catchAll((error) => Effect_exports.logWarning("Pi transcript read failed", error).pipe(Effect_exports.as(null))));
|
|
2469
|
+
var snapshotImpl = (shardDir, s, path, format, cache = "retain") => format === "pi" ? piSnapshot(path) : withPathLock(
|
|
2470
|
+
s,
|
|
2471
|
+
path,
|
|
2472
|
+
s.readSem.withPermits(1)(
|
|
2473
|
+
Effect_exports.gen(function* () {
|
|
2474
|
+
const result = yield* Effect_exports.tryPromise({
|
|
2475
|
+
try: () => refreshFile(shardDir, s, path, format),
|
|
2476
|
+
catch: (cause) => new FSError({ path, op: "read", cause })
|
|
2477
|
+
});
|
|
2478
|
+
if (!result) return null;
|
|
2479
|
+
const { entry, changed, generation } = result;
|
|
2480
|
+
if (changed || s.unpersistedEntries.has(entry)) {
|
|
2481
|
+
const file = shardPath(shardDir, path);
|
|
2482
|
+
yield* Effect_exports.tryPromise({
|
|
2483
|
+
try: () => writeAtomically(file, JSON.stringify(entry)),
|
|
2484
|
+
catch: (cause) => new FSError({ path: file, op: "write", cause })
|
|
2485
|
+
}).pipe(
|
|
2486
|
+
Effect_exports.tap(() => Effect_exports.sync(() => {
|
|
2487
|
+
s.unpersistedEntries.delete(entry);
|
|
2488
|
+
if (generation === transcriptGeneration(path)) s.blockedShards.delete(path);
|
|
2489
|
+
})),
|
|
2490
|
+
Effect_exports.catchAll((err) => Effect_exports.sync(() => s.unpersistedEntries.add(entry)).pipe(
|
|
2491
|
+
Effect_exports.zipRight(Effect_exports.logWarning("transcript index: shard write failed", err))
|
|
2492
|
+
))
|
|
2493
|
+
);
|
|
2494
|
+
}
|
|
2495
|
+
if (generation !== transcriptGeneration(path)) return null;
|
|
2496
|
+
retainEntry(s, entry, cache);
|
|
2497
|
+
return toSnapshot(entry);
|
|
2498
|
+
})
|
|
2499
|
+
)
|
|
2500
|
+
).pipe(
|
|
2501
|
+
Effect_exports.catchAll(
|
|
2502
|
+
(err) => Effect_exports.logWarning("transcript index: unreadable transcript").pipe(
|
|
2503
|
+
Effect_exports.annotateLogs({ path: err.path }),
|
|
2504
|
+
Effect_exports.as(null)
|
|
2505
|
+
)
|
|
2506
|
+
)
|
|
2507
|
+
);
|
|
2508
|
+
var CODEX_HEADS_FILE = "codex-heads.json";
|
|
2509
|
+
var CODEX_HEADS_VERSION = 2;
|
|
2510
|
+
var HEAD_MAX_BYTES = 1024 * 1024;
|
|
2511
|
+
var CODEX_STAT_CONCURRENCY = 16;
|
|
2512
|
+
var readFirstCompleteLine = async (path) => {
|
|
2513
|
+
const fh = await open3(path, "r");
|
|
2514
|
+
try {
|
|
2515
|
+
const chunks = [];
|
|
2516
|
+
let pos = 0;
|
|
2517
|
+
while (pos < HEAD_MAX_BYTES) {
|
|
2518
|
+
const buf = Buffer.alloc(Math.min(64 * 1024, HEAD_MAX_BYTES - pos));
|
|
2519
|
+
const { bytesRead } = await fh.read(buf, 0, buf.length, pos);
|
|
2520
|
+
if (bytesRead <= 0) return null;
|
|
2521
|
+
const slice = buf.subarray(0, bytesRead);
|
|
2522
|
+
const nl = slice.indexOf(10);
|
|
2523
|
+
if (nl >= 0) {
|
|
2524
|
+
chunks.push(slice.subarray(0, nl));
|
|
2525
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
2526
|
+
}
|
|
2527
|
+
chunks.push(slice);
|
|
2528
|
+
pos += bytesRead;
|
|
2529
|
+
}
|
|
2530
|
+
return null;
|
|
2531
|
+
} finally {
|
|
2532
|
+
await fh.close();
|
|
2533
|
+
}
|
|
2534
|
+
};
|
|
2535
|
+
var canonicalPath = async (p) => {
|
|
2536
|
+
let current = resolve5(p);
|
|
2537
|
+
const rest = [];
|
|
2538
|
+
for (; ; ) {
|
|
2539
|
+
try {
|
|
2540
|
+
const real = await realpath(current);
|
|
2541
|
+
return rest.length > 0 ? join8(real, ...rest.reverse()) : real;
|
|
2542
|
+
} catch {
|
|
2543
|
+
const parent = dirname2(current);
|
|
2544
|
+
if (parent === current) return resolve5(p);
|
|
2545
|
+
rest.push(basename(current));
|
|
2546
|
+
current = parent;
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
};
|
|
2550
|
+
var parseCodexMetaLine = async (line) => {
|
|
2551
|
+
let entry;
|
|
2552
|
+
try {
|
|
2553
|
+
entry = JSON.parse(line);
|
|
2554
|
+
} catch {
|
|
2555
|
+
return null;
|
|
2556
|
+
}
|
|
2557
|
+
const p = entry?.payload;
|
|
2558
|
+
const id = p?.id;
|
|
2559
|
+
const cwd = p?.cwd;
|
|
2560
|
+
if (entry?.type !== "session_meta" || typeof id !== "string" || !id || typeof cwd !== "string" || !cwd) return null;
|
|
2561
|
+
const cwdRealpath = await canonicalPath(cwd);
|
|
2562
|
+
const parent = typeof p.parent_thread_id === "string" ? p.parent_thread_id : "";
|
|
2563
|
+
const isSubagent = p.thread_source === "subagent" || !!parent;
|
|
2564
|
+
return {
|
|
2565
|
+
id,
|
|
2566
|
+
cwd,
|
|
2567
|
+
cwdRealpath,
|
|
2568
|
+
...isSubagent ? {
|
|
2569
|
+
parentThreadId: parent,
|
|
2570
|
+
...typeof p.agent_role === "string" && p.agent_role ? { agentRole: p.agent_role } : {},
|
|
2571
|
+
...typeof p.agent_nickname === "string" && p.agent_nickname ? { agentNickname: p.agent_nickname } : {}
|
|
2572
|
+
} : {}
|
|
2573
|
+
};
|
|
2574
|
+
};
|
|
2575
|
+
var loadCodexHeads = (shardDir, s) => s.codexHeadsLoad ??= (async () => {
|
|
2576
|
+
const persisted = await readFile4(join8(shardDir, CODEX_HEADS_FILE), "utf8").then((raw) => JSON.parse(raw)).catch(() => null);
|
|
2577
|
+
if (persisted?.v !== CODEX_HEADS_VERSION || !persisted.heads || typeof persisted.heads !== "object") return;
|
|
2578
|
+
for (const [path, head] of Object.entries(persisted.heads)) {
|
|
2579
|
+
if (typeof head?.ino !== "number") continue;
|
|
2580
|
+
const meta = head.meta;
|
|
2581
|
+
if (meta !== null && (typeof meta?.id !== "string" || typeof meta.cwd !== "string")) continue;
|
|
2582
|
+
s.codexHeads.set(path, { ino: head.ino, meta });
|
|
2583
|
+
}
|
|
2584
|
+
})();
|
|
2585
|
+
var flushCodexHeads = (shardDir, s) => Effect_exports.gen(function* () {
|
|
2586
|
+
s.codexHeadsFlushScheduled = false;
|
|
2587
|
+
if (!s.codexHeadsDirty) return;
|
|
2588
|
+
s.codexHeadsDirty = false;
|
|
2589
|
+
const file = join8(shardDir, CODEX_HEADS_FILE);
|
|
2590
|
+
const text = JSON.stringify({ v: CODEX_HEADS_VERSION, heads: Object.fromEntries(s.codexHeads) });
|
|
2591
|
+
yield* Effect_exports.tryPromise({
|
|
2592
|
+
try: () => writeAtomically(file, text),
|
|
2593
|
+
catch: (cause) => new FSError({ path: file, op: "write", cause })
|
|
2594
|
+
}).pipe(
|
|
2595
|
+
Effect_exports.catchAll(
|
|
2596
|
+
(err) => Effect_exports.sync(() => {
|
|
2597
|
+
s.codexHeadsDirty = true;
|
|
2598
|
+
}).pipe(Effect_exports.zipRight(Effect_exports.logWarning("transcript index: codex heads write failed").pipe(Effect_exports.annotateLogs({ path: err.path }))))
|
|
2599
|
+
)
|
|
2600
|
+
);
|
|
2601
|
+
});
|
|
2602
|
+
var markCodexHeadsDirty = (shardDir, s) => {
|
|
2603
|
+
s.codexById = null;
|
|
2604
|
+
s.codexHeadsDirty = true;
|
|
2605
|
+
if (s.codexHeadsFlushScheduled) return;
|
|
2606
|
+
s.codexHeadsFlushScheduled = true;
|
|
2607
|
+
Effect_exports.runFork(Effect_exports.sleep(FLUSH_DELAY).pipe(Effect_exports.zipRight(flushCodexHeads(shardDir, s))));
|
|
2608
|
+
};
|
|
2609
|
+
var discover = async (path, op, read) => read().catch((cause) => {
|
|
2610
|
+
if (cause.code === "ENOENT") return null;
|
|
2611
|
+
throw new FSError({ path, op, cause });
|
|
2612
|
+
});
|
|
2613
|
+
var discoveryEffect = (path, read) => Effect_exports.tryPromise({ try: read, catch: (cause) => cause instanceof FSError ? cause : new FSError({ path, op: "read", cause }) });
|
|
2614
|
+
var listCodexRollouts = (s) => s.codexWalkInflight ??= walkCodexRollouts(s).finally(() => {
|
|
2615
|
+
s.codexWalkInflight = null;
|
|
2616
|
+
});
|
|
2617
|
+
var walkCodexRollouts = async (s) => {
|
|
2618
|
+
const out = [];
|
|
2619
|
+
const stack = [CODEX_SESSIONS_DIR];
|
|
2620
|
+
while (stack.length > 0) {
|
|
2621
|
+
const dir = stack.pop();
|
|
2622
|
+
const mtimeMs = (await discover(dir, "stat", () => stat3(dir)))?.mtimeMs ?? null;
|
|
2623
|
+
if (mtimeMs === null) {
|
|
2624
|
+
s.codexDirs.delete(dir);
|
|
2625
|
+
continue;
|
|
2626
|
+
}
|
|
2627
|
+
let listing = s.codexDirs.get(dir);
|
|
2628
|
+
if (!listing || listing.version !== 1 || listing.mtimeMs !== mtimeMs) {
|
|
2629
|
+
const entries = await discover(dir, "read", () => readdir3(dir, { withFileTypes: true }));
|
|
2630
|
+
if (!entries) {
|
|
2631
|
+
s.codexDirs.delete(dir);
|
|
2632
|
+
continue;
|
|
2633
|
+
}
|
|
2634
|
+
listing = {
|
|
2635
|
+
version: 1,
|
|
2636
|
+
mtimeMs,
|
|
2637
|
+
dirs: entries.filter((e) => e.isDirectory()).map((e) => join8(dir, e.name)),
|
|
2638
|
+
files: [...new Set(entries.filter((e) => e.isFile() && (e.name.endsWith(".jsonl") || e.name.endsWith(`.jsonl${CODEX_NO_HISTORY_SUFFIX}`))).map((e) => join8(dir, e.name.endsWith(CODEX_NO_HISTORY_SUFFIX) ? e.name.slice(0, -CODEX_NO_HISTORY_SUFFIX.length) : e.name)))]
|
|
2639
|
+
};
|
|
2640
|
+
s.codexDirs.set(dir, listing);
|
|
2641
|
+
}
|
|
2642
|
+
out.push(...listing.files);
|
|
2643
|
+
stack.push(...listing.dirs);
|
|
2644
|
+
}
|
|
2645
|
+
return out;
|
|
2646
|
+
};
|
|
2647
|
+
var codexHeadFor = async (shardDir, s, path, ino, sourcePath = path) => {
|
|
2648
|
+
const head = s.codexHeads.get(path);
|
|
2649
|
+
if (head?.meta && head.ino === ino) return head.meta;
|
|
2650
|
+
const inflight = s.codexHeadInflight.get(path);
|
|
2651
|
+
if (inflight) return inflight;
|
|
2652
|
+
const read = (async () => {
|
|
2653
|
+
s.codexHeadReads++;
|
|
2654
|
+
const line = await discover(sourcePath, "read", () => readFirstCompleteLine(sourcePath));
|
|
2655
|
+
const meta = line ? await parseCodexMetaLine(line) : null;
|
|
2656
|
+
s.codexHeads.set(path, { ino, meta });
|
|
2657
|
+
markCodexHeadsDirty(shardDir, s);
|
|
2658
|
+
return meta;
|
|
2659
|
+
})().finally(() => s.codexHeadInflight.delete(path));
|
|
2660
|
+
s.codexHeadInflight.set(path, read);
|
|
2661
|
+
return read;
|
|
2662
|
+
};
|
|
2663
|
+
var codexEntry = async (shardDir, s, path) => {
|
|
2664
|
+
const entry = await Effect_exports.runPromise(withTranscriptLayout(path, "codex", (layout) => discoveryEffect(path, async () => {
|
|
2665
|
+
const identity = layout.history ?? layout.current;
|
|
2666
|
+
if (!identity) return null;
|
|
2667
|
+
const source = layout.history ? codexNoHistoryStashPath(path) : path;
|
|
2668
|
+
const meta = await codexHeadFor(shardDir, s, path, identity.ino, source);
|
|
2669
|
+
return meta ? { ...meta, path, modifiedAt: Math.max(layout.current?.mtimeMs ?? 0, layout.history?.mtimeMs ?? 0), size: (layout.current?.size ?? 0) + (layout.history?.size ?? 0) } : null;
|
|
2670
|
+
})));
|
|
2671
|
+
if (!entry && s.codexHeads.delete(path)) markCodexHeadsDirty(shardDir, s);
|
|
2672
|
+
return entry;
|
|
2673
|
+
};
|
|
2674
|
+
var codexSessionsImpl = (shardDir, s) => Effect_exports.gen(function* () {
|
|
2675
|
+
yield* discoveryEffect(shardDir, () => loadCodexHeads(shardDir, s));
|
|
2676
|
+
const files = yield* discoveryEffect(CODEX_SESSIONS_DIR, () => listCodexRollouts(s));
|
|
2677
|
+
const entries = yield* Effect_exports.forEach(files, (path) => discoveryEffect(path, () => codexEntry(shardDir, s, path)), {
|
|
2678
|
+
concurrency: CODEX_STAT_CONCURRENCY
|
|
2679
|
+
});
|
|
2680
|
+
const live = new Set(files);
|
|
2681
|
+
for (const path of s.codexHeads.keys()) {
|
|
2682
|
+
if (!live.has(path)) {
|
|
2683
|
+
s.codexHeads.delete(path);
|
|
2684
|
+
markCodexHeadsDirty(shardDir, s);
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
return entries.filter((e) => e !== null).sort((a, b) => b.modifiedAt - a.modifiedAt);
|
|
2688
|
+
});
|
|
2689
|
+
var codexPathsById = (s, id) => {
|
|
2690
|
+
if (!s.codexById) {
|
|
2691
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2692
|
+
for (const [path, head] of s.codexHeads) {
|
|
2693
|
+
if (!head.meta) continue;
|
|
2694
|
+
const list = byId.get(head.meta.id);
|
|
2695
|
+
if (list) list.push(path);
|
|
2696
|
+
else byId.set(head.meta.id, [path]);
|
|
2697
|
+
}
|
|
2698
|
+
s.codexById = byId;
|
|
2699
|
+
}
|
|
2700
|
+
return s.codexById.get(id) ?? [];
|
|
2701
|
+
};
|
|
2702
|
+
var resolveCodexImpl = (shardDir, s, threadId) => Effect_exports.gen(function* () {
|
|
2703
|
+
const id = normalizeCodexSessionId(threadId);
|
|
2704
|
+
yield* discoveryEffect(shardDir, () => loadCodexHeads(shardDir, s));
|
|
2705
|
+
const fromKnown = async () => {
|
|
2706
|
+
for (const path of codexPathsById(s, id)) {
|
|
2707
|
+
const entry = await codexEntry(shardDir, s, path);
|
|
2708
|
+
if (entry?.id === id) return entry;
|
|
2709
|
+
}
|
|
2710
|
+
return null;
|
|
2711
|
+
};
|
|
2712
|
+
const known = yield* discoveryEffect(CODEX_SESSIONS_DIR, fromKnown);
|
|
2713
|
+
if (known) return known;
|
|
2714
|
+
const files = yield* discoveryEffect(CODEX_SESSIONS_DIR, () => listCodexRollouts(s));
|
|
2715
|
+
const pending = files.filter((f) => !s.codexHeads.get(f)?.meta);
|
|
2716
|
+
yield* Effect_exports.forEach(pending, (path) => discoveryEffect(path, () => codexEntry(shardDir, s, path)), {
|
|
2717
|
+
concurrency: CODEX_STAT_CONCURRENCY,
|
|
2718
|
+
discard: true
|
|
2719
|
+
});
|
|
2720
|
+
return yield* discoveryEffect(CODEX_SESSIONS_DIR, fromKnown);
|
|
2721
|
+
});
|
|
2722
|
+
var invalidateTranscript = (path) => {
|
|
2723
|
+
advanceTranscriptGeneration(path);
|
|
2724
|
+
for (const [shardDir, s] of states) {
|
|
2725
|
+
s.blockedShards.add(path);
|
|
2726
|
+
s.entries.delete(path);
|
|
2727
|
+
scheduleShardRemoval(shardDir, s, path);
|
|
2728
|
+
if (s.codexHeads.delete(path)) markCodexHeadsDirty(shardDir, s);
|
|
2729
|
+
}
|
|
2730
|
+
};
|
|
2731
|
+
var TranscriptIndexLive = Layer_exports.effect(
|
|
2732
|
+
TranscriptIndex,
|
|
2733
|
+
Effect_exports.gen(function* () {
|
|
2734
|
+
const cfg = yield* CockpitConfig;
|
|
2735
|
+
const shardDir = join8(cfg.cockpitDir, "transcript-index");
|
|
2736
|
+
const s = stateFor(shardDir);
|
|
2737
|
+
return TranscriptIndex.of({
|
|
2738
|
+
snapshot: (path, format, cache) => snapshotImpl(shardDir, s, path, format, cache).pipe(Effect_exports.withSpan("transcriptIndex.snapshot")),
|
|
2739
|
+
snapshots: (files) => Effect_exports.forEach(files, (f) => snapshotImpl(shardDir, s, f.path, f.format, "scan"), {
|
|
2740
|
+
concurrency: READ_CONCURRENCY * 2
|
|
2741
|
+
}).pipe(Effect_exports.withSpan("transcriptIndex.snapshots")),
|
|
2742
|
+
codexSessions: codexSessionsImpl(shardDir, s).pipe(Effect_exports.withSpan("transcriptIndex.codexSessions")),
|
|
2743
|
+
resolveCodex: (threadId) => resolveCodexImpl(shardDir, s, threadId).pipe(Effect_exports.withSpan("transcriptIndex.resolveCodex")),
|
|
2744
|
+
invalidate: (path) => Effect_exports.sync(() => invalidateTranscript(path)),
|
|
2745
|
+
counters: Effect_exports.sync(
|
|
2746
|
+
() => ({
|
|
2747
|
+
bytesParsed: s.bytesParsed,
|
|
2748
|
+
rebuilds: s.rebuilds,
|
|
2749
|
+
codexHeadReads: s.codexHeadReads,
|
|
2750
|
+
cachedFiles: s.entries.size,
|
|
2751
|
+
estimatedCacheBytes: cacheBytes(s)
|
|
2752
|
+
})
|
|
2753
|
+
)
|
|
2754
|
+
});
|
|
2755
|
+
})
|
|
2756
|
+
);
|
|
2757
|
+
var runWithTranscriptIndex = (f) => Effect_exports.runPromise(Effect_exports.flatMap(TranscriptIndex, f).pipe(Effect_exports.provide(TranscriptIndexLive)));
|
|
2758
|
+
var findCodexSession = (threadId) => runWithTranscriptIndex((index) => index.resolveCodex(threadId));
|
|
2759
|
+
var codexSessionEntries = Effect_exports.flatMap(
|
|
2760
|
+
TranscriptIndex,
|
|
2761
|
+
(index) => index.codexSessions
|
|
2762
|
+
).pipe(Effect_exports.provide(TranscriptIndexLive));
|
|
2763
|
+
var transcriptSnapshot = (path, format, cache) => Effect_exports.flatMap(TranscriptIndex, (index) => index.snapshot(path, format, cache)).pipe(Effect_exports.provide(TranscriptIndexLive));
|
|
2764
|
+
|
|
2765
|
+
// packages/feature/agent/src/server/api/session/sessionStore.ts
|
|
2766
|
+
async function resolveSessionPath(cwd, sessionId) {
|
|
2767
|
+
const probes = [
|
|
2768
|
+
["grok", async () => /^[a-zA-Z0-9_-]+$/.test(sessionId) ? grokSessionPath(cwd, sessionId) : null],
|
|
2769
|
+
["claude", async () => getClaudeSessionPath(cwd, sessionId)],
|
|
2770
|
+
["codex", async () => (await findCodexSession(sessionId))?.path ?? null]
|
|
2771
|
+
];
|
|
2772
|
+
for (const [engine, locate] of probes) {
|
|
2773
|
+
const sessionPath = await locate();
|
|
2774
|
+
if (sessionPath && (engine === "codex" || await Effect_exports.runPromise(transcriptExists(sessionPath, engine)))) return { sessionPath, engine };
|
|
2775
|
+
}
|
|
2776
|
+
const pi = await Effect_exports.runPromise(findPiSession(cwd, sessionId));
|
|
2777
|
+
return pi ? { sessionPath: pi.path, engine: pi.engine } : null;
|
|
2778
|
+
}
|
|
2779
|
+
function isForkableStore(store) {
|
|
2780
|
+
return store.engine !== "grok";
|
|
2781
|
+
}
|
|
2782
|
+
function newSessionPathInStore(store, cwd, newSessionId) {
|
|
2783
|
+
switch (store.engine) {
|
|
2784
|
+
case "claude":
|
|
2785
|
+
return getClaudeSessionPath(cwd, newSessionId);
|
|
2786
|
+
case "codex": {
|
|
2787
|
+
const now = /* @__PURE__ */ new Date();
|
|
2788
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
2789
|
+
const yyyy = String(now.getFullYear());
|
|
2790
|
+
const mm = pad(now.getMonth() + 1);
|
|
2791
|
+
const dd = pad(now.getDate());
|
|
2792
|
+
const stamp = `${yyyy}-${mm}-${dd}T${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}`;
|
|
2793
|
+
return join9(CODEX_SESSIONS_DIR, yyyy, mm, dd, `rollout-${stamp}-${newSessionId}.jsonl`);
|
|
2794
|
+
}
|
|
2795
|
+
default:
|
|
2796
|
+
return null;
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
export {
|
|
2801
|
+
CockpitConfig,
|
|
2802
|
+
ConfigLive,
|
|
2803
|
+
encodePath,
|
|
2804
|
+
COCKPIT_DIR,
|
|
2805
|
+
GROK_SESSIONS_DIR,
|
|
2806
|
+
COCKPIT_PROJECTS_DIR,
|
|
2807
|
+
GLOBAL_STATE_FILE,
|
|
2808
|
+
PINNED_SESSIONS_FILE,
|
|
2809
|
+
PUSH_SUBSCRIPTIONS_FILE,
|
|
2810
|
+
PUSH_VAPID_FILE,
|
|
2811
|
+
SCHEDULED_TASKS_FILE,
|
|
2812
|
+
SETTINGS_FILE,
|
|
2813
|
+
SKILLS_FILE,
|
|
2814
|
+
BOTS_FILE,
|
|
2815
|
+
SESSION_BOTS_FILE,
|
|
2816
|
+
BOTS_DIR,
|
|
2817
|
+
BUILTIN_SKILLS_SRC_DIR,
|
|
2818
|
+
BUILTIN_BOTS_SRC_DIR,
|
|
2819
|
+
CLAUDE_PROJECTS_DIR,
|
|
2820
|
+
DEEPSEEK_CREDENTIALS_FILE,
|
|
2821
|
+
KIMI_CREDENTIALS_FILE,
|
|
2822
|
+
GLM_CREDENTIALS_FILE,
|
|
2823
|
+
OLLAMA_CONFIG_FILE,
|
|
2824
|
+
tightenSecretFiles,
|
|
2825
|
+
tightenPrivateData,
|
|
2826
|
+
getCockpitProjectDir,
|
|
2827
|
+
getSessionFilePath,
|
|
2828
|
+
getTerminalHistoryPath,
|
|
2829
|
+
getTerminalOutputPath,
|
|
2830
|
+
getBubbleOrderPath,
|
|
2831
|
+
getClaudeSessionPath,
|
|
2832
|
+
CODEX_SESSIONS_DIR,
|
|
2833
|
+
normalizeCodexSessionId,
|
|
2834
|
+
ensureParentDir,
|
|
2835
|
+
readJsonFile,
|
|
2836
|
+
readJsonFileForUpdate,
|
|
2837
|
+
writeJsonFile,
|
|
2838
|
+
withFileLock,
|
|
2839
|
+
mutateJsonFile,
|
|
2840
|
+
isPiEngine,
|
|
2841
|
+
PI_AGENT_DIR,
|
|
2842
|
+
PI_SESSIONS_DIR,
|
|
2843
|
+
getPiSessionsDir,
|
|
2844
|
+
isPiSessionPath,
|
|
2845
|
+
createPiRunUsage,
|
|
2846
|
+
piRunEvents,
|
|
2847
|
+
readPiEntries,
|
|
2848
|
+
readPiManager,
|
|
2849
|
+
piSelection,
|
|
2850
|
+
findPiSession,
|
|
2851
|
+
readPiSession,
|
|
2852
|
+
readPiModel,
|
|
2853
|
+
noHistoryStashPath,
|
|
2854
|
+
CODEX_NO_HISTORY_SUFFIX,
|
|
2855
|
+
codexNoHistoryStashPath,
|
|
2856
|
+
transcriptFormat,
|
|
2857
|
+
transcriptStashPath,
|
|
2858
|
+
readJsonOr,
|
|
2859
|
+
writeAtomically,
|
|
2860
|
+
sentOriginLine,
|
|
2861
|
+
delegatedOriginLine,
|
|
2862
|
+
parseMessageOrigin,
|
|
2863
|
+
footerHeader,
|
|
2864
|
+
humanUserText,
|
|
2865
|
+
generateTitle,
|
|
2866
|
+
generateCodexTitle,
|
|
2867
|
+
CODEX_IMAGE_ONLY_TEXT,
|
|
2868
|
+
projectCodexUserMessage,
|
|
2869
|
+
codexPromptText,
|
|
2870
|
+
isCodexSubagent,
|
|
2871
|
+
previewMessages,
|
|
2872
|
+
defaultSessionTitle,
|
|
2873
|
+
transcriptGeneration,
|
|
2874
|
+
identifyTranscriptFile,
|
|
2875
|
+
sameTranscriptFile,
|
|
2876
|
+
withTranscriptLayout,
|
|
2877
|
+
codexUsageToClaude,
|
|
2878
|
+
CODEX_TOOL_NAMES,
|
|
2879
|
+
CODEX_SPAWN_FN_NAME,
|
|
2880
|
+
CODEX_WAIT_FN_NAME,
|
|
2881
|
+
CODEX_AGENT_MESSAGE_TYPE,
|
|
2882
|
+
CODEX_EXEC_SCRIPT_FN_NAME,
|
|
2883
|
+
CODEX_CUSTOM_TOOL_NAMES,
|
|
2884
|
+
normalizeCodexToolName,
|
|
2885
|
+
codexWebSearchCall,
|
|
2886
|
+
parseCodexExecScript,
|
|
2887
|
+
codexExecScriptCall,
|
|
2888
|
+
codexToolOutputText,
|
|
2889
|
+
parseCodexTokenUsage,
|
|
2890
|
+
parseCodexUnknownCall,
|
|
2891
|
+
codexUnknownCallResult,
|
|
2892
|
+
parseCodexSpawnInput,
|
|
2893
|
+
parseCodexSubAgentActivity,
|
|
2894
|
+
parseCodexAgentMessage,
|
|
2895
|
+
codexSpawnDescription,
|
|
2896
|
+
parseCodexSpawnOutput,
|
|
2897
|
+
parseCodexWaitOutput,
|
|
2898
|
+
parseCodexAgentsStates,
|
|
2899
|
+
codexAgentResultText,
|
|
2900
|
+
normalizeCodexToolInput,
|
|
2901
|
+
extractCodexUserContent,
|
|
2902
|
+
codexItemBubble,
|
|
2903
|
+
injectionKind,
|
|
2904
|
+
isHumanTurnStart,
|
|
2905
|
+
queuedPromptAsUserEntry,
|
|
2906
|
+
TRANSCRIPT_INDEX_VERSION,
|
|
2907
|
+
invalidateTranscript,
|
|
2908
|
+
TranscriptIndexLive,
|
|
2909
|
+
findCodexSession,
|
|
2910
|
+
codexSessionEntries,
|
|
2911
|
+
transcriptSnapshot,
|
|
2912
|
+
object,
|
|
2913
|
+
GrokRpcError,
|
|
2914
|
+
GrokAcpClient,
|
|
2915
|
+
grokSessionPath,
|
|
2916
|
+
appendGrokTranscript,
|
|
2917
|
+
resolveSessionPath,
|
|
2918
|
+
isForkableStore,
|
|
2919
|
+
newSessionPathInStore
|
|
2920
|
+
};
|