dal-code 1.0.14 → 1.0.15

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/core/agent-session-services.d.ts +7 -0
  3. package/dist/core/agent-session-services.d.ts.map +1 -1
  4. package/dist/core/agent-session-services.js +73 -0
  5. package/dist/core/agent-session-services.js.map +1 -1
  6. package/dist/core/model-runtime.d.ts +28 -0
  7. package/dist/core/model-runtime.d.ts.map +1 -1
  8. package/dist/core/model-runtime.js +49 -0
  9. package/dist/core/model-runtime.js.map +1 -1
  10. package/dist/main.d.ts.map +1 -1
  11. package/dist/main.js +8 -7
  12. package/dist/main.js.map +1 -1
  13. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  14. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  15. package/dist/node_modules/@dalcode/dal-gateway/src/index.ts +84 -84
  16. package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
  17. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  18. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  19. package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
  20. package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
  21. package/dist/node_modules/@dalcode/dal-mcp/src/index.ts +136 -9
  22. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  23. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  24. package/dist/node_modules/@dalcode/dal-router/package.json +3 -3
  25. package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
  26. package/dist/node_modules/@dalcode/dal-skills/src/index.ts +65 -33
  27. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  28. package/dist/node_modules/@dalcode/dal-telemetry/package.json +2 -2
  29. package/dist/node_modules/@dalcode/deepailab/package.json +4 -3
  30. package/dist/node_modules/@dalcode/deepailab/src/cache.ts +62 -0
  31. package/dist/node_modules/@dalcode/deepailab/src/index.ts +286 -127
  32. package/dist/node_modules/@earendil-works/chord/package.json +1 -1
  33. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  34. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  35. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  36. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
  37. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
  38. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  39. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  40. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  41. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  42. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  43. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  44. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  45. package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
  46. package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
  47. package/dist/node_modules/@earendil-works/pi-server/package.json +3 -3
  48. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/package.json +3 -3
  49. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  50. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  51. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  52. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  53. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  54. package/examples/extensions/gondolin/package-lock.json +2 -2
  55. package/examples/extensions/gondolin/package.json +1 -1
  56. package/examples/extensions/sandbox/package-lock.json +2 -2
  57. package/examples/extensions/sandbox/package.json +1 -1
  58. package/examples/extensions/with-deps/package-lock.json +2 -2
  59. package/examples/extensions/with-deps/package.json +1 -1
  60. package/npm-shrinkwrap.json +2 -2
  61. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-lang",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -17,8 +17,8 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@dalcode/dal-pi-kit": "1.0.14",
21
- "@dalcode/dal-bridge": "1.0.14"
20
+ "@dalcode/dal-pi-kit": "1.0.15",
21
+ "@dalcode/dal-bridge": "1.0.15"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@earendil-works/pi-coding-agent": "^1.0.9"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-lsp",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -19,8 +19,8 @@
19
19
  ]
20
20
  },
21
21
  "dependencies": {
22
- "@dalcode/dal-bridge": "1.0.14",
23
- "@dalcode/dal-pi-kit": "1.0.14",
22
+ "@dalcode/dal-bridge": "1.0.15",
23
+ "@dalcode/dal-pi-kit": "1.0.15",
24
24
  "cross-spawn": "7.0.6",
25
25
  "typebox": "1.3.7"
26
26
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-mcp",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -23,10 +23,10 @@
23
23
  ]
24
24
  },
25
25
  "dependencies": {
26
- "@dalcode/dal-bridge": "1.0.14",
27
- "@dalcode/dal-guard": "1.0.14",
28
- "@dalcode/dal-pi-kit": "1.0.14",
29
- "@dalcode/deepailab": "1.0.14",
26
+ "@dalcode/dal-bridge": "1.0.15",
27
+ "@dalcode/dal-guard": "1.0.15",
28
+ "@dalcode/dal-pi-kit": "1.0.15",
29
+ "@dalcode/deepailab": "1.0.15",
30
30
  "cross-spawn": "7.0.6"
31
31
  },
