@hyperwindmill/caretaker-cli 0.29.0 → 0.30.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 (53) hide show
  1. package/dist/agents/dispatch.d.ts.map +1 -1
  2. package/dist/agents/dispatch.js +4 -1
  3. package/dist/cli/web/server.d.ts.map +1 -1
  4. package/dist/cli/web/server.js +29 -7
  5. package/dist/cli/web/session_scope.d.ts +11 -0
  6. package/dist/cli/web/session_scope.d.ts.map +1 -0
  7. package/dist/cli/web/session_scope.js +13 -0
  8. package/dist/cli/web/turn_guard.d.ts +9 -0
  9. package/dist/cli/web/turn_guard.d.ts.map +1 -0
  10. package/dist/cli/web/turn_guard.js +18 -0
  11. package/dist/cli/web/voice_builtin.d.ts +3 -0
  12. package/dist/cli/web/voice_builtin.d.ts.map +1 -0
  13. package/dist/cli/web/voice_builtin.js +55 -0
  14. package/dist/cli/web/voice_proxy.d.ts +33 -1
  15. package/dist/cli/web/voice_proxy.d.ts.map +1 -1
  16. package/dist/cli/web/voice_proxy.js +173 -27
  17. package/dist/commands/loader.js +2 -2
  18. package/dist/harness/tools/builtin/index.d.ts.map +1 -1
  19. package/dist/harness/tools/builtin/index.js +4 -0
  20. package/dist/harness/tools/builtin/set_workspace.d.ts +3 -0
  21. package/dist/harness/tools/builtin/set_workspace.d.ts.map +1 -0
  22. package/dist/harness/tools/builtin/set_workspace.js +49 -0
  23. package/dist/plugins/manifest.d.ts +1 -1
  24. package/dist/plugins/manifest.js +1 -1
  25. package/dist/session/store.d.ts +6 -0
  26. package/dist/session/store.d.ts.map +1 -1
  27. package/dist/session/store.js +8 -0
  28. package/dist/session/types.d.ts +4 -0
  29. package/dist/session/types.d.ts.map +1 -1
  30. package/dist/voice/pocket/catalog.d.ts +24 -0
  31. package/dist/voice/pocket/catalog.d.ts.map +1 -0
  32. package/dist/voice/pocket/catalog.js +152 -0
  33. package/dist/voice/pocket/engine.d.ts +17 -0
  34. package/dist/voice/pocket/engine.d.ts.map +1 -0
  35. package/dist/voice/pocket/engine.js +145 -0
  36. package/dist/voice/pocket/inference.d.ts +36 -0
  37. package/dist/voice/pocket/inference.d.ts.map +1 -0
  38. package/dist/voice/pocket/inference.js +228 -0
  39. package/dist/voice/pocket/install.d.ts +54 -0
  40. package/dist/voice/pocket/install.d.ts.map +1 -0
  41. package/dist/voice/pocket/install.js +275 -0
  42. package/dist/voice/pocket/tokenizer.d.ts +42 -0
  43. package/dist/voice/pocket/tokenizer.d.ts.map +1 -0
  44. package/dist/voice/pocket/tokenizer.js +279 -0
  45. package/dist/voice/pocket/voices.d.ts +9 -0
  46. package/dist/voice/pocket/voices.d.ts.map +1 -0
  47. package/dist/voice/pocket/voices.js +88 -0
  48. package/dist/voice/pronunciation.d.ts +16 -0
  49. package/dist/voice/pronunciation.d.ts.map +1 -0
  50. package/dist/voice/pronunciation.js +51 -0
  51. package/dist/webview/standalone.js +1508 -701
  52. package/dist/webview/standalone.js.map +4 -4
  53. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/agents/dispatch.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAQ,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,WAAW,CAcjG;AAED,MAAM,WAAW,cAAc;IAC7B;yEACqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IACvC;6EACyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,WAAW,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CA2ElF"}
1
+ {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/agents/dispatch.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAQ,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,WAAW,CAcjG;AAED,MAAM,WAAW,cAAc;IAC7B;yEACqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IACvC;6EACyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,WAAW,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAiFlF"}
@@ -52,7 +52,10 @@ export async function dispatchAgent(opts) {
52
52
  guardError: `dispatch depth exceeded (${MAX_DISPATCH_DEPTH})`,
53
53
  };
54
54
  }
