zcode-acp-server 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/README.md +98 -1
  2. package/README.zh-CN.md +81 -1
  3. package/dist/backend/client.d.ts +12 -4
  4. package/dist/backend/client.d.ts.map +1 -1
  5. package/dist/backend/client.js +72 -7
  6. package/dist/backend/client.js.map +1 -1
  7. package/dist/backend/credentials.d.ts.map +1 -1
  8. package/dist/backend/credentials.js +2 -1
  9. package/dist/backend/credentials.js.map +1 -1
  10. package/dist/backend/listener.d.ts +12 -4
  11. package/dist/backend/listener.d.ts.map +1 -1
  12. package/dist/backend/listener.js +68 -12
  13. package/dist/backend/listener.js.map +1 -1
  14. package/dist/backend/types.d.ts +1 -1
  15. package/dist/backend/types.d.ts.map +1 -1
  16. package/dist/bin/quota.d.ts +54 -0
  17. package/dist/bin/quota.d.ts.map +1 -0
  18. package/dist/bin/quota.js +333 -0
  19. package/dist/bin/quota.js.map +1 -0
  20. package/dist/config/auto-compact.d.ts +23 -0
  21. package/dist/config/auto-compact.d.ts.map +1 -0
  22. package/dist/config/auto-compact.js +67 -0
  23. package/dist/config/auto-compact.js.map +1 -0
  24. package/dist/config/mcp-discovery.d.ts +34 -0
  25. package/dist/config/mcp-discovery.d.ts.map +1 -0
  26. package/dist/config/mcp-discovery.js +153 -0
  27. package/dist/config/mcp-discovery.js.map +1 -0
  28. package/dist/config/model-cache.d.ts +12 -1
  29. package/dist/config/model-cache.d.ts.map +1 -1
  30. package/dist/config/model-cache.js +30 -8
  31. package/dist/config/model-cache.js.map +1 -1
  32. package/dist/config/options.d.ts +87 -9
  33. package/dist/config/options.d.ts.map +1 -1
  34. package/dist/config/options.js +248 -45
  35. package/dist/config/options.js.map +1 -1
  36. package/dist/config/plugin-commands.d.ts +24 -0
  37. package/dist/config/plugin-commands.d.ts.map +1 -0
  38. package/dist/config/plugin-commands.js +107 -0
  39. package/dist/config/plugin-commands.js.map +1 -0
  40. package/dist/config/provider-registry.d.ts +60 -0
  41. package/dist/config/provider-registry.d.ts.map +1 -0
  42. package/dist/config/provider-registry.js +128 -0
  43. package/dist/config/provider-registry.js.map +1 -0
  44. package/dist/config/runtime-model.d.ts +54 -18
  45. package/dist/config/runtime-model.d.ts.map +1 -1
  46. package/dist/config/runtime-model.js +105 -61
  47. package/dist/config/runtime-model.js.map +1 -1
  48. package/dist/config/skill-discovery.d.ts +35 -0
  49. package/dist/config/skill-discovery.d.ts.map +1 -0
  50. package/dist/config/skill-discovery.js +188 -0
  51. package/dist/config/skill-discovery.js.map +1 -0
  52. package/dist/handlers/background-tasks.d.ts +72 -0
  53. package/dist/handlers/background-tasks.d.ts.map +1 -0
  54. package/dist/handlers/background-tasks.js +330 -0
  55. package/dist/handlers/background-tasks.js.map +1 -0
  56. package/dist/handlers/dispatch.d.ts.map +1 -1
  57. package/dist/handlers/dispatch.js +134 -22
  58. package/dist/handlers/dispatch.js.map +1 -1
  59. package/dist/handlers/extensions.d.ts +15 -0
  60. package/dist/handlers/extensions.d.ts.map +1 -1
  61. package/dist/handlers/extensions.js +43 -27
  62. package/dist/handlers/extensions.js.map +1 -1
  63. package/dist/handlers/io.d.ts +11 -2
  64. package/dist/handlers/io.d.ts.map +1 -1
  65. package/dist/handlers/io.js +51 -7
  66. package/dist/handlers/io.js.map +1 -1
  67. package/dist/handlers/server-requests.d.ts +20 -4
  68. package/dist/handlers/server-requests.d.ts.map +1 -1
  69. package/dist/handlers/server-requests.js +293 -63
  70. package/dist/handlers/server-requests.js.map +1 -1
  71. package/dist/handlers/session.d.ts +113 -10
  72. package/dist/handlers/session.d.ts.map +1 -1
  73. package/dist/handlers/session.js +876 -220
  74. package/dist/handlers/session.js.map +1 -1
  75. package/dist/handlers/slash.d.ts +14 -0
  76. package/dist/handlers/slash.d.ts.map +1 -1
  77. package/dist/handlers/slash.js +80 -6
  78. package/dist/handlers/slash.js.map +1 -1
  79. package/dist/index.js +38 -4
  80. package/dist/index.js.map +1 -1
  81. package/dist/interaction/adapter.d.ts +19 -33
  82. package/dist/interaction/adapter.d.ts.map +1 -1
  83. package/dist/interaction/adapter.js +80 -79
  84. package/dist/interaction/adapter.js.map +1 -1
  85. package/dist/lazy-sessions.d.ts +35 -0
  86. package/dist/lazy-sessions.d.ts.map +1 -0
  87. package/dist/lazy-sessions.js +98 -0
  88. package/dist/lazy-sessions.js.map +1 -0
  89. package/dist/quota/cache.d.ts +18 -0
  90. package/dist/quota/cache.d.ts.map +1 -0
  91. package/dist/quota/cache.js +32 -0
  92. package/dist/quota/cache.js.map +1 -0
  93. package/dist/quota/client.d.ts +30 -0
  94. package/dist/quota/client.d.ts.map +1 -0
  95. package/dist/quota/client.js +57 -0
  96. package/dist/quota/client.js.map +1 -0
  97. package/dist/quota/color.d.ts +58 -0
  98. package/dist/quota/color.d.ts.map +1 -0
  99. package/dist/quota/color.js +95 -0
  100. package/dist/quota/color.js.map +1 -0
  101. package/dist/quota/combined.d.ts +66 -0
  102. package/dist/quota/combined.d.ts.map +1 -0
  103. package/dist/quota/combined.js +179 -0
  104. package/dist/quota/combined.js.map +1 -0
  105. package/dist/quota/format.d.ts +105 -0
  106. package/dist/quota/format.d.ts.map +1 -0
  107. package/dist/quota/format.js +219 -0
  108. package/dist/quota/format.js.map +1 -0
  109. package/dist/quota/index.d.ts +23 -0
  110. package/dist/quota/index.d.ts.map +1 -0
  111. package/dist/quota/index.js +42 -0
  112. package/dist/quota/index.js.map +1 -0
  113. package/dist/quota/opencode-go/cache.d.ts +17 -0
  114. package/dist/quota/opencode-go/cache.d.ts.map +1 -0
  115. package/dist/quota/opencode-go/cache.js +31 -0
  116. package/dist/quota/opencode-go/cache.js.map +1 -0
  117. package/dist/quota/opencode-go/client.d.ts +28 -0
  118. package/dist/quota/opencode-go/client.d.ts.map +1 -0
  119. package/dist/quota/opencode-go/client.js +48 -0
  120. package/dist/quota/opencode-go/client.js.map +1 -0
  121. package/dist/quota/opencode-go/config.d.ts +37 -0
  122. package/dist/quota/opencode-go/config.d.ts.map +1 -0
  123. package/dist/quota/opencode-go/config.js +58 -0
  124. package/dist/quota/opencode-go/config.js.map +1 -0
  125. package/dist/quota/opencode-go/format.d.ts +36 -0
  126. package/dist/quota/opencode-go/format.d.ts.map +1 -0
  127. package/dist/quota/opencode-go/format.js +87 -0
  128. package/dist/quota/opencode-go/format.js.map +1 -0
  129. package/dist/quota/opencode-go/index.d.ts +30 -0
  130. package/dist/quota/opencode-go/index.d.ts.map +1 -0
  131. package/dist/quota/opencode-go/index.js +108 -0
  132. package/dist/quota/opencode-go/index.js.map +1 -0
  133. package/dist/quota/opencode-go/parse.d.ts +41 -0
  134. package/dist/quota/opencode-go/parse.d.ts.map +1 -0
  135. package/dist/quota/opencode-go/parse.js +75 -0
  136. package/dist/quota/opencode-go/parse.js.map +1 -0
  137. package/dist/quota/opencode-go/types.d.ts +48 -0
  138. package/dist/quota/opencode-go/types.d.ts.map +1 -0
  139. package/dist/quota/opencode-go/types.js +11 -0
  140. package/dist/quota/opencode-go/types.js.map +1 -0
  141. package/dist/quota/parse.d.ts +33 -0
  142. package/dist/quota/parse.d.ts.map +1 -0
  143. package/dist/quota/parse.js +200 -0
  144. package/dist/quota/parse.js.map +1 -0
  145. package/dist/quota/types.d.ts +72 -0
  146. package/dist/quota/types.d.ts.map +1 -0
  147. package/dist/quota/types.js +10 -0
  148. package/dist/quota/types.js.map +1 -0
  149. package/dist/server.d.ts +104 -0
  150. package/dist/server.d.ts.map +1 -1
  151. package/dist/server.js +119 -2
  152. package/dist/server.js.map +1 -1
  153. package/dist/tasks-index.d.ts +14 -4
  154. package/dist/tasks-index.d.ts.map +1 -1
  155. package/dist/tasks-index.js +145 -46
  156. package/dist/tasks-index.js.map +1 -1
  157. package/dist/translators/event-translator.d.ts +33 -0
  158. package/dist/translators/event-translator.d.ts.map +1 -1
  159. package/dist/translators/event-translator.js +101 -0
  160. package/dist/translators/event-translator.js.map +1 -1
  161. package/dist/translators/index.d.ts +1 -1
  162. package/dist/translators/index.d.ts.map +1 -1
  163. package/dist/translators/index.js +1 -1
  164. package/dist/translators/index.js.map +1 -1
  165. package/dist/translators/projection-differ.d.ts +8 -0
  166. package/dist/translators/projection-differ.d.ts.map +1 -1
  167. package/dist/translators/projection-differ.js +19 -9
  168. package/dist/translators/projection-differ.js.map +1 -1
  169. package/dist/translators/tool-helpers.d.ts +28 -0
  170. package/dist/translators/tool-helpers.d.ts.map +1 -1
  171. package/dist/translators/tool-helpers.js +104 -0
  172. package/dist/translators/tool-helpers.js.map +1 -1
  173. package/dist/translators/types.d.ts +38 -1
  174. package/dist/translators/types.d.ts.map +1 -1
  175. package/dist/translators/types.js.map +1 -1
  176. package/dist/utils.d.ts +35 -6
  177. package/dist/utils.d.ts.map +1 -1
  178. package/dist/utils.js +52 -4
  179. package/dist/utils.js.map +1 -1
  180. package/docs/ARCHITECTURE.md +96 -38
  181. package/docs/BACKLOG.md +57 -0
  182. package/docs/DEVELOPMENT.md +5 -0
  183. package/docs/PROTOCOL.md +270 -5
  184. package/docs/TROUBLESHOOTING.md +98 -14
  185. package/docs/agents/domain.md +51 -0
  186. package/docs/agents/issue-tracker.md +22 -0
  187. package/docs/agents/triage-labels.md +15 -0
  188. package/package.json +6 -5