32
32
  "peerDependencies": {
@@ -14,8 +14,10 @@
14
14
  * bypass the approval gate even if the pipeline around it changes.
15
15
  */
16
16
 
17
+ import { createHash } from "node:crypto";
17
18
  import { evaluateToolCall } from "@dalcode/dal-guard";
18
19
  import { t } from "@dalcode/dal-pi-kit";
20
+ import { accountTag, readCache, writeCache } from "@dalcode/deepailab/cache";
19
21
  import { defaultConfig } from "@dalcode/deepailab/oidc";
20
22
  import type { ExtensionAPI, ExtensionContext, ToolCallEvent } from "@earendil-works/pi-coding-agent";
21
23
  import { fetchAccountMcpServers } from "./account-layer.ts";
@@ -33,7 +35,13 @@ import { addMcpServerEntry, type McpConfigScope, removeMcpServerEntry } from "./
33
35
  import { McpHttpClient } from "./http-client.ts";
34
36
  import { type McpStatusItem, rememberMcpSessionId, reportMcpStatus } from "./report.ts";
35
37
  import { McpStdioClient } from "./stdio-client.ts";
36
- import { isHttpMcpConfig, type McpClient, type McpServerConfig, type McpTool } from "./types.ts";
38
+ import {
39
+ isHttpMcpConfig,
40
+ type McpClient,
41
+ type McpHttpServerConfig,
42
+ type McpServerConfig,
43
+ type McpTool,
44
+ } from "./types.ts";
37
45
 
38
46
  export type McpServerStatus = "connected" | "disconnected" | "failed";
39
47
 
@@ -52,6 +60,71 @@ export interface McpServerState {
52
60
  const registry = new Map<string, McpServerState>();
53
61
  const autoReconnectAttempted = new Set<string>();
54
62
  const AUTO_RECONNECT_DELAY_MS = 2_000;
63
+ /**
64
+ * Cache key for a server's tool list: the whole config, so a changed URL,
65
+ * command, argument or header is treated as a different server.
66
+ */
67
+ function toolCacheName(name: string, config: McpServerConfig): string {
68
+ return `mcp-tools-${createHash("sha256")
69
+ .update(JSON.stringify([name, config]))
70
+ .digest("hex")
71
+ .slice(0, 16)}`;
72
+ }
73
+
74
+ function isToolList(value: unknown): value is McpTool[] {
75
+ return (
76
+ Array.isArray(value) &&
77
+ value.every(
78
+ (tool) =>
79
+ typeof tool?.name === "string" &&
80
+ tool.name.length > 0 &&
81
+ (tool.description === undefined || typeof tool.description === "string") &&
82
+ (tool.inputSchema === undefined || (typeof tool.inputSchema === "object" && tool.inputSchema !== null)),
83
+ )
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Cached account servers are held to the same rule as fetched ones (see
89
+ * account-layer.ts): https URLs only, never a command to spawn.
90
+ */
91
+ function isAccountServerMap(value: unknown): value is Record<string, McpHttpServerConfig> {
92
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
93
+ return Object.values(value).every((entry) => {
94
+ if (typeof entry !== "object" || entry === null || "command" in entry) return false;
95
+ const { url, headers } = entry as { url?: unknown; headers?: unknown };
96
+ if (typeof url !== "string" || !url.startsWith("https://")) return false;
97
+ return (
98
+ headers === undefined ||
99
+ (typeof headers === "object" &&
100
+ headers !== null &&
101
+ Object.values(headers).every((header) => typeof header === "string"))
102
+ );
103
+ });
104
+ }
105
+
106
+ /**
107
+ * Stands in for a server that is not connected yet: a call first waits for
108
+ * `ensureConnected`, then goes to the live client, or fails with the connect
109
+ * error.
110
+ */
111
+ function pendingClient(name: string, ensureConnected: () => Promise<void>): McpClient {
112
+ return {
113
+ connect: ensureConnected,
114
+ listTools: async () => [],
115
+ callTool: async (tool, args) => {
116
+ await ensureConnected();
117
+ const state = registry.get(name);
118
+ if (!state?.client) {
119
+ throw new Error(
120
+ `${t('dal-mcp:连接 MCP 服务器 "')}${name}${t('" 失败:')}${state?.lastError ?? "not connected"}`,
121
+ );
122
+ }
123
+ return state.client.callTool(tool, args);
124
+ },
125
+ disconnect: () => {},
126
+ };
127
+ }
55
128
 
56
129
  /** Snapshot of every configured server's current connection state, for /mcp. */
57
130
  export function getMcpServerStates(): McpServerState[] {
@@ -182,6 +255,11 @@ async function connectServer(
182
255
  for (const tool of tools) {
183
256
  pi.registerTool(buildMcpToolDefinition(client, name, tool, cwd) as never);
184
257
  }
258
+ try {
259
+ writeCache(toolCacheName(name, config), tools);
260
+ } catch {
261
+ // An unwritable cache only costs the next session this same wait.
262
+ }
185
263
  state.client = client;
186
264
  state.tools = tools;
187
265
  state.status = "connected";
@@ -393,10 +471,29 @@ export default function (pi: ExtensionAPI) {
393
471
  try {
394
472
  const vk = await ctx.modelRegistry?.getApiKeyForProvider?.("deepailab");
395
473
  if (vk) {
396
- const layer = await fetchAccountMcpServers(defaultConfig().apiBase, vk);
397
- accountServers = layer.servers;
398
- for (const name of layer.rejected) {
399
- report(ctx, `${t("已拒绝账号下发的 MCP 条目(只接受 https 远程服务器):")}${name}`, "warning");
474
+ // Start from the last copy for this account and revalidate in the
475
+ // background; with no copy yet, wait for the fetch. A server the
476
+ // account adds is picked up by the next session.
477
+ const cacheName = `mcp-account-${accountTag(vk)}`;
478
+ const cached = readCache(cacheName, isAccountServerMap);
479
+ const revalidation = fetchAccountMcpServers(defaultConfig().apiBase, vk).then((layer) => {
480
+ for (const name of layer.rejected) {
481
+ report(ctx, `${t("已拒绝账号下发的 MCP 条目(只接受 https 远程服务器):")}${name}`, "warning");
482
+ }
483
+ try {
484
+ writeCache(cacheName, layer.servers);
485
+ } catch {
486
+ // An unwritable cache only costs the next session this same wait.
487
+ }
488
+ return layer.servers;
489
+ });
490
+ if (cached) {
491
+ accountServers = cached.value;
492
+ revalidation.catch((error) => {
493
+ report(ctx, `${t("无法获取账号的 MCP 配置:")}${errorMessage(error)}`, "warning");
494
+ });
495
+ } else {
496
+ accountServers = await revalidation;
400
497
  }
401
498
  }
402
499
  } catch (error) {
@@ -412,13 +509,43 @@ export default function (pi: ExtensionAPI) {
412
509
  for (const problem of takeMcpConfigProblems()) {
413
510
  report(ctx, `${t("MCP 配置有问题:")}${problem}`, "warning");
414
511
  }
512
+ // A server whose tool list is cached gets those tools registered now,
513
+ // without waiting for it: with a UI it connects in the background, and a
514
+ // headless run (`dal -p`, one process per DAL Office turn) connects only
515
+ // if the model calls one of its tools. A call made before the server is
516
+ // connected waits for the connection (pendingClient). Only servers seen
517
+ // for the first time hold up the session, and they connect in parallel.
518
+ // Connecting used to be serial and awaited: a hosted server needs three
519
+ // requests (initialize, initialized, tools/list), each a new connection
520
+ // taking 5-6s behind a proxy, so one such server added ~17s before every
521
+ // first turn, and a headless run paid it even when no MCP tool was used.
522
+ const firstConnections: Promise<void>[] = [];
415
523
  for (const [name, config] of Object.entries(servers)) {
416
- try {
417
- await connectServer(pi, name, config, ctx.cwd);
418
- } catch (error) {
419
- ctx.ui.notify(`${t('dal-mcp:连接 MCP 服务器 "')}${name}${t('" 失败:')}${errorMessage(error)}`, "warning");
524
+ let connection: Promise<void> | undefined;
525
+ const ensureConnected = (): Promise<void> => {
526
+ connection ??= connectServer(pi, name, config, ctx.cwd).then(
527
+ () => {},
528
+ (error) => {
529
+ report(
530
+ ctx,
531
+ `${t('dal-mcp:连接 MCP 服务器 "')}${name}${t('" 失败:')}${errorMessage(error)}`,
532
+ "warning",
533
+ );
534
+ },
535
+ );
536
+ return connection;
537
+ };
538
+ const cachedTools = readCache(toolCacheName(name, config), isToolList);
539
+ if (!cachedTools) {
540
+ firstConnections.push(ensureConnected());
541
+ continue;
542
+ }
543
+ for (const tool of cachedTools.value) {
544
+ pi.registerTool(buildMcpToolDefinition(pendingClient(name, ensureConnected), name, tool, ctx.cwd) as never);
420
545
  }
546
+ if (ctx.hasUI) void ensureConnected().then(pushMcpStatus);
421
547
  }
548
+ await Promise.all(firstConnections);
422
549
  pushMcpStatus();
423
550
  });
424
551
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-office",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -17,7 +17,7 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@dalcode/dal-pi-kit": "1.0.14",
20
+ "@dalcode/dal-pi-kit": "1.0.15",
21
21
  "docx": "9.7.1",
22
22
  "echarts": "6.1.0",
23
23
  "exceljs": "4.4.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-pi-kit",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "description": "Shared i18n helpers for DAL pi extensions. No engine peer.",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-router",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -22,8 +22,8 @@
22
22
  ]
23
23
  },
24
24
  "dependencies": {
25
- "@dalcode/dal-pi-kit": "1.0.14",
26
- "@earendil-works/pi-tui": "^1.0.14"
25
+ "@dalcode/dal-pi-kit": "1.0.15",
26
+ "@earendil-works/pi-tui": "^1.0.15"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@earendil-works/pi-coding-agent": "^1.0.0"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-skills",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -19,8 +19,8 @@
19
19
  ]
20
20
  },
21
21
  "dependencies": {
22
- "@dalcode/dal-pi-kit": "1.0.14",
23
- "@dalcode/deepailab": "1.0.14",
22
+ "@dalcode/dal-pi-kit": "1.0.15",
23
+ "@dalcode/deepailab": "1.0.15",
24
24
  "typebox": "1.3.7"
25
25
  },
26
26
  "peerDependencies": {
@@ -25,6 +25,7 @@
25
25
  */
26
26
 
27
27
  import { t } from "@dalcode/dal-pi-kit";
28
+ import { accountTag, readCache, writeCache } from "@dalcode/deepailab/cache";
28
29
  import { defaultConfig } from "@dalcode/deepailab/oidc";
29
30
  import {
30
31
  type ExtensionAPI,
@@ -49,6 +50,19 @@ const skillSchema = Type.Object({
49
50
  name: Type.String({ description: t("要加载的技能名称,取自本工具描述中列出的清单") }),
50
51
  });
51
52
 
53
+ function isSkillList(value: unknown): value is SkillSummary[] {
54
+ return (
55
+ Array.isArray(value) &&
56
+ value.every(
57
+ (s) =>
58
+ typeof s?.id === "string" &&
59
+ s.id.length > 0 &&
60
+ typeof s.name === "string" &&
61
+ typeof s.description === "string",
62
+ )
63
+ );
64
+ }
65
+
52
66
  /** Cheap guard against a skill whose body is enormous by accident. */
53
67
  const MAX_BODY_CHARS = 60_000;
54
68
 
@@ -106,41 +120,59 @@ export default function (pi: ExtensionAPI) {
106
120
  else process.stderr.write(`${message}\n`);
107
121
  };
108
122
 
109
- try {
110
- // No ETag is sent, so 304 is not something our own service can answer —
111
- // but a proxy or CDN in front of it can, and returning here would leave
112
- // the tool unregistered with nothing on screen. Treated as "no
113
- // catalogue this session" and reported, rather than silently skipped.
114
- const index = await fetchSkillIndex(cfg.apiBase, vk);
115
- if (index === "not-modified") {
116
- reportFailure(t("服务端返回了意外的 304"));
117
- return;
123
+ // Index: start from the last good copy for this account and revalidate
124
+ // in the background. It used to be fetched before the first turn of
125
+ // every process, 5-6s on a proxied connection; a copy that is a few
126
+ // minutes old lists the same skills, and a skill added since is still
127
+ // resolvable by name once the revalidation lands (resolve() reads the
128
+ // live `catalogue`). With no copy yet, the first fetch is awaited.
129
+ const cacheName = `skills-index-${accountTag(vk)}`;
130
+ const cached = readCache(cacheName, isSkillList);
131
+ const revalidation = (async (): Promise<void> => {
132
+ try {
133
+ // No ETag is sent, so 304 is not something our own service can answer —
134
+ // but a proxy or CDN in front of it can, and taking it as "unchanged"
135
+ // would leave the tool unregistered with nothing on screen. Treated
136
+ // as "no catalogue" and reported, rather than silently skipped.
137
+ const index = await fetchSkillIndex(cfg.apiBase, vk);
138
+ if (index === "not-modified") {
139
+ reportFailure(t("服务端返回了意外的 304"));
140
+ return;
141
+ }
142
+ catalogue = index.skills;
143
+ try {
144
+ writeCache(cacheName, index.skills);
145
+ } catch {
146
+ // An unwritable cache only costs the next process this same fetch.
147
+ }
148
+ } catch (error) {
149
+ // Not silent: skills the user is paying for quietly not being there is
150
+ // exactly the class of failure this codebase keeps getting bitten by.
151
+ // With a cached copy the session keeps working from it, and says so.
152
+ const reason = error instanceof Error && error.name === "AbortError" ? t("请求超时") : String(error);
153
+ reportFailure(reason);
118
154
  }
119
- catalogue = index.skills;
120
- } catch (error) {
121
- // Not silent: skills the user is paying for quietly not being there is
122
- // exactly the class of failure this codebase keeps getting bitten by.
123
- const reason = error instanceof Error && error.name === "AbortError" ? t("请求超时") : String(error);
124
- reportFailure(reason);
125
- return;
126
- }
155
+ })();
156
+ if (cached) catalogue = cached.value;
157
+ else await revalidation;
127
158
 
128
- // Best-effort and quiet on failure: a recommendation list that cannot be
129
- // fetched is not worth interrupting anyone over, unlike skills or MCP which
130
- // change what the agent can do.
131
- try {
132
- const account = await fetchAccountPackages(cfg.apiBase, vk);
133
- const installed = readInstalledSources(getAgentDir());
134
- pendingPackages = missingPackages(account, installed);
135
- if (ctx.hasUI && shouldAnnouncePending(getAgentDir(), pendingPackages)) {
136
- ctx.ui.notify(
137
- `${t("账号里有")}${pendingPackages.length}${t(" 个扩展本机还没装,/install 可直接安装。")}`,
138
- "info",
139
- );
140
- }
141
- } catch {
142
- // Ignored on purpose — see above.
143
- }
159
+ // Best-effort, quiet on failure, and never awaited: a recommendation list
160
+ // is not worth delaying the first turn or interrupting anyone over,
161
+ // unlike skills or MCP which change what the agent can do.
162
+ void fetchAccountPackages(cfg.apiBase, vk)
163
+ .then((account) => {
164
+ const installed = readInstalledSources(getAgentDir());
165
+ pendingPackages = missingPackages(account, installed);
166
+ if (ctx.hasUI && shouldAnnouncePending(getAgentDir(), pendingPackages)) {
167
+ ctx.ui.notify(
168
+ `${t("账号里有")}${pendingPackages.length}${t(" 个扩展本机还没装,/install 可直接安装。")}`,
169
+ "info",
170
+ );
171
+ }
172
+ })
173
+ .catch(() => {
174
+ // Ignored on purpose — see above.
175
+ });
144
176
 
145
177
  if (catalogue.length === 0) return;
146
178
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-subagent",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -17,10 +17,10 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@dalcode/dal-pi-kit": "1.0.14",
21
- "@dalcode/dal-guard": "1.0.14",
22
- "@earendil-works/pi-agent-core": "^1.0.14",
23
- "@earendil-works/pi-ai": "^1.0.14",
20
+ "@dalcode/dal-pi-kit": "1.0.15",
21
+ "@dalcode/dal-guard": "1.0.15",
22
+ "@earendil-works/pi-agent-core": "^1.0.15",
23
+ "@earendil-works/pi-ai": "^1.0.15",
24
24
  "typebox": "1.3.7"
25
25
  },
26
26
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dalcode/dal-telemetry",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -20,7 +20,7 @@
20
20
  ]
21
21
  },
22
22
  "dependencies": {
23
- "@dalcode/dal-pi-kit": "1.0.14"
23
+ "@dalcode/dal-pi-kit": "1.0.15"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@earendil-works/pi-coding-agent": "^1.0.9"
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@dalcode/deepailab",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
7
7
  "exports": {
8
8
  ".": "./src/index.ts",
9
+ "./cache": "./src/cache.ts",
9
10
  "./model-defaults": "./src/model-defaults.ts",
10
11
  "./oidc": "./src/oidc.ts",
11
12
  "./package.json": "./package.json"
@@ -19,8 +20,8 @@
19
20
  ]
20
21
  },
21
22
  "dependencies": {
22
- "@dalcode/dal-pi-kit": "1.0.14",
23
- "@earendil-works/pi-ai": "^1.0.14"
23
+ "@dalcode/dal-pi-kit": "1.0.15",
24
+ "@earendil-works/pi-ai": "^1.0.15"
24
25
  },
25
26
  "peerDependencies": {
26
27
  "@earendil-works/pi-coding-agent": "^1.0.9"
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Last-known-good copies of account data fetched from the DeepAILab gateway.
3
+ *
4
+ * Every `dal` process used to fetch the skill index, the account's MCP
5
+ * servers and each MCP server's tool list before the first model request,
6
+ * one after another. Each is a fresh HTTPS connection, and on a machine
7
+ * behind a proxy each took 5-6s (measured 2026-09-23), so a one-line headless
8
+ * prompt spent ~40s before it reached the model. DAL Office spawns a process
9
+ * per chat turn and paid that every turn.
10
+ *
11
+ * Callers use these to start from the last good copy and revalidate in the
12
+ * background (stale-while-revalidate). Files live under
13
+ * `<agent dir>/cache/`, written 0600 like auth.json: an account MCP entry can
14
+ * carry request headers.
15
+ */
16
+
17
+ import { createHash } from "node:crypto";
18
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
19
+ import { dirname, join } from "node:path";
20
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
21
+
22
+ export interface Cached<T> {
23
+ value: T;
24
+ /** Unix ms when the value was fetched. */
25
+ savedAt: number;
26
+ }
27
+
28
+ function cachePath(name: string): string {
29
+ return join(getAgentDir(), "cache", `${name}.json`);
30
+ }
31
+
32
+ /**
33
+ * Short, non-reversible tag for a credential, used to key per-account caches
34
+ * so a different sign-in never starts from another account's data.
35
+ */
36
+ export function accountTag(key: string): string {
37
+ return createHash("sha256").update(key).digest("hex").slice(0, 16);
38
+ }
39
+
40
+ export function readCache<T>(name: string, isValue: (value: unknown) => value is T): Cached<T> | undefined {
41
+ let parsed: { value?: unknown; savedAt?: unknown };
42
+ try {
43
+ parsed = JSON.parse(readFileSync(cachePath(name), "utf8")) as typeof parsed;
44
+ } catch {
45
+ // Missing or unreadable: the caller fetches, exactly as with no cache.
46
+ return undefined;
47
+ }
48
+ if (typeof parsed.savedAt !== "number" || !isValue(parsed.value)) return undefined;
49
+ return { value: parsed.value, savedAt: parsed.savedAt };
50
+ }
51
+
52
+ /**
53
+ * Atomic (temp file + rename), so a concurrent reader never sees half a file.
54
+ * Throws on failure; callers decide whether that is worth reporting.
55
+ */
56
+ export function writeCache(name: string, value: unknown): void {
57
+ const path = cachePath(name);
58
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
59
+ const temporary = `${path}.${process.pid}.tmp`;
60
+ writeFileSync(temporary, JSON.stringify({ savedAt: Date.now(), value }), { mode: 0o600 });
61
+ renameSync(temporary, path);
62
+ }