@xmoon76/dsh-pi-tui 0.5.7 → 0.5.8

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 (33) hide show
  1. package/README.en.md +13 -11
  2. package/README.md +13 -11
  3. package/dist/{bootstrap-C9nl6e13.mjs → bootstrap-CMIjGyuk.mjs} +532 -416
  4. package/dist/builtins.mjs +2 -2
  5. package/dist/{client-bootstrap-CGezi85O.mjs → client-bootstrap-BjGPc-DM.mjs} +826 -3
  6. package/dist/{daemon-launcher-H_1r5Cqs.mjs → daemon-launcher-Dult7Jxv.mjs} +121 -4
  7. package/dist/daemon-launcher.mjs +1 -1
  8. package/dist/{entry-control-jBfKn1qO.mjs → entry-control-DjNsE3I0.mjs} +1 -1
  9. package/dist/{extensions-6a5vvJUT.mjs → extensions-B4uLpSTv.mjs} +1 -4
  10. package/dist/extensions.mjs +1 -1
  11. package/dist/{host-foundation-probe-DK7n5jDu.mjs → host-foundation-probe-DMNTmNrH.mjs} +1 -1
  12. package/dist/index.mjs +532 -298
  13. package/dist/{local-acp-listener-CNkguN5-.mjs → local-acp-listener-B65J0Bx4.mjs} +561 -12
  14. package/dist/local-client.mjs +442 -45
  15. package/dist/{local-daemon-control-Cu_4FIdd.mjs → local-daemon-control-C14q9KnD.mjs} +5 -2
  16. package/dist/{local-daemon-control-Bg9s2aYi.mjs → local-daemon-control-TCnERL7n.mjs} +3 -3
  17. package/dist/{local-discovery-Bq3jLAn1.mjs → local-discovery-DOSsCh9q.mjs} +1 -1
  18. package/dist/{local-discovery-BMoNXZjJ.mjs → local-discovery-egN4_gsQ.mjs} +1 -1
  19. package/dist/{local-discovery-BPZw1wEd.mjs → local-discovery-uOBfFq5j.mjs} +1 -1
  20. package/dist/local-host.mjs +24 -6
  21. package/dist/local-profile-daemon-admin-BmQSdzT0.mjs +210 -0
  22. package/dist/{local-scope-DEuGAy8l.mjs → local-scope-DamiMqPd.mjs} +118 -1
  23. package/dist/{local-transport-X4ZCe2uE.mjs → local-transport-Iwo0mtu3.mjs} +2 -2
  24. package/dist/{local-web-control-DKWtXIkr.mjs → local-web-control-DMrjwCkl.mjs} +2 -2
  25. package/dist/{session-DC0XQr5O.mjs → session-C6tSs86s.mjs} +2 -2
  26. package/dist/{session-Cihe8PPS.mjs → session-CstInGIA.mjs} +1 -1
  27. package/dist/{startup-CARqn3kV.mjs → startup-EG5UqIcd.mjs} +3 -3
  28. package/dist/startup.mjs +1 -1
  29. package/dist/{terminal-progress-source-D4DHyXDo.mjs → terminal-progress-source-CpfpQO_h.mjs} +3 -6
  30. package/dist/{transcript-view-hvNVkPtv.mjs → transcript-view-C1YtJ49Y.mjs} +191 -192
  31. package/dist/{transcript-view-a7cROAaI.mjs → transcript-view-CuJYWkhp.mjs} +190 -191
  32. package/package.json +6 -6
  33. package/dist/local-profile-daemon-admin-AXgVH-6y.mjs +0 -91
@@ -1,4 +1,4 @@
1
- import "./local-scope-DEuGAy8l.mjs";
1
+ import "./local-scope-DamiMqPd.mjs";
2
2
  import { i as runDetached, r as observeSettled } from "./tasks-D_z5Yjjr.mjs";
3
3
  import { i as parsePiTuiAcpAccessStatus } from "./pi-tui-acp-access-contract-BdLwduU6.mjs";
4
4
  import { randomUUID } from "node:crypto";
@@ -126,6 +126,399 @@ async function observeAuthenticatedLocalAcpStatus(verified) {
126
126
  }
127
127
  }
128
128
  //#endregion
