@skaile/workspaces 3.16.1 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/dist/app-sdk/index.js +1 -1
- package/dist/{asset-feeds-TS76HDGE.js → asset-feeds-FQT6GH24.js} +4 -4
- package/dist/{asset-feeds-TS76HDGE.js.map → asset-feeds-FQT6GH24.js.map} +1 -1
- package/dist/asset-manager/index.js +1 -1
- package/dist/bridge/codex-app-server.d.ts +2 -0
- package/dist/bridge/codex-app-server.js +206 -0
- package/dist/bridge/codex-app-server.js.map +1 -0
- package/dist/bridge/drivers/claude-sdk.js +39 -1
- package/dist/bridge/drivers/claude-sdk.js.map +1 -1
- package/dist/bridge/drivers/codex.js +1 -1
- package/dist/bridge/drivers/continue.js +2 -2
- package/dist/bridge/drivers/echo.js +3 -3
- package/dist/bridge/drivers/echo.js.map +1 -1
- package/dist/bridge/drivers/gemini.js +3 -3
- package/dist/bridge/drivers/goose.js +2 -2
- package/dist/bridge/drivers/omp.js +1 -1
- package/dist/bridge/drivers/opencode.js +2 -2
- package/dist/bridge/drivers/qwen.js +3 -3
- package/dist/bridge/index.js +2 -2
- package/dist/bridge/src/codex/native-protocol.generated.d.ts +1325 -0
- package/dist/bridge/src/codex/native-protocol.generated.d.ts.map +1 -0
- package/dist/bridge/src/codex-app-server.d.ts +55 -0
- package/dist/bridge/src/codex-app-server.d.ts.map +1 -0
- package/dist/bridge/src/drivers/claude-sdk.d.ts +12 -0
- package/dist/bridge/src/drivers/claude-sdk.d.ts.map +1 -1
- package/dist/bridge/src/drivers/echo.d.ts.map +1 -1
- package/dist/{chunk-EVQDXN27.js → chunk-2XGFQKNJ.js} +2 -2
- package/dist/{chunk-EVQDXN27.js.map → chunk-2XGFQKNJ.js.map} +1 -1
- package/dist/{chunk-2KBA5OO2.js → chunk-BCOGOM6F.js} +4 -4
- package/dist/{chunk-2KBA5OO2.js.map → chunk-BCOGOM6F.js.map} +1 -1
- package/dist/{chunk-PCDNZROC.js → chunk-CMGYUF5P.js} +6 -6
- package/dist/{chunk-PCDNZROC.js.map → chunk-CMGYUF5P.js.map} +1 -1
- package/dist/{chunk-775OMGVP.js → chunk-EO7IJY3Q.js} +3 -3
- package/dist/{chunk-775OMGVP.js.map → chunk-EO7IJY3Q.js.map} +1 -1
- package/dist/{chunk-VC2MWHRH.js → chunk-EXT2LNST.js} +4 -4
- package/dist/{chunk-VC2MWHRH.js.map → chunk-EXT2LNST.js.map} +1 -1
- package/dist/{chunk-NIUG3MIH.js → chunk-FRER2PEN.js} +2 -2
- package/dist/{chunk-NIUG3MIH.js.map → chunk-FRER2PEN.js.map} +1 -1
- package/dist/{chunk-4J24AU4Q.js → chunk-HEKLK4NG.js} +3 -3
- package/dist/{chunk-4J24AU4Q.js.map → chunk-HEKLK4NG.js.map} +1 -1
- package/dist/{chunk-OEK2ACRR.js → chunk-KCI7DAKE.js} +145 -44
- package/dist/chunk-KCI7DAKE.js.map +1 -0
- package/dist/{chunk-OGTS7QJX.js → chunk-NIQPSQFN.js} +4 -4
- package/dist/{chunk-OGTS7QJX.js.map → chunk-NIQPSQFN.js.map} +1 -1
- package/dist/{chunk-4W2OOVN5.js → chunk-NMAICJUA.js} +3 -3
- package/dist/{chunk-4W2OOVN5.js.map → chunk-NMAICJUA.js.map} +1 -1
- package/dist/{chunk-5FCBPIOK.js → chunk-PBRMY64S.js} +3 -3
- package/dist/{chunk-5FCBPIOK.js.map → chunk-PBRMY64S.js.map} +1 -1
- package/dist/{chunk-QA52GQQN.js → chunk-PYX4WZLJ.js} +6 -6
- package/dist/{chunk-QA52GQQN.js.map → chunk-PYX4WZLJ.js.map} +1 -1
- package/dist/{chunk-QG6C3XOS.js → chunk-QFYEDM63.js} +3 -3
- package/dist/{chunk-QG6C3XOS.js.map → chunk-QFYEDM63.js.map} +1 -1
- package/dist/{chunk-GP2AYOC2.js → chunk-SWUVULBU.js} +2 -2
- package/dist/{chunk-GP2AYOC2.js.map → chunk-SWUVULBU.js.map} +1 -1
- package/dist/{chunk-6KPCHQP5.js → chunk-VT4MPCRK.js} +3 -3
- package/dist/{chunk-6KPCHQP5.js.map → chunk-VT4MPCRK.js.map} +1 -1
- package/dist/{chunk-U2UNQBXB.js → chunk-X7FJ3ES3.js} +3 -3
- package/dist/{chunk-U2UNQBXB.js.map → chunk-X7FJ3ES3.js.map} +1 -1
- package/dist/cli/index.js +31 -31
- package/dist/connectors/index.js +3 -3
- package/dist/{ensure-sources-I2F6XBDJ.js → ensure-sources-4GBXK6UR.js} +4 -4
- package/dist/{ensure-sources-I2F6XBDJ.js.map → ensure-sources-4GBXK6UR.js.map} +1 -1
- package/dist/factory-assets/connectors/box.js +3 -3
- package/dist/factory-assets/connectors/deploy.js +3 -3
- package/dist/factory-assets/connectors/devserver.js +3 -3
- package/dist/factory-assets/connectors/flow/adapter.js +3 -3
- package/dist/factory-assets/connectors/flow/run-flow.js +4 -4
- package/dist/factory-assets/connectors/flow.js +3 -3
- package/dist/factory-assets/connectors/git.js +3 -3
- package/dist/factory-assets/connectors/gmail.js +3 -3
- package/dist/factory-assets/connectors/googledrive.js +3 -3
- package/dist/factory-assets/connectors/local.js +3 -3
- package/dist/factory-assets/connectors/mattermost.js +3 -3
- package/dist/factory-assets/connectors/memory.js +3 -3
- package/dist/factory-assets/connectors/minio.js +3 -3
- package/dist/factory-assets/connectors/postgres.js +3 -3
- package/dist/factory-assets/connectors/s3.js +3 -3
- package/dist/factory-assets/connectors/sharepoint.js +3 -3
- package/dist/factory-assets/connectors/sqlite.js +3 -3
- package/dist/factory-assets/connectors/static-server.js +3 -3
- package/dist/factory-assets/connectors/tunnel.js +3 -3
- package/dist/factory-assets/connectors/webdav.js +3 -3
- package/dist/factory-assets/connectors/xstate-store.js +3 -3
- package/dist/factory-assets/connectors/xstate.js +3 -3
- package/dist/{helpers-Y66CM6LO.js → helpers-26LW4IXY.js} +4 -4
- package/dist/{helpers-Y66CM6LO.js.map → helpers-26LW4IXY.js.map} +1 -1
- package/dist/{library-publish-SNUOWBUD.js → library-publish-IYGHOPEK.js} +6 -6
- package/dist/{library-publish-SNUOWBUD.js.map → library-publish-IYGHOPEK.js.map} +1 -1
- package/dist/{open-library-IO4TSO2H.js → open-library-HH5LST7Z.js} +5 -5
- package/dist/{open-library-IO4TSO2H.js.map → open-library-HH5LST7Z.js.map} +1 -1
- package/dist/{project-OR524CQ3.js → project-U5QRUCBN.js} +5 -5
- package/dist/{project-OR524CQ3.js.map → project-U5QRUCBN.js.map} +1 -1
- package/dist/runner/index.js +7 -7
- package/dist/runner/src/codex-init.d.ts +14 -0
- package/dist/runner/src/codex-init.d.ts.map +1 -0
- package/dist/runner/src/serve.d.ts.map +1 -1
- package/dist/sdk/asset-manager.js +1 -1
- package/dist/sdk/bridge.js +2 -2
- package/dist/sdk/index.js +7 -7
- package/dist/sdk/runner.js +7 -7
- package/dist/sdk/session.js +2 -2
- package/dist/sdk/types.js +1 -1
- package/dist/session/index.js +2 -2
- package/dist/{setup-5OG442AZ.js → setup-XKTBHRWM.js} +4 -4
- package/dist/{setup-5OG442AZ.js.map → setup-XKTBHRWM.js.map} +1 -1
- package/dist/{source-DTV7VK3C.js → source-ODR4IU6R.js} +6 -6
- package/dist/{source-DTV7VK3C.js.map → source-ODR4IU6R.js.map} +1 -1
- package/dist/{source-manifest-publish-HC3K7D63.js → source-manifest-publish-WCJY3GAM.js} +7 -7
- package/dist/{source-manifest-publish-HC3K7D63.js.map → source-manifest-publish-WCJY3GAM.js.map} +1 -1
- package/dist/tui/index.js +7 -7
- package/dist/types/index.js +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/lifecycle.d.ts +43 -0
- package/dist/types/src/lifecycle.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/workspace-plugin/adapters/mcp.js +1 -1
- package/dist/workspace-plugin/index.js +1 -1
- package/package.json +8 -1
- package/dist/chunk-OEK2ACRR.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.17.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#653](https://github.com/skaile-ai/workspaces/pull/653) [`f648965`](https://github.com/skaile-ai/workspaces/commit/f64896576ecea955c540494033745e6a301252ba) Thanks [@peteralbert](https://github.com/peteralbert)! - Add a narrow production Codex App Server stdio client derived from the retained native protocol, with bounded requests, native callbacks and safe terminal disposal. Extend protocol 3.11 with optional runtime feature requirements, explicit OpenAI auth mode, dedicated AI credential delivery and subscription refresh contracts. Unsupported managed Codex initialization fails before credentials are consumed; existing Claude and standalone Codex behavior remains unchanged. This does not advertise or enable a Codex runtime.
|
|
8
|
+
|
|
9
|
+
## 3.16.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#650](https://github.com/skaile-ai/workspaces/pull/650) [`49a4659`](https://github.com/skaile-ai/workspaces/commit/49a4659d64eadb40f56e443815f9036326369a5f) Thanks [@Frozen666](https://github.com/Frozen666)! - Line-anchor the echo driver's `[test-cap:<name>]` sentinel so it survives host
|
|
14
|
+
prompt decoration (skaile-ai/platform#1053).
|
|
15
|
+
|
|
16
|
+
Hosts decorate outbound user messages, so the keyword never sat at string
|
|
17
|
+
start and the old message-anchored `/^\s*\[test-cap:…\]\s*(.*)$/s` never fired
|
|
18
|
+
— leaving the capability-dispatch seam unreachable from an e2e. This is the
|
|
19
|
+
same bug `[test-flow]` had, and it gets the same fix that shipped in [#401](https://github.com/skaile-ai/workspaces/issues/401):
|
|
20
|
+
`/^[ \t]*\[test-cap:([\w.\-_]+)\][ \t]*(.*)$/m`, matching a line that _begins_
|
|
21
|
+
with the exact token.
|
|
22
|
+
|
|
23
|
+
Dropping the `s` flag is load-bearing, not cosmetic: under dotAll the greedy
|
|
24
|
+
`(.*)$` swallows the trailing `\n</user_message>` into the JSON body, so
|
|
25
|
+
`JSON.parse` throws and the capability input silently degrades to `{}`
|
|
26
|
+
(`invalid_input` for `platform.open_file`). `[ \t]` rather than `\s` keeps the
|
|
27
|
+
token anchored to its own line.
|
|
28
|
+
|
|
29
|
+
Dropping `s` also narrows the body to a SINGLE line: a pretty-printed,
|
|
30
|
+
multi-line JSON body used to parse under dotAll and now degrades to `{}`. No
|
|
31
|
+
in-repo caller does that, but callers must keep the JSON on the sentinel's own
|
|
32
|
+
line.
|
|
33
|
+
|
|
34
|
+
Callers arm the sentinel on its own line — send `"\n[test-cap:…] {json}\n"` —
|
|
35
|
+
exactly as the platform's `flow-persistence.spec.ts` already does for
|
|
36
|
+
`[test-flow]`; a bare sentinel is inline with the `<user_message>` wrapper and
|
|
37
|
+
does not arm.
|
|
38
|
+
|
|
39
|
+
- [#644](https://github.com/skaile-ai/workspaces/pull/644) [`9eb4884`](https://github.com/skaile-ai/workspaces/commit/9eb4884b548f9b6556d874f04d0551c9be570c76) Thanks [@Frozen666](https://github.com/Frozen666)! - Report per-phase elapsed ms across the session wake path, so the wall-clock of a
|
|
40
|
+
tier-1 resume can be attributed for the first time (skaile-ai/workspaces#421).
|
|
41
|
+
|
|
42
|
+
A resume of a large conversation can hold a queued prompt for minutes, and none
|
|
43
|
+
of that time was accounted for anywhere: `serve.ts` carried no elapsed-ms
|
|
44
|
+
instrumentation at all, so the second session build and the SDK replaying the
|
|
45
|
+
transcript were indistinguishable from a log. The runner now reports
|
|
46
|
+
`session_build`, `session_recreate`, `session_rebuild` (split into dispose and
|
|
47
|
+
create), `session_ready`, `prompt_gate_wait` and `driver_start` under a uniform
|
|
48
|
+
`phase` field; the claude-sdk driver reports `transcript_scrub` and
|
|
49
|
+
`query_first_message`, the two costs that sit past the readiness gate.
|
|
50
|
+
|
|
51
|
+
Observability only — no behaviour change. The double build this measures is
|
|
52
|
+
still there: the resume hint reaches the session only through the recreate,
|
|
53
|
+
because the honor/reject capability signature needs the first build's wired
|
|
54
|
+
registry.
|
|
55
|
+
|
|
3
56
|
## 3.16.1
|
|
4
57
|
|
|
5
58
|
### Patch Changes
|
package/dist/app-sdk/index.js
CHANGED
|
@@ -65,7 +65,7 @@ async function libraryAssets() {
|
|
|
65
65
|
const domains = [];
|
|
66
66
|
try {
|
|
67
67
|
const [{ openLibraryManager }, { skaileHomeDir }, { getGlobalCacheDir }] = await Promise.all([
|
|
68
|
-
import('./open-library-
|
|
68
|
+
import('./open-library-HH5LST7Z.js'),
|
|
69
69
|
import('./library/index.js'),
|
|
70
70
|
import('./core/index.js')
|
|
71
71
|
]);
|
|
@@ -98,7 +98,7 @@ async function libraryAssets() {
|
|
|
98
98
|
async function storeAssets(projectDir) {
|
|
99
99
|
const notes = [];
|
|
100
100
|
try {
|
|
101
|
-
const { resolveCatalogSource } = await import('./open-library-
|
|
101
|
+
const { resolveCatalogSource } = await import('./open-library-HH5LST7Z.js');
|
|
102
102
|
const { source, close } = await resolveCatalogSource({ projectDir });
|
|
103
103
|
try {
|
|
104
104
|
const assets = await source.listAssets();
|
|
@@ -202,5 +202,5 @@ function dedupeBySlug(domains) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
export { gatherAssetFeeds };
|
|
205
|
-
//# sourceMappingURL=asset-feeds-
|
|
206
|
-
//# sourceMappingURL=asset-feeds-
|
|
205
|
+
//# sourceMappingURL=asset-feeds-FQT6GH24.js.map
|
|
206
|
+
//# sourceMappingURL=asset-feeds-FQT6GH24.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../cli/src/asset-feeds.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAqFA,SAAS,QAAQ,CAAA,EAAmB;AAClC,EAAA,OAAO,CAAA,CAAE,KAAA,CAAW,IAAA,CAAA,GAAG,CAAA,CAAE,KAAK,GAAG,CAAA;AACnC;AAGA,eAAe,cAAc,IAAA,EAAmC;AAC9D,EAAA,MAAM,MAAkB,EAAC;AACzB,EAAA,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AO,CAAC,GAAG,IAAA,CAAK,KAAA,EAAO,GAAG,KAAA,CAAM,KAAA,EAAO,GAAG,OAAA,CAAQ,KAAK;AAAA,GACzD;AACF;AAGA,SAAS,aAAa,OAAA,EAA2C;AAC/D,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,MAAuB,EAAC;AAC9B,EAAA,KAAA,MAAW,KAAK,OAAA,EAAS;AACvB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,CAAE,IAAI,CAAA,EAAG;AACtB,IAAA,IAAA,CAAK,GAAA,CAAI,EAAE,IAAI,CAAA;AACf,IAAA,GAAA,CAAI,KAAK,CAAC,CAAA;AAAA,EACZ;AACA,EAAA,OAAO,GAAA;AACT","file":"asset-feeds-TS76HDGE.js","sourcesContent":["/**\n * asset-feeds.ts — gather installable assets from every feed the manage TUI\n * surfaces.\n *\n * Four feeds, normalized into `CatalogEntry`:\n * - **Project sources** — `skaile.yaml` `sources:` entries (scanned via\n * `AssetManager.search()`; the new `sources:` field is merged into the\n * legacy repositories map in `AssetManager.loadConfig`).\n * - **Local libraries** — user authoring places from `LocalIndex` (filesystem\n * scan of each library's `path`).\n * - **Factory assets** — the bundled first-party `factory-assets` tree\n * (`factoryAssetRoots()`), scanned from disk. Always present; no network.\n * - **Remote store** — the configured catalog source when `catalog.url` is\n * not `local`. Failures are non-fatal — they surface as notes.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport {\n type AssetKind,\n type CatalogDomain,\n type CatalogEntry,\n factoryAssetRoots,\n parseFrontmatter,\n scanRepo,\n walkDir,\n} from \"@skaile/workspaces/core\";\nimport {\n assignDomain,\n buildDomainIndex,\n DOMAIN_MD_FILENAME,\n type DomainMd,\n parseDomainMd,\n} from \"@skaile/workspaces/discovery\";\n\n/** One non-fatal note returned to the caller for surfacing in the UI. */\nexport interface FeedNote {\n feed: \"sources\" | \"libraries\" | \"store\" | \"factory\";\n message: string;\n}\n\n/**\n * Which feed an asset came from. This is the top-level grouping axis in the\n * manage TUI (\"where is this skill coming from?\") and is intentionally distinct\n * from `publisher` (asset-intrinsic identity): the same publisher can legitimately\n * appear under more than one origin (e.g. a github repo you added as a `source`\n * that is also listed in the remote `store`).\n */\nexport type AssetOrigin = \"source\" | \"library\" | \"factory\" | \"store\";\n\n/** A catalog entry tagged with the feed it was gathered from. */\nexport interface OriginEntry {\n origin: AssetOrigin;\n entry: CatalogEntry;\n /**\n * Second-level grouping label for the manage tree. Defaults (when unset) to the\n * entry's `publisher`; the source feed sets it to the source's short repo name\n * so the Sources band groups by source — \"which repo did this come from\" — not\n * by the asset-intrinsic publisher.\n */\n group?: string;\n}\n\nexport interface AssetFeedResult {\n entries: OriginEntry[];\n /**\n * Display-only domain metadata, keyed (by the consumer) on `slug`. Populated\n * from the store's `catalog.listDomains` when the connected catalog source\n * exposes it; empty otherwise. The manage TUI joins `entry.domainSlug` → a\n * domain for grouping headers, descriptions, and relation badges.\n */\n domains: CatalogDomain[];\n notes: FeedNote[];\n}\n\n// ── Domain stamping (on-disk feeds) ──────────────────────────────────────────\n//\n// `scanRepo` (the source / library / factory scan path) does not read the\n// `DOMAIN.md` sidecars, so its entries arrive with no `domainSlug` and render\n// flat under their publisher band. We re-derive the grouping here from the\n// root's `DOMAIN.md` files (the same sidecars the remote store computes\n// server-side), and fall back to the repo/source name for any entry no domain\n// claims so it still groups instead of landing in the synthetic \"no domain\" pile.\n\n/** Repo-relative POSIX path (DOMAIN.md slugs are matched whole-segment, `/`-joined). */\nfunction toPosix(p: string): string {\n return p.split(path.sep).join(\"/\");\n}\n\n/** Parse every `DOMAIN.md` sidecar under `root` into a {@link DomainMd}. */\nasync function loadDomainMds(root: string): Promise<DomainMd[]> {\n const out: DomainMd[] = [];\n for await (const { path: filePath, name } of walkDir(root)) {\n if (name !== DOMAIN_MD_FILENAME) continue;\n try {\n const { data } = parseFrontmatter(readFileSync(filePath, \"utf8\"));\n out.push(parseDomainMd(toPosix(path.relative(root, filePath)), data));\n } catch {}\n }\n return out;\n}\n\n/**\n * Stamp `domainSlug` onto every entry scanned from `root` using the root's\n * `DOMAIN.md` sidecars. Returns the `CatalogDomain` registry for the real\n * domains, plus a synthetic fallback domain when any entry used the fallback.\n * Mutates `entries` in place (sets `entry.domainSlug`).\n *\n * `synthesizeFallback` (default true): entries no domain claims fall back to\n * `fallbackSlug` (the repo/source name). Pass `false` when the caller already\n * groups these entries one level up (e.g. the source feed groups by source\n * node) — unmatched entries then get no domain (`\"\"`) and hang directly under\n * that parent, instead of nesting under a same-named fallback domain.\n */\nasync function stampDomains(\n root: string,\n fallbackSlug: string,\n entries: CatalogEntry[],\n synthesizeFallback = true,\n): Promise<CatalogDomain[]> {\n const domainMds = await loadDomainMds(root);\n const assignables = entries.map((entry) => ({\n entry,\n ref: `${entry.kind}:${entry.name}`,\n relativePath: toPosix(path.relative(root, entry.source)),\n }));\n\n let usedFallback = false;\n for (const a of assignables) {\n const slug = assignDomain(a.relativePath, domainMds);\n if (slug) a.entry.domainSlug = slug;\n else if (synthesizeFallback) {\n a.entry.domainSlug = fallbackSlug;\n usedFallback = true;\n } else a.entry.domainSlug = \"\";\n }\n\n const { index } = buildDomainIndex(assignables, domainMds);\n const catalog: CatalogDomain[] = Object.values(index).map((d) => ({\n slug: d.slug,\n title: d.title,\n ...(d.description ? { description: d.description } : {}),\n ...(d.relation ? { relation: d.relation } : {}),\n ...(d.order !== undefined ? { order: d.order } : {}),\n ...(d.recommended[0] ? { recommendedRef: d.recommended[0] } : {}),\n }));\n if (usedFallback) catalog.push({ slug: fallbackSlug, title: fallbackSlug });\n return catalog;\n}\n\n/**\n * Pull assets from local libraries (the authoring places under\n * `~/.skaile/libraries/<name>/`, not the `~/.skaile/cache/sources/` cache). Each\n * library's `path` is scanned with `scanRepo` and grouped under the bare library\n * name (`group: <name>`) so the manage TUI shows a clean `<name>` band — no\n * `library:` prefix and no redundant same-named fallback domain (mirrors the\n * source feed).\n */\nasync function libraryAssets(): Promise<{\n entries: OriginEntry[];\n domains: CatalogDomain[];\n notes: FeedNote[];\n}> {\n const notes: FeedNote[] = [];\n const domains: CatalogDomain[] = [];\n try {\n const [{ openLibraryManager }, { skaileHomeDir }, { getGlobalCacheDir }] = await Promise.all([\n import(\"./open-library.ts\"),\n import(\"@skaile/workspaces/library\"),\n import(\"@skaile/workspaces/core\"),\n ]);\n const { manager, close } = await openLibraryManager();\n try {\n // Authoring libraries are the rows that are NOT source clones. index.db\n // rows predating the cache migration still carry the legacy\n // ~/.skaile/sources path, so exclude both roots.\n const newRoot = getGlobalCacheDir();\n const legacyRoot = path.join(skaileHomeDir(), \"sources\");\n const libs = (await manager.listLibraries()).filter(\n (l) => !l.path.startsWith(newRoot) && !l.path.startsWith(legacyRoot),\n );\n const entries: OriginEntry[] = [];\n for (const lib of libs) {\n if (!existsSync(lib.path)) continue;\n // Scan + group under the bare library name. `synthesizeFallback: false`\n // (as the source feed does) keeps domainless assets directly under the\n // library band instead of a redundant same-named fallback domain.\n const libEntries = [...(await scanRepo(lib.path, lib.name))];\n domains.push(...(await stampDomains(lib.path, lib.name, libEntries, false)));\n for (const entry of libEntries) entries.push({ origin: \"library\", entry, group: lib.name });\n }\n return { entries, domains, notes };\n } finally {\n close();\n }\n } catch (err) {\n notes.push({\n feed: \"libraries\",\n message: err instanceof Error ? err.message : String(err),\n });\n return { entries: [], domains, notes };\n }\n}\n\n/**\n * Pull a (best-effort) snapshot of the connected remote store catalog.\n *\n * - Returns no entries when the resolved catalog is local-only or the host\n * is unreachable (the failure becomes a note, not an exception).\n * - Maps `CatalogAsset` → `CatalogEntry`, carrying `publisher`, `repo`, and\n * `category` straight through and using `source = \"store://<id>\"`; per-file\n * `source` paths are not available for remote assets so the canonical ref is\n * a stable placeholder.\n */\nasync function storeAssets(projectDir: string): Promise<{\n entries: CatalogEntry[];\n domains: CatalogDomain[];\n notes: FeedNote[];\n}> {\n const notes: FeedNote[] = [];\n try {\n const { resolveCatalogSource } = await import(\"./open-library.ts\");\n const { source, close } = await resolveCatalogSource({ projectDir });\n try {\n const assets = await source.listAssets();\n const entries: CatalogEntry[] = assets.map((a) => ({\n name: a.name,\n kind: (a.kind as AssetKind) ?? \"skill\",\n description: a.description ?? \"\",\n source: `store://${a.id}`,\n publisher: a.publisher,\n repo: a.repo,\n domainSlug: a.domainSlug,\n category: a.category,\n version: a.version,\n requires: [],\n dependencies: [],\n }));\n // Domains are optional on the catalog source — only the store backend\n // (post Part 4 `catalog.listDomains`) exposes them. Duck-type the call so\n // older sources and the local catalog degrade to no domains, not an error.\n const domains = await loadDomains(source);\n return { entries, domains, notes };\n } finally {\n close();\n }\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n // Local-only catalog throws a recognizable message — silence it; absence\n // is the user's choice, not an error.\n if (!/local/i.test(msg)) {\n notes.push({ feed: \"store\", message: msg });\n }\n return { entries: [], domains: [], notes };\n }\n}\n\n/** Optional `listDomains` capability — returns `[]` when the source lacks it. */\nasync function loadDomains(source: unknown): Promise<CatalogDomain[]> {\n const fn = (source as { listDomains?: () => Promise<CatalogDomain[]> }).listDomains;\n if (typeof fn !== \"function\") return [];\n const domains = await fn.call(source);\n return Array.isArray(domains) ? domains : [];\n}\n\n/** The slice of `AssetManager` the source feed needs (kept narrow for tests). */\ninterface AssetManagerLike {\n search: () => Promise<CatalogEntry[]>;\n searchRepoRoots: () => { repoName: string; root: string }[];\n}\n\n/**\n * Project-source feed: leans on `AssetManager.search()`, which now merges\n * `skaile.yaml`'s `sources:` field into the repositories map, then stamps\n * `DOMAIN.md`-derived domain grouping onto the scanned entries via\n * `searchRepoRoots()`.\n */\nasync function sourceAssets(\n am: AssetManagerLike,\n): Promise<{ entries: OriginEntry[]; domains: CatalogDomain[] }> {\n // The bundled factory tree is injected into the repositories map as an implicit\n // source, so `am.search()` returns it too. It has its own `factory` origin band,\n // so drop it here — otherwise the same first-party skills list twice under Sources.\n const factoryPrefixes = factoryAssetRoots().map((r) => (r.endsWith(path.sep) ? r : r + path.sep));\n const isFactoryPath = (p: string) =>\n factoryPrefixes.some((fp) => p === fp.slice(0, -1) || p.startsWith(fp));\n\n const all = (await am.search()).filter((e) => !isFactoryPath(e.source));\n const entries: OriginEntry[] = [];\n const domains: CatalogDomain[] = [];\n // Group each source's entries under the source node (its short repo name), not\n // the publisher: under Sources the navigational question is \"which repo did\n // this come from\". Each entry's `source` (absolute manifest path) lives under\n // exactly one declared root, so group + stamp by prefix. The cache slug is\n // URL-keyed `github.com/<org>/<repo>` — take the trailing segment.\n for (const { repoName, root } of am.searchRepoRoots()) {\n if (isFactoryPath(root)) continue;\n const prefix = root.endsWith(path.sep) ? root : root + path.sep;\n const owned = all.filter((e) => e.source === root || e.source.startsWith(prefix));\n if (owned.length === 0) continue;\n const sourceName = repoName.split(\"/\").pop() || repoName;\n // No synthetic fallback domain — the source node already groups these, so a\n // same-named fallback would just nest the source under itself.\n domains.push(...(await stampDomains(root, sourceName, owned, false)));\n for (const entry of owned) entries.push({ origin: \"source\", entry, group: sourceName });\n }\n return { entries, domains };\n}\n\n/**\n * Factory-asset feed: scan the bundled first-party `factory-assets` tree(s)\n * resolved by `factoryAssetRoots()` (the `SKAILE_FACTORY_ASSETS_DIR` override\n * layer ahead of the bundled tree). Local disk only, no network — the entries are\n * the built-in skills / connectors / bundles that ship with `@skaile/workspaces`.\n * `factoryAssetRoots()` already dedupes, so the env override pointing at the\n * bundled dir collapses to one root.\n */\nasync function factoryAssets(): Promise<{\n entries: CatalogEntry[];\n domains: CatalogDomain[];\n notes: FeedNote[];\n}> {\n const notes: FeedNote[] = [];\n const domains: CatalogDomain[] = [];\n try {\n const entries: CatalogEntry[] = [];\n for (const root of factoryAssetRoots()) {\n const rootEntries = [...(await scanRepo(root, \"skaile-factory\"))];\n domains.push(...(await stampDomains(root, \"skaile-factory\", rootEntries)));\n entries.push(...rootEntries);\n }\n return { entries, domains, notes };\n } catch (err) {\n notes.push({\n feed: \"factory\",\n message: err instanceof Error ? err.message : String(err),\n });\n return { entries: [], domains, notes };\n }\n}\n\n/** Tag a flat entry list with a single origin. */\nfunction tag(origin: AssetOrigin, entries: CatalogEntry[]): OriginEntry[] {\n return entries.map((entry) => ({ origin, entry }));\n}\n\n/**\n * Run all feeds and return a single normalized result.\n *\n * Feeds run in parallel where possible — the store fetch is the slow one\n * (one HTTP call) and is fired alongside the local library walk. The factory\n * scan is local disk only, so it runs inline.\n */\nexport async function gatherAssetFeeds(\n am: AssetManagerLike,\n projectDir: string,\n): Promise<AssetFeedResult> {\n const [libs, store] = await Promise.all([libraryAssets(), storeAssets(projectDir)]);\n const factory = await factoryAssets();\n const src = await sourceAssets(am);\n return {\n entries: [\n ...src.entries,\n ...libs.entries,\n ...tag(\"factory\", factory.entries),\n ...tag(\"store\", store.entries),\n ],\n // Store domains first (server-curated), then the on-disk feeds; dedupe by\n // slug, first-wins, so a store-served domain shadows a same-slug local one.\n domains: dedupeBySlug([...store.domains, ...src.domains, ...libs.domains, ...factory.domains]),\n notes: [...libs.notes, ...store.notes, ...factory.notes],\n };\n}\n\n/** First-wins dedupe of a domain list by `slug`. */\nfunction dedupeBySlug(domains: CatalogDomain[]): CatalogDomain[] {\n const seen = new Set<string>();\n const out: CatalogDomain[] = [];\n for (const d of domains) {\n if (seen.has(d.slug)) continue;\n seen.add(d.slug);\n out.push(d);\n }\n return out;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../cli/src/asset-feeds.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAqFA,SAAS,QAAQ,CAAA,EAAmB;AAClC,EAAA,OAAO,CAAA,CAAE,KAAA,CAAW,IAAA,CAAA,GAAG,CAAA,CAAE,KAAK,GAAG,CAAA;AACnC;AAGA,eAAe,cAAc,IAAA,EAAmC;AAC9D,EAAA,MAAM,MAAkB,EAAC;AACzB,EAAA,WAAA,MAAiB,EAAE,IAAA,EAAM,QAAA,EAAU,MAAK,IAAK,OAAA,CAAQ,IAAI,CAAA,EAAG;AAC1D,IAAA,IA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ACzD;AACF;AAGA,SAAS,aAAa,OAAA,EAA2C;AAC/D,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,MAAuB,EAAC;AAC9B,EAAA,KAAA,MAAW,KAAK,OAAA,EAAS;AACvB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,CAAA,CAAE,IAAI,CAAA,EAAG;AACtB,IAAA,IAAA,CAAK,GAAA,CAAI,EAAE,IAAI,CAAA;AACf,IAAA,GAAA,CAAI,KAAK,CAAC,CAAA;AAAA,EACZ;AACA,EAAA,OAAO,GAAA;AACT","file":"asset-feeds-FQT6GH24.js","sourcesContent":["/**\n * asset-feeds.ts — gather installable assets from every feed the manage TUI\n * surfaces.\n *\n * Four feeds, normalized into `CatalogEntry`:\n * - **Project sources** — `skaile.yaml` `sources:` entries (scanned via\n * `AssetManager.search()`; the new `sources:` field is merged into the\n * legacy repositories map in `AssetManager.loadConfig`).\n * - **Local libraries** — user authoring places from `LocalIndex` (filesystem\n * scan of each library's `path`).\n * - **Factory assets** — the bundled first-party `factory-assets` tree\n * (`factoryAssetRoots()`), scanned from disk. Always present; no network.\n * - **Remote store** — the configured catalog source when `catalog.url` is\n * not `local`. Failures are non-fatal — they surface as notes.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport {\n type AssetKind,\n type CatalogDomain,\n type CatalogEntry,\n factoryAssetRoots,\n parseFrontmatter,\n scanRepo,\n walkDir,\n} from \"@skaile/workspaces/core\";\nimport {\n assignDomain,\n buildDomainIndex,\n DOMAIN_MD_FILENAME,\n type DomainMd,\n parseDomainMd,\n} from \"@skaile/workspaces/discovery\";\n\n/** One non-fatal note returned to the caller for surfacing in the UI. */\nexport interface FeedNote {\n feed: \"sources\" | \"libraries\" | \"store\" | \"factory\";\n message: string;\n}\n\n/**\n * Which feed an asset came from. This is the top-level grouping axis in the\n * manage TUI (\"where is this skill coming from?\") and is intentionally distinct\n * from `publisher` (asset-intrinsic identity): the same publisher can legitimately\n * appear under more than one origin (e.g. a github repo you added as a `source`\n * that is also listed in the remote `store`).\n */\nexport type AssetOrigin = \"source\" | \"library\" | \"factory\" | \"store\";\n\n/** A catalog entry tagged with the feed it was gathered from. */\nexport interface OriginEntry {\n origin: AssetOrigin;\n entry: CatalogEntry;\n /**\n * Second-level grouping label for the manage tree. Defaults (when unset) to the\n * entry's `publisher`; the source feed sets it to the source's short repo name\n * so the Sources band groups by source — \"which repo did this come from\" — not\n * by the asset-intrinsic publisher.\n */\n group?: string;\n}\n\nexport interface AssetFeedResult {\n entries: OriginEntry[];\n /**\n * Display-only domain metadata, keyed (by the consumer) on `slug`. Populated\n * from the store's `catalog.listDomains` when the connected catalog source\n * exposes it; empty otherwise. The manage TUI joins `entry.domainSlug` → a\n * domain for grouping headers, descriptions, and relation badges.\n */\n domains: CatalogDomain[];\n notes: FeedNote[];\n}\n\n// ── Domain stamping (on-disk feeds) ──────────────────────────────────────────\n//\n// `scanRepo` (the source / library / factory scan path) does not read the\n// `DOMAIN.md` sidecars, so its entries arrive with no `domainSlug` and render\n// flat under their publisher band. We re-derive the grouping here from the\n// root's `DOMAIN.md` files (the same sidecars the remote store computes\n// server-side), and fall back to the repo/source name for any entry no domain\n// claims so it still groups instead of landing in the synthetic \"no domain\" pile.\n\n/** Repo-relative POSIX path (DOMAIN.md slugs are matched whole-segment, `/`-joined). */\nfunction toPosix(p: string): string {\n return p.split(path.sep).join(\"/\");\n}\n\n/** Parse every `DOMAIN.md` sidecar under `root` into a {@link DomainMd}. */\nasync function loadDomainMds(root: string): Promise<DomainMd[]> {\n const out: DomainMd[] = [];\n for await (const { path: filePath, name } of walkDir(root)) {\n if (name !== DOMAIN_MD_FILENAME) continue;\n try {\n const { data } = parseFrontmatter(readFileSync(filePath, \"utf8\"));\n out.push(parseDomainMd(toPosix(path.relative(root, filePath)), data));\n } catch {}\n }\n return out;\n}\n\n/**\n * Stamp `domainSlug` onto every entry scanned from `root` using the root's\n * `DOMAIN.md` sidecars. Returns the `CatalogDomain` registry for the real\n * domains, plus a synthetic fallback domain when any entry used the fallback.\n * Mutates `entries` in place (sets `entry.domainSlug`).\n *\n * `synthesizeFallback` (default true): entries no domain claims fall back to\n * `fallbackSlug` (the repo/source name). Pass `false` when the caller already\n * groups these entries one level up (e.g. the source feed groups by source\n * node) — unmatched entries then get no domain (`\"\"`) and hang directly under\n * that parent, instead of nesting under a same-named fallback domain.\n */\nasync function stampDomains(\n root: string,\n fallbackSlug: string,\n entries: CatalogEntry[],\n synthesizeFallback = true,\n): Promise<CatalogDomain[]> {\n const domainMds = await loadDomainMds(root);\n const assignables = entries.map((entry) => ({\n entry,\n ref: `${entry.kind}:${entry.name}`,\n relativePath: toPosix(path.relative(root, entry.source)),\n }));\n\n let usedFallback = false;\n for (const a of assignables) {\n const slug = assignDomain(a.relativePath, domainMds);\n if (slug) a.entry.domainSlug = slug;\n else if (synthesizeFallback) {\n a.entry.domainSlug = fallbackSlug;\n usedFallback = true;\n } else a.entry.domainSlug = \"\";\n }\n\n const { index } = buildDomainIndex(assignables, domainMds);\n const catalog: CatalogDomain[] = Object.values(index).map((d) => ({\n slug: d.slug,\n title: d.title,\n ...(d.description ? { description: d.description } : {}),\n ...(d.relation ? { relation: d.relation } : {}),\n ...(d.order !== undefined ? { order: d.order } : {}),\n ...(d.recommended[0] ? { recommendedRef: d.recommended[0] } : {}),\n }));\n if (usedFallback) catalog.push({ slug: fallbackSlug, title: fallbackSlug });\n return catalog;\n}\n\n/**\n * Pull assets from local libraries (the authoring places under\n * `~/.skaile/libraries/<name>/`, not the `~/.skaile/cache/sources/` cache). Each\n * library's `path` is scanned with `scanRepo` and grouped under the bare library\n * name (`group: <name>`) so the manage TUI shows a clean `<name>` band — no\n * `library:` prefix and no redundant same-named fallback domain (mirrors the\n * source feed).\n */\nasync function libraryAssets(): Promise<{\n entries: OriginEntry[];\n domains: CatalogDomain[];\n notes: FeedNote[];\n}> {\n const notes: FeedNote[] = [];\n const domains: CatalogDomain[] = [];\n try {\n const [{ openLibraryManager }, { skaileHomeDir }, { getGlobalCacheDir }] = await Promise.all([\n import(\"./open-library.ts\"),\n import(\"@skaile/workspaces/library\"),\n import(\"@skaile/workspaces/core\"),\n ]);\n const { manager, close } = await openLibraryManager();\n try {\n // Authoring libraries are the rows that are NOT source clones. index.db\n // rows predating the cache migration still carry the legacy\n // ~/.skaile/sources path, so exclude both roots.\n const newRoot = getGlobalCacheDir();\n const legacyRoot = path.join(skaileHomeDir(), \"sources\");\n const libs = (await manager.listLibraries()).filter(\n (l) => !l.path.startsWith(newRoot) && !l.path.startsWith(legacyRoot),\n );\n const entries: OriginEntry[] = [];\n for (const lib of libs) {\n if (!existsSync(lib.path)) continue;\n // Scan + group under the bare library name. `synthesizeFallback: false`\n // (as the source feed does) keeps domainless assets directly under the\n // library band instead of a redundant same-named fallback domain.\n const libEntries = [...(await scanRepo(lib.path, lib.name))];\n domains.push(...(await stampDomains(lib.path, lib.name, libEntries, false)));\n for (const entry of libEntries) entries.push({ origin: \"library\", entry, group: lib.name });\n }\n return { entries, domains, notes };\n } finally {\n close();\n }\n } catch (err) {\n notes.push({\n feed: \"libraries\",\n message: err instanceof Error ? err.message : String(err),\n });\n return { entries: [], domains, notes };\n }\n}\n\n/**\n * Pull a (best-effort) snapshot of the connected remote store catalog.\n *\n * - Returns no entries when the resolved catalog is local-only or the host\n * is unreachable (the failure becomes a note, not an exception).\n * - Maps `CatalogAsset` → `CatalogEntry`, carrying `publisher`, `repo`, and\n * `category` straight through and using `source = \"store://<id>\"`; per-file\n * `source` paths are not available for remote assets so the canonical ref is\n * a stable placeholder.\n */\nasync function storeAssets(projectDir: string): Promise<{\n entries: CatalogEntry[];\n domains: CatalogDomain[];\n notes: FeedNote[];\n}> {\n const notes: FeedNote[] = [];\n try {\n const { resolveCatalogSource } = await import(\"./open-library.ts\");\n const { source, close } = await resolveCatalogSource({ projectDir });\n try {\n const assets = await source.listAssets();\n const entries: CatalogEntry[] = assets.map((a) => ({\n name: a.name,\n kind: (a.kind as AssetKind) ?? \"skill\",\n description: a.description ?? \"\",\n source: `store://${a.id}`,\n publisher: a.publisher,\n repo: a.repo,\n domainSlug: a.domainSlug,\n category: a.category,\n version: a.version,\n requires: [],\n dependencies: [],\n }));\n // Domains are optional on the catalog source — only the store backend\n // (post Part 4 `catalog.listDomains`) exposes them. Duck-type the call so\n // older sources and the local catalog degrade to no domains, not an error.\n const domains = await loadDomains(source);\n return { entries, domains, notes };\n } finally {\n close();\n }\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n // Local-only catalog throws a recognizable message — silence it; absence\n // is the user's choice, not an error.\n if (!/local/i.test(msg)) {\n notes.push({ feed: \"store\", message: msg });\n }\n return { entries: [], domains: [], notes };\n }\n}\n\n/** Optional `listDomains` capability — returns `[]` when the source lacks it. */\nasync function loadDomains(source: unknown): Promise<CatalogDomain[]> {\n const fn = (source as { listDomains?: () => Promise<CatalogDomain[]> }).listDomains;\n if (typeof fn !== \"function\") return [];\n const domains = await fn.call(source);\n return Array.isArray(domains) ? domains : [];\n}\n\n/** The slice of `AssetManager` the source feed needs (kept narrow for tests). */\ninterface AssetManagerLike {\n search: () => Promise<CatalogEntry[]>;\n searchRepoRoots: () => { repoName: string; root: string }[];\n}\n\n/**\n * Project-source feed: leans on `AssetManager.search()`, which now merges\n * `skaile.yaml`'s `sources:` field into the repositories map, then stamps\n * `DOMAIN.md`-derived domain grouping onto the scanned entries via\n * `searchRepoRoots()`.\n */\nasync function sourceAssets(\n am: AssetManagerLike,\n): Promise<{ entries: OriginEntry[]; domains: CatalogDomain[] }> {\n // The bundled factory tree is injected into the repositories map as an implicit\n // source, so `am.search()` returns it too. It has its own `factory` origin band,\n // so drop it here — otherwise the same first-party skills list twice under Sources.\n const factoryPrefixes = factoryAssetRoots().map((r) => (r.endsWith(path.sep) ? r : r + path.sep));\n const isFactoryPath = (p: string) =>\n factoryPrefixes.some((fp) => p === fp.slice(0, -1) || p.startsWith(fp));\n\n const all = (await am.search()).filter((e) => !isFactoryPath(e.source));\n const entries: OriginEntry[] = [];\n const domains: CatalogDomain[] = [];\n // Group each source's entries under the source node (its short repo name), not\n // the publisher: under Sources the navigational question is \"which repo did\n // this come from\". Each entry's `source` (absolute manifest path) lives under\n // exactly one declared root, so group + stamp by prefix. The cache slug is\n // URL-keyed `github.com/<org>/<repo>` — take the trailing segment.\n for (const { repoName, root } of am.searchRepoRoots()) {\n if (isFactoryPath(root)) continue;\n const prefix = root.endsWith(path.sep) ? root : root + path.sep;\n const owned = all.filter((e) => e.source === root || e.source.startsWith(prefix));\n if (owned.length === 0) continue;\n const sourceName = repoName.split(\"/\").pop() || repoName;\n // No synthetic fallback domain — the source node already groups these, so a\n // same-named fallback would just nest the source under itself.\n domains.push(...(await stampDomains(root, sourceName, owned, false)));\n for (const entry of owned) entries.push({ origin: \"source\", entry, group: sourceName });\n }\n return { entries, domains };\n}\n\n/**\n * Factory-asset feed: scan the bundled first-party `factory-assets` tree(s)\n * resolved by `factoryAssetRoots()` (the `SKAILE_FACTORY_ASSETS_DIR` override\n * layer ahead of the bundled tree). Local disk only, no network — the entries are\n * the built-in skills / connectors / bundles that ship with `@skaile/workspaces`.\n * `factoryAssetRoots()` already dedupes, so the env override pointing at the\n * bundled dir collapses to one root.\n */\nasync function factoryAssets(): Promise<{\n entries: CatalogEntry[];\n domains: CatalogDomain[];\n notes: FeedNote[];\n}> {\n const notes: FeedNote[] = [];\n const domains: CatalogDomain[] = [];\n try {\n const entries: CatalogEntry[] = [];\n for (const root of factoryAssetRoots()) {\n const rootEntries = [...(await scanRepo(root, \"skaile-factory\"))];\n domains.push(...(await stampDomains(root, \"skaile-factory\", rootEntries)));\n entries.push(...rootEntries);\n }\n return { entries, domains, notes };\n } catch (err) {\n notes.push({\n feed: \"factory\",\n message: err instanceof Error ? err.message : String(err),\n });\n return { entries: [], domains, notes };\n }\n}\n\n/** Tag a flat entry list with a single origin. */\nfunction tag(origin: AssetOrigin, entries: CatalogEntry[]): OriginEntry[] {\n return entries.map((entry) => ({ origin, entry }));\n}\n\n/**\n * Run all feeds and return a single normalized result.\n *\n * Feeds run in parallel where possible — the store fetch is the slow one\n * (one HTTP call) and is fired alongside the local library walk. The factory\n * scan is local disk only, so it runs inline.\n */\nexport async function gatherAssetFeeds(\n am: AssetManagerLike,\n projectDir: string,\n): Promise<AssetFeedResult> {\n const [libs, store] = await Promise.all([libraryAssets(), storeAssets(projectDir)]);\n const factory = await factoryAssets();\n const src = await sourceAssets(am);\n return {\n entries: [\n ...src.entries,\n ...libs.entries,\n ...tag(\"factory\", factory.entries),\n ...tag(\"store\", store.entries),\n ],\n // Store domains first (server-curated), then the on-disk feeds; dedupe by\n // slug, first-wins, so a store-served domain shadows a same-slug local one.\n domains: dedupeBySlug([...store.domains, ...src.domains, ...libs.domains, ...factory.domains]),\n notes: [...libs.notes, ...store.notes, ...factory.notes],\n };\n}\n\n/** First-wins dedupe of a domain list by `slug`. */\nfunction dedupeBySlug(domains: CatalogDomain[]): CatalogDomain[] {\n const seen = new Set<string>();\n const out: CatalogDomain[] = [];\n for (const d of domains) {\n if (seen.has(d.slug)) continue;\n seen.add(d.slug);\n out.push(d);\n }\n return out;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AssetManager, FACTORY_SOURCE_URL, MissingManifestError, NON_DEPLOYABLE_KINDS, normalizeRepoUrl, parseCanonicalLockKey, parseRefTolerant, renderMcpServerConfig, softDepName } from '../chunk-
|
|
1
|
+
export { AssetManager, FACTORY_SOURCE_URL, MissingManifestError, NON_DEPLOYABLE_KINDS, normalizeRepoUrl, parseCanonicalLockKey, parseRefTolerant, renderMcpServerConfig, softDepName } from '../chunk-SWUVULBU.js';
|
|
2
2
|
import '../chunk-C4AP3XZB.js';
|
|
3
3
|
import '../chunk-DZ4UZOFB.js';
|
|
4
4
|
import '../chunk-UKJMQZV6.js';
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import '../chunk-NSBPE2FW.js';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
|
|
4
|
+
var CodexAppServerError = class extends Error {
|
|
5
|
+
constructor(code) {
|
|
6
|
+
super(`Codex App Server ${code}`);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.name = "CodexAppServerError";
|
|
9
|
+
}
|
|
10
|
+
code;
|
|
11
|
+
};
|
|
12
|
+
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13
|
+
var validId = (value) => typeof value === "string" || typeof value === "number" && Number.isSafeInteger(value);
|
|
14
|
+
function bound(value, fallback, maximum) {
|
|
15
|
+
const result = value ?? fallback;
|
|
16
|
+
if (!Number.isSafeInteger(result) || result <= 0 || result > maximum)
|
|
17
|
+
throw new CodexAppServerError("protocol");
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
var CodexAppServerClient = class _CodexAppServerClient {
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.timeout = bound(options.requestTimeoutMs, 15e3, 3e5);
|
|
24
|
+
this.callbackTimeout = bound(options.serverRequestTimeoutMs, 3e4, 3e5);
|
|
25
|
+
this.capacity = bound(options.maxPendingRequests, 64, 1024);
|
|
26
|
+
this.frameLimit = bound(options.maxFrameBytes, 1024 * 1024, 16 * 1024 * 1024);
|
|
27
|
+
this.child = spawn(options.command, options.args, {
|
|
28
|
+
cwd: options.cwd,
|
|
29
|
+
env: options.env,
|
|
30
|
+
stdio: "pipe"
|
|
31
|
+
});
|
|
32
|
+
this.closed = new Promise((resolve) => this.child.once("close", () => resolve()));
|
|
33
|
+
this.child.stdout.setEncoding("utf8");
|
|
34
|
+
this.child.stdout.on("data", (chunk) => this.receive(chunk));
|
|
35
|
+
this.child.stderr.resume();
|
|
36
|
+
this.child.on("error", () => this.fail("process"));
|
|
37
|
+
this.child.stdin.on("error", () => this.fail("process"));
|
|
38
|
+
this.child.stdout.on("error", () => this.fail("process"));
|
|
39
|
+
this.child.stderr.on("error", () => this.fail("process"));
|
|
40
|
+
this.child.once("exit", () => this.fail("process"));
|
|
41
|
+
}
|
|
42
|
+
options;
|
|
43
|
+
pending = /* @__PURE__ */ new Map();
|
|
44
|
+
callbacks = /* @__PURE__ */ new Map();
|
|
45
|
+
timeout;
|
|
46
|
+
callbackTimeout;
|
|
47
|
+
capacity;
|
|
48
|
+
frameLimit;
|
|
49
|
+
child;
|
|
50
|
+
closed;
|
|
51
|
+
terminal = false;
|
|
52
|
+
nextId = 1;
|
|
53
|
+
buffer = "";
|
|
54
|
+
/** Spawn and finish the native initialize/initialized handshake before returning. */
|
|
55
|
+
static async connect(options) {
|
|
56
|
+
let client;
|
|
57
|
+
try {
|
|
58
|
+
client = new _CodexAppServerClient(options);
|
|
59
|
+
await client.request("initialize", {
|
|
60
|
+
clientInfo: options.clientInfo,
|
|
61
|
+
capabilities: { experimentalApi: true }
|
|
62
|
+
});
|
|
63
|
+
client.write({ method: "initialized" });
|
|
64
|
+
return client;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
await client?.dispose();
|
|
67
|
+
throw error instanceof CodexAppServerError ? error : new CodexAppServerError("process");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Timeout closes this generation, so late replies can never satisfy a later request. */
|
|
71
|
+
request(method, params) {
|
|
72
|
+
if (this.terminal) return Promise.reject(new CodexAppServerError("closed"));
|
|
73
|
+
if (this.pending.size >= this.capacity)
|
|
74
|
+
return Promise.reject(new CodexAppServerError("capacity"));
|
|
75
|
+
const id = this.nextId++;
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const timer = setTimeout(() => this.fail("timeout"), this.timeout);
|
|
78
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
79
|
+
try {
|
|
80
|
+
this.write({ id, method, params });
|
|
81
|
+
} catch {
|
|
82
|
+
this.fail("protocol");
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** Reject pending work immediately and wait a bounded interval for process shutdown. */
|
|
87
|
+
async dispose() {
|
|
88
|
+
this.fail("closed");
|
|
89
|
+
let timer;
|
|
90
|
+
await Promise.race([
|
|
91
|
+
this.closed,
|
|
92
|
+
new Promise((resolve) => {
|
|
93
|
+
timer = setTimeout(resolve, 1e3);
|
|
94
|
+
})
|
|
95
|
+
]);
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
}
|
|
98
|
+
fail(code) {
|
|
99
|
+
if (this.terminal) return;
|
|
100
|
+
this.terminal = true;
|
|
101
|
+
this.buffer = "";
|
|
102
|
+
for (const request of this.pending.values()) {
|
|
103
|
+
clearTimeout(request.timer);
|
|
104
|
+
request.reject(new CodexAppServerError(code));
|
|
105
|
+
}
|
|
106
|
+
this.pending.clear();
|
|
107
|
+
for (const controller of this.callbacks.values()) controller.abort();
|
|
108
|
+
this.callbacks.clear();
|
|
109
|
+
this.child.kill("SIGKILL");
|
|
110
|
+
try {
|
|
111
|
+
this.options.onClose?.(new CodexAppServerError(code));
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
write(frame) {
|
|
116
|
+
if (this.terminal) throw new CodexAppServerError("closed");
|
|
117
|
+
const line = `${JSON.stringify(frame)}
|
|
118
|
+
`;
|
|
119
|
+
if (Buffer.byteLength(line) > this.frameLimit) throw new CodexAppServerError("protocol");
|
|
120
|
+
this.child.stdin.write(line);
|
|
121
|
+
}
|
|
122
|
+
receive(chunk) {
|
|
123
|
+
if (this.terminal) return;
|
|
124
|
+
this.buffer += chunk;
|
|
125
|
+
try {
|
|
126
|
+
for (; ; ) {
|
|
127
|
+
const end = this.buffer.indexOf("\n");
|
|
128
|
+
if (end < 0) break;
|
|
129
|
+
const line = this.buffer.slice(0, end);
|
|
130
|
+
this.buffer = this.buffer.slice(end + 1);
|
|
131
|
+
if (Buffer.byteLength(line) > this.frameLimit) throw new CodexAppServerError("protocol");
|
|
132
|
+
if (!line.trim()) continue;
|
|
133
|
+
const frame = JSON.parse(line);
|
|
134
|
+
if (!record(frame)) throw new CodexAppServerError("protocol");
|
|
135
|
+
if (typeof frame.method === "string") {
|
|
136
|
+
if ("id" in frame) {
|
|
137
|
+
if (!validId(frame.id)) throw new CodexAppServerError("protocol");
|
|
138
|
+
void this.handleServerRequest(frame.id, frame.method, frame.params);
|
|
139
|
+
} else this.options.onNotification?.(frame.method, frame.params);
|
|
140
|
+
} else {
|
|
141
|
+
if (typeof frame.id !== "number" || !Number.isSafeInteger(frame.id) || "error" in frame === "result" in frame)
|
|
142
|
+
throw new CodexAppServerError("protocol");
|
|
143
|
+
const request = this.pending.get(frame.id);
|
|
144
|
+
if (!request) throw new CodexAppServerError("protocol");
|
|
145
|
+
clearTimeout(request.timer);
|
|
146
|
+
this.pending.delete(frame.id);
|
|
147
|
+
if ("error" in frame) request.reject(new CodexAppServerError("rejected"));
|
|
148
|
+
else request.resolve(frame.result);
|
|
149
|
+
}
|
|
150
|
+
if (this.terminal) return;
|
|
151
|
+
}
|
|
152
|
+
if (Buffer.byteLength(this.buffer) > this.frameLimit)
|
|
153
|
+
throw new CodexAppServerError("protocol");
|
|
154
|
+
} catch {
|
|
155
|
+
this.fail("protocol");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async handleServerRequest(id, method, params) {
|
|
159
|
+
if (this.callbacks.has(id) || this.callbacks.size >= this.capacity)
|
|
160
|
+
return this.fail("protocol");
|
|
161
|
+
const controller = new AbortController();
|
|
162
|
+
this.callbacks.set(id, controller);
|
|
163
|
+
let timer;
|
|
164
|
+
try {
|
|
165
|
+
const handler = Object.hasOwn(this.options.onServerRequest ?? {}, method) ? this.options.onServerRequest?.[method] : void 0;
|
|
166
|
+
if (!handler) throw new CodexAppServerError("rejected");
|
|
167
|
+
const result = await Promise.race([
|
|
168
|
+
Promise.resolve().then(() => {
|
|
169
|
+
if (this.terminal || controller.signal.aborted) throw new CodexAppServerError("closed");
|
|
170
|
+
return handler(
|
|
171
|
+
params,
|
|
172
|
+
controller.signal
|
|
173
|
+
);
|
|
174
|
+
}),
|
|
175
|
+
new Promise((_, reject) => {
|
|
176
|
+
controller.signal.addEventListener(
|
|
177
|
+
"abort",
|
|
178
|
+
() => reject(new CodexAppServerError("closed")),
|
|
179
|
+
{ once: true }
|
|
180
|
+
);
|
|
181
|
+
timer = setTimeout(() => {
|
|
182
|
+
controller.abort();
|
|
183
|
+
reject(new CodexAppServerError("timeout"));
|
|
184
|
+
}, this.callbackTimeout);
|
|
185
|
+
})
|
|
186
|
+
]);
|
|
187
|
+
this.write({ id, result });
|
|
188
|
+
} catch {
|
|
189
|
+
if (!this.terminal) {
|
|
190
|
+
try {
|
|
191
|
+
this.write({ id, error: { code: -32603, message: "Codex client request failed" } });
|
|
192
|
+
} catch {
|
|
193
|
+
this.fail("protocol");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
clearTimeout(timer);
|
|
198
|
+
controller.abort();
|
|
199
|
+
this.callbacks.delete(id);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export { CodexAppServerClient, CodexAppServerError };
|
|
205
|
+
//# sourceMappingURL=codex-app-server.js.map
|
|
206
|
+
//# sourceMappingURL=codex-app-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../bridge/src/codex-app-server.ts"],"names":[],"mappings":";;;AA6BO,IAAM,mBAAA,GAAN,cAAkC,KAAA,CAAM;AAAA,EAC7C,YACW,IAAA,EACT;AACA,IAAA,KAAA,CAAM,CAAA,iBAAA,EAAoB,IAAI,CAAA,CAAE,CAAA;AAFvB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAGT,IAAA,IAAA,CAAK,IAAA,GAAO,qBAAA;AAAA,EACd;AAAA,EAJW,IAAA;AAKb;AAMA,IAAM,MAAA,GAAS,CAAC,KAAA,KACd,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK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YAAA,UAAA,CAAW,KAAA,EAAM;AACjB,YAAA,MAAA,CAAO,IAAI,mBAAA,CAAoB,SAAS,CAAC,CAAA;AAAA,UAC3C,CAAA,EAAG,KAAK,eAAe,CAAA;AAAA,QACzB,CAAC;AAAA,OACF,CAAA;AACD,MAAA,IAAA,CAAK,KAAA,CAAM,EAAE,EAAA,EAAI,MAAA,EAAQ,CAAA;AAAA,IAC3B,CAAA,CAAA,MAAQ;AACN,MAAA,IAAI,CAAC,KAAK,QAAA,EAAU;AAClB,QAAA,IAAI;AACF,UAAA,IAAA,CAAK,KAAA,CAAM,EAAE,EAAA,EAAI,KAAA,EAAO,EAAE,MAAM,CAAA,KAAA,EAAQ,OAAA,EAAS,6BAAA,EAA8B,EAAG,CAAA;AAAA,QACpF,CAAA,CAAA,MAAQ;AACN,UAAA,IAAA,CAAK,KAAK,UAAU,CAAA;AAAA,QACtB;AAAA,MACF;AAAA,IACF,CAAA,SAAE;AACA,MAAA,YAAA,CAAa,KAAK,CAAA;AAClB,MAAA,UAAA,CAAW,KAAA,EAAM;AACjB,MAAA,IAAA,CAAK,SAAA,CAAU,OAAO,EAAE,CAAA;AAAA,IAC1B;AAAA,EACF;AACF","file":"codex-app-server.js","sourcesContent":["import { spawn, type ChildProcessWithoutNullStreams } from \"node:child_process\";\nimport type { NativeRequests, NativeServerRequests } from \"./codex/native-protocol.generated.js\";\n\n/** The retained native request types, exposed only through this client surface. */\nexport type CodexRequestMethod = keyof NativeRequests;\n/** Native callback handlers receive cancellation when their process is disposed. */\nexport type CodexServerRequestHandlers = {\n [M in keyof NativeServerRequests]?: (\n params: NativeServerRequests[M][\"params\"],\n signal: AbortSignal,\n ) => Promise<NativeServerRequests[M][\"result\"]>;\n};\n/** Explicit process inputs keep managed callers from inheriting ambient credentials. */\nexport interface CodexAppServerOptions {\n command: string;\n args: string[];\n cwd: string;\n env: Record<string, string>;\n clientInfo: NativeRequests[\"initialize\"][\"params\"][\"clientInfo\"];\n requestTimeoutMs?: number;\n serverRequestTimeoutMs?: number;\n maxPendingRequests?: number;\n maxFrameBytes?: number;\n onServerRequest?: CodexServerRequestHandlers;\n onNotification?: (method: string, params: unknown) => void;\n /** Exactly once on terminal failure or disposal, even with no RPC pending. */\n onClose?: (error: CodexAppServerError) => void;\n}\n/** Safe error codes never contain stderr, native errors, RPC payloads or credentials. */\nexport class CodexAppServerError extends Error {\n constructor(\n readonly code: \"closed\" | \"process\" | \"protocol\" | \"timeout\" | \"rejected\" | \"capacity\",\n ) {\n super(`Codex App Server ${code}`);\n this.name = \"CodexAppServerError\";\n }\n}\ntype Pending = {\n resolve: (value: unknown) => void;\n reject: (error: CodexAppServerError) => void;\n timer: ReturnType<typeof setTimeout>;\n};\nconst record = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\nconst validId = (value: unknown): value is string | number =>\n typeof value === \"string\" || (typeof value === \"number\" && Number.isSafeInteger(value));\nfunction bound(value: number | undefined, fallback: number, maximum: number): number {\n const result = value ?? fallback;\n if (!Number.isSafeInteger(result) || result <= 0 || result > maximum)\n throw new CodexAppServerError(\"protocol\");\n return result;\n}\n\n/** One initialized stdio process with correlated, bounded requests and terminal disposal. */\nexport class CodexAppServerClient {\n private readonly pending = new Map<number, Pending>();\n private readonly callbacks = new Map<string | number, AbortController>();\n private readonly timeout: number;\n private readonly callbackTimeout: number;\n private readonly capacity: number;\n private readonly frameLimit: number;\n private readonly child: ChildProcessWithoutNullStreams;\n private readonly closed: Promise<void>;\n private terminal = false;\n private nextId = 1;\n private buffer = \"\";\n\n private constructor(private readonly options: CodexAppServerOptions) {\n this.timeout = bound(options.requestTimeoutMs, 15_000, 300_000);\n this.callbackTimeout = bound(options.serverRequestTimeoutMs, 30_000, 300_000);\n this.capacity = bound(options.maxPendingRequests, 64, 1024);\n this.frameLimit = bound(options.maxFrameBytes, 1024 * 1024, 16 * 1024 * 1024);\n this.child = spawn(options.command, options.args, {\n cwd: options.cwd,\n env: options.env,\n stdio: \"pipe\",\n });\n this.closed = new Promise((resolve) => this.child.once(\"close\", () => resolve()));\n this.child.stdout.setEncoding(\"utf8\");\n this.child.stdout.on(\"data\", (chunk: string) => this.receive(chunk));\n // Drain without retaining raw diagnostic output: native stderr can contain secrets.\n this.child.stderr.resume();\n this.child.on(\"error\", () => this.fail(\"process\"));\n this.child.stdin.on(\"error\", () => this.fail(\"process\"));\n this.child.stdout.on(\"error\", () => this.fail(\"process\"));\n this.child.stderr.on(\"error\", () => this.fail(\"process\"));\n this.child.once(\"exit\", () => this.fail(\"process\"));\n }\n\n /** Spawn and finish the native initialize/initialized handshake before returning. */\n static async connect(options: CodexAppServerOptions): Promise<CodexAppServerClient> {\n let client: CodexAppServerClient | undefined;\n try {\n client = new CodexAppServerClient(options);\n await client.request(\"initialize\", {\n clientInfo: options.clientInfo,\n capabilities: { experimentalApi: true },\n });\n client.write({ method: \"initialized\" });\n return client;\n } catch (error) {\n await client?.dispose();\n throw error instanceof CodexAppServerError ? error : new CodexAppServerError(\"process\");\n }\n }\n\n /** Timeout closes this generation, so late replies can never satisfy a later request. */\n request<M extends CodexRequestMethod>(\n method: M,\n params: NativeRequests[M][\"params\"],\n ): Promise<NativeRequests[M][\"result\"]> {\n if (this.terminal) return Promise.reject(new CodexAppServerError(\"closed\"));\n if (this.pending.size >= this.capacity)\n return Promise.reject(new CodexAppServerError(\"capacity\"));\n const id = this.nextId++;\n return new Promise((resolve, reject) => {\n const timer = setTimeout(() => this.fail(\"timeout\"), this.timeout);\n this.pending.set(id, { resolve: resolve as (value: unknown) => void, reject, timer });\n try {\n this.write({ id, method, params });\n } catch {\n this.fail(\"protocol\");\n }\n });\n }\n\n /** Reject pending work immediately and wait a bounded interval for process shutdown. */\n async dispose(): Promise<void> {\n this.fail(\"closed\");\n let timer: ReturnType<typeof setTimeout> | undefined;\n await Promise.race([\n this.closed,\n new Promise<void>((resolve) => {\n timer = setTimeout(resolve, 1000);\n }),\n ]);\n clearTimeout(timer);\n }\n\n private fail(code: CodexAppServerError[\"code\"]): void {\n if (this.terminal) return;\n this.terminal = true;\n this.buffer = \"\";\n for (const request of this.pending.values()) {\n clearTimeout(request.timer);\n request.reject(new CodexAppServerError(code));\n }\n this.pending.clear();\n for (const controller of this.callbacks.values()) controller.abort();\n this.callbacks.clear();\n this.child.kill(\"SIGKILL\");\n try {\n this.options.onClose?.(new CodexAppServerError(code));\n } catch {\n // Observer failures cannot interrupt transport cleanup.\n }\n }\n\n private write(frame: unknown): void {\n if (this.terminal) throw new CodexAppServerError(\"closed\");\n const line = `${JSON.stringify(frame)}\\n`;\n if (Buffer.byteLength(line) > this.frameLimit) throw new CodexAppServerError(\"protocol\");\n this.child.stdin.write(line);\n }\n\n private receive(chunk: string): void {\n if (this.terminal) return;\n this.buffer += chunk;\n try {\n for (;;) {\n const end = this.buffer.indexOf(\"\\n\");\n if (end < 0) break;\n const line = this.buffer.slice(0, end);\n this.buffer = this.buffer.slice(end + 1);\n if (Buffer.byteLength(line) > this.frameLimit) throw new CodexAppServerError(\"protocol\");\n if (!line.trim()) continue;\n const frame: unknown = JSON.parse(line);\n if (!record(frame)) throw new CodexAppServerError(\"protocol\");\n if (typeof frame.method === \"string\") {\n if (\"id\" in frame) {\n if (!validId(frame.id)) throw new CodexAppServerError(\"protocol\");\n void this.handleServerRequest(frame.id, frame.method, frame.params);\n } else this.options.onNotification?.(frame.method, frame.params);\n } else {\n if (\n typeof frame.id !== \"number\" ||\n !Number.isSafeInteger(frame.id) ||\n \"error\" in frame === \"result\" in frame\n )\n throw new CodexAppServerError(\"protocol\");\n const request = this.pending.get(frame.id);\n if (!request) throw new CodexAppServerError(\"protocol\");\n clearTimeout(request.timer);\n this.pending.delete(frame.id);\n if (\"error\" in frame) request.reject(new CodexAppServerError(\"rejected\"));\n else request.resolve(frame.result);\n }\n if (this.terminal) return;\n }\n if (Buffer.byteLength(this.buffer) > this.frameLimit)\n throw new CodexAppServerError(\"protocol\");\n } catch {\n this.fail(\"protocol\");\n }\n }\n\n private async handleServerRequest(\n id: string | number,\n method: string,\n params: unknown,\n ): Promise<void> {\n if (this.callbacks.has(id) || this.callbacks.size >= this.capacity)\n return this.fail(\"protocol\");\n const controller = new AbortController();\n this.callbacks.set(id, controller);\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n const handler = Object.hasOwn(this.options.onServerRequest ?? {}, method)\n ? this.options.onServerRequest?.[method as keyof NativeServerRequests]\n : undefined;\n if (!handler) throw new CodexAppServerError(\"rejected\");\n const result = await Promise.race([\n Promise.resolve().then(() => {\n if (this.terminal || controller.signal.aborted) throw new CodexAppServerError(\"closed\");\n return (handler as (params: unknown, signal: AbortSignal) => Promise<unknown>)(\n params,\n controller.signal,\n );\n }),\n new Promise<never>((_, reject) => {\n controller.signal.addEventListener(\n \"abort\",\n () => reject(new CodexAppServerError(\"closed\")),\n { once: true },\n );\n timer = setTimeout(() => {\n controller.abort();\n reject(new CodexAppServerError(\"timeout\"));\n }, this.callbackTimeout);\n }),\n ]);\n this.write({ id, result });\n } catch {\n if (!this.terminal) {\n try {\n this.write({ id, error: { code: -32603, message: \"Codex client request failed\" } });\n } catch {\n this.fail(\"protocol\");\n }\n }\n } finally {\n clearTimeout(timer);\n controller.abort();\n this.callbacks.delete(id);\n }\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { scrubPoisonedTranscript, resolveClaudeConfigDir, SUPPORTED_CLOUDS, buil
|
|
|
2
2
|
import { dispatchCapability } from '../../chunk-RRVQAE5D.js';
|
|
3
3
|
import { fetchProviderModels } from '../../chunk-GURXUF2J.js';
|
|
4
4
|
import { AuthError, classifyClaudeSdkError, reclassifyAuthAsAccountUnavailable, AccountUnavailableError } from '../../chunk-GAH4YRCI.js';
|
|
5
|
-
import { BUILTIN_DRIVER_CATALOG, AgentDriver, getBridgeLogger } from '../../chunk-
|
|
5
|
+
import { BUILTIN_DRIVER_CATALOG, AgentDriver, getBridgeLogger } from '../../chunk-FRER2PEN.js';
|
|
6
6
|
import '../../chunk-6E6PKKAD.js';
|
|
7
7
|
import '../../chunk-CIPK5JMJ.js';
|
|
8
8
|
import '../../chunk-F3HNW354.js';
|
|
@@ -329,6 +329,18 @@ var ClaudeSdkDriver = class extends AgentDriver {
|
|
|
329
329
|
* ceiling. See {@link armTurnStallWatchdog}.
|
|
330
330
|
*/
|
|
331
331
|
firstSdkMessageSeen = false;
|
|
332
|
+
/** When the live query was spawned — the origin for the first-message timing. */
|
|
333
|
+
queryStartedAt = 0;
|
|
334
|
+
/**
|
|
335
|
+
* One-shot: armed at each spawn, disarmed by the first message of THAT spawn.
|
|
336
|
+
* Deliberately not `firstSdkMessageSeen`, which the stall watchdog resets every
|
|
337
|
+
* turn — a resident query serves turns 2..N without re-spawning, so reusing it
|
|
338
|
+
* would measure from the original spawn and report the idle time between turns
|
|
339
|
+
* as SDK latency.
|
|
340
|
+
*/
|
|
341
|
+
awaitingFirstMessageOfSpawn = false;
|
|
342
|
+
/** What the spawn actually resumed, captured before a fallback can clear it. */
|
|
343
|
+
spawnResumed = false;
|
|
332
344
|
/**
|
|
333
345
|
* `num_turns` reported by the most recent result message. Feeds
|
|
334
346
|
* {@link shouldRecycleQuery}; reset on every fresh spawn.
|
|
@@ -1090,8 +1102,14 @@ var ClaudeSdkDriver = class extends AgentDriver {
|
|
|
1090
1102
|
* the safety net for poison introduced mid-turn within the current lifetime.
|
|
1091
1103
|
*/
|
|
1092
1104
|
async preventivelyScrubTranscript() {
|
|
1105
|
+
const scrubStartedAt = Date.now();
|
|
1093
1106
|
const sessionId = this.config.resumeSessionId || this.sessionId;
|
|
1094
1107
|
if (!sessionId) {
|
|
1108
|
+
this.log.info("transcript scrub skipped", {
|
|
1109
|
+
phase: "transcript_scrub",
|
|
1110
|
+
elapsedMs: 0,
|
|
1111
|
+
outcome: "no_session"
|
|
1112
|
+
});
|
|
1095
1113
|
return;
|
|
1096
1114
|
}
|
|
1097
1115
|
try {
|
|
@@ -1100,6 +1118,12 @@ var ClaudeSdkDriver = class extends AgentDriver {
|
|
|
1100
1118
|
sessionId,
|
|
1101
1119
|
log: this.log
|
|
1102
1120
|
});
|
|
1121
|
+
this.log.info("transcript scrub complete", {
|
|
1122
|
+
phase: "transcript_scrub",
|
|
1123
|
+
elapsedMs: Date.now() - scrubStartedAt,
|
|
1124
|
+
outcome: "ok",
|
|
1125
|
+
changed: scrub.changed
|
|
1126
|
+
});
|
|
1103
1127
|
if (scrub.changed) {
|
|
1104
1128
|
this.log.warn("preventively scrubbed poisoned Claude Code transcript before resume", {
|
|
1105
1129
|
sessionId,
|
|
@@ -1110,6 +1134,9 @@ var ClaudeSdkDriver = class extends AgentDriver {
|
|
|
1110
1134
|
}
|
|
1111
1135
|
} catch (err) {
|
|
1112
1136
|
this.log.warn("preventive transcript scrub failed; continuing", {
|
|
1137
|
+
phase: "transcript_scrub",
|
|
1138
|
+
elapsedMs: Date.now() - scrubStartedAt,
|
|
1139
|
+
outcome: "failed",
|
|
1113
1140
|
sessionId,
|
|
1114
1141
|
error: err instanceof Error ? err.message : String(err)
|
|
1115
1142
|
});
|
|
@@ -1130,6 +1157,9 @@ var ClaudeSdkDriver = class extends AgentDriver {
|
|
|
1130
1157
|
}
|
|
1131
1158
|
async startQuery(message) {
|
|
1132
1159
|
this._querySpawnGeneration++;
|
|
1160
|
+
this.queryStartedAt = Date.now();
|
|
1161
|
+
this.awaitingFirstMessageOfSpawn = true;
|
|
1162
|
+
this.spawnResumed = !!(this.config.resumeSessionId || this.sessionId || this.hasSession);
|
|
1133
1163
|
this.abortController = new AbortController();
|
|
1134
1164
|
await this.preventivelyScrubTranscript();
|
|
1135
1165
|
const cloud = this.resolveCloud();
|
|
@@ -1441,6 +1471,14 @@ var ClaudeSdkDriver = class extends AgentDriver {
|
|
|
1441
1471
|
if (this.query !== servedQuery) break;
|
|
1442
1472
|
if (this.abortController?.signal.aborted) break;
|
|
1443
1473
|
this.lastSdkMessageAt = Date.now();
|
|
1474
|
+
if (this.awaitingFirstMessageOfSpawn) {
|
|
1475
|
+
this.awaitingFirstMessageOfSpawn = false;
|
|
1476
|
+
this.log.info("first sdk message", {
|
|
1477
|
+
phase: "query_first_message",
|
|
1478
|
+
elapsedMs: Date.now() - this.queryStartedAt,
|
|
1479
|
+
resumed: this.spawnResumed
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1444
1482
|
this.firstSdkMessageSeen = true;
|
|
1445
1483
|
this.captureSessionId(msg);
|
|
1446
1484
|
this.handleSdkMessage(msg);
|