55
- const effective = effectiveAgent(opts.invoked, caller);
55
+ // Inherit the caller's *live* working dir, not its stored config: a chat
56
+ // moved by `set_workspace` mutates ctx.workingDir, and a sub-agent must
57
+ // follow the session into that project.
58
+ const effective = effectiveAgent(opts.invoked, caller && { ...caller, workingDir: opts.ctx.workingDir });
56
59
  if (!effective.provider) {
57
60
  return {
58
61
  text: '',
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","s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,eAAe,CAAC,CAAC;IACtF,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,qBAAa,oBAAoB;IAQ7B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAPvB,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2B;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;gBAGjB,IAAI,EAAE;QACrB,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,cAAc,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAMH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,eAAe,IAAI,GAAG;IAIhB,KAAK,CACT,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,aAAa,EACjB,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EACtE,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,IAAI,CAAC;IAsFhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAutC3E"}
@@ -20,12 +20,15 @@ import { createSource, deleteSource, patchSource, refreshSource, } from '../../p
20
20
  import { createMcpServer, deleteMcpServer, patchMcpServer, readOAuthBlob } from '../../mcp/server_manager.js';
21
21
  import { authenticateMcpServer, revokeMcpAuth } from '../../mcp/oauth.js';
22
22
  import { listForAgent, readSession, deleteSession, computeContextUsage, createSession, userMessage, appendMessage, saveAttachment, attachmentsDir, } from '../../session/index.js';
23
+ import { sessionRunScope } from './session_scope.js';
24
+ import { guardTurnCallbacks } from './turn_guard.js';
23
25
  import { watchCycleStream } from './scheduler/cycle_events.js';
24
26
  import { startBackgroundScheduler, loadTaskRuns } from './scheduler.js';
25
27
  import { fsRouter } from './fs.js';
26
28
  import { activationStatus, resolvePlanningEnabled } from './scheduler/task_roles.js';
27
- import { registerVoiceProxy, voiceClientConfig, fetchVoiceCatalog } from './voice_proxy.js';
29
+ import { registerVoiceProxy, voiceClientConfig, fetchVoiceCatalog, formKeyFor, KEY_WITHHELD_HINT, } from './voice_proxy.js';
28
30
  import { registerVoiceBackend, maybeAutoStartBackend } from './voice_backend.js';
31
+ import { registerVoiceBuiltin } from './voice_builtin.js';
29
32
  import { fetchAcpRegistry, installAcpAgent } from '../../acp/index.js';
30
33
  // Resolve Webview static files path.
31
34
  // Published npm package ships the assets under dist/webview (see scripts/copy-webview.mjs);
@@ -86,7 +89,13 @@ export class WebSessionController {
86
89
  this.history = [];
87
90
  }
88
91
  }
92
+ else {
93
+ // Re-read the latest session_meta every turn: `set_workspace` may have
94
+ // appended a workspace override during the previous turn.
95
+ this.metaRecord = (await readSession(this.opts.agent.id, this.metaRecord.id)).meta;
96
+ }
89
97
  const meta = this.metaRecord;
98
+ const scope = sessionRunScope(meta, this.opts.workingDir);
90
99
  const attachmentRecords = [];
91
100
  if (rawAttachments && rawAttachments.length > 0) {
92
101
  for (const att of rawAttachments) {
@@ -109,7 +118,8 @@ export class WebSessionController {
109
118
  prompt,
110
119
  history: priorHistory,
111
120
  signal: ac.signal,
112
- workingDir: this.opts.workingDir,
121
+ workingDir: scope.workingDir,
122
+ memoryProjectId: scope.memoryProjectId,
113
123
  sessionId: meta.id,
114
124
  promptAttachments: attachmentRecords.length > 0 ? attachmentRecords : undefined,
115
125
  voiceConversation,
@@ -149,6 +159,7 @@ export async function startServer(port, host) {
149
159
  registerTaskBridge(app);
150
160
  registerVoiceProxy(app);
151
161
  registerVoiceBackend(app);
162
+ registerVoiceBuiltin(app);
152
163
  // Pure-Node static serving with absolute path validation and fallback
153
164
  app.get('/', (c) => {
154
165
  try {
@@ -863,6 +874,10 @@ export async function startServer(port, host) {
863
874
  controller = null;
864
875
  post({ type: 'contextUsage', usage: null });
865
876
  await loadSessionsAndSend(agent.id);
877
+ // Ack: the switch is complete server-side. The desktop assistant waits
878
+ // for it before opening the mic, so a `start` cannot reach the previous
879
+ // agent while this one's MCP servers are still connecting.
880
+ post({ type: 'agentSelected', agentId: agent.id });
866
881
  };
867
882
  const loadSessionsAndSend = async (agentId) => {
868
883
  try {
@@ -990,7 +1005,8 @@ export async function startServer(port, host) {
990
1005
  sessionId: currentSessionId ?? undefined,
991
1006
  });
992
1007
  }
993
- await controller.start(msg.prompt, {
1008
+ const turnController = controller;
1009
+ await controller.start(msg.prompt, guardTurnCallbacks({
994
1010
  onChunk: (text) => post({ type: 'chunk', text }),
995
1011
  onThinking: (text) => post({ type: 'thinking', text }),
996
1012
  onToolCall: (id, name, args) => post({ type: 'tool_call', id, name, args }),
@@ -1015,7 +1031,7 @@ export async function startServer(port, host) {
1015
1031
  currentSessionId = sessionId;
1016
1032
  void loadSessionsAndSend(currentAgent.id);
1017
1033
  },
1018
- }, msg.attachments, msg.voice);
1034
+ }, () => controller === turnController), msg.attachments, msg.voice);
1019
1035
  return;
1020
1036
  }
1021
1037
  case 'abort':
@@ -1048,6 +1064,9 @@ export async function startServer(port, host) {
1048
1064
  return;
1049
1065
  }
1050
1066
  case 'createSession': {
1067
+ // A confirm card of the superseded turn can no longer be answered
1068
+ // (the view was cleared); reject it so that run can wind down.
1069
+ resolveAllPending('reject');
1051
1070
  currentSessionId = null;
1052
1071
  controller = null;
1053
1072
  post({ type: 'contextUsage', usage: null });
@@ -1275,15 +1294,18 @@ export async function startServer(port, host) {
1275
1294
  post({ type: 'acpInstallResult', agentId: msg.agentId, ok: false, error: String(err) });
1276
1295
  }
1277
1296
  return;
1278
- case 'fetchVoiceModels':
1297
+ case 'fetchVoiceModels': {
1298
+ const { key, withheld } = formKeyFor(msg.endpoint, msg.apiKey, (await loadConfig()).voice);
1279
1299
  try {
1280
- const catalog = await fetchVoiceCatalog(msg.endpoint, msg.apiKey ?? null);
1300
+ const catalog = await fetchVoiceCatalog(msg.endpoint, key);
1281
1301
  post({ type: 'voiceModelsFetched', result: { ok: true, catalog }, target: msg.target });
1282
1302
  }
1283
1303
  catch (err) {
1284
- post({ type: 'voiceModelsFetched', result: { ok: false, error: String(err) }, target: msg.target });
1304
+ const error = withheld && /\b40[13]\b/.test(String(err)) ? `${KEY_WITHHELD_HINT} (${err})` : String(err);
1305
+ post({ type: 'voiceModelsFetched', result: { ok: false, error }, target: msg.target });
1285
1306
  }
1286
1307
  return;
1308
+ }
1287
1309
  case 'watchCycle': {
1288
1310
  // Ids name files on disk; the same rule as the bridge parser.
1289
1311
  if (!/^[A-Za-z0-9_-]+$/.test(msg.agentId) || !/^[A-Za-z0-9_-]+$/.test(msg.sessionId))
@@ -0,0 +1,11 @@
1
+ import type { SessionMetaRecord } from '../../session/types.js';
2
+ /** Working dir + memory scope for one chat turn. The `set_workspace` override
3
+ * on the session meta wins over the agent's own workingDir and brings its
4
+ * projectId along (passed explicitly: a managed clone's blank
5
+ * `projects[].workingDir` never prefix-matches, so dir-based resolution
6
+ * would degrade the turn to global-only memories). */
7
+ export declare function sessionRunScope(meta: Pick<SessionMetaRecord, 'workingDir' | 'projectId'> | undefined, agentWorkingDir: string): {
8
+ workingDir: string;
9
+ memoryProjectId?: string;
10
+ };
11
+ //# sourceMappingURL=session_scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session_scope.d.ts","sourceRoot":"","sources":["../../../src/cli/web/session_scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;uDAIuD;AACvD,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG,SAAS,EACrE,eAAe,EAAE,MAAM,GACtB;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,CAOlD"}
@@ -0,0 +1,13 @@
1
+ /** Working dir + memory scope for one chat turn. The `set_workspace` override
2
+ * on the session meta wins over the agent's own workingDir and brings its
3
+ * projectId along (passed explicitly: a managed clone's blank
4
+ * `projects[].workingDir` never prefix-matches, so dir-based resolution
5
+ * would degrade the turn to global-only memories). */
6
+ export function sessionRunScope(meta, agentWorkingDir) {
7
+ if (meta?.workingDir) {
8
+ return meta.projectId
9
+ ? { workingDir: meta.workingDir, memoryProjectId: meta.projectId }
10
+ : { workingDir: meta.workingDir };
11
+ }
12
+ return { workingDir: agentWorkingDir };
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { ChatCallbacks } from './server.js';
2
+ /** Silence a chat turn once it is superseded. Dropping the controller
3
+ * (new session, agent switch) does not stop its run, and the run's callbacks
4
+ * post straight to the socket — without this, a still-streaming turn keeps
5
+ * writing chunks, `done` and confirm cards into the session that replaced
6
+ * it. The old run keeps going; only its output is cut. A superseded turn's
7
+ * confirmations resolve `reject`: nobody can answer them any more. */
8
+ export declare function guardTurnCallbacks(cb: ChatCallbacks, isCurrent: () => boolean): ChatCallbacks;
9
+ //# sourceMappingURL=turn_guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn_guard.d.ts","sourceRoot":"","sources":["../../../src/cli/web/turn_guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;uEAKuE;AACvE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,GAAG,aAAa,CAY7F"}
@@ -0,0 +1,18 @@
1
+ /** Silence a chat turn once it is superseded. Dropping the controller
2
+ * (new session, agent switch) does not stop its run, and the run's callbacks
3
+ * post straight to the socket — without this, a still-streaming turn keeps
4
+ * writing chunks, `done` and confirm cards into the session that replaced
5
+ * it. The old run keeps going; only its output is cut. A superseded turn's
6
+ * confirmations resolve `reject`: nobody can answer them any more. */
7
+ export function guardTurnCallbacks(cb, isCurrent) {
8
+ return {
9
+ onChunk: (t) => isCurrent() && cb.onChunk(t),
10
+ onThinking: (t) => isCurrent() && cb.onThinking(t),
11
+ onToolCall: (id, name, args) => isCurrent() && cb.onToolCall(id, name, args),
12
+ onToolResult: (id, content) => isCurrent() && cb.onToolResult(id, content),
13
+ askConfirm: (id, toolName, args) => isCurrent() ? cb.askConfirm(id, toolName, args) : Promise.resolve('reject'),
14
+ onError: (m) => isCurrent() && cb.onError(m),
15
+ onDone: () => isCurrent() && cb.onDone(),
16
+ onSessionCreated: (id) => isCurrent() && cb.onSessionCreated?.(id),
17
+ };
18
+ }
@@ -0,0 +1,3 @@
1
+ import type { Hono } from 'hono';
2
+ export declare function registerVoiceBuiltin(app: Hono): void;
3
+ //# sourceMappingURL=voice_builtin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice_builtin.d.ts","sourceRoot":"","sources":["../../../src/cli/web/voice_builtin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAwBjC,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAgCpD"}
@@ -0,0 +1,55 @@
1
+ // Routes for the built-in voice installer. The in-flight guard is per language so a
2
+ // second install of the same language cannot start a parallel download.
3
+ import { stream } from 'hono/streaming';
4
+ import { POCKET_LANGUAGES } from '../../voice/pocket/catalog.js';
5
+ import { builtinVoiceStatus, deleteBuiltinVoice, installBuiltinVoice, } from '../../voice/pocket/install.js';
6
+ import { releasePocketModels, runtimeLoadError, runtimeLoaded, speakBuiltin } from '../../voice/pocket/engine.js';
7
+ import { setBuiltinSpeaker } from './voice_proxy.js';
8
+ // One install or delete at a time: languages share the runtime directory.
9
+ let busy = null;
10
+ function reqLanguage(q) {
11
+ return q && Object.hasOwn(POCKET_LANGUAGES, q) ? q : null;
12
+ }
13
+ async function statusWithLoadError() {
14
+ const status = await builtinVoiceStatus();
15
+ const loadError = runtimeLoadError();
16
+ return loadError ? { ...status, runtime: { ...status.runtime, loadError } } : status;
17
+ }
18
+ export function registerVoiceBuiltin(app) {
19
+ setBuiltinSpeaker(speakBuiltin);
20
+ app.get('/api/voice/builtin', async (c) => c.json(await statusWithLoadError()));
21
+ app.post('/api/voice/builtin/install', async (c) => {
22
+ const lang = reqLanguage(c.req.query('language'));
23
+ if (!lang)
24
+ return c.text('Unknown language.', 400);
25
+ if (busy)
26
+ return c.text(`An install of ${busy} is already in progress.`, 409);
27
+ busy = lang;
28
+ c.header('Content-Type', 'application/x-ndjson');
29
+ return stream(c, async (s) => {
30
+ try {
31
+ for await (const p of installBuiltinVoice(lang))
32
+ await s.writeln(JSON.stringify(p));
33
+ }
34
+ finally {
35
+ busy = null;
36
+ }
37
+ });
38
+ });
39
+ app.post('/api/voice/builtin/delete', async (c) => {
40
+ const lang = reqLanguage(c.req.query('language'));
41
+ if (!lang)
42
+ return c.text('Unknown language.', 400);
43
+ if (busy)
44
+ return c.text('An install is in progress; wait for it to finish.', 409);
45
+ busy = lang;
46
+ try {
47
+ await releasePocketModels();
48
+ await deleteBuiltinVoice(lang, { keepRuntime: runtimeLoaded() });
49
+ }
50
+ finally {
51
+ busy = null;
52
+ }
53
+ return c.json(await statusWithLoadError());
54
+ });
55
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Hono } from 'hono';
2
- import type { CaretakerConfig, VoiceConfig } from 'caretaker-types';
2
+ import type { CaretakerConfig, PronunciationEntry, VoiceConfig } from 'caretaker-types';
3
3
  import type { VoiceCatalog, VoiceClientConfig } from 'webview-ui/bridge';
4
4
  export declare function voiceClientConfig(config: CaretakerConfig): VoiceClientConfig | null;
5
5
  /** Resolve the usable voice config, or a reason it cannot be used. Shared with
@@ -22,6 +22,38 @@ export declare function ttsTarget(voice: VoiceConfig): {
22
22
  apiKey?: string;
23
23
  };
24
24
  export declare function registerVoiceProxy(app: Hono): void;
25
+ export type SynthesisSettings = Pick<VoiceConfig, 'ttsEngine' | 'ttsLanguage' | 'ttsVoice' | 'ttsModel' | 'ttsSpeed' | 'ttsEndpoint' | 'pronunciationEnabled'> & {
26
+ pronunciation?: PronunciationEntry[];
27
+ };
28
+ /** The saved voice config if synthesis can run: voice enabled, and (for the
29
+ * endpoint engine) some endpoint to talk to. The built-in engine needs none. */
30
+ export declare function resolveSynthesis(): Promise<{
31
+ voice: VoiceConfig;
32
+ } | {
33
+ error: string;
34
+ }>;
35
+ /** Same server: scheme, host and port. A different path or a trailing slash is
36
+ * not a different host, so it keeps the saved key. */
37
+ export declare function sameHost(a?: string, b?: string): boolean;
38
+ export declare const KEY_WITHHELD_HINT = "The endpoint changed: enter the API key again, or save first, to use it with the new endpoint.";
39
+ /** The key to send to `endpoint` for a request built from the settings form. A key
40
+ * typed in the form is the user's own, for that endpoint. The stored key (the form
41
+ * round-trips its encrypted blob) goes only to the host it was saved for;
42
+ * otherwise it is withheld and the request goes without a key. */
43
+ export declare function formKeyFor(endpoint: string, formKey: string | null | undefined, saved: VoiceConfig | undefined): {
44
+ key: string | null;
45
+ withheld: boolean;
46
+ };
47
+ /** Overlay the form's unsaved synthesis settings on the saved config. The saved
48
+ * `ttsApiKey` is dropped when the previewed `ttsEndpoint` is on another host than
49
+ * the saved one, so editing the URL can never send the stored key to a new host. */
50
+ export declare function mergePreview(saved: VoiceConfig, s: SynthesisSettings): VoiceConfig;
51
+ export type BuiltinSpeaker = (voice: VoiceConfig, text: string, signal: AbortSignal) => Promise<Response>;
52
+ /** The built-in engine registers itself here; null unregisters. */
53
+ export declare function setBuiltinSpeaker(fn: BuiltinSpeaker | null): void;
54
+ /** Synthesize `text` with the configured engine, dictionary applied, streaming
55
+ * the audio back. Failures are Responses (status + readable body), not throws. */
56
+ export declare function synthesize(voice: VoiceConfig, text: string, signal: AbortSignal): Promise<Response>;
25
57
  /**
26
58
  * Read a speech endpoint's installed models so the settings form can offer real
27
59
  * choices instead of free text.
@@ -1 +1 @@
1
- {"version":3,"file":"voice_proxy.d.ts","sourceRoot":"","sources":["../../../src/cli/web/voice_proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGpE,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAIzE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,iBAAiB,GAAG,IAAI,CAUnF;AAED;;0EAE0E;AAC1E,wBAAsB,YAAY,IAAI,OAAO,CAAC;IAAE,KAAK,EAAE,WAAW,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAUxF;AASD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE3E;AAED;uEACuE;AACvE,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGrF;AAED;;6CAE6C;AAC7C,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAInF;AAOD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CA2ElD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,M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../../store/json.js';
2
2
  import { decrypt, isEncrypted } from '../../lib/encryption.js';
3
+ import { applyPronunciation, dictionaryFor, synthesisLanguage } from '../../voice/pronunciation.js';
3
4
  export function voiceClientConfig(config) {
4
5
  const voice = config.voice;
5
6
  if (!voice)
@@ -7,10 +8,14 @@ export function voiceClientConfig(config) {
7
8
  const out = {
8
9
  enabled: voice.enabled === true,
9
10
  configured: typeof voice.endpoint === 'string' && voice.endpoint.trim().length > 0,
10
- canSpeak: typeof voice.ttsModel === 'string' && voice.ttsModel.trim().length > 0,
11
+ canSpeak: voice.ttsEngine === 'builtin'
12
+ ? typeof voice.ttsLanguage === 'string' && voice.ttsLanguage.length > 0
13
+ : typeof voice.ttsModel === 'string' && voice.ttsModel.trim().length > 0,
11
14
  };
12
15
  if (voice.lang)
13
16
  out.lang = voice.lang;
17
+ if (Number.isFinite(voice.playbackBufferMs))
18
+ out.playbackBufferMs = voice.playbackBufferMs;
14
19
  return out;
15
20
  }
16
21
  /** Resolve the usable voice config, or a reason it cannot be used. Shared with
@@ -96,41 +101,182 @@ export function registerVoiceProxy(app) {
96
101
  });
97
102
  });
98
103
  app.post('/api/voice/speak', async (c) => {
99
- const resolved = await resolveVoice();
104
+ const resolved = await resolveSynthesis();
100
105
  if ('error' in resolved)
101
106
  return c.text(resolved.error, 503);
102
- const { voice } = resolved;
103
- if (!voice.ttsModel)
104
- return c.text('No synthesis model configured.', 400);
105
- const { text } = await c.req.json();
106
- if (!text || text.trim().length === 0)
107
+ const body = await c.req.json().catch(() => ({}));
108
+ const text = body.text;
109
+ if (typeof text !== 'string' || text.trim().length === 0)
107
110
  return c.text('No text to speak.', 400);
108
- const payload = { model: voice.ttsModel, input: text };
109
- if (voice.ttsVoice)
110
- payload.voice = voice.ttsVoice;
111
- if (Number.isFinite(voice.ttsSpeed) && voice.ttsSpeed > 0) {
112
- payload.speed = voice.ttsSpeed;
111
+ if (text.length > MAX_SPEAK_CHARS)
112
+ return c.text('Text is too long to speak.', 400);
113
+ return synthesize(resolved.voice, text, c.req.raw.signal);
114
+ });
115
+ // Listen: synthesize with the form's unsaved settings. Credentials never
116
+ // come from the view; mergePreview keeps the saved ones (see its comment).
117
+ app.post('/api/voice/preview', async (c) => {
118
+ const resolved = await resolveSynthesis();
119
+ if ('error' in resolved)
120
+ return c.text(resolved.error, 503);
121
+ const body = await c.req.json().catch(() => null);
122
+ const parsed = parsePreviewBody(body);
123
+ if (typeof parsed === 'string')
124
+ return c.text(parsed, 400);
125
+ const voice = mergePreview(resolved.voice, parsed.settings);
126
+ return synthesize(voice, parsed.text, c.req.raw.signal);
127
+ });
128
+ }
129
+ const MAX_SPEAK_CHARS = 20_000;
130
+ const MAX_PREVIEW_CHARS = 2_000;
131
+ const MAX_DICTIONARY_ROWS = 500;
132
+ /** Validate the preview body; returns the parsed request or an error message. */
133
+ function parsePreviewBody(body) {
134
+ if (!body || typeof body !== 'object')
135
+ return 'Expected a JSON body.';
136
+ const { text, settings } = body;
137
+ if (typeof text !== 'string' || text.trim().length === 0)
138
+ return 'No text to speak.';
139
+ if (text.length > MAX_PREVIEW_CHARS)
140
+ return 'Text is too long for a preview.';
141
+ if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
142
+ return 'Expected a "settings" object.';
143
+ }
144
+ const s = settings;
145
+ const optString = (k) => s[k] === undefined || typeof s[k] === 'string';
146
+ for (const k of ['ttsLanguage', 'ttsVoice', 'ttsModel', 'ttsEndpoint']) {
147
+ if (!optString(k))
148
+ return `"${k}" must be a string.`;
149
+ }
150
+ if (s.ttsEngine !== undefined && s.ttsEngine !== 'endpoint' && s.ttsEngine !== 'builtin') {
151
+ return '"ttsEngine" must be "endpoint" or "builtin".';
152
+ }
153
+ if (s.ttsSpeed !== undefined && (typeof s.ttsSpeed !== 'number' || !Number.isFinite(s.ttsSpeed))) {
154
+ return '"ttsSpeed" must be a number.';
155
+ }
156
+ if (s.pronunciationEnabled !== undefined && typeof s.pronunciationEnabled !== 'boolean') {
157
+ return '"pronunciationEnabled" must be a boolean.';
158
+ }
159
+ if (s.pronunciation !== undefined) {
160
+ if (!Array.isArray(s.pronunciation) || s.pronunciation.length > MAX_DICTIONARY_ROWS) {
161
+ return '"pronunciation" must be a list of at most 500 entries.';
113
162
  }
114
- let upstream;
163
+ const ok = s.pronunciation.every((e) => e && typeof e.term === 'string' && typeof e.say === 'string');
164
+ if (!ok)
165
+ return 'Each pronunciation entry needs a string "term" and "say".';
166
+ }
167
+ return { text, settings: s };
168
+ }
169
+ /** The saved voice config if synthesis can run: voice enabled, and (for the
170
+ * endpoint engine) some endpoint to talk to. The built-in engine needs none. */
171
+ export async function resolveSynthesis() {
172
+ const voice = (await loadConfig()).voice;
173
+ if (!voice || voice.enabled !== true) {
174
+ return { error: 'Voice mode is disabled. Enable it in Settings → Voice.' };
175
+ }
176
+ if (voice.ttsEngine !== 'builtin' && !voice.endpoint?.trim() && !voice.ttsEndpoint?.trim()) {
177
+ return { error: 'No voice endpoint configured. Set one in Settings → Voice.' };
178
+ }
179
+ return { voice };
180
+ }
181
+ /** Same server: scheme, host and port. A different path or a trailing slash is
182
+ * not a different host, so it keeps the saved key. */
183
+ export function sameHost(a, b) {
184
+ const origin = (u) => {
185
+ const t = (u ?? '').trim();
115
186
  try {
116
- const target = ttsTarget(voice);
117
- upstream = await fetch(url(target.endpoint, '/audio/speech'), {
118
- method: 'POST',
119
- headers: { ...authHeaders(target.apiKey), 'content-type': 'application/json' },
120
- body: JSON.stringify(payload),
121
- });
187
+ return new URL(t).origin;
122
188
  }
123
- catch (err) {
124
- return c.text(`Could not reach the voice endpoint: ${err}`, 502);
189
+ catch {
190
+ return t.replace(/\/+$/, '');
125
191
  }
126
- if (!upstream.ok) {
127
- return c.body(await upstream.arrayBuffer(), upstream.status, {
128
- 'content-type': upstream.headers.get('content-type') ?? 'text/plain',
129
- });
192
+ };
193
+ return origin(a) === origin(b);
194
+ }
195
+ export const KEY_WITHHELD_HINT = 'The endpoint changed: enter the API key again, or save first, to use it with the new endpoint.';
196
+ /** The key to send to `endpoint` for a request built from the settings form. A key
197
+ * typed in the form is the user's own, for that endpoint. The stored key (the form
198
+ * round-trips its encrypted blob) goes only to the host it was saved for;
199
+ * otherwise it is withheld and the request goes without a key. */
200
+ export function formKeyFor(endpoint, formKey, saved) {
201
+ if (!formKey)
202
+ return { key: null, withheld: false };
203
+ if (!isEncrypted(formKey))
204
+ return { key: formKey, withheld: false };
205
+ const pairs = [
206
+ [saved?.apiKey, saved?.endpoint],
207
+ [saved?.ttsApiKey, saved?.ttsEndpoint],
208
+ ];
209
+ return pairs.some(([k, ep]) => k === formKey && sameHost(ep, endpoint))
210
+ ? { key: formKey, withheld: false }
211
+ : { key: null, withheld: true };
212
+ }
213
+ /** Overlay the form's unsaved synthesis settings on the saved config. The saved
214
+ * `ttsApiKey` is dropped when the previewed `ttsEndpoint` is on another host than
215
+ * the saved one, so editing the URL can never send the stored key to a new host. */
216
+ export function mergePreview(saved, s) {
217
+ const merged = {
218
+ ...saved,
219
+ ttsEngine: s.ttsEngine,
220
+ ttsLanguage: s.ttsLanguage,
221
+ ttsVoice: s.ttsVoice,
222
+ ttsModel: s.ttsModel,
223
+ ttsSpeed: s.ttsSpeed,
224
+ ttsEndpoint: s.ttsEndpoint,
225
+ pronunciationEnabled: s.pronunciationEnabled,
226
+ };
227
+ if (!sameHost(s.ttsEndpoint, saved.ttsEndpoint))
228
+ delete merged.ttsApiKey;
229
+ if (s.pronunciation) {
230
+ const code = synthesisLanguage(merged);
231
+ if (code)
232
+ merged.pronunciation = { ...saved.pronunciation, [code]: s.pronunciation };
233
+ }
234
+ return merged;
235
+ }
236
+ let builtinSpeaker = null;
237
+ /** The built-in engine registers itself here; null unregisters. */
238
+ export function setBuiltinSpeaker(fn) {
239
+ builtinSpeaker = fn;
240
+ }
241
+ /** Synthesize `text` with the configured engine, dictionary applied, streaming
242
+ * the audio back. Failures are Responses (status + readable body), not throws. */
243
+ export async function synthesize(voice, text, signal) {
244
+ const code = voice.pronunciationEnabled ? synthesisLanguage(voice) : null;
245
+ const input = code ? applyPronunciation(text, dictionaryFor(voice, code)) : text;
246
+ if (voice.ttsEngine === 'builtin') {
247
+ if (!builtinSpeaker) {
248
+ return new Response('The built-in voice engine is not available.', { status: 503 });
130
249
  }
131
- return c.body(await upstream.arrayBuffer(), 200, {
132
- 'content-type': upstream.headers.get('content-type') ?? 'audio/mpeg',
250
+ return builtinSpeaker(voice, input, signal);
251
+ }
252
+ if (!voice.ttsModel)
253
+ return new Response('No synthesis model configured.', { status: 400 });
254
+ const payload = { model: voice.ttsModel, input };
255
+ if (voice.ttsVoice)
256
+ payload.voice = voice.ttsVoice;
257
+ if (Number.isFinite(voice.ttsSpeed) && voice.ttsSpeed > 0) {
258
+ payload.speed = voice.ttsSpeed;
259
+ }
260
+ let upstream;
261
+ try {
262
+ const target = ttsTarget(voice);
263
+ upstream = await fetch(url(target.endpoint, '/audio/speech'), {
264
+ method: 'POST',
265
+ headers: { ...authHeaders(target.apiKey), 'content-type': 'application/json' },
266
+ body: JSON.stringify(payload),
267
+ signal,
133
268
  });
269
+ }
270
+ catch (err) {
271
+ return new Response(`Could not reach the voice endpoint: ${err}`, { status: 502 });
272
+ }
273
+ // Stream through; failures are propagated verbatim (a wrong model id must
274
+ // surface as the provider's own message).
275
+ return new Response(upstream.body, {
276
+ status: upstream.status,
277
+ headers: {
278
+ 'content-type': upstream.headers.get('content-type') ?? (upstream.ok ? 'audio/mpeg' : 'text/plain'),
279
+ },
134
280
  });
135
281
  }
136
282
  /**
@@ -3,8 +3,8 @@
3
3
  // — same model as skills. No separate store; the plugin record is the
4
4
  // source of truth.
5
5
  //
6
- // Names are scoped: a plugin named "contract-workflow" with
7
- // `commands/contract-writing.md` registers as `/contract-writing`. On a
6
+ // Names are scoped: a plugin named "release-tools" with
7
+ // `commands/changelog.md` registers as `/changelog`. On a
8
8
  // collision (two active plugins both define `/foo`), the first plugin
9
9
  // listed in `agent.plugins` wins; the duplicate is dropped silently and
10
10
  // the user can disambiguate by removing the conflicting plugin from the
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CA+D7D;AAED,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,cAAc,GACf,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAA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AAkB,EAClB,SAAS,EACT,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,cAAc,GACf,CAAC"}
@@ -18,6 +18,7 @@ import { listSkillsTool } from './list_skills.js';
18
18
  import { readSkillTool } from './read_skill.js';
19
19
  import { listAgentsTool } from './list_agents.js';
20
20
  import { invokeAgentTool } from './invoke_agent.js';
21
+ import { setWorkspaceTool } from './set_workspace.js';
21
22
  import { listCommandsTool } from './list_commands.js';
22
23
  import { invokeCommandTool } from './invoke_command.js';
23
24
  import { getAgentContextTool } from './get_agent_context.js';
@@ -49,6 +50,9 @@ export function registerBuiltins(registry) {
49
50
  // more than one agent configured — they're useless otherwise).
50
51
  registry.register(listAgentsTool);
51
52
  registry.register(invokeAgentTool);
53
+ // Session workspace switch (opt-in via allowedTools like any capability
54
+ // tool; session-bound, so not part of a served mcp__* namespace).
55
+ registry.register(setWorkspaceTool);
52
56
  // Slash commands as tools — same gating as skills (auto-included when
53
57
  // the agent has at least one plugin active).
54
58
  registry.register(listCommandsTool);
@@ -0,0 +1,3 @@
1
+ import type { Tool } from '../types.js';
2
+ export declare const setWorkspaceTool: Tool;
3
+ //# sourceMappingURL=set_workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set_workspace.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/set_workspace.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAEpD,eAAO,MAAM,gBAAgB,EAAE,IAoC9B,CAAC"}