129
+ //#region src/app/remote-process/local-acp-model-selection.ts
130
+ const JSONRPC_INVALID_PARAMS$1 = -32602;
131
+ const JSONRPC_MODEL_UNAVAILABLE = -32042;
132
+ const JSONRPC_MODEL_BUSY = -32046;
133
+ /** One classified model-configuration rejection. */
134
+ var AcpModelError = class extends Error {
135
+ code;
136
+ rpcCode;
137
+ data;
138
+ constructor(code, message, rpcCode, data = {}) {
139
+ super(message);
140
+ this.name = "AcpModelError";
141
+ this.code = code;
142
+ this.rpcCode = rpcCode;
143
+ this.data = data;
144
+ }
145
+ };
146
+ const MODEL_CONFIG_ID = "model";
147
+ const THOUGHT_LEVEL_CONFIG_ID = "thought_level";
148
+ const MODEL_OPTION_NAME = "Model";
149
+ const THOUGHT_LEVEL_OPTION_NAME = "Reasoning effort";
150
+ const MODEL_DEFAULT_EFFORT_NAME = "Model default";
151
+ const CURRENT_MODEL_PLACEHOLDER = "Current (unavailable) — choose another model";
152
+ const CURRENT_EFFORT_PLACEHOLDER = "Current effort (unavailable)";
153
+ const NO_MODEL_PLACEHOLDER = "No model selected";
154
+ const UNAVAILABLE_GROUP_NAME = "Unavailable";
155
+ /** Encode one exact model route as an opaque ACP select value. */
156
+ function modelValue(providerId, modelId) {
157
+ return JSON.stringify([providerId, modelId]);
158
+ }
159
+ /** Encode the "omit explicit effort, use the adapter default" choice. */
160
+ function defaultEffortValue() {
161
+ return JSON.stringify(["default"]);
162
+ }
163
+ /** Encode one explicit official reasoning effort id. */
164
+ function effortValue(effortId) {
165
+ return JSON.stringify(["effort", effortId]);
166
+ }
167
+ /** Presentation-only selector value for a current effort the catalog no longer advertises. */
168
+ function unavailableEffortValue(effortId) {
169
+ return JSON.stringify(["unavailable", effortId]);
170
+ }
171
+ /** The one internal presentation-only value that no valid model route uses. */
172
+ const UNSET_MODEL_VALUE = JSON.stringify(["unset"]);
173
+ function invalidOption(message) {
174
+ return new AcpModelError("LOCAL_ACP_MODEL_INVALID_OPTION", message, JSONRPC_INVALID_PARAMS$1);
175
+ }
176
+ function modelUnavailable(message) {
177
+ return new AcpModelError("LOCAL_ACP_MODEL_UNAVAILABLE", message, JSONRPC_MODEL_UNAVAILABLE);
178
+ }
179
+ function agentBusy() {
180
+ return new AcpModelError("LOCAL_ACP_MODEL_AGENT_BUSY", "the session agent is busy", JSONRPC_MODEL_BUSY);
181
+ }
182
+ function viewBusy() {
183
+ return new AcpModelError("LOCAL_ACP_MODEL_VIEW_BUSY", "a prompt is already in flight for this session view", JSONRPC_MODEL_BUSY);
184
+ }
185
+ function staleSelection() {
186
+ return new AcpModelError("LOCAL_ACP_MODEL_STALE", "the attached session changed during the model request", JSONRPC_MODEL_UNAVAILABLE);
187
+ }
188
+ function conflictingSelection() {
189
+ return new AcpModelError("LOCAL_ACP_MODEL_CONFLICT", "the session model changed during the request", JSONRPC_MODEL_BUSY);
190
+ }
191
+ /** A detached copy so a later Agent mutation can never rewrite the baseline. */
192
+ function copySelection(selection) {
193
+ if (selection === void 0) return void 0;
194
+ return {
195
+ provider: selection.provider,
196
+ model: selection.model,
197
+ ...selection.reasoningEffort === void 0 ? {} : { reasoningEffort: selection.reasoningEffort }
198
+ };
199
+ }
200
+ /** Compare the complete selection; an absent effort is its own value. */
201
+ function sameSelection(left, right) {
202
+ if (left === void 0 || right === void 0) return left === right;
203
+ return left.provider === right.provider && left.model === right.model && left.reasoningEffort === right.reasoningEffort;
204
+ }
205
+ function parseModelValue(value) {
206
+ if (typeof value !== "string") return void 0;
207
+ let parsed;
208
+ try {
209
+ parsed = JSON.parse(value);
210
+ } catch {
211
+ return;
212
+ }
213
+ if (!Array.isArray(parsed) || parsed.length !== 2) return void 0;
214
+ const [provider, model] = parsed;
215
+ if (typeof provider !== "string" || provider.length === 0 || typeof model !== "string" || model.length === 0) return void 0;
216
+ return {
217
+ provider,
218
+ model
219
+ };
220
+ }
221
+ function parseEffortValue(value) {
222
+ if (typeof value !== "string") return void 0;
223
+ let parsed;
224
+ try {
225
+ parsed = JSON.parse(value);
226
+ } catch {
227
+ return;
228
+ }
229
+ if (!Array.isArray(parsed)) return void 0;
230
+ if (parsed.length === 1 && parsed[0] === "default") return { kind: "default" };
231
+ if (parsed.length === 2 && parsed[0] === "effort" && typeof parsed[1] === "string" && parsed[1].length > 0) return {
232
+ kind: "effort",
233
+ effortId: parsed[1]
234
+ };
235
+ }
236
+ /**
237
+ * Project one official catalog plus the exact current selection into the full
238
+ * standard ACP option list. Pure and detached: every call re-reads the caller's
239
+ * catalog snapshot and never remembers a previous option table.
240
+ */
241
+ function projectModelState(catalog, current) {
242
+ const groups = [];
243
+ const modelChoices = /* @__PURE__ */ new Map();
244
+ const reasoningByModel = /* @__PURE__ */ new Map();
245
+ const presentationOnlyValues = /* @__PURE__ */ new Set();
246
+ for (const group of catalog.groups) {
247
+ const entries = [];
248
+ for (const model of group.models) {
249
+ const value = modelValue(group.id, model.id);
250
+ modelChoices.set(value, {
251
+ provider: group.id,
252
+ model: model.id
253
+ });
254
+ if (model.reasoning !== void 0 && model.reasoning.efforts.length > 0) reasoningByModel.set(value, model.reasoning);
255
+ entries.push({
256
+ value,
257
+ name: model.name,
258
+ ...model.description === void 0 ? {} : { description: model.description }
259
+ });
260
+ }
261
+ if (entries.length > 0) groups.push({
262
+ group: `group:${group.id}`,
263
+ name: group.name,
264
+ options: entries
265
+ });
266
+ }
267
+ let currentModelValue;
268
+ if (current === void 0) {
269
+ currentModelValue = UNSET_MODEL_VALUE;
270
+ presentationOnlyValues.add(currentModelValue);
271
+ groups.push({
272
+ group: "group:unavailable",
273
+ name: UNAVAILABLE_GROUP_NAME,
274
+ options: [{
275
+ value: currentModelValue,
276
+ name: NO_MODEL_PLACEHOLDER
277
+ }]
278
+ });
279
+ } else {
280
+ currentModelValue = modelValue(current.provider, current.model);
281
+ if (!modelChoices.has(currentModelValue)) {
282
+ presentationOnlyValues.add(currentModelValue);
283
+ const groupId = `group:${current.provider}`;
284
+ let group = groups.find((candidate) => candidate.group === groupId);
285
+ if (group === void 0) {
286
+ group = {
287
+ group: groupId,
288
+ name: current.provider,
289
+ options: []
290
+ };
291
+ groups.push(group);
292
+ }
293
+ group.options.unshift({
294
+ value: currentModelValue,
295
+ name: CURRENT_MODEL_PLACEHOLDER
296
+ });
297
+ }
298
+ }
299
+ const options = [{
300
+ id: MODEL_CONFIG_ID,
301
+ name: MODEL_OPTION_NAME,
302
+ category: "model",
303
+ type: "select",
304
+ currentValue: currentModelValue,
305
+ options: groups
306
+ }];
307
+ if (current !== void 0) {
308
+ const reasoning = reasoningByModel.get(modelValue(current.provider, current.model));
309
+ if (reasoning !== void 0 && reasoning.efforts.length > 0) {
310
+ const thoughtOptions = [{
311
+ value: defaultEffortValue(),
312
+ name: MODEL_DEFAULT_EFFORT_NAME
313
+ }];
314
+ for (const effort of reasoning.efforts) thoughtOptions.push({
315
+ value: effortValue(effort.id),
316
+ name: effort.name,
317
+ ...effort.description === void 0 ? {} : { description: effort.description }
318
+ });
319
+ let currentThoughtValue;
320
+ if (current.reasoningEffort === void 0) currentThoughtValue = defaultEffortValue();
321
+ else if (reasoning.efforts.some((effort) => effort.id === current.reasoningEffort)) currentThoughtValue = effortValue(current.reasoningEffort);
322
+ else {
323
+ currentThoughtValue = unavailableEffortValue(current.reasoningEffort);
324
+ presentationOnlyValues.add(currentThoughtValue);
325
+ thoughtOptions.unshift({
326
+ value: currentThoughtValue,
327
+ name: CURRENT_EFFORT_PLACEHOLDER
328
+ });
329
+ }
330
+ options.push({
331
+ id: THOUGHT_LEVEL_CONFIG_ID,
332
+ name: THOUGHT_LEVEL_OPTION_NAME,
333
+ category: "thought_level",
334
+ type: "select",
335
+ currentValue: currentThoughtValue,
336
+ options: thoughtOptions
337
+ });
338
+ }
339
+ }
340
+ return {
341
+ options,
342
+ modelChoices,
343
+ reasoningByModel,
344
+ presentationOnlyValues
345
+ };
346
+ }
347
+ /** Read one stable host error code without exposing its message or stack. */
348
+ function hostErrorCode$1(error) {
349
+ if (typeof error === "object" && error !== null && "code" in error) {
350
+ const code = error.code;
351
+ if (typeof code === "string" && code.length > 0) return code;
352
+ }
353
+ }
354
+ /**
355
+ * The internal Session-only model service bound once per Host ACP access.
356
+ * It owns no persistent state: every request re-reads the Host authority.
357
+ */
358
+ var AcpSessionModelService = class {
359
+ host;
360
+ constructor(host) {
361
+ this.host = host;
362
+ }
363
+ /**
364
+ * Read the complete standard option state for one exact attached Agent.
365
+ * A missing catalog is a real failure; the caller may omit optional display.
366
+ */
367
+ async readOptions(expectedAgent, expectedSession) {
368
+ this.assertExact(expectedAgent, expectedSession);
369
+ try {
370
+ const catalog = await this.readCatalog();
371
+ this.assertExact(expectedAgent, expectedSession);
372
+ return projectModelState(catalog, copySelection(expectedAgent.model.current())).options;
373
+ } catch (error) {
374
+ this.assertExact(expectedAgent, expectedSession);
375
+ throw error;
376
+ }
377
+ }
378
+ /**
379
+ * Validate and commit one Session-only model/effort selection.
380
+ *
381
+ * All provider/catalog reads happen BEFORE `runMaintenance`. The maintenance
382
+ * callback itself performs only synchronous identity, baseline and abort
383
+ * checks followed by the official `agent.model.select()` and a readback; it
384
+ * never awaits provider I/O, so a slow catalog cannot block a TUI turn.
385
+ */
386
+ async selectSessionOnly(expectedAgent, expectedSession, request, signal, stillCurrent) {
387
+ this.validateRequestShape(request);
388
+ this.assertCurrent(expectedAgent, expectedSession, signal, stillCurrent);
389
+ const baseline = copySelection(expectedAgent.model.current());
390
+ if (expectedAgent.status !== "idle") throw agentBusy();
391
+ const catalog = await this.readCatalog();
392
+ this.assertCurrent(expectedAgent, expectedSession, signal, stillCurrent);
393
+ const projected = projectModelState(catalog, baseline);
394
+ let intended;
395
+ if (request.configId === MODEL_CONFIG_ID) {
396
+ if (typeof request.value !== "string" || projected.presentationOnlyValues.has(request.value)) throw invalidOption("the requested model option is not selectable");
397
+ const choice = projected.modelChoices.get(request.value);
398
+ if (choice === void 0) {
399
+ const parsed = parseModelValue(request.value);
400
+ if (parsed !== void 0 && this.catalogKnowsProvider(catalog, parsed.provider)) throw modelUnavailable("the requested model is not available from the Host");
401
+ throw invalidOption("the requested model option is unknown");
402
+ }
403
+ await this.assertModelRoutable(choice.provider, choice.model, signal);
404
+ this.assertCurrent(expectedAgent, expectedSession, signal, stillCurrent);
405
+ intended = baseline !== void 0 && baseline.provider === choice.provider && baseline.model === choice.model ? copySelection(baseline) : {
406
+ provider: choice.provider,
407
+ model: choice.model
408
+ };
409
+ } else {
410
+ const baselineSelection = baseline;
411
+ if (baselineSelection === void 0) throw invalidOption("no model is selected for this session");
412
+ const reasoning = projected.reasoningByModel.get(modelValue(baselineSelection.provider, baselineSelection.model));
413
+ if (reasoning === void 0 || reasoning.efforts.length === 0) throw invalidOption("the selected model declares no reasoning efforts");
414
+ const parsed = parseEffortValue(request.value);
415
+ if (parsed === void 0) throw invalidOption("the requested reasoning effort is unknown");
416
+ if (parsed.kind === "effort" && !reasoning.efforts.some((effort) => effort.id === parsed.effortId)) throw invalidOption("the requested reasoning effort is not available for this model");
417
+ intended = {
418
+ provider: baselineSelection.provider,
419
+ model: baselineSelection.model,
420
+ ...parsed.kind === "effort" ? { reasoningEffort: parsed.effortId } : {}
421
+ };
422
+ await this.assertModelRoute(intended, signal);
423
+ this.assertCurrent(expectedAgent, expectedSession, signal, stillCurrent);
424
+ }
425
+ return projectModelState(catalog, await this.commitIfCurrent(expectedAgent, expectedSession, intended, baseline, signal, stillCurrent)).options;
426
+ }
427
+ /** Reject everything outside the standard select subset for the two known config ids. */
428
+ validateRequestShape(request) {
429
+ if (request.type === "boolean") throw invalidOption("boolean session config options are not supported");
430
+ if (request.configId !== MODEL_CONFIG_ID && request.configId !== THOUGHT_LEVEL_CONFIG_ID) throw invalidOption("unknown session config option");
431
+ if (typeof request.value !== "string" || request.value.length === 0) throw invalidOption("the session config option requires a non-empty select value");
432
+ }
433
+ /** The exact live Agent/Session must still be the ones this View attached. */
434
+ assertExact(expectedAgent, expectedSession) {
435
+ const sessionId = expectedAgent.id;
436
+ if (this.host.currentAgent(sessionId) !== expectedAgent || this.host.currentSession(sessionId) !== expectedSession) throw staleSelection();
437
+ }
438
+ /** Exact identity + View claim + request abort fence after an await. */
439
+ assertCurrent(expectedAgent, expectedSession, signal, stillCurrent) {
440
+ if (signal.aborted) throw staleSelection();
441
+ const currentness = stillCurrent();
442
+ if (currentness === "view-busy") throw viewBusy();
443
+ if (currentness !== "current") throw staleSelection();
444
+ this.assertExact(expectedAgent, expectedSession);
445
+ }
446
+ /** Read the official Host catalog; any failure is the stable unavailable class. */
447
+ async readCatalog() {
448
+ try {
449
+ return await this.host.modelCatalog();
450
+ } catch {
451
+ throw modelUnavailable("the Host model catalog is unavailable");
452
+ }
453
+ }
454
+ /** Whether the provider is a real catalog route that currently failed or holds no such model. */
455
+ catalogKnowsProvider(catalog, providerId) {
456
+ return catalog.groups.some((group) => group.id === providerId) || (catalog.failures ?? []).some((failure) => failure.id === providerId);
457
+ }
458
+ /** Model selection validation: the fresh provider/model directory plus adapter defaults. */
459
+ async assertModelRoutable(providerId, modelId, signal) {
460
+ await this.assertModelRoute({
461
+ provider: providerId,
462
+ model: modelId
463
+ }, signal);
464
+ }
465
+ /**
466
+ * Validate one exact route against the live LLM registry. A missing route is
467
+ * `UNAVAILABLE`; an unsupported explicit effort is `INVALID_OPTION` because it
468
+ * is the caller's option value that is wrong for the model, not a vanished
469
+ * provider.
470
+ */
471
+ async assertModelRoute(route, signal) {
472
+ let providers;
473
+ try {
474
+ providers = this.host.listProviders();
475
+ } catch {
476
+ throw modelUnavailable("the Host model provider list is unavailable");
477
+ }
478
+ if (!providers.some((provider) => provider.id === route.provider)) throw modelUnavailable("the requested model provider is not available");
479
+ let models;
480
+ try {
481
+ models = await this.host.listModels(route.provider);
482
+ } catch {
483
+ throw modelUnavailable("the requested model provider catalog is unavailable");
484
+ }
485
+ if (signal.aborted) throw staleSelection();
486
+ if (!models.some((model) => model.id === route.model)) throw modelUnavailable("the requested model is not available");
487
+ try {
488
+ await this.host.resolveCallConfig(route, signal);
489
+ } catch (error) {
490
+ if (route.reasoningEffort !== void 0 && hostErrorCode$1(error) === "UNSUPPORTED_REASONING_EFFORT") throw invalidOption("the requested reasoning effort is not supported by this model");
491
+ throw modelUnavailable("the requested model configuration is not available");
492
+ }
493
+ if (signal.aborted) throw staleSelection();
494
+ }
495
+ /**
496
+ * Claim the true idle phase, re-check every currentness fence synchronously,
497
+ * then perform the one official Session-only write and an authority readback.
498
+ */
499
+ async commitIfCurrent(expectedAgent, expectedSession, intended, baseline, signal, stillCurrent) {
500
+ const sessionId = expectedAgent.id;
501
+ let maintenance;
502
+ try {
503
+ maintenance = expectedAgent.runMaintenance(async (maintenanceSignal) => {
504
+ if (signal.aborted || maintenanceSignal.aborted) throw staleSelection();
505
+ const currentness = stillCurrent();
506
+ if (currentness === "view-busy") throw viewBusy();
507
+ if (currentness !== "current") throw staleSelection();
508
+ if (this.host.currentAgent(sessionId) !== expectedAgent || this.host.currentSession(sessionId) !== expectedSession) throw staleSelection();
509
+ if (!sameSelection(expectedAgent.model.current(), baseline)) throw conflictingSelection();
510
+ expectedAgent.model.select(intended);
511
+ const committed = expectedAgent.model.current();
512
+ if (!sameSelection(committed, intended)) throw staleSelection();
513
+ return copySelection(committed);
514
+ });
515
+ } catch {
516
+ throw agentBusy();
517
+ }
518
+ return await maintenance;
519
+ }
520
+ };
521
+ //#endregion
129
522
  //#region src/app/remote-process/local-acp-session-view.ts