@@ -207,23 +207,33 @@ export function parseAskUserResponse(acpResp) {
207
207
  return optionId;
208
208
  }
209
209
  // ---------- elicitation form (preferred when client supports it) ----------
210
+ /**
211
+ * Sentinel `const` value marking a single-select question as skipped in the
212
+ * elicitation form. Paired with a human-readable `title` ("Skip this question")
213
+ * via `oneOf`, so the client renders the label — never the raw sentinel.
214
+ */
215
+ const ELICIT_SKIP = "__skip__";
210
216
  /**
211
217
  * Build an elicitation form schema for an AskUserQuestion request.
212
218
  *
213
- * Each question becomes one property in the form:
214
- * - Single-select string enum of labels + a trailing "Skip" option
215
- * - Multi-select → string array enum of labels
219
+ * ACP/MCP elicitation string fields are EITHER an enum (restricted dropdown) OR
220
+ * free text the spec ("enum strictly restricts the allowed string values")
221
+ * forbids "dropdown whose last row accepts custom input". To give the user both
222
+ * a pick list AND custom entry, each question is rendered as TWO fields:
216
223
  *
217
- * When the client supports form-based elicitation, this lets the user answer
218
- * all questions in one form rather than one popup per question. Single-select
219
- * fields include a "Skip" option so the user can opt out of a question without
220
- * cancelling the whole form (mirrors the request_permission fallback, which
221
- * appends a Skip option per question).
224
+ * - `q_<i>`: enum dropdown of the model's suggested answers + a trailing
225
+ * "Skip this question" option. Uses `oneOf`/`anyOf` with `{const, title}`
226
+ * so the skip sentinel has a readable label instead of the raw `__skip__`.
227
+ * - `q_<i>_other`: free-text string. If non-empty it OVERRIDES the dropdown
228
+ * (single-select) or is APPENDED to the picked values (multi-select).
229
+ *
230
+ * A non-required free-text field plus a Skip enum option lets the user opt out
231
+ * of a single question without cancelling the whole form. Required is left
232
+ * empty so neither field forces an answer.
222
233
  */
