@blackbelt-technology/pi-dashboard-extension 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.pi/skills/browser/SKILL.md +12 -7
- package/.pi/skills/browser/references/dashboard-relay.md +232 -31
- package/.pi/skills/browser/references/own-browser.agent.md +73 -0
- package/.pi/skills/pi-dashboard/references/api-reference.md +56 -0
- package/.pi/skills/project-init/SKILL.agent.md +70 -0
- package/.pi/skills/project-init/SKILL.md +136 -24
- package/package.json +8 -8
- package/src/ask-user-tool.ts +65 -3
- package/src/auto-session-namer.ts +190 -50
- package/src/bridge-handlers/dispatch.ts +450 -0
- package/src/bridge-handlers/forwarders.ts +616 -0
- package/src/bridge-handlers/instance.ts +220 -0
- package/src/bridge-handlers/lifecycle.ts +1030 -0
- package/src/bridge-handlers/ui-prompt-patch.ts +198 -0
- package/src/bridge-identity-log.ts +45 -0
- package/src/bridge.ts +480 -2510
- package/src/command-handler.ts +180 -11
- package/src/connection.ts +265 -18
- package/src/dashboard-context-injector.ts +26 -47
- package/src/empty-actionable-guard.ts +8 -3
- package/src/flow-event-wiring.ts +1 -1
- package/src/followup-buffer.ts +1 -1
- package/src/followup-drain.ts +79 -0
- package/src/local-token-header.ts +161 -17
- package/src/message-update-coalescer.ts +3 -1
- package/src/model-refresh.ts +19 -0
- package/src/multiselect-list.ts +6 -2
- package/src/multiselect-polyfill.ts +2 -2
- package/src/openspec-cli-shim.ts +1 -1
- package/src/path-gate/decide.ts +15 -41
- package/src/path-gate/grant-cache.ts +3 -1
- package/src/path-gate/handler.ts +51 -2
- package/src/path-gate/index.ts +12 -1
- package/src/path-gate/resolve.ts +6 -124
- package/src/path-gate/roots.ts +4 -1
- package/src/path-gate/suppression.ts +4 -1
- package/src/path-gate/yolo-link.ts +104 -0
- package/src/plugin-event-forward-registry.ts +200 -0
- package/src/project-trust.ts +119 -25
- package/src/prompt-expander.ts +5 -1
- package/src/prompt-meta.ts +64 -0
- package/src/provider-register.ts +87 -20
- package/src/role-manager.ts +5 -4
- package/src/server-auto-start.ts +12 -5
- package/src/server-launcher.ts +11 -13
- package/src/session-move.ts +19 -0
- package/src/session-sync.ts +31 -38
- package/src/spawn-token.ts +46 -0
- package/src/stream-forward-buffer.ts +161 -0
- package/src/subagent-frame-buffer.ts +6 -2
- package/src/subagent-tick-throttle.ts +3 -1
- package/src/vault-delivery.ts +394 -0
- package/src/vault-forwarder.ts +128 -0
- package/src/vault-masker.ts +165 -0
- package/src/vault-redaction.ts +181 -0
- package/src/vcs-info.ts +5 -2
|
@@ -98,17 +98,84 @@ Record the answer as `DOX_ENABLED`. The `dox` flag in `profile.json` only sets
|
|
|
98
98
|
the default; the user's answer decides. Step 5 gates on `DOX_ENABLED`, not the
|
|
99
99
|
raw flag.
|
|
100
100
|
|
|
101
|
-
### 3b —
|
|
101
|
+
### 3b — Detect OpenSpec state (coding profile only)
|
|
102
102
|
|
|
103
103
|
**Gate: only when the selected profile is `coding`** (skip for `docs` / any
|
|
104
|
-
OpenSpec-off profile), mirroring Steps 4b and 5.
|
|
105
|
-
`
|
|
106
|
-
|
|
104
|
+
OpenSpec-off profile), mirroring Steps 4b and 5. Compute `OPENSPEC_MODE` — one of
|
|
105
|
+
`offer`, `repair`, `skip` — from the table below; **the first matching row wins**.
|
|
106
|
+
Run the checks in order and stop at the first match. The actual run happens in
|
|
107
|
+
Step 6.
|
|
108
|
+
|
|
109
|
+
`TARGET` is the absolute path of the directory being initialized.
|
|
110
|
+
|
|
111
|
+
**Dashboard config.** Read `~/.pi/dashboard/config.json` (the `openspec` object:
|
|
112
|
+
`enabled`, `offerInitialization`, `optOutDirectories`). An **absent file**, or an
|
|
113
|
+
**absent key** within it, takes the dashboard default: `enabled: true`,
|
|
114
|
+
`offerInitialization: true`, `optOutDirectories: []`. A file that exists but is
|
|
115
|
+
unreadable or not valid JSON, or a present `enabled` / `offerInitialization` of
|
|
116
|
+
the wrong type (non-boolean) or `optOutDirectories` that is non-array, is
|
|
117
|
+
undeterminable: **fail closed** (the server would silently use last-good values
|
|
118
|
+
the skill cannot see).
|
|
119
|
+
|
|
120
|
+
**Workflow-schema flag.** Also read `openspec.workflowSchema.defaultForNewProjects`
|
|
121
|
+
from the same file as `ENABLE_SCHEMA`. Only a literal `true` makes it true; an
|
|
122
|
+
absent file, key, or object — or any other value — is false. It never affects
|
|
123
|
+
`OPENSPEC_MODE` and is never a reason to fail closed. It is used only in the
|
|
124
|
+
`offer` flow (Steps 3c and 6).
|
|
125
|
+
|
|
126
|
+
**Opt-out match.** Compare `TARGET` against every `optOutDirectories` entry with
|
|
127
|
+
the dashboard's `pathKey` semantics: resolve to an absolute path, normalize
|
|
128
|
+
separators to `/`, strip trailing separators, and lowercase unless the platform
|
|
129
|
+
is `linux`. Run this exact one-liner — do not re-derive it:
|
|
107
130
|
|
|
108
|
-
|
|
109
|
-
|
|
131
|
+
```bash
|
|
132
|
+
OPT_OUT_JSON='["<each optOutDirectories entry as a JSON string>"]' # '[]' when none
|
|
133
|
+
node -e 'const n=p=>{p=require("path").resolve(p);if(process.platform!=="linux")p=p.replace(/\\/g,"/").toLowerCase();return p.replace(/\/+$/,"")};console.log(JSON.parse(process.argv[2]||"[]").some(d=>n(d)===n(process.argv[1]))?"match":"no-match")' "$TARGET" "$OPT_OUT_JSON"
|
|
134
|
+
```
|
|
110
135
|
|
|
111
|
-
|
|
136
|
+
Worked example (`darwin`): target `/Users/x/Proj` vs entry `/users/x/proj/` →
|
|
137
|
+
`match`; vs `/Users/x/Other` → `no-match`. On `linux` the comparison is
|
|
138
|
+
case-sensitive: `/Users/x/Proj` vs `/users/x/proj` → `no-match`.
|
|
139
|
+
|
|
140
|
+
**Git placement** (only when `TARGET` is inside a git repository, i.e.
|
|
141
|
+
`git -C "$TARGET" rev-parse --is-inside-work-tree` succeeds; a non-git directory
|
|
142
|
+
is never skipped by this check). Fail closed — this is deliberately stricter than
|
|
143
|
+
the server's "failed probe = not in a repo":
|
|
144
|
+
|
|
145
|
+
- `git -C "$TARGET" rev-parse --path-format=absolute --git-dir --git-common-dir`
|
|
146
|
+
fails (e.g. git < 2.31) → placement undetermined;
|
|
147
|
+
- the two printed paths differ after `realpath` → a linked worktree;
|
|
148
|
+
- `realpath "$(git -C "$TARGET" rev-parse --show-toplevel)"` differs from
|
|
149
|
+
`realpath "$TARGET"` → a subdirectory of a checkout (the dashboard resolves
|
|
150
|
+
skills at the checkout root, so repairing/verifying a subdirectory would
|
|
151
|
+
diverge).
|
|
152
|
+
|
|
153
|
+
`--separate-git-dir` checkouts and submodules compare equal and are NOT skipped.
|
|
154
|
+
|
|
155
|
+
| # | Condition (first match wins) | `OPENSPEC_MODE` | Action |
|
|
156
|
+
|---|---|---|---|
|
|
157
|
+
| 1 | Dashboard config undeterminable (see above) | `skip` | No prompt, no command. Warn that OpenSpec state could not be determined. |
|
|
158
|
+
| 2 | `openspec.enabled === false`, or the opt-out one-liner printed `match` | `skip` | No prompt, no command. Note OpenSpec is disabled / opted out for this directory. |
|
|
159
|
+
| 3 | Git placement: undetermined, linked worktree, or not the checkout top-level | `skip` | No prompt, no command. Note why. |
|
|
160
|
+
| 4 | `./openspec/` absent AND `offerInitialization === false` | `skip` | No prompt, no command. |
|
|
161
|
+
| 5 | `./openspec/` absent | `offer` | `ask_user` (confirm): "Initialize OpenSpec for this project? Runs `openspec init --tools pi --force`, which creates the `openspec/` scaffold and wires the OpenSpec commands into pi." Declined → `skip`. |
|
|
162
|
+
| 6 | `./openspec/` present, `.pi/skills/openspec-explore/` absent | `repair` | **No question.** Disclosed in the Step 3c preview as a repair; the preview confirmation is the overwrite confirmation. |
|
|
163
|
+
| 7 | Both present | `skip` | No prompt, no command. |
|
|
164
|
+
|
|
165
|
+
The `repair` row covers a directory initialized for OpenSpec but never wired into
|
|
166
|
+
pi: the user already chose OpenSpec for it (and did not opt it out), so complete
|
|
167
|
+
the wiring rather than ask again. `offerInitialization === false` suppresses only
|
|
168
|
+
the `offer` (row 4), never the `repair`.
|
|
169
|
+
|
|
170
|
+
**Legacy artifacts** (needed for the Step 3c disclosure; detect only when mode is
|
|
171
|
+
`offer` or `repair`). The OpenSpec CLI cleans these up automatically under
|
|
172
|
+
`--tools`, so name each one found in the preview:
|
|
173
|
+
|
|
174
|
+
- root agent-config files `CLAUDE.md`, `CLINE.md`, `CODEBUDDY.md`, `COSTRICT.md`, `QODER.md`, `IFLOW.md`, `AGENTS.md`, `QWEN.md` — only when the file contains **both**
|
|
175
|
+
`<!-- OPENSPEC:START -->` and `<!-- OPENSPEC:END -->` (the marker block);
|
|
176
|
+
- legacy command directories `.claude/commands/openspec`, `.codebuddy/commands/openspec`, `.qoder/commands/openspec`, `.lingma/commands/openspec`, `.crush/commands/openspec`, `.gemini/commands/openspec`, `.cospec/openspec/commands`;
|
|
177
|
+
- files starting with `openspec-` or `opsx-` inside these command-file
|
|
178
|
+
directories: `.cursor/commands`, `.windsurf/workflows`, `.kilocode/workflows`, `.kiro/prompts`, `.github/prompts`, `.amazonq/prompts`, `.clinerules/workflows`, `.roo/commands`, `.augment/commands`, `.factory/commands`, `.continue/prompts`, `.agent/workflows`, `.iflow/commands`, `.qwen/commands`, `.codex/prompts`, `.opencode/command`, `.junie/commands`.
|
|
112
179
|
|
|
113
180
|
### 3c — Preview + confirm
|
|
114
181
|
|
|
@@ -124,10 +191,24 @@ When `DOX_ENABLED` is true, ALSO name in the preview:
|
|
|
124
191
|
- the DOX pointer block appended to `./AGENTS.md` (see Step 5)
|
|
125
192
|
- the `doctrine` choice + kb toolset flip written to `./.pi/dashboard/knowledge_base.json`
|
|
126
193
|
|
|
127
|
-
When `
|
|
128
|
-
plain file
|
|
129
|
-
|
|
130
|
-
|
|
194
|
+
When `OPENSPEC_MODE` is `offer` (confirmed) or `repair`, ALSO disclose the side
|
|
195
|
+
effects (see Step 6) — NOT plain file writes. For `repair`, label it explicitly as
|
|
196
|
+
a **repair** of an OpenSpec directory not yet wired into pi (no question was
|
|
197
|
+
asked; confirming this preview is the confirmation):
|
|
198
|
+
|
|
199
|
+
- runs `openspec init --tools pi --force` (scaffolding `./openspec/` for `offer`; wiring pi into the existing one for `repair`)
|
|
200
|
+
- writes the generated `openspec-*` skills under `./.pi/skills/`, **overwriting** any existing ones of the same name
|
|
201
|
+
- each legacy OpenSpec artifact detected in Step 3b, by path (e.g. `AGENTS.md` — the `OPENSPEC:START`/`OPENSPEC:END` marker block, or `.claude/commands/openspec/`), worded "may be removed"
|
|
202
|
+
- the OpenSpec CLI may also remove other legacy OpenSpec files it recognizes beyond the paths listed
|
|
203
|
+
- the OpenSpec CLI may migrate its global config profile (`~/.config/openspec`) — a machine-wide side effect
|
|
204
|
+
|
|
205
|
+
When `OPENSPEC_MODE` is `offer` (confirmed) AND `ENABLE_SCHEMA` is true (the
|
|
206
|
+
dashboard's `openspec.workflowSchema.defaultForNewProjects` is `true`), ALSO
|
|
207
|
+
list, as the last item, the follow-up that Step 6 performs: after a successful
|
|
208
|
+
init, request `POST /api/openspec/workflow-schema` with `{"cwd": TARGET,
|
|
209
|
+
"action": "enable"}`, which writes `openspec/schemas/pi-spec-driven/` and
|
|
210
|
+
`openspec/config.yaml`. Never list it for `repair` (switching an existing shared
|
|
211
|
+
project's schema is a team decision) or when `ENABLE_SCHEMA` is false or absent.
|
|
131
212
|
|
|
132
213
|
When the chosen profile is `coding`, ALSO disclose the possible side effect (see
|
|
133
214
|
Step 4b) — NOT a file write:
|
|
@@ -256,27 +337,58 @@ kb dox init
|
|
|
256
337
|
invoke the `dox-describe` skill (ships with `packages/kb-extension`); on no,
|
|
257
338
|
tell the user they can run it later.
|
|
258
339
|
|
|
259
|
-
## Step 6 — Run OpenSpec init (only
|
|
340
|
+
## Step 6 — Run OpenSpec init (only on `repair`, or `offer` that was confirmed)
|
|
260
341
|
|
|
261
|
-
Gated on
|
|
262
|
-
the `
|
|
263
|
-
|
|
342
|
+
Gated on `OPENSPEC_MODE` from Step 3b: run only when it is `repair`, or `offer`
|
|
343
|
+
and the user confirmed. `skip` (any reason) runs nothing. For `repair` the Step 3c
|
|
344
|
+
preview confirmation already served as the overwrite confirmation. Mirrors Step
|
|
345
|
+
4b's side-effect pattern — disclosed, verified, never forced beyond that.
|
|
264
346
|
|
|
265
347
|
**Run** (always non-interactive so it never hijacks the conversation):
|
|
266
348
|
|
|
267
349
|
```bash
|
|
268
|
-
openspec init --tools pi
|
|
350
|
+
openspec init --tools pi --force
|
|
269
351
|
```
|
|
270
352
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
353
|
+
`--tools pi` pins the wiring to pi and skips OpenSpec's interactive tool picker;
|
|
354
|
+
`--force` is a belt-and-braces non-interactive guard (identical argv to the
|
|
355
|
+
dashboard's init endpoint). `openspec` resolves from PATH — on dashboard
|
|
356
|
+
machines that is the dashboard shim (`~/.pi/dashboard/openspec-shim/openspec`).
|
|
357
|
+
|
|
358
|
+
**Verify** exit 0 AND that `./.pi/skills/openspec-explore/` now exists (and
|
|
359
|
+
`./openspec/` for `offer`). On success, tell the user OpenSpec is wired (the
|
|
360
|
+
`coding` AGENTS.md already documents `openspec change new <name>`). On non-zero
|
|
361
|
+
exit, a missing `openspec` binary, or a still-missing skills directory, warn the
|
|
362
|
+
user, include the actual contents (`ls .pi/skills`), and point them at
|
|
363
|
+
`openspec init --tools pi --force` to run manually — do NOT error the init; the
|
|
364
|
+
scaffold is already written.
|
|
365
|
+
|
|
366
|
+
**Enable the `pi-spec-driven` workflow schema (only `offer`, only when
|
|
367
|
+
`ENABLE_SCHEMA` is true).** After a successful init (exit 0, verification
|
|
368
|
+
passed) in mode `offer` — the directory had no `openspec/` before — and only
|
|
369
|
+
when `ENABLE_SCHEMA` was true in Step 3b and disclosed in the Step 3c preview,
|
|
370
|
+
request the dashboard's enable flow, `POST /api/openspec/workflow-schema`:
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
curl -sS -X POST "http://localhost:${PORT:-8000}/api/openspec/workflow-schema" \
|
|
374
|
+
-H 'Content-Type: application/json' \
|
|
375
|
+
-d '{"cwd": "<TARGET>", "action": "enable"}'
|
|
376
|
+
```
|
|
277
377
|
|
|
278
|
-
|
|
279
|
-
`
|
|
378
|
+
`PORT` is `port` from `~/.pi/dashboard/config.json` (default `8000`). A
|
|
379
|
+
`success: true` response lists the paths it wrote in `data.written`; report them
|
|
380
|
+
in the summary (expect `openspec/schemas/pi-spec-driven/` and
|
|
381
|
+
`openspec/config.yaml`). Skip this step — silently, with no request — when the
|
|
382
|
+
user declined the `offer` (mode `skip`), in mode `repair`, and whenever
|
|
383
|
+
`ENABLE_SCHEMA` is false or absent. When the dashboard is unreachable, the call
|
|
384
|
+
fails, or it returns `success: false`, skip it, show the error if any, finish
|
|
385
|
+
the init, and tell the user they can enable the schema later from Settings →
|
|
386
|
+
OpenSpec → OpenSpec Workflow Schema. Do NOT error the init: the scaffold is
|
|
387
|
+
already written.
|
|
388
|
+
|
|
389
|
+
**Idempotent re-run:** a re-run after success lands in `skip` (row 7: both
|
|
390
|
+
`./openspec/` and `.pi/skills/openspec-explore/` present) — no prompt, no
|
|
391
|
+
command, no clobber. A re-run after a failed repair lands in `repair` again.
|
|
280
392
|
|
|
281
393
|
## Step 7 — Done
|
|
282
394
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbelt-technology/pi-dashboard-extension",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Pi bridge extension for pi-dashboard",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"!**/*.test.tsx"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@blackbelt-technology/pi-dashboard-bus-client": "^0.
|
|
52
|
-
"@blackbelt-technology/pi-dashboard-shared": "^0.
|
|
53
|
-
"@fission-ai/openspec": "1.
|
|
51
|
+
"@blackbelt-technology/pi-dashboard-bus-client": "^0.10.0",
|
|
52
|
+
"@blackbelt-technology/pi-dashboard-shared": "^0.10.0",
|
|
53
|
+
"@fission-ai/openspec": "1.14.3",
|
|
54
54
|
"minimatch": "^10.0.0",
|
|
55
55
|
"ws": "^8.18.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@earendil-works/pi-ai": ">=1.
|
|
59
|
-
"@earendil-works/pi-coding-agent": ">=1.
|
|
60
|
-
"@earendil-works/pi-tui": ">=1.
|
|
58
|
+
"@earendil-works/pi-ai": ">=1.3.0",
|
|
59
|
+
"@earendil-works/pi-coding-agent": ">=1.3.0",
|
|
60
|
+
"@earendil-works/pi-tui": ">=1.3.0",
|
|
61
61
|
"typebox": ">=1.3.6"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@earendil-works/pi-tui": "^1.
|
|
75
|
+
"@earendil-works/pi-tui": "^1.3.0",
|
|
76
76
|
"@types/ws": "^8.18.1",
|
|
77
77
|
"typebox": "^1.3.7"
|
|
78
78
|
}
|
package/src/ask-user-tool.ts
CHANGED
|
@@ -67,6 +67,14 @@ const MethodEnum = Type.Union(
|
|
|
67
67
|
// runtime in `execute`.
|
|
68
68
|
//
|
|
69
69
|
// See change: fix-multiselect-auto-cancel-on-dashboard.
|
|
70
|
+
// `allowOther` description is dashboard-only (the terminal UI never shows it).
|
|
71
|
+
// See change: add-ask-user-inline-other.
|
|
72
|
+
const ALLOW_OTHER_FIELD = () =>
|
|
73
|
+
Type.Boolean({
|
|
74
|
+
description:
|
|
75
|
+
"select/multiselect only. In the dashboard the user may type a custom answer beside the options (default true). Set false only when the answer must be exactly one of the options. The terminal UI shows the options only.",
|
|
76
|
+
});
|
|
77
|
+
|
|
70
78
|
const SubQuestionSchema = Type.Object(
|
|
71
79
|
{
|
|
72
80
|
method: Type.Union(
|
|
@@ -91,6 +99,7 @@ const SubQuestionSchema = Type.Object(
|
|
|
91
99
|
message: Type.Optional(
|
|
92
100
|
Type.String({ description: "Additional context for this sub-question" }),
|
|
93
101
|
),
|
|
102
|
+
allowOther: Type.Optional(ALLOW_OTHER_FIELD()),
|
|
94
103
|
},
|
|
95
104
|
{
|
|
96
105
|
description:
|
|
@@ -104,6 +113,30 @@ const SubQuestionSchema = Type.Object(
|
|
|
104
113
|
|
|
105
114
|
type NormalizationWarning = string;
|
|
106
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Rescue `allowOther` / its pi-flows alias `allowCustom` in place: coerce the
|
|
118
|
+
* strings "true"/"false" to booleans, drop any other non-boolean (counts as
|
|
119
|
+
* absent), map `allowCustom` → `allowOther` when the latter is absent, then
|
|
120
|
+
* delete `allowCustom`. See change: add-ask-user-inline-other.
|
|
121
|
+
*/
|
|
122
|
+
function rescueAllowOther(obj: Record<string, unknown>): void {
|
|
123
|
+
const coerce = (v: unknown): boolean | undefined =>
|
|
124
|
+
typeof v === "boolean" ? v : v === "true" ? true : v === "false" ? false : undefined;
|
|
125
|
+
const other = coerce(obj.allowOther);
|
|
126
|
+
const custom = coerce(obj.allowCustom);
|
|
127
|
+
delete obj.allowCustom;
|
|
128
|
+
delete obj.allowOther;
|
|
129
|
+
const effective = other ?? custom;
|
|
130
|
+
if (effective !== undefined) obj.allowOther = effective;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Custom (non-option) values in a select string / multiselect array answer. */
|
|
134
|
+
function customValues(answer: unknown, options: readonly string[]): string[] {
|
|
135
|
+
if (typeof answer === "string") return options.includes(answer) ? [] : [answer];
|
|
136
|
+
if (Array.isArray(answer)) return answer.filter((v): v is string => typeof v === "string" && !options.includes(v));
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
|
|
107
140
|
function normalizeSubQuestion(
|
|
108
141
|
sq: unknown,
|
|
109
142
|
warnings: NormalizationWarning[],
|
|
@@ -145,6 +178,8 @@ function normalizeSubQuestion(
|
|
|
145
178
|
);
|
|
146
179
|
}
|
|
147
180
|
|
|
181
|
+
rescueAllowOther(obj);
|
|
182
|
+
|
|
148
183
|
return obj;
|
|
149
184
|
}
|
|
150
185
|
|
|
@@ -217,6 +252,7 @@ export function registerAskUserTool(pi: ExtensionAPI): void {
|
|
|
217
252
|
description: "Placeholder for method 'input'. Ignored for other methods.",
|
|
218
253
|
}),
|
|
219
254
|
),
|
|
255
|
+
allowOther: Type.Optional(ALLOW_OTHER_FIELD()),
|
|
220
256
|
questions: Type.Optional(
|
|
221
257
|
Type.Array(SubQuestionSchema, {
|
|
222
258
|
description:
|
|
@@ -297,6 +333,9 @@ export function registerAskUserTool(pi: ExtensionAPI): void {
|
|
|
297
333
|
obj.title = typeof candidate === "string" ? candidate : "Questions";
|
|
298
334
|
}
|
|
299
335
|
|
|
336
|
+
// 6b. Rescue `allowOther` / `allowCustom` at the top level.
|
|
337
|
+
rescueAllowOther(obj);
|
|
338
|
+
|
|
300
339
|
// 7. For batch calls, normalize each sub-question (input_type, question/header, {label,value}).
|
|
301
340
|
const warnings: NormalizationWarning[] = [];
|
|
302
341
|
if (obj.method === "batch" && Array.isArray(obj.questions)) {
|
|
@@ -356,6 +395,11 @@ export function registerAskUserTool(pi: ExtensionAPI): void {
|
|
|
356
395
|
message: sq.message,
|
|
357
396
|
options: Array.isArray(sq.options) ? sq.options : undefined,
|
|
358
397
|
placeholder: sq.placeholder,
|
|
398
|
+
// Inline Other opt-in: select/multiselect only; sub-question wins over top-level.
|
|
399
|
+
...((sq.method === "select" || sq.method === "multiselect") &&
|
|
400
|
+
(sq.allowOther ?? params.allowOther) !== false
|
|
401
|
+
? { allowOther: true }
|
|
402
|
+
: {}),
|
|
359
403
|
}));
|
|
360
404
|
|
|
361
405
|
// ONE request. ctx.ui.batch resolves to BatchAnswer[] on submit or
|
|
@@ -396,7 +440,10 @@ export function registerAskUserTool(pi: ExtensionAPI): void {
|
|
|
396
440
|
}
|
|
397
441
|
params.questions.forEach((sq: any, i: number) => {
|
|
398
442
|
const ans = i < results.length ? results[i] : "(not asked)";
|
|
399
|
-
|
|
443
|
+
const isChoice = sq.method === "select" || sq.method === "multiselect";
|
|
444
|
+
const custom =
|
|
445
|
+
isChoice && i < results.length && customValues(ans, Array.isArray(sq.options) ? sq.options : []).length > 0;
|
|
446
|
+
lines.push(` ${i + 1}. ${sq.title ?? sq.method}: ${JSON.stringify(ans)}${custom ? " (custom)" : ""}`);
|
|
400
447
|
});
|
|
401
448
|
if (warnings.length > 0) {
|
|
402
449
|
lines.push("", "Warnings:");
|
|
@@ -416,7 +463,12 @@ export function registerAskUserTool(pi: ExtensionAPI): void {
|
|
|
416
463
|
|
|
417
464
|
// ── Single-question branches (unchanged behavior) ────────────────
|
|
418
465
|
let result: unknown;
|
|
419
|
-
const
|
|
466
|
+
const choiceOptIn = (params.method === "select" || params.method === "multiselect") && params.allowOther !== false;
|
|
467
|
+
const baseOpts = {
|
|
468
|
+
...(params.message ? { message: params.message } : {}),
|
|
469
|
+
...(choiceOptIn ? { allowOther: true } : {}),
|
|
470
|
+
};
|
|
471
|
+
const msgOpts = withTcid(Object.keys(baseOpts).length > 0 ? baseOpts : undefined);
|
|
420
472
|
const title = params.title || params.message || "Question";
|
|
421
473
|
|
|
422
474
|
const options: string[] = Array.isArray(params.options)
|
|
@@ -454,8 +506,18 @@ export function registerAskUserTool(pi: ExtensionAPI): void {
|
|
|
454
506
|
break;
|
|
455
507
|
}
|
|
456
508
|
|
|
509
|
+
// Note line (before the unchanged final `User responded:` line) when the
|
|
510
|
+
// answer is custom. See change: add-ask-user-inline-other.
|
|
511
|
+
let note = "";
|
|
512
|
+
if (params.method === "select" && typeof result === "string" && customValues(result, options).length > 0) {
|
|
513
|
+
note = "Custom answer (not one of the options).\n";
|
|
514
|
+
} else if (params.method === "multiselect") {
|
|
515
|
+
const custom = customValues(result, options);
|
|
516
|
+
if (custom.length > 0) note = `Custom values (not among the options): ${JSON.stringify(custom)}.\n`;
|
|
517
|
+
}
|
|
518
|
+
|
|
457
519
|
return {
|
|
458
|
-
content: [{ type: "text", text:
|
|
520
|
+
content: [{ type: "text", text: `${note}User responded: ${JSON.stringify(result)}` }],
|
|
459
521
|
details: { method: params.method, result },
|
|
460
522
|
};
|
|
461
523
|
},
|