130
523
  /**
131
524
  * Connection-scoped Host ACP Session View.
@@ -212,6 +605,10 @@ const JSONRPC_INTERNAL_ERROR = -32603;
212
605
  function promptError(code, message, rpcCode, data = {}) {
213
606
  return new LocalAcpViewError(code, message, rpcCode, data);
214
607
  }
608
+ /** The stable rejection when an attached View/Agent/Session identity changed mid-request. */
609
+ function staleModelSelection() {
610
+ return new LocalAcpViewError("LOCAL_ACP_MODEL_STALE", "the attached session changed during the model request", -32042);
611
+ }
215
612
  /** A stable code from a rejecting Host call, never its message or stack. */
216
613
  function hostErrorCode(error) {
217
614
  if (typeof error === "object" && error !== null && "code" in error) {
@@ -336,6 +733,72 @@ var AcpSessionViewRegistry = class {
336
733
  return state.phase;
337
734
  }
338
735
  /**
736
+ * The ONE attached claim this connection owns for a Session. An idle,
737
+ * closed, re-bound or foreign View holds no model capability.
738
+ */
739
+ attachedClaim(state, sessionId) {
740
+ const claim = this.claims.get(sessionId);
741
+ if (state.phase !== "attached" || claim === void 0 || claim.connectionIdentity !== state || claim.detachedWithFence || claim.exactAgent === void 0 || claim.exactSession === void 0) throw new LocalAcpViewError("LOCAL_ACP_VIEW_NOT_OWNED", "this ACP connection holds no view for that session", JSONRPC_INVALID_PARAMS);
742
+ return claim;
743
+ }
744
+ /** Whether this exact claim is still the live attached View of this connection. */
745
+ isStillAttached(state, claim, agent, session) {
746
+ return this.claims.get(claim.sessionId) === claim && claim.connectionIdentity === state && state.phase === "attached" && !claim.detachedWithFence && claim.exactAgent === agent && claim.exactSession === session;
747
+ }
748
+ /** Map one typed Host model rejection onto the existing View error boundary. */
749
+ async callModelAccess(operation) {
750
+ try {
751
+ return await operation();
752
+ } catch (error) {
753
+ if (error instanceof AcpModelError) throw new LocalAcpViewError(error.code, error.message, error.rpcCode, error.data);
754
+ throw error;
755
+ }
756
+ }
757
+ /**
758
+ * Read the complete standard config-option state of the EXACT attached View.
759
+ * The async Host read is fenced against a close/re-bind/rebind before its
760
+ * result is returned to the connection.
761
+ */
762
+ async modelOptions(state, access, sessionId) {
763
+ const claim = this.attachedClaim(state, sessionId);
764
+ const agent = claim.exactAgent;
765
+ const session = claim.exactSession;
766
+ try {
767
+ const options = await this.callModelAccess(() => access.modelOptions(agent, session));
768
+ if (!this.isStillAttached(state, claim, agent, session)) throw staleModelSelection();
769
+ return options;
770
+ } catch (error) {
771
+ if (!this.isStillAttached(state, claim, agent, session)) throw staleModelSelection();
772
+ throw error;
773
+ }
774
+ }
775
+ /**
776
+ * Commit ONE Session-only model/effort selection on the EXACT attached View.
777
+ * A View with any unsettled prompt obligation is refused before the Host
778
+ * service is reached; the Host service re-checks the exact Agent/Session
779
+ * identity and the View claim after every asynchronous validation step.
780
+ */
781
+ async setModelOption(state, access, request, signal) {
782
+ const claim = this.attachedClaim(state, request.sessionId);
783
+ if (claim.inflight !== void 0 || claim.unclaimedHostObligation !== void 0) throw new LocalAcpViewError("LOCAL_ACP_MODEL_VIEW_BUSY", "a prompt is already in flight for this session view", -32046);
784
+ const agent = claim.exactAgent;
785
+ const session = claim.exactSession;
786
+ const stillCurrent = () => {
787
+ if (!this.isStillAttached(state, claim, agent, session)) return "stale";
788
+ if (claim.inflight !== void 0 || claim.unclaimedHostObligation !== void 0) return "view-busy";
789
+ return "current";
790
+ };
791
+ const options = await this.callModelAccess(() => access.selectModelOnly(agent, session, {
792
+ configId: request.configId,
793
+ ...request.type === void 0 ? {} : { type: request.type },
794
+ value: request.value
795
+ }, signal, stillCurrent));
796
+ const currentness = stillCurrent();
797
+ if (currentness === "view-busy") throw new LocalAcpViewError("LOCAL_ACP_MODEL_VIEW_BUSY", "a prompt is already in flight for this session view", -32046);
798
+ if (currentness !== "current") throw staleModelSelection();
799
+ return options;
800
+ }
801
+ /**
339
802
  * Attach a freshly created Host Session to this connection's View. `session/new`
340
803
  * creates ONE Host Workspace, then ONE Host Session, then borrows the official
341
804
  * live Agent. The failure category is decided by the HOST result: a definite
@@ -343,7 +806,7 @@ var AcpSessionViewRegistry = class {
343
806
  * real created Session id, an unconfirmed outcome, or success. It is never
344
807
  * retried and never rolled back.
345
808
  */
346
- async newSession(state, access, request) {
809
+ async newSession(state, access, request, notifyConfigOptions) {
347
810
  const op = this.beginAttach(state);
348
811
  try {
349
812
  this.validateNew(request);
@@ -382,7 +845,7 @@ var AcpSessionViewRegistry = class {
382
845
  };
383
846
  this.claims.set(sessionId, claim);
384
847
  const agent = await this.resolveForView(access, state, op, claim);
385
- this.commitAttached(state, op, claim, access, agent);
848
+ this.commitAttached(state, op, claim, access, agent, notifyConfigOptions);
386
849
  return { sessionId };
387
850
  }
388
851
  /**
@@ -390,7 +853,7 @@ var AcpSessionViewRegistry = class {
390
853
  * `resolveAgent` is the only cold-resume owner; a live Session borrows the
391
854
  * same Agent object. The request cwd never changes the Host Session.
392
855
  */
393
- async resumeSession(state, access, request) {
856
+ async resumeSession(state, access, request, notifyConfigOptions) {
394
857
  const op = this.beginAttach(state);
395
858
  try {
396
859
  this.validateResume(request);
@@ -410,7 +873,7 @@ var AcpSessionViewRegistry = class {
410
873
  this.claims.set(sessionId, claim);
411
874
  const agent = await this.resolveForView(access, state, op, claim);
412
875
  if (agent.session.header.cwd !== request.cwd) this.diag.warn("local-acp.view.cwd-mismatch", { mismatch: true });
413
- this.commitAttached(state, op, claim, access, agent);
876
+ this.commitAttached(state, op, claim, access, agent, notifyConfigOptions);
414
877
  return {};
415
878
  }
416
879
  /**
@@ -508,6 +971,7 @@ var AcpSessionViewRegistry = class {
508
971
  /** Release one settled claim and record the idempotent close fact. */
509
972
  finishClose(state, sessionId, claim) {
510
973
  if (this.claims.get(sessionId) !== claim || claim.detachedWithFence || state.phase === "closed") return {};
974
+ claim.notifyConfigOptions = void 0;
511
975
  if (claim.retiringTurn !== void 0) claim.detachedWithFence = true;
512
976
  else if (this.claims.get(sessionId) === claim) {
513
977
  this.claims.delete(sessionId);
@@ -793,6 +1257,7 @@ var AcpSessionViewRegistry = class {
793
1257
  onSessionEvent(session, event) {
794
1258
  for (const claim of this.claims.values()) {
795
1259
  if (claim.exactSession !== session) continue;
1260
+ if (event.type === "model/selection" && claim.notifyConfigOptions !== void 0) this.enqueueConfigNotification(claim, session);
796
1261
  const data = event.data;
797
1262
  if (event.type === "turn/end" && typeof data?.turn === "number" && claim.retiringTurn?.turn === data.turn) this.endRetiringFence(claim.sessionId, claim);
798
1263
  const flight = claim.inflight;
@@ -818,6 +1283,38 @@ var AcpSessionViewRegistry = class {
818
1283
  }
819
1284
  }
820
1285
  /**
1286
+ * Queue ONE full-option refresh on the claim's ordered notification chain.
1287
+ * The chain is transient and per claim: a close/re-bind/teardown clears the
1288
+ * callback, a late catalog read never reaches a newer View, and a delivery
1289
+ * failure retires only this callback instead of becoming a Host failure.
1290
+ */
1291
+ enqueueConfigNotification(claim, session) {
1292
+ const notify = claim.notifyConfigOptions;
1293
+ const agent = claim.exactAgent;
1294
+ if (notify === void 0 || agent === void 0) return;
1295
+ claim.configNotifyTail = (claim.configNotifyTail ?? Promise.resolve()).then(async () => {
1296
+ if (claim.notifyConfigOptions !== notify) return;
1297
+ if (this.claims.get(claim.sessionId) !== claim || claim.exactSession !== session || claim.exactAgent !== agent) return;
1298
+ if (claim.connectionIdentity.phase !== "attached" || claim.detachedWithFence) return;
1299
+ const access = this.access;
1300
+ if (access === void 0) return;
1301
+ let options;
1302
+ try {
1303
+ options = await access.modelOptions(agent, session);
1304
+ } catch {
1305
+ return;
1306
+ }
1307
+ if (claim.notifyConfigOptions !== notify) return;
1308
+ if (this.claims.get(claim.sessionId) !== claim || claim.exactSession !== session || claim.exactAgent !== agent) return;
1309
+ if (claim.connectionIdentity.phase !== "attached" || claim.detachedWithFence) return;
1310
+ try {
1311
+ await notify(claim.sessionId, options);
1312
+ } catch {
1313
+ claim.notifyConfigOptions = void 0;
1314
+ }
1315
+ }).catch(() => {});
1316
+ }
1317
+ /**
821
1318
  * A discard only triggers verification: edit/steer can reinsert the same id
822
1319
  * within the current synchronous Host mutation. Cross it once, then read the
823
1320
  * official pending projection and the CURRENT responsibility of this claim.
@@ -976,6 +1473,7 @@ var AcpSessionViewRegistry = class {
976
1473
  state.op += 1;
977
1474
  for (const [sessionId, claim] of this.claims) {
978
1475
  if (claim.connectionIdentity !== state) continue;
1476
+ claim.notifyConfigOptions = void 0;
979
1477
  const flight = claim.inflight;
980
1478
  if (flight !== void 0) {
981
1479
  const bound = access ?? this.access;
@@ -1095,7 +1593,7 @@ var AcpSessionViewRegistry = class {
1095
1593
  * this exact claim instead of publishing a stale View, and never mutates a
1096
1594
  * state now owned by a newer/closed operation.
1097
1595
  */
1098
- commitAttached(state, op, claim, access, agent) {
1596
+ commitAttached(state, op, claim, access, agent, notifyConfigOptions) {
1099
1597
  if (state.op !== op || this.claims.get(claim.sessionId) !== claim || claim.connectionIdentity !== state) {
1100
1598
  this.releaseReservation(state, claim);
1101
1599
  throw new LocalAcpViewError("LOCAL_ACP_VIEW_CLOSED", "the ACP view was released before it attached", JSONRPC_INVALID_PARAMS, { sessionId: claim.sessionId });
@@ -1108,6 +1606,7 @@ var AcpSessionViewRegistry = class {
1108
1606
  state.phase = "attached";
1109
1607
  claim.exactAgent = agent;
1110
1608
  claim.exactSession = agent.session;
1609
+ claim.notifyConfigOptions = notifyConfigOptions;
1111
1610
  }
1112
1611
  /**
1113
1612
  * Remove ONE exact reservation. Identity is by the CLAIM OBJECT (and its
@@ -2090,22 +2589,61 @@ function buildAgentApp(state, view, context, fail) {
2090
2589
  ...error.data,
2091
2590
  code: error.code
2092
2591
  }) : error;
2093
- app.onRequest(methods.agent.session.new, async ({ params }) => {
2592
+ /**
2593
+ * Read the optional config options of an already-attached View. ONLY a real
2594
+ * model-catalog unavailability may omit the optional display; a stale,
2595
+ * closed or foreign View identity is a lifecycle failure and must propagate
2596
+ * through the normal JSON-RPC error boundary instead of falsely confirming
2597
+ * an attachment that no longer exists.
2598
+ */
2599
+ const readConfigOptionsOrLog = async (sessionId) => {
2600
+ try {
2601
+ return await views.modelOptions(view, access, sessionId);
2602
+ } catch (error) {
2603
+ if (!(error instanceof LocalAcpViewError && error.code === "LOCAL_ACP_MODEL_UNAVAILABLE")) throw error;
2604
+ context.diag.warn("local-acp.model-catalog-unavailable", {
2605
+ code: "LOCAL_ACP_MODEL_CATALOG_UNAVAILABLE",
2606
+ reason: error.code
2607
+ });
2608
+ return;
2609
+ }
2610
+ };
2611
+ /** The transient notification sink of ONE connection's attached View. */
2612
+ const configNotifierFor = (client) => async (sessionId, configOptions) => {
2613
+ await client.notify(methods.client.session.update, {
2614
+ sessionId,
2615
+ update: {
2616
+ sessionUpdate: "config_option_update",
2617
+ configOptions: [...configOptions]
2618
+ }
2619
+ });
2620
+ };
2621
+ app.onRequest(methods.agent.session.new, async ({ params, client }) => {
2094
2622
  beginRequest();
2095
2623
  try {
2096
2624
  requireInitialized();
2097
- return await views.newSession(view, access, params);
2625
+ const result = await views.newSession(view, access, params, configNotifierFor(client));
2626
+ const configOptions = await readConfigOptionsOrLog(result.sessionId);
2627
+ return {
2628
+ ...result,
2629
+ ...configOptions === void 0 ? {} : { configOptions }
2630
+ };
2098
2631
  } catch (error) {
2099
2632
  throw asRequestError(error);
2100
2633
  } finally {
2101
2634
  state.pendingRequests -= 1;
2102
2635
  }
2103
2636
  });
2104
- app.onRequest(methods.agent.session.resume, async ({ params }) => {
2637
+ app.onRequest(methods.agent.session.resume, async ({ params, client }) => {
2105
2638
  beginRequest();
2106
2639
  try {
2107
2640
  requireInitialized();
2108
- return await views.resumeSession(view, access, params);
2641
+ const result = await views.resumeSession(view, access, params, configNotifierFor(client));
2642
+ const configOptions = await readConfigOptionsOrLog(params.sessionId);
2643
+ return {
2644
+ ...result,
2645
+ ...configOptions === void 0 ? {} : { configOptions }
2646
+ };
2109
2647
  } catch (error) {
2110
2648
  throw asRequestError(error);
2111
2649
  } finally {
@@ -2145,14 +2683,25 @@ function buildAgentApp(state, view, context, fail) {
2145
2683
  state.pendingRequests -= 1;
2146
2684
  }
2147
2685
  });
2686
+ app.onRequest(methods.agent.session.setConfigOption, async ({ params, signal }) => {
2687
+ beginRequest();
2688
+ try {
2689
+ requireInitialized();
2690
+ return { configOptions: await views.setModelOption(view, access, params, signal) };
2691
+ } catch (error) {
2692
+ throw asRequestError(error);
2693
+ } finally {
2694
+ state.pendingRequests -= 1;
2695
+ }
2696
+ });
2148
2697
  } else {
2149
2698
  app.onRequest(methods.agent.session.new, acceptAnyParams, rejectSessionOperation);
2150
2699
  app.onRequest(methods.agent.session.resume, acceptAnyParams, rejectSessionOperation);
2151
2700
  app.onRequest(methods.agent.session.close, acceptAnyParams, rejectSessionOperation);
2152
2701
  app.onRequest(methods.agent.session.prompt, acceptAnyParams, rejectSessionOperation);
2702
+ app.onRequest(methods.agent.session.setConfigOption, acceptAnyParams, rejectSessionOperation);
2153
2703
  }
2154
2704
  app.onRequest(methods.agent.session.list, acceptAnyParams, rejectSessionOperation);
2155
- app.onRequest(methods.agent.session.setConfigOption, acceptAnyParams, rejectSessionOperation);
2156
2705
  if (access !== void 0 && views !== void 0 && view !== void 0) app.onNotification(methods.agent.session.cancel, ({ params }) => {
2157
2706
  if (!state.initialized) return;
2158
2707
  if (typeof params?.sessionId !== "string" || params.sessionId === "") return;
@@ -2563,4 +3112,4 @@ async function startLocalAcpListener(options) {
2563
3112
  };
2564
3113
  }
2565
3114
  //#endregion
2566
- export { ACP_IMAGE_MEDIA_TYPES as a, createLocalAcpStatusHandler as c, startLocalAcpListener as i, observeAuthenticatedLocalAcpStatus as l, darwinAcpSocketPaths as n, AcpSessionViewRegistry as o, parseAcpMaxConnections as r, LOCAL_ACP_STATUS_ROUTE as s, LocalAcpError as t };
3115
+ export { ACP_IMAGE_MEDIA_TYPES as a, LOCAL_ACP_STATUS_ROUTE as c, startLocalAcpListener as i, createLocalAcpStatusHandler as l, darwinAcpSocketPaths as n, AcpSessionViewRegistry as o, parseAcpMaxConnections as r, AcpSessionModelService as s, LocalAcpError as t, observeAuthenticatedLocalAcpStatus as u };