223
234
  export function buildAskUserElicitationForm(params, acpSid, toolCallId) {
224
235
  const questions = params.questions?.length ? params.questions : (params.input?.questions ?? []);
225
236
  const properties = {};
226
- const required = [];
227
237
  for (let i = 0; i < questions.length; i++) {
228
238
  const q = questions[i];
229
239
  if (!q || typeof q.question !== "string")
@@ -234,47 +244,64 @@ export function buildAskUserElicitationForm(params, acpSid, toolCallId) {
234
244
  .filter((l) => l.length > 0);
235
245
  if (labels.length === 0)
236
246
  continue;
247
+ // Titled enum option for "skip": const carries the sentinel value the
248
+ // parser recognizes; title is what the client renders in the dropdown.
249
+ const skipOption = { const: ELICIT_SKIP, title: "Skip this question" };
237
250
  if (q.multiSelect) {
238
251
  properties[key] = {
239
252
  type: "array",
240
- items: { type: "string", enum: labels },
241
253
  title: q.question,
242
- description: q.question,
254
+ items: { anyOf: labels.map((l) => ({ const: l, title: l })) },
243
255
  };
244
256
  }
245
257
  else {
246
- // Append a Skip option so the user can opt out of this question without
247
- // cancelling the whole form (parity with the request_permission path).
248
258
  properties[key] = {
249
259
  type: "string",
250
- enum: [...labels, ELICIT_SKIP],
251
260
  title: q.question,
252
- description: q.question,
261
+ oneOf: [...labels.map((l) => ({ const: l, title: l })), skipOption],
253
262
  };
254
- required.push(key);
255
263
  }
264
+ // Companion free-text field. Zed renders a string field's title
265
+ // prominently, and falls back to the description when title is absent — so
266
+ // a bright label here is unavoidable. Prefix with "↳" + padding so it reads
267
+ // as a continuation of the question above, and make the title self-contained
268
+ // (no description needed).
269
+ properties[`${key}_other`] = {
270
+ type: "string",
271
+ title: q.multiSelect
272
+ ? "↳ or add a custom value (combined with the selection)"
273
+ : "↳ or type a custom value (overrides the selection)",
274
+ };
256
275
  }
276
+ // The question text already appears as each field's `title` (its label), so
277
+ // the form `message` must NOT repeat it — otherwise Zed shows the question
278
+ // twice (top banner + field label). Use a neutral prompt instead. For a
279
+ // single question this reads naturally above its labeled field; for several,
280
+ // it tells the user how many fields follow.
257
281
  const message = questions.length === 1
258
- ? (questions[0]?.question ?? "Please answer the question.")
282
+ ? "Please answer the question."
259
283
  : `Please answer ${questions.length} questions.`;
260
284
  const form = {
261
285
  mode: "form",
262
286
  sessionId: acpSid,
263
287
  message,
264
- requestedSchema: { type: "object", properties, required },
288
+ // No required fields: the user can skip any question (via Skip option or
289
+ // blank free-text) without being blocked by validation.
290
+ requestedSchema: { type: "object", properties, required: [] },
265
291
  };
266
292
  if (toolCallId)
267
293
  form.toolCallId = toolCallId;
268
294
  return form;
269
295
  }
270
- /** Sentinel enum value marking a single-select question as skipped in the form. */
271
- const ELICIT_SKIP = "__skip__";
272
296
  /**
273
297
  * Parse an elicitation form response into the zcode answers map.
274
298
  *
275
- * Maps each `q_<i>` form field back to the original question text. Multi-select
276
- * answers (arrays) are comma-joined to match the request_permission path's
277
- * `"a, b"` format. Returns null if the user declined/cancelled.
299
+ * For each question the free-text companion (`q_<i>_other`) takes precedence:
300
+ * - Single-select: non-empty free-text OVERRIDES the dropdown. Otherwise the
301
+ * dropdown value is used, unless it's the skip sentinel or absent (omitted).
302
+ * - Multi-select: free-text is APPENDED to the picked values (de-duped, order
303
+ * preserved). The skip sentinel never appears in multi-select.
304
+ * Returns null if the user declined/cancelled.
278
305
  */
279
306
  export function parseAskUserElicitationResponse(acpResp, params) {
280
307
  if (!acpResp || typeof acpResp !== "object")
@@ -289,65 +316,39 @@ export function parseAskUserElicitationResponse(acpResp, params) {
289
316
  if (!q || typeof q.question !== "string")
290
317
  continue;
291
318
  const key = `q_${i}`;
292
- const val = resp.content[key];
293
- if (val == null)
294
- continue;
295
- if (Array.isArray(val)) {
296
- answers[q.question] = val.filter((v) => typeof v === "string").join(", ");
319
+ const otherKey = `${key}_other`;
320
+ const picked = resp.content[key];
321
+ const otherRaw = resp.content[otherKey];
322
+ const other = typeof otherRaw === "string" ? otherRaw.trim() : "";
323
+ if (q.multiSelect) {
324
+ const arr = Array.isArray(picked)
325
+ ? picked.filter((v) => typeof v === "string" && v.length > 0)
326
+ : [];
327
+ // Merge selected values + custom free-text, preserving order and dropping dups.
328
+ const merged = [];
329
+ for (const v of [...arr, ...(other ? [other] : [])]) {
330
+ if (!merged.includes(v))
331
+ merged.push(v);
332
+ }
333
+ if (merged.length > 0)
334
+ answers[q.question] = merged.join(", ");
297
335
  }
298
- else if (typeof val === "string" && val !== ELICIT_SKIP) {
299
- // Skip the sentinel "__skip__" so a skipped single-select question is
300
- // simply omitted from the answers map (parity with the request_permission
301
- // path, which leaves the question unanswered on Skip).
302
- answers[q.question] = val;
336
+ else {
337
+ // Free-text override wins when present; else use the dropdown value
338
+ // (skip sentinel / absent question left unanswered).
339
+ if (other) {
340
+ answers[q.question] = other;
341
+ }
342
+ else if (typeof picked === "string" && picked.length > 0 && picked !== ELICIT_SKIP) {
343
+ answers[q.question] = picked;
344
+ }
303
345
  }
304
346
  }
305
347
  return answers;
306
348
  }
307
- /**
308
- * Build an elicitation form for ExitPlanMode (approve/reject).
309
- *
310
- * Uses a single required boolean-style enum so the client renders a clear
311
- * approve/reject choice in the form UI.
312
- */
313
- export function buildExitPlanModeElicitationForm(params, acpSid, toolCallId) {
314
- const planText = params.input && typeof params.input === "object"
315
- ? (params.input.plan ?? "")
316
- : "";
317
- const message = planText ? `Ready to code?\n\n${planText}` : "Ready to code?";
318
- const form = {
319
- mode: "form",
320
- sessionId: acpSid,
321
- message,
322
- requestedSchema: {
323
- type: "object",
324
- properties: {
325
- decision: {
326
- type: "string",
327
- enum: ["approve", "reject"],
328
- title: "Decision",
329
- description: "Approve to exit plan mode and start coding, or reject to keep planning.",
330
- },
331
- },
332
- required: ["decision"],
333
- },
334
- };
335
- if (toolCallId)
336
- form.toolCallId = toolCallId;
337
- return form;
338
- }
339
- /** Parse an ExitPlanMode elicitation response → zcode accept/decline. */
340
- export function parseExitPlanModeElicitationResponse(acpResp) {
341
- if (!acpResp || typeof acpResp !== "object") {
342
- return { action: "decline", reason: "invalid client response" };
343
- }
344
- const resp = acpResp;
345
- if (resp.action !== "accept" || !resp.content) {
346
- return { action: "decline", reason: "cancelled" };
347
- }
348
- if (resp.content.decision === "approve") {
349
- return { action: "accept", content: { answer_0: "approve" } };
350
- }
351
- return { action: "decline", reason: "rejected" };
352
- }
349
+ // ExitPlanMode is handled via session/request_permission (see
350
+ // `exitPlanModeToAcpPermission` / `acpPermissionResponseToExitPlanMode` above)
351
+ // not via elicitation/create. Plan approval is a permission decision, and
352
+ // routing it through elicitation surfaces a generic "input request" shell that
353
+ // reads wrong for this flow. AskUserQuestion is the elicitation use case.
353
354
  //# sourceMappingURL=adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/interaction/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAUH,uCAAuC;AAEvC,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,OAAO,MAAM,KAAK,+BAA+B,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,OAAO,MAAM,KAAK,8BAA8B,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAe;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,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,oEAAoE;YACpE,uDAAuD;YACvD,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;iBAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;gBACrF,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,8DAA8D;AAC9D,iFAAiF;AACjF,0EAA0E;AAC1E,+EAA+E;AAC/E,0EAA0E"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Durable alias store for lazy `session/new` placeholders.
3
+ *
4
+ * `session/new` returns a placeholder id with no backend session behind it
5
+ * (the real `session/create` is deferred to first use). The editor stores this
6
+ * placeholder and may resume it later — including after a bridge restart, when
7
+ * the in-memory `pendingSessions`/`sessionMap` are gone. Without a durable
8
+ * record, `session/resume` then fails with "Session not found".
9
+ *
10
+ * This module keeps a tiny JSON file (`~/.zcode/v2/acp-lazy-sessions.json`,
11
+ * next to tasks-index.sqlite) mapping acp_sid → { cwd, zcodeSid?, createdAt }:
12
+ * - `rememberLazySession` — written at session/new (no zcodeSid yet);
13
+ * - `recordMaterializedSession` — updated once the placeholder materializes;
14
+ * - `lookupLazySession` — lets resume/load/ensureRealSession recover a
15
+ * placeholder from a previous bridge lifetime.
16
+ *
17
+ * Best-effort side-channel like tasks-index: failures are logged and swallowed
18
+ * so a store problem never breaks session/new or first use. Records older than
19
+ * 30 days are pruned on load — the real session stays reachable via
20
+ * session/list after that, only the placeholder alias expires.
21
+ */
22
+ /** Placeholder alias record persisted in the store. */
23
+ export interface LazySessionRecord {
24
+ cwd: string;
25
+ /** Backend session id once the placeholder materialized (absent = never used). */
26
+ zcodeSid?: string;
27
+ createdAt: number;
28
+ }
29
+ /** Record a new placeholder at session/new (no backend session yet). */
30
+ export declare function rememberLazySession(acpSid: string, cwd: string): void;
31
+ /** Attach the backend session id once the placeholder materializes. */
32
+ export declare function recordMaterializedSession(acpSid: string, zcodeSid: string, cwd: string): void;
33
+ /** Look up a placeholder alias (undefined = unknown to this bridge and store). */
34
+ export declare function lookupLazySession(acpSid: string): LazySessionRecord | undefined;
35
+ //# sourceMappingURL=lazy-sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-sessions.d.ts","sourceRoot":"","sources":["../src/lazy-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAQH,uDAAuD;AACvD,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAqDD,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAIrE;AAED,uEAAuE;AACvE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAU7F;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAE/E"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Durable alias store for lazy `session/new` placeholders.
3
+ *
4
+ * `session/new` returns a placeholder id with no backend session behind it
5
+ * (the real `session/create` is deferred to first use). The editor stores this
6
+ * placeholder and may resume it later — including after a bridge restart, when
7
+ * the in-memory `pendingSessions`/`sessionMap` are gone. Without a durable
8
+ * record, `session/resume` then fails with "Session not found".
9
+ *
10
+ * This module keeps a tiny JSON file (`~/.zcode/v2/acp-lazy-sessions.json`,
11
+ * next to tasks-index.sqlite) mapping acp_sid → { cwd, zcodeSid?, createdAt }:
12
+ * - `rememberLazySession` — written at session/new (no zcodeSid yet);
13
+ * - `recordMaterializedSession` — updated once the placeholder materializes;
14
+ * - `lookupLazySession` — lets resume/load/ensureRealSession recover a
15
+ * placeholder from a previous bridge lifetime.
16
+ *
17
+ * Best-effort side-channel like tasks-index: failures are logged and swallowed
18
+ * so a store problem never breaks session/new or first use. Records older than
19
+ * 30 days are pruned on load — the real session stays reachable via
20
+ * session/list after that, only the placeholder alias expires.
21
+ */
22
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
23
+ import path from "node:path";
24
+ import process from "node:process";
25
+ import { log, warn } from "./utils.js";
26
+ /** Store file lives next to config.json / tasks-index.sqlite under ~/.zcode/v2/. */
27
+ const STORE_FILENAME = "acp-lazy-sessions.json";
28
+ /** Placeholder aliases expire after 30 days; the real session remains listable. */
29
+ const TTL_MS = 30 * 24 * 60 * 60 * 1000;
30
+ /** Resolved at call time so tests can stub HOME without re-importing. */
31
+ function storePath() {
32
+ const home = process.env.HOME || process.env.USERPROFILE || "~";
33
+ return path.join(home, ".zcode", "v2", STORE_FILENAME);
34
+ }
35
+ /** Read the store, pruning expired/corrupt records. Returns {} on any failure. */
36
+ function loadRecords() {
37
+ try {
38
+ const p = storePath();
39
+ if (!existsSync(p))
40
+ return {};
41
+ const raw = JSON.parse(readFileSync(p, "utf8"));
42
+ if (typeof raw !== "object" || raw === null)
43
+ return {};
44
+ const now = Date.now();
45
+ let pruned = false;
46
+ const out = {};
47
+ for (const [acpSid, rec] of Object.entries(raw)) {
48
+ if (typeof rec?.createdAt !== "number" || now - rec.createdAt > TTL_MS) {
49
+ pruned = true;
50
+ continue;
51
+ }
52
+ out[acpSid] = rec;
53
+ }
54
+ if (pruned)
55
+ writeRecords(out);
56
+ return out;
57
+ }
58
+ catch (e) {
59
+ warn(`lazy-sessions: store read failed ` +
60
+ `(${e instanceof Error ? e.message : String(e)}) — placeholder aliases unavailable`);
61
+ return {};
62
+ }
63
+ }
64
+ /** Overwrite the store file. Failures are logged, never thrown. */
65
+ function writeRecords(records) {
66
+ try {
67
+ const p = storePath();
68
+ mkdirSync(path.dirname(p), { recursive: true });
69
+ writeFileSync(p, JSON.stringify(records, null, 2));
70
+ }
71
+ catch (e) {
72
+ log(`lazy-sessions: store write failed (${e instanceof Error ? e.message : String(e)})`);
73
+ }
74
+ }
75
+ /** Record a new placeholder at session/new (no backend session yet). */
76
+ export function rememberLazySession(acpSid, cwd) {
77
+ const records = loadRecords();
78
+ records[acpSid] = { cwd, createdAt: Date.now() };
79
+ writeRecords(records);
80
+ }
81
+ /** Attach the backend session id once the placeholder materializes. */
82
+ export function recordMaterializedSession(acpSid, zcodeSid, cwd) {
83
+ const records = loadRecords();
84
+ const existing = records[acpSid];
85
+ if (existing?.zcodeSid === zcodeSid)
86
+ return;
87
+ records[acpSid] = {
88
+ cwd: existing?.cwd ?? cwd,
89
+ zcodeSid,
90
+ createdAt: existing?.createdAt ?? Date.now(),
91
+ };
92
+ writeRecords(records);
93
+ }
94
+ /** Look up a placeholder alias (undefined = unknown to this bridge and store). */
95
+ export function lookupLazySession(acpSid) {
96
+ return loadRecords()[acpSid];
97
+ }
98
+ //# sourceMappingURL=lazy-sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-sessions.js","sourceRoot":"","sources":["../src/lazy-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAUvC,oFAAoF;AACpF,MAAM,cAAc,GAAG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;QAAE,OAAO;IAC5C,OAAO,CAAC,MAAM,CAAC,GAAG;QAChB,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG;QACzB,QAAQ;QACR,SAAS,EAAE,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;KAC7C,CAAC;IACF,YAAY,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * In-memory TTL cache for quota results.
3
+ *
4
+ * `/quota` is user-triggered, so the cache only guards against rapid repeats
5
+ * (e.g. double-entering the command). The TTL is intentionally short — 10s —
6
+ * so the displayed figures stay fresh while still debouncing bursts. There is
7
+ * no file persistence and no per-key sharding: a single process-wide slot.
8
+ */
9
+ import type { QuotaResult } from "./types.js";
10
+ /** Return the cached result if still fresh, else `null`. */
11
+ export declare function getCached(): QuotaResult | null;
12
+ /** Store a fresh result, stamping it with the current time. */
13
+ export declare function setCached(result: QuotaResult): void;
14
+ /** Clear the cache (test helper). */
15
+ export declare function clearCache(): void;
16
+ /** Override the clock (test-only). Pass `undefined` to restore real time. */
17
+ export declare function setClock(fn?: () => number): void;
18
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/quota/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAU9C,4DAA4D;AAC5D,wBAAgB,SAAS,IAAI,WAAW,GAAG,IAAI,CAG9C;AAED,+DAA+D;AAC/D,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAEnD;AAED,qCAAqC;AACrC,wBAAgB,UAAU,IAAI,IAAI,CAEjC;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAEhD"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * In-memory TTL cache for quota results.
3
+ *
4
+ * `/quota` is user-triggered, so the cache only guards against rapid repeats
5
+ * (e.g. double-entering the command). The TTL is intentionally short — 10s —
6
+ * so the displayed figures stay fresh while still debouncing bursts. There is
7
+ * no file persistence and no per-key sharding: a single process-wide slot.
8
+ */
9
+ /** How long a cached result is served before re-querying. */
10
+ const TTL_MS = 10_000;
11
+ let slot = null;
12
+ /** Inject a fake clock — only tests should need this. */
13
+ let now = () => Date.now();
14
+ /** Return the cached result if still fresh, else `null`. */
15
+ export function getCached() {
16
+ if (slot && now() - slot.at < TTL_MS)
17
+ return slot.result;
18
+ return null;
19
+ }
20
+ /** Store a fresh result, stamping it with the current time. */
21
+ export function setCached(result) {
22
+ slot = { result, at: now() };
23
+ }
24
+ /** Clear the cache (test helper). */
25
+ export function clearCache() {
26
+ slot = null;
27
+ }
28
+ /** Override the clock (test-only). Pass `undefined` to restore real time. */
29
+ export function setClock(fn) {
30
+ now = fn ?? (() => Date.now());
31
+ }
32
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/quota/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,6DAA6D;AAC7D,MAAM,MAAM,GAAG,MAAM,CAAC;AAEtB,IAAI,IAAI,GAA+C,IAAI,CAAC;AAE5D,yDAAyD;AACzD,IAAI,GAAG,GAAiB,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAEzC,4DAA4D;AAC5D,MAAM,UAAU,SAAS;IACvB,IAAI,IAAI,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,MAAM;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC;IACzD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,SAAS,CAAC,MAAmB;IAC3C,IAAI,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;AAC/B,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,UAAU;IACxB,IAAI,GAAG,IAAI,CAAC;AACd,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,QAAQ,CAAC,EAAiB;IACxC,GAAG,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * GLM quota API HTTP client.
3
+ *
4
+ * Queries `bigmodel.cn` (CN) or `api.z.ai` (intl) for the current account's
5
+ * usage limits. Credentials come from the active ZCode provider in
6
+ * `~/.zcode/v2/config.json` via {@link loadZcodeCredentials} — the same apiKey
7
+ * the backend already uses for model calls.
8
+ */
9
+ /** Raw response from the quota endpoint, pre-parsing. */
10
+ export interface QuotaResponse {
11
+ status: number;
12
+ json: unknown;
13
+ text: string;
14
+ }
15
+ /**
16
+ * Pick the quota host from a provider `baseURL`.
17
+ *
18
+ * `api.z.ai` → intl; anything else (including `open.bigmodel.cn`,
19
+ * `bigmodel.cn`, empty) → CN. This mirrors how the backend routes model
20
+ * traffic.
21
+ */
22
+ export declare function resolveQuotaHost(baseURL: string): string;
23
+ /**
24
+ * Fetch the quota envelope from the GLM API.
25
+ *
26
+ * @throws if the active provider has no apiKey in config, or on network/timeout
27
+ * errors. The caller maps these to `unavailable`.
28
+ */
29
+ export declare function fetchQuotaResponse(fetchImpl?: typeof globalThis.fetch): Promise<QuotaResponse>;
30
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/quota/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,GAAE,OAAO,UAAU,CAAC,KAAwB,GACpD,OAAO,CAAC,aAAa,CAAC,CAyBxB"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * GLM quota API HTTP client.
3
+ *
4
+ * Queries `bigmodel.cn` (CN) or `api.z.ai` (intl) for the current account's
5
+ * usage limits. Credentials come from the active ZCode provider in
6
+ * `~/.zcode/v2/config.json` via {@link loadZcodeCredentials} — the same apiKey
7
+ * the backend already uses for model calls.
8
+ */
9
+ import { loadZcodeCredentials } from "../backend/credentials.js";
10
+ /** Quota endpoint path, appended to the chosen host. */
11
+ const QUOTA_PATH = "/api/monitor/usage/quota/limit";
12
+ /** Request timeout (ms). The endpoint is fast; keep this tight. */
13
+ const TIMEOUT_MS = 8000;
14
+ /** Hosts for the CN and intl deployments. */
15
+ const HOST_CN = "https://open.bigmodel.cn";
16
+ const HOST_INTL = "https://api.z.ai";
17
+ /**
18
+ * Pick the quota host from a provider `baseURL`.
19
+ *
20
+ * `api.z.ai` → intl; anything else (including `open.bigmodel.cn`,
21
+ * `bigmodel.cn`, empty) → CN. This mirrors how the backend routes model
22
+ * traffic.
23
+ */
24
+ export function resolveQuotaHost(baseURL) {
25
+ return baseURL.includes("api.z.ai") ? HOST_INTL : HOST_CN;
26
+ }
27
+ /**
28
+ * Fetch the quota envelope from the GLM API.
29
+ *
30
+ * @throws if the active provider has no apiKey in config, or on network/timeout
31
+ * errors. The caller maps these to `unavailable`.
32
+ */
33
+ export async function fetchQuotaResponse(fetchImpl = globalThis.fetch) {
34
+ const { ANTHROPIC_API_KEY, ZCODE_BASE_URL } = loadZcodeCredentials();
35
+ if (!ANTHROPIC_API_KEY) {
36
+ throw new Error("no apiKey in ZCode config — cannot query quota");
37
+ }
38
+ const url = resolveQuotaHost(ZCODE_BASE_URL ?? "") + QUOTA_PATH;
39
+ const resp = await fetchImpl(url, {
40
+ method: "GET",
41
+ headers: {
42
+ Accept: "application/json, text/plain, */*",
43
+ Authorization: `Bearer ${ANTHROPIC_API_KEY}`,
44
+ },
45
+ signal: AbortSignal.timeout(TIMEOUT_MS),
46
+ });
47
+ const text = await resp.text();
48
+ let json = null;
49
+ try {
50
+ json = text ? JSON.parse(text) : null;
51
+ }
52
+ catch {
53
+ // Non-JSON body — leave json null; the parser treats it as unavailable.
54
+ }
55
+ return { status: resp.status, json, text };
56
+ }
57
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/quota/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,wDAAwD;AACxD,MAAM,UAAU,GAAG,gCAAgC,CAAC;AAEpD,mEAAmE;AACnE,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,6CAA6C;AAC7C,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAC3C,MAAM,SAAS,GAAG,kBAAkB,CAAC;AASrC;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,OAAO,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,YAAqC,UAAU,CAAC,KAAK;IAErD,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,oBAAoB,EAAE,CAAC;IACrE,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,GAAG,GAAG,gBAAgB,CAAC,cAAc,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC;IAChE,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,MAAM,EAAE,mCAAmC;YAC3C,aAAa,EAAE,UAAU,iBAAiB,EAAE;SAC7C;QACD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC;KACxC,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,IAAI,GAAY,IAAI,CAAC;IACzB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACxC,CAAC;IAAC,MAAM,CAAC;QACP,wEAAwE;IAC1E,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Color progress-bar rendering for the `zcode-quota` CLI.
3
+ *
4
+ * The default CLI view overlays the usage numbers directly onto a heat-colored
5
+ * (green→yellow→red) bar using 24-bit ANSI background colors, so the percentage
6
+ * or used/total counter reads from inside the bar and the right margin stays
7
+ * short (just the reset time). `--plain` and the `/quota` slash command bypass
8
+ * this module entirely and keep the classic monochrome `█`/`░` layout from
9
+ * {@link renderBar}.
10
+ *
11
+ * Only real terminals render 24-bit color; the CLI caller gates this on
12
+ * `process.stdout.isTTY` so piping to a file or another command never emits
13
+ * raw escape codes.
14
+ */
15
+ /** ANSI reset (cancel all attributes). */
16
+ export declare const RESET = "\u001B[0m";
17
+ /** 24-bit RGB triple. */
18
+ type Rgb = readonly [number, number, number];
19
+ /**
20
+ * Green→yellow→red heat color for a usage percent.
21
+ *
22
+ * 0% → green `(34,197,94)`, 50% → yellow `(234,179,8)`, 100% → red
23
+ * `(239,68,68)`, piecewise-linearly interpolated. Input is clamped to [0, 100].
24
+ */
25
+ export declare function heatColor(pct: number): Rgb;
26
+ /**
27
+ * Pick the overlay text drawn inside the bar.
28
+ *
29
+ * Returns `"used/total"` when the item carries both absolute counters (e.g. the
30
+ * MCP limit), otherwise `"NN%"` (the rounded used percent). This lets
31
+ * counter-bearing limits show their exact counts in-bar while counter-less
32
+ * limits (5h, Opencode Go windows) show the percent.
33
+ */
34
+ export declare function pickOverlay(item: {
35
+ usedPercent: number;
36
+ usedCount?: number;
37
+ totalCount?: number;
38
+ }): string;
39
+ /** Options for {@link renderColorBar}. */
40
+ export interface ColorBarOptions {
41
+ /** Text drawn centered inside the bar (e.g. `"73%"` or `"237/1000"`). */
42
+ overlay?: string;
43
+ /** Total cell count; defaults to 20 to match the plain {@link renderBar}. */
44
+ width?: number;
45
+ }
46
+ /**
47
+ * Render a heat-colored progress bar with optional centered overlay text.
48
+ *
49
+ * Each cell is one background color: the fill cells use {@link heatColor} (so
50
+ * low usage reads green, high usage red), the empty cells use a constant dark
51
+ * gray. When an overlay string is supplied its characters are written over the
52
+ * bar with a contrasting foreground (white on fill, gray on empty), centered
53
+ * across the `width` cells. The result always ends with {@link RESET} so the
54
+ * color never leaks into the text that follows.
55
+ */
56
+ export declare function renderColorBar(usedPercent: number, opts?: ColorBarOptions): string;
57
+ export {};
58
+ //# sourceMappingURL=color.d.ts.map