vc-extras 0.1.0 → 0.1.1
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/README.md +128 -71
- package/agent-install.mjs +159 -0
- package/agents/tester.md +23 -23
- package/install-extras.mjs +41 -109
- package/install-menu.mjs +22 -43
- package/install-skills.mjs +112 -112
- package/package.json +72 -28
- package/plugin-registry.mjs +73 -0
- package/plugins/config-ui/index.ts +159 -159
- package/plugins/config-ui/lib/arguments.mjs +24 -24
- package/plugins/config-ui/lib/documents.mjs +67 -67
- package/plugins/config-ui/lib/frontmatter.mjs +91 -91
- package/plugins/config-ui/lib/open.mjs +16 -16
- package/plugins/config-ui/lib/ownership.mjs +99 -99
- package/plugins/config-ui/lib/page.mjs +11 -11
- package/plugins/config-ui/lib/patch.mjs +35 -35
- package/plugins/config-ui/lib/paths.mjs +14 -14
- package/plugins/config-ui/lib/plugin-fields.mjs +86 -86
- package/plugins/config-ui/lib/plugin-validation.mjs +28 -28
- package/plugins/config-ui/lib/redaction.mjs +8 -8
- package/plugins/config-ui/lib/registry.mjs +282 -282
- package/plugins/config-ui/lib/secrets.mjs +44 -44
- package/plugins/config-ui/lib/server.mjs +250 -250
- package/plugins/config-ui/lib/sources.mjs +96 -96
- package/plugins/config-ui/lib/state.mjs +156 -156
- package/plugins/config-ui/lib/themes.mjs +113 -113
- package/plugins/config-ui/lib/writer.mjs +690 -690
- package/plugins/config-ui/project-local-owner.ts +106 -106
- package/plugins/config-ui/vc-extras.plugin.json +13 -0
- package/plugins/config-ui/web/app.mjs +997 -997
- package/plugins/config-ui/web/index.html +342 -342
- package/plugins/pi-blackhole/vc-extras.plugin.json +12 -0
- package/plugins/pi-btw/vc-extras.plugin.json +12 -0
- package/plugins/pi-claude-code/vc-extras.plugin.json +12 -0
- package/plugins/pi-fff/vc-extras.plugin.json +12 -0
- package/plugins/pi-jev-auto-mode/vc-extras.plugin.json +12 -0
- package/plugins/pi-mcp-adapter/vc-extras.plugin.json +12 -0
- package/plugins/pi-web-access/vc-extras.plugin.json +12 -0
- package/plugins/vc-ask/claude-hook.mjs +37 -0
- package/plugins/vc-ask/codex-native.mjs +28 -0
- package/plugins/vc-ask/host-channel.mjs +75 -0
- package/plugins/vc-ask/index.ts +57 -0
- package/plugins/vc-ask/native-questions.mjs +33 -0
- package/plugins/vc-ask/package.json +10 -0
- package/plugins/vc-ask/payload.ts +170 -0
- package/plugins/vc-ask/questionnaire/LICENSE.ask-user-question +21 -0
- package/plugins/vc-ask/questionnaire/UPSTREAM.md +104 -0
- package/plugins/vc-ask/questionnaire/answer-channel.ts +135 -0
- package/plugins/vc-ask/questionnaire/config.ts +180 -0
- package/plugins/vc-ask/questionnaire/events.ts +154 -0
- package/plugins/vc-ask/questionnaire/execute.ts +688 -0
- package/plugins/vc-ask/questionnaire/i18n.ts +73 -0
- package/plugins/vc-ask/questionnaire/inline-entry.ts +312 -0
- package/plugins/vc-ask/questionnaire/locales/de.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/en.json +42 -0
- package/plugins/vc-ask/questionnaire/locales/es.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/fr.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/pt-BR.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/pt.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/ru.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/uk.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/zh.json +46 -0
- package/plugins/vc-ask/questionnaire/presentation.ts +11 -0
- package/plugins/vc-ask/questionnaire/question-preview.ts +6 -0
- package/plugins/vc-ask/questionnaire/rpc.ts +221 -0
- package/plugins/vc-ask/questionnaire/session-timeout.ts +67 -0
- package/plugins/vc-ask/questionnaire/state/build-questionnaire.ts +144 -0
- package/plugins/vc-ask/questionnaire/state/external-editor.ts +62 -0
- package/plugins/vc-ask/questionnaire/state/geometry.ts +131 -0
- package/plugins/vc-ask/questionnaire/state/key-router.ts +382 -0
- package/plugins/vc-ask/questionnaire/state/panel-router.ts +32 -0
- package/plugins/vc-ask/questionnaire/state/questionnaire-session.ts +642 -0
- package/plugins/vc-ask/questionnaire/state/row-intent.ts +143 -0
- package/plugins/vc-ask/questionnaire/state/selectors/contract.ts +24 -0
- package/plugins/vc-ask/questionnaire/state/selectors/derivations.ts +40 -0
- package/plugins/vc-ask/questionnaire/state/selectors/focus.ts +17 -0
- package/plugins/vc-ask/questionnaire/state/selectors/projections.ts +99 -0
- package/plugins/vc-ask/questionnaire/state/state-reducer.ts +455 -0
- package/plugins/vc-ask/questionnaire/state/state.ts +90 -0
- package/plugins/vc-ask/questionnaire/state/vertical.ts +158 -0
- package/plugins/vc-ask/questionnaire/timeout.ts +59 -0
- package/plugins/vc-ask/questionnaire/tool/external-answer.ts +103 -0
- package/plugins/vc-ask/questionnaire/tool/format-answer.ts +24 -0
- package/plugins/vc-ask/questionnaire/tool/normalize-params.ts +37 -0
- package/plugins/vc-ask/questionnaire/tool/response-envelope.ts +75 -0
- package/plugins/vc-ask/questionnaire/tool/types.ts +74 -0
- package/plugins/vc-ask/questionnaire/tool/validate-questionnaire.ts +75 -0
- package/plugins/vc-ask/questionnaire/view/card-theme.ts +245 -0
- package/plugins/vc-ask/questionnaire/view/components/inline-input.ts +66 -0
- package/plugins/vc-ask/questionnaire/view/components/multi-select-view.ts +177 -0
- package/plugins/vc-ask/questionnaire/view/components/option-list-view.ts +65 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/markdown-content-cache.ts +101 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-block-renderer.ts +130 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-box-renderer.ts +86 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-layout-decider.ts +204 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-pane.ts +257 -0
- package/plugins/vc-ask/questionnaire/view/components/submit-picker.ts +65 -0
- package/plugins/vc-ask/questionnaire/view/components/tab-bar.ts +57 -0
- package/plugins/vc-ask/questionnaire/view/components/wrapping-select.ts +269 -0
- package/plugins/vc-ask/questionnaire/view/dialog-builder.ts +319 -0
- package/plugins/vc-ask/questionnaire/view/document-theme.ts +53 -0
- package/plugins/vc-ask/questionnaire/view/document-view.ts +306 -0
- package/plugins/vc-ask/questionnaire/view/panel-chrome.ts +133 -0
- package/plugins/vc-ask/questionnaire/view/props-adapter.ts +77 -0
- package/plugins/vc-ask/questionnaire/view/stateful-view.ts +24 -0
- package/plugins/vc-ask/questionnaire/view/tab-components.ts +16 -0
- package/plugins/vc-ask/questionnaire/view/tab-content-strategy.ts +280 -0
- package/plugins/vc-ask/questionnaire/view/vertical-view.ts +218 -0
- package/plugins/vc-ask/user-input-events.ts +34 -0
- package/plugins/vc-ask/vc-extras.plugin.json +18 -0
- package/plugins/vc-footer/agents/claude-code/adapter.mjs +29 -0
- package/plugins/vc-footer/agents/claude-code/cli.mjs +23 -0
- package/plugins/vc-footer/agents/claude-code/renderer.mjs +1 -0
- package/plugins/vc-footer/agents/claude-code/types.d.ts +38 -0
- package/plugins/vc-footer/agents/codex/adapter.mjs +13 -0
- package/plugins/vc-footer/agents/codex/mcp.mjs +45 -0
- package/plugins/vc-footer/agents/codex/native.mjs +19 -0
- package/plugins/vc-footer/agents/codex/renderer.mjs +2 -0
- package/plugins/vc-footer/agents/pi/adapter.mjs +23 -0
- package/plugins/vc-footer/agents/pi/index.js +84 -0
- package/plugins/vc-footer/agents/pi/project-local-owner.mjs +97 -0
- package/plugins/vc-footer/agents/pi/renderer.mjs +5 -0
- package/plugins/vc-footer/core/data.mjs +218 -0
- package/plugins/vc-footer/core/render.mjs +291 -0
- package/plugins/vc-footer/core/types.d.ts +29 -0
- package/plugins/vc-footer/package.json +22 -0
- package/plugins/vc-footer/vc-extras.plugin.json +32 -0
- package/skills/animate/LICENSE +21 -21
- package/skills/animate/RECIPES.md +324 -324
- package/skills/animate/SKILL.md +208 -208
- package/skills/animate/UPSTREAM.md +19 -19
- package/skills/animation-performance/LICENSE +21 -21
- package/skills/animation-performance/SKILL.md +223 -223
- package/skills/animation-performance/UPSTREAM.md +19 -19
- package/skills/answer-me-with-html/SKILL.md +174 -174
- package/skills/answer-me-with-html/scripts/am.mjs +12896 -12896
- package/skills/apple-design/LICENSE +21 -21
- package/skills/apple-design/SKILL.md +291 -291
- package/skills/apple-design/UPSTREAM.md +19 -19
- package/skills/bad-smell/SKILL.md +44 -44
- package/skills/commit/SKILL.md +90 -90
- package/skills/emil-design-eng/LICENSE +21 -21
- package/skills/emil-design-eng/SKILL.md +677 -677
- package/skills/emil-design-eng/UPSTREAM.md +19 -19
- package/skills/find-the-truth/SKILL.md +38 -38
- package/skills/find-the-truth/references/trace-method.md +48 -48
- package/skills/find-the-truth/references/truth-method.md +39 -39
- package/skills/gestures/LICENSE +21 -21
- package/skills/gestures/SKILL.md +107 -107
- package/skills/gestures/UPSTREAM.md +19 -19
- package/skills/humanizer-zh/LICENSE +21 -21
- package/skills/humanizer-zh/SKILL.md +409 -409
- package/skills/humanizer-zh/UPSTREAM.md +7 -7
- package/skills/impeccable/LICENSE +191 -191
- package/skills/impeccable/NOTICE.md +11 -11
- package/skills/impeccable/SKILL.md +89 -89
- package/skills/impeccable/licenses/modern-screenshot-MIT.txt +8 -8
- package/skills/impeccable/licenses/platform-design-skills-MIT.txt +21 -21
- package/skills/impeccable/reference/adapt.md +318 -318
- package/skills/impeccable/reference/adapt.native.md +58 -58
- package/skills/impeccable/reference/android.md +46 -46
- package/skills/impeccable/reference/animate.md +89 -89
- package/skills/impeccable/reference/audit.md +139 -139
- package/skills/impeccable/reference/audit.native.md +139 -139
- package/skills/impeccable/reference/bolder.md +33 -33
- package/skills/impeccable/reference/clarify.md +94 -94
- package/skills/impeccable/reference/colorize.md +86 -86
- package/skills/impeccable/reference/component-review.md +63 -63
- package/skills/impeccable/reference/craft-floor.md +44 -44
- package/skills/impeccable/reference/craft.md +5 -5
- package/skills/impeccable/reference/critique.md +819 -819
- package/skills/impeccable/reference/degraded/asset-producer.md +41 -41
- package/skills/impeccable/reference/degraded/documenter.md +23 -23
- package/skills/impeccable/reference/degraded/finish-reviewer.md +37 -37
- package/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -92
- package/skills/impeccable/reference/delight.md +70 -70
- package/skills/impeccable/reference/distill.md +111 -111
- package/skills/impeccable/reference/doctor.md +54 -54
- package/skills/impeccable/reference/document.md +416 -416
- package/skills/impeccable/reference/extract.md +69 -69
- package/skills/impeccable/reference/generate.md +101 -101
- package/skills/impeccable/reference/harden.md +362 -362
- package/skills/impeccable/reference/hooks.md +114 -114
- package/skills/impeccable/reference/init.md +131 -131
- package/skills/impeccable/reference/ios.md +51 -51
- package/skills/impeccable/reference/layout.md +84 -84
- package/skills/impeccable/reference/live-setup.md +104 -104
- package/skills/impeccable/reference/live.md +327 -327
- package/skills/impeccable/reference/mode-operate.md +21 -21
- package/skills/impeccable/reference/mode-persuade.md +19 -19
- package/skills/impeccable/reference/mode-read.md +21 -21
- package/skills/impeccable/reference/new-work.md +152 -152
- package/skills/impeccable/reference/onboard.md +234 -234
- package/skills/impeccable/reference/operate.md +61 -61
- package/skills/impeccable/reference/optimize.md +257 -257
- package/skills/impeccable/reference/overdrive.md +127 -127
- package/skills/impeccable/reference/polish.md +105 -105
- package/skills/impeccable/reference/quieter.md +99 -99
- package/skills/impeccable/reference/region-map.md +26 -26
- package/skills/impeccable/reference/routing.md +24 -24
- package/skills/impeccable/reference/shape.md +59 -59
- package/skills/impeccable/reference/typeset.md +90 -90
- package/skills/impeccable/reference/visualize.md +47 -47
- package/skills/impeccable/scripts/VERSION +1 -1
- package/skills/impeccable/scripts/command-metadata.json +98 -98
- package/skills/impeccable/scripts/data/font-index-failures.json +120 -120
- package/skills/impeccable/scripts/engine-checksums.txt +9 -9
- package/skills/impeccable/scripts/impeccable +249 -249
- package/skills/impeccable/scripts/impeccable.cmd +278 -278
- package/skills/impeccable/scripts/live-browser-dom.js +320 -320
- package/skills/impeccable/scripts/live-browser-ignores.js +246 -246
- package/skills/impeccable/scripts/live-browser-session.js +183 -183
- package/skills/impeccable/scripts/live-browser.js +13862 -13862
- package/skills/impeccable/scripts/modern-screenshot.umd.js +14 -14
- package/skills/improve-animations/AUDIT.md +115 -115
- package/skills/improve-animations/LICENSE +21 -21
- package/skills/improve-animations/PLAN-TEMPLATE.md +73 -73
- package/skills/improve-animations/SKILL.md +110 -110
- package/skills/improve-animations/UPSTREAM.md +19 -19
- package/skills/pick-ui-library/LICENSE +21 -21
- package/skills/pick-ui-library/SKILL.md +85 -85
- package/skills/pick-ui-library/UPSTREAM.md +19 -19
- package/skills/review-animations/LICENSE +21 -21
- package/skills/review-animations/SKILL.md +120 -120
- package/skills/review-animations/STANDARDS.md +187 -187
- package/skills/review-animations/UPSTREAM.md +19 -19
- package/skills/test/SKILL.md +29 -29
- package/skills/test/references/test-method.md +60 -60
- package/skills/write-doc/SKILL.md +115 -115
- package/skills/write-doc/examples/result-report.md +53 -53
- package/skills/write-doc/examples/task-summary.md +45 -45
- package/skills/write-doc/references/terminology.md +147 -147
- package/specs/ask-host-protocol-v1.md +58 -0
- package/specs/design-demo.md +1102 -1102
- package/specs/frontend-immersive.md +28 -28
- package/specs/plugin-install-v2.md +123 -0
- package/specs/plugin-install.md +38 -0
- package/specs/web-modes/explore.md +31 -31
- package/specs/web-modes/risk.md +15 -15
- package/specs/web-modes/verify.md +16 -16
- package/vc-extras.mjs +46 -62
- package/plugins/essrj/context.ts +0 -47
- package/plugins/essrj/data.ts +0 -190
- package/plugins/essrj/index.ts +0 -139
- package/plugins/essrj/package.json +0 -12
- package/plugins/essrj/project-local-owner.ts +0 -106
- package/plugins/essrj/render.ts +0 -217
- package/plugins/essrj/types.ts +0 -40
- package/plugins.json +0 -38
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { askHost } from './host-channel.mjs';
|
|
3
|
+
import { nativeQuestions, nativeAnswers } from './native-questions.mjs';
|
|
4
|
+
|
|
5
|
+
export async function handleQuestion(event, options) {
|
|
6
|
+
if (event?.hook_event_name !== 'PreToolUse' || event.tool_name !== 'AskUserQuestion' ||
|
|
7
|
+
typeof event.session_id !== 'string' || !event.session_id || typeof event.tool_use_id !== 'string' || !event.tool_use_id ||
|
|
8
|
+
Object.hasOwn(event.tool_input ?? {}, 'answers')) return;
|
|
9
|
+
const questions = nativeQuestions(event.tool_input?.questions);
|
|
10
|
+
if (!questions || new Set(questions.map(q => q.question)).size !== questions.length ||
|
|
11
|
+
questions.some(q => q.multiSelect && q.options.some(o => o.label.includes(',')))) return;
|
|
12
|
+
const result = await askHost({ agent: 'claude-code', sessionId: event.session_id, toolCallId: event.tool_use_id,
|
|
13
|
+
paneId: process.env.TTY7_PANE, questions }, reply => {
|
|
14
|
+
const values = nativeAnswers(questions, reply);
|
|
15
|
+
return values && Object.fromEntries(questions.map((q, i) => [q.question, values[i].join(',')]));
|
|
16
|
+
}, options);
|
|
17
|
+
if (result.status === 'unclaimed') return;
|
|
18
|
+
return { hookSpecificOutput: { hookEventName: 'PreToolUse', ...(result.status === 'answered'
|
|
19
|
+
? { permissionDecision: 'allow', updatedInput: { ...event.tool_input, answers: result.value } }
|
|
20
|
+
: { permissionDecision: 'deny', permissionDecisionReason: `Questionnaire ended (${result.status}). No user answer was received.` }) } };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url && process.env.VC_ASK_SOCKET) {
|
|
24
|
+
let bytes = 0;
|
|
25
|
+
const chunks = [];
|
|
26
|
+
for await (const chunk of process.stdin) {
|
|
27
|
+
bytes += chunk.length;
|
|
28
|
+
if (bytes > 256 * 1024) break;
|
|
29
|
+
chunks.push(chunk);
|
|
30
|
+
}
|
|
31
|
+
if (bytes <= 256 * 1024) {
|
|
32
|
+
let event;
|
|
33
|
+
try { event = JSON.parse(Buffer.concat(chunks).toString('utf8')); } catch { /* keep native UI */ }
|
|
34
|
+
const result = await handleQuestion(event);
|
|
35
|
+
if (result) process.stdout.write(JSON.stringify(result) + '\n');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { askHost } from './host-channel.mjs';
|
|
2
|
+
import { nativeQuestions, nativeAnswers } from './native-questions.mjs';
|
|
3
|
+
|
|
4
|
+
/** Call from an App Server client receiving the native user-input request. */
|
|
5
|
+
export async function handleCodexQuestion(request, options) {
|
|
6
|
+
if (request?.method !== 'item/tool/requestUserInput' ||
|
|
7
|
+
!['number', 'string'].includes(typeof request.id)) return;
|
|
8
|
+
const { threadId, questions: raw } = request.params ?? {};
|
|
9
|
+
const questions = nativeQuestions(raw, { freeText: true });
|
|
10
|
+
if (typeof threadId !== 'string' || !threadId || !questions ||
|
|
11
|
+
raw.some(q => typeof q.id !== 'string' || !q.id || q.isSecret === true) ||
|
|
12
|
+
new Set(raw.map(q => q.id)).size !== raw.length) return;
|
|
13
|
+
for (const [i, question] of questions.entries()) {
|
|
14
|
+
question.multiSelect = false;
|
|
15
|
+
question.allowFreeText = question.options.length === 0 || raw[i].isOther === true;
|
|
16
|
+
}
|
|
17
|
+
const result = await askHost({ agent: 'codex', sessionId: threadId, toolCallId: String(request.id),
|
|
18
|
+
paneId: process.env.TTY7_PANE, isBlocking: request.params.isBlocking !== false, questions }, reply => {
|
|
19
|
+
const values = nativeAnswers(questions, reply);
|
|
20
|
+
if (!values) return;
|
|
21
|
+
for (const answer of reply.answers) {
|
|
22
|
+
if (typeof answer.text === 'string') values[answer.questionIndex] = [`user_note: ${values[answer.questionIndex][0]}`];
|
|
23
|
+
}
|
|
24
|
+
return Object.fromEntries(raw.map((q, i) => [q.id, { answers: values[i] }]));
|
|
25
|
+
}, options);
|
|
26
|
+
if (result.status === 'unclaimed') return;
|
|
27
|
+
return { id: request.id, result: { answers: result.status === 'answered' ? result.value : {} } };
|
|
28
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createConnection } from 'node:net';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { isAbsolute } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const LIMIT = 256 * 1024;
|
|
6
|
+
|
|
7
|
+
/** Local, trusted host socket. A claim is scoped to this connection and UUID. */
|
|
8
|
+
export function askHost(prompt, validate, { endpoint = process.env.VC_ASK_SOCKET, signal, claimMs = 1000, waitMs = 590000, onTimeout } = {}) {
|
|
9
|
+
if (signal?.aborted) return Promise.resolve({ status: 'cancelled' });
|
|
10
|
+
if (!endpoint || (process.platform === 'win32' ? !endpoint.startsWith('\\\\.\\pipe\\') : !isAbsolute(endpoint))) {
|
|
11
|
+
return Promise.resolve({ status: 'unclaimed' });
|
|
12
|
+
}
|
|
13
|
+
const requestId = randomUUID();
|
|
14
|
+
const deadlineAt = Number.isSafeInteger(prompt.deadlineAt) ? prompt.deadlineAt : waitMs === null ? undefined : Date.now() + waitMs;
|
|
15
|
+
const expired = () => deadlineAt !== undefined && Date.now() >= deadlineAt;
|
|
16
|
+
const claimDeadline = Date.now() + claimMs;
|
|
17
|
+
const message = JSON.stringify({ ...prompt, protocol: 'vc-ask/v1', event: 'prompt', requestId, deadlineAt }) + '\n';
|
|
18
|
+
if (Buffer.byteLength(message) > LIMIT) return Promise.resolve({ status: 'unclaimed' });
|
|
19
|
+
if (expired()) return Promise.resolve({ status: 'timeout', value: onTimeout?.().value });
|
|
20
|
+
return new Promise(resolve => {
|
|
21
|
+
let claimed = false, done = false, buffer = '';
|
|
22
|
+
const socket = createConnection(endpoint);
|
|
23
|
+
const send = (event, fields = {}) => socket.write(JSON.stringify({ protocol: 'vc-ask/v1', event, requestId, ...fields }) + '\n');
|
|
24
|
+
const timer = setTimeout(() => finish(expired() ? 'timeout' : 'unclaimed'), Math.max(0, Math.min(claimDeadline, deadlineAt ?? Infinity) - Date.now()));
|
|
25
|
+
let expiry;
|
|
26
|
+
function finish(status, value) {
|
|
27
|
+
if (done) return;
|
|
28
|
+
done = true;
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
clearTimeout(expiry);
|
|
31
|
+
signal?.removeEventListener('abort', abort);
|
|
32
|
+
const timed = status === 'timeout' ? onTimeout?.() : undefined;
|
|
33
|
+
if (claimed && socket.writable) {
|
|
34
|
+
socket.end(JSON.stringify({ protocol: 'vc-ask/v1', event: 'closed', requestId, status, ...timed?.fields }) + '\n');
|
|
35
|
+
socket.destroySoon();
|
|
36
|
+
} else socket.destroy();
|
|
37
|
+
resolve({ status, value: timed ? timed.value : value });
|
|
38
|
+
}
|
|
39
|
+
const abort = () => finish('cancelled');
|
|
40
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
41
|
+
const disconnected = () => finish(claimed ? 'disconnected' : 'unclaimed');
|
|
42
|
+
socket.on('connect', () => socket.write(message));
|
|
43
|
+
socket.on('error', disconnected);
|
|
44
|
+
socket.on('close', disconnected);
|
|
45
|
+
socket.on('end', disconnected);
|
|
46
|
+
socket.setEncoding('utf8');
|
|
47
|
+
socket.on('data', chunk => {
|
|
48
|
+
if (done) return;
|
|
49
|
+
buffer += chunk;
|
|
50
|
+
if (Buffer.byteLength(buffer) > LIMIT) return disconnected();
|
|
51
|
+
let i;
|
|
52
|
+
while (!done && (i = buffer.indexOf('\n')) >= 0) {
|
|
53
|
+
const line = buffer.slice(0, i);
|
|
54
|
+
buffer = buffer.slice(i + 1);
|
|
55
|
+
let event;
|
|
56
|
+
try { event = JSON.parse(line); } catch { continue; }
|
|
57
|
+
if (event?.protocol !== 'vc-ask/v1' || event.requestId !== requestId) continue;
|
|
58
|
+
if (expired()) return finish('timeout');
|
|
59
|
+
if (event.event === 'claim' && !claimed) {
|
|
60
|
+
if (Date.now() >= claimDeadline) return finish('unclaimed');
|
|
61
|
+
claimed = true;
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
if (deadlineAt !== undefined) expiry = setTimeout(() => finish('timeout'), Math.max(0, deadlineAt - Date.now()));
|
|
64
|
+
send('claimed');
|
|
65
|
+
} else if (claimed && event.event === 'cancel') finish('cancelled');
|
|
66
|
+
else if (claimed && event.event === 'answer') {
|
|
67
|
+
let value;
|
|
68
|
+
try { value = validate(event); } catch { /* Invalid answer leaves request open. */ }
|
|
69
|
+
if (value === undefined) send('rejected', { reason: 'invalid_answer' });
|
|
70
|
+
else finish('answered', value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getAgentDir, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { TimeoutPolicy } from './questionnaire/timeout.ts';
|
|
3
|
+
import { ASK_TOOL_PARAMETERS, DEFAULT_ASK_DESCRIPTION, parseAskPayload } from './payload.js';
|
|
4
|
+
import { runQuestionnaire } from './questionnaire/execute.js';
|
|
5
|
+
import { registerAskEntryRenderer } from './questionnaire/inline-entry.js';
|
|
6
|
+
import { initializeLocale } from './questionnaire/i18n.js';
|
|
7
|
+
import { loadQuestionnaireConfig, resolveGuidance } from './questionnaire/config.js';
|
|
8
|
+
import { buildQuestionnaireResponse, buildToolResult } from './questionnaire/tool/response-envelope.js';
|
|
9
|
+
import { registerSessionTimeout } from './questionnaire/session-timeout.js';
|
|
10
|
+
|
|
11
|
+
export default function vcAsk(pi: ExtensionAPI) {
|
|
12
|
+
registerAskEntryRenderer(pi);
|
|
13
|
+
const active = new Map<string, AbortController>();
|
|
14
|
+
const timeoutFor = registerSessionTimeout(pi, getAgentDir);
|
|
15
|
+
let guidance: ReturnType<typeof resolveGuidance> = {};
|
|
16
|
+
try { guidance = resolveGuidance(loadQuestionnaireConfig()); }
|
|
17
|
+
catch (error) { console.error(String(error)); }
|
|
18
|
+
const present: typeof runQuestionnaire = async options => {
|
|
19
|
+
const { sessionId, signal } = options;
|
|
20
|
+
const timeout: TimeoutPolicy | undefined = options.timeout;
|
|
21
|
+
const deadlineAt = timeout && options.context.mode === 'tui' && !options.document && !options.fullPreview
|
|
22
|
+
? Date.now() + timeout.seconds * 1000 : undefined;
|
|
23
|
+
if (active.has(sessionId)) throw new Error('There is already an active questionnaire in this session');
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
active.set(sessionId, controller);
|
|
26
|
+
const abort = () => controller.abort();
|
|
27
|
+
if (signal?.aborted) abort(); else signal?.addEventListener('abort', abort, { once: true });
|
|
28
|
+
try {
|
|
29
|
+
initializeLocale();
|
|
30
|
+
return await runQuestionnaire({ ...options, pi, signal: controller.signal, deadlineAt });
|
|
31
|
+
} finally {
|
|
32
|
+
signal?.removeEventListener('abort', abort);
|
|
33
|
+
active.delete(sessionId);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
// Workflow approvals can share the presenter, but cannot opt into auto-answering.
|
|
37
|
+
const remove = pi.events.on('vc-ask:service.v1', (request: { present?: typeof runQuestionnaire }) => {
|
|
38
|
+
if (request && typeof request === 'object') request.present = options => present({ ...options, timeout: undefined, deadlineAt: undefined });
|
|
39
|
+
});
|
|
40
|
+
pi.on('session_shutdown', event => {
|
|
41
|
+
for (const controller of active.values()) controller.abort();
|
|
42
|
+
if (event.reason === 'quit' || event.reason === 'reload') remove();
|
|
43
|
+
});
|
|
44
|
+
pi.registerTool({
|
|
45
|
+
name: 'ask', label: 'Ask', description: guidance.description ?? DEFAULT_ASK_DESCRIPTION,
|
|
46
|
+
...guidance, parameters: ASK_TOOL_PARAMETERS,
|
|
47
|
+
async execute(id, input, signal, _update, context) {
|
|
48
|
+
const sessionId = context.sessionManager.getSessionId();
|
|
49
|
+
const { mode, params } = parseAskPayload(input.p);
|
|
50
|
+
const document = mode === 'document';
|
|
51
|
+
const timeout = !document && context.mode === 'tui' ? timeoutFor(sessionId, message => context.ui.notify(message, 'warning')) : undefined;
|
|
52
|
+
const result = await present({ pi, context, params, sessionId, requestId: id, signal,
|
|
53
|
+
minimumOptions: 1, document, fullPreview: document, vertical: !document, timeout, useHostChannel: true });
|
|
54
|
+
return result.error ? buildToolResult(result.message ?? result.error, result) : buildQuestionnaireResponse(result, params);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function nativeQuestions(raw, { freeText = false } = {}) {
|
|
2
|
+
if (!Array.isArray(raw) || !raw.length || raw.length > 12) return;
|
|
3
|
+
const questions = [];
|
|
4
|
+
for (const q of raw) {
|
|
5
|
+
if (typeof q?.question !== 'string' || !q.question.trim()) return;
|
|
6
|
+
const options = q.options ?? [];
|
|
7
|
+
if (!Array.isArray(options) || options.length > 12 || (!freeText && options.length < 2)) return;
|
|
8
|
+
if (options.some(o => typeof o?.label !== 'string' || !o.label.trim()) || new Set(options.map(o => o.label)).size !== options.length) return;
|
|
9
|
+
questions.push({ question: q.question, header: typeof q.header === 'string' ? q.header : '', multiSelect: q.multiSelect === true,
|
|
10
|
+
options: options.map(o => ({ label: o.label, ...(typeof o.description === 'string' ? { description: o.description } : {}) })) });
|
|
11
|
+
}
|
|
12
|
+
return questions;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function nativeAnswers(questions, reply) {
|
|
16
|
+
if (!Array.isArray(reply.answers) || reply.answers.length !== questions.length || reply.globalNote) return;
|
|
17
|
+
const answers = Array(questions.length).fill(null);
|
|
18
|
+
for (const a of reply.answers) {
|
|
19
|
+
if (!Number.isInteger(a?.questionIndex) || a.notes) return;
|
|
20
|
+
const q = questions[a.questionIndex];
|
|
21
|
+
if (!q || answers[a.questionIndex]) return;
|
|
22
|
+
const indexes = a.optionIndexes ?? [];
|
|
23
|
+
if (!Array.isArray(indexes) || new Set(indexes).size !== indexes.length || indexes.some(i => !Number.isInteger(i) || !q.options[i])) return;
|
|
24
|
+
if (indexes.length) {
|
|
25
|
+
if (a.text != null || (!q.multiSelect && indexes.length !== 1)) return;
|
|
26
|
+
answers[a.questionIndex] = indexes.map(i => q.options[i].label);
|
|
27
|
+
} else {
|
|
28
|
+
if (q.allowFreeText === false || typeof a.text !== 'string' || !a.text.trim()) return;
|
|
29
|
+
answers[a.questionIndex] = [a.text.trim()];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return answers;
|
|
33
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vc-ask",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": ["pi-package"],
|
|
7
|
+
"engines": { "node": ">=22.19.0" },
|
|
8
|
+
"files": ["claude-hook.mjs", "codex-native.mjs", "host-channel.mjs", "native-questions.mjs", "index.ts", "payload.ts", "user-input-events.ts", "questionnaire", "vc-extras.plugin.json"],
|
|
9
|
+
"pi": { "extensions": ["./index.ts"] }
|
|
10
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { t } from "./questionnaire/i18n.js";
|
|
3
|
+
import { MAX_HEADER_LENGTH, MAX_LABEL_LENGTH, MAX_OPTIONS, MAX_QUESTIONS, type OptionData, type QuestionData, type QuestionParams as QuestionnaireParams } from "./questionnaire/tool/types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One cap for the whole ask payload. A form is already bounded structurally (12 questions x 4
|
|
7
|
+
* options x label lengths), while a document carries the model's Markdown plan, report or
|
|
8
|
+
* findings — the stage tools scale their bound with the text they authored, so this has to fit a
|
|
9
|
+
* long report too.
|
|
10
|
+
*/
|
|
11
|
+
const MAX_ASK_PAYLOAD = 64 * 1024;
|
|
12
|
+
|
|
13
|
+
function objectValue(value: unknown, label: string): Record<string, unknown> {
|
|
14
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
15
|
+
throw new Error(`Invalid ${label}`);
|
|
16
|
+
return value as Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function nonEmptyString(value: unknown, label: string): string {
|
|
20
|
+
if (typeof value !== "string" || !value.trim())
|
|
21
|
+
throw new Error(`Invalid ${label}`);
|
|
22
|
+
return value.trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The provider-facing schema stays a single opaque blob: the compact payload is parsed and
|
|
26
|
+
// validated at call time, where the messages can name the offending question and field.
|
|
27
|
+
export const ASK_TOOL_PARAMETERS = Type.Object({
|
|
28
|
+
p: Type.Unknown(),
|
|
29
|
+
}, { additionalProperties: false });
|
|
30
|
+
|
|
31
|
+
export const DEFAULT_ASK_DESCRIPTION =
|
|
32
|
+
"p={v:2,mode:'form'|'document'}; form qs:[{q,o:[[label,desc?,preview?]],h?,t?,p?,m?,r?}] 1-12 questions/1-4 options, m multi, r recommended indexes; document p:markdown,o:[[label,desc?]] 1-4 actions; answers return as text.";
|
|
33
|
+
|
|
34
|
+
type AskMode = "form" | "document";
|
|
35
|
+
type ParsedAsk = { mode: AskMode; params: QuestionnaireParams };
|
|
36
|
+
|
|
37
|
+
const ASK_PAYLOAD_FORMAT =
|
|
38
|
+
'Expected {v:2,mode:"form",qs:[{q,h?,t?,p?,m?,r?,o:[[label,description?,preview?]]}]} ' +
|
|
39
|
+
'or {v:2,mode:"document",p:<markdown>,o:[[label,description?]]}';
|
|
40
|
+
|
|
41
|
+
/** Decode a compact payload: a JSON string or an already-parsed object, size-bounded. */
|
|
42
|
+
function decodeQuestionnairePayload(payload: unknown, maxPayloadLength: number): Record<string, unknown> {
|
|
43
|
+
if (typeof payload === "string") {
|
|
44
|
+
if (!payload || payload.length > maxPayloadLength)
|
|
45
|
+
throw new Error(`Emma questionnaire payload must be 1-${maxPayloadLength} characters`);
|
|
46
|
+
try {
|
|
47
|
+
return objectValue(JSON.parse(payload), "Emma questionnaire payload");
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error instanceof SyntaxError) throw new Error("Invalid Emma questionnaire JSON");
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let serialized: string | undefined;
|
|
54
|
+
try {
|
|
55
|
+
serialized = JSON.stringify(payload);
|
|
56
|
+
} catch {
|
|
57
|
+
throw new Error("Invalid Emma questionnaire payload");
|
|
58
|
+
}
|
|
59
|
+
if (!serialized || serialized.length > maxPayloadLength)
|
|
60
|
+
throw new Error(`Emma questionnaire payload must be 1-${maxPayloadLength} characters`);
|
|
61
|
+
return objectValue(payload, "Emma questionnaire payload");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function rejectUnknownFields(value: Record<string, unknown>, allowed: readonly string[], label: string): void {
|
|
65
|
+
const unsupported = Object.keys(value).filter((key) => !allowed.includes(key));
|
|
66
|
+
if (unsupported.length > 0)
|
|
67
|
+
throw new Error(`Invalid ${label} fields: ${unsupported.join(", ")}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** One option as `[label, description?, preview?]`; the label is the answer identity. */
|
|
71
|
+
function parseAskOption(rawOption: unknown, questionLabel: string, index: number): OptionData {
|
|
72
|
+
const label = `${questionLabel} option ${index + 1}`;
|
|
73
|
+
if (!Array.isArray(rawOption) || rawOption.length < 1 || rawOption.length > 3)
|
|
74
|
+
throw new Error(`Emma ${label} must be [label, description?, preview?]`);
|
|
75
|
+
const text = nonEmptyString(rawOption[0], `${label} label`);
|
|
76
|
+
if (text.length > MAX_LABEL_LENGTH)
|
|
77
|
+
throw new Error(`Emma ${label} label must be at most ${MAX_LABEL_LENGTH} characters`);
|
|
78
|
+
const description = rawOption[1] === undefined || rawOption[1] === null
|
|
79
|
+
? undefined
|
|
80
|
+
: nonEmptyString(rawOption[1], `${label} description`);
|
|
81
|
+
const preview = rawOption[2] === undefined || rawOption[2] === null
|
|
82
|
+
? undefined
|
|
83
|
+
: nonEmptyString(rawOption[2], `${label} preview`);
|
|
84
|
+
return { label: text, ...(description ? { description } : {}), ...(preview ? { preview } : {}) };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function parseRecommendations(value: unknown, optionCount: number, multiSelect: boolean, label: string): number[] {
|
|
88
|
+
if (!Array.isArray(value) || value.some((entry) => !Number.isInteger(entry)))
|
|
89
|
+
throw new Error(`Emma ${label} recommendations must be option indexes`);
|
|
90
|
+
const indexes = value as number[];
|
|
91
|
+
if (new Set(indexes).size !== indexes.length ||
|
|
92
|
+
indexes.some((index) => index < 0 || index >= optionCount) ||
|
|
93
|
+
(!multiSelect && indexes.length > 1))
|
|
94
|
+
throw new Error(`Invalid Emma recommendations in ${label}`);
|
|
95
|
+
return indexes;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function parseAskQuestion(rawQuestion: unknown, index: number): QuestionData {
|
|
99
|
+
const label = `question ${index + 1}`;
|
|
100
|
+
const raw = objectValue(rawQuestion, label);
|
|
101
|
+
rejectUnknownFields(raw, ["q", "h", "t", "p", "m", "r", "o"], `Emma ${label}`);
|
|
102
|
+
if (!Array.isArray(raw.o) || raw.o.length < 1 || raw.o.length > MAX_OPTIONS)
|
|
103
|
+
throw new Error(`Emma ${label} requires 1-${MAX_OPTIONS} options`);
|
|
104
|
+
const options = raw.o.map((rawOption, optionIndex) => parseAskOption(rawOption, label, optionIndex));
|
|
105
|
+
const multiSelect = raw.m === true;
|
|
106
|
+
const recommended = raw.r === undefined
|
|
107
|
+
? undefined
|
|
108
|
+
: parseRecommendations(raw.r, options.length, multiSelect, label);
|
|
109
|
+
const question = nonEmptyString(raw.q, `${label} text`);
|
|
110
|
+
const header = raw.h === undefined ? question.slice(0, MAX_HEADER_LENGTH) : nonEmptyString(raw.h, `${label} header`);
|
|
111
|
+
if (header.length > MAX_HEADER_LENGTH)
|
|
112
|
+
throw new Error(`Emma ${label} header must be at most ${MAX_HEADER_LENGTH} characters`);
|
|
113
|
+
const title = raw.t === undefined ? undefined : nonEmptyString(raw.t, `${label} title`);
|
|
114
|
+
const preview = raw.p === undefined ? undefined : nonEmptyString(raw.p, `${label} preview`);
|
|
115
|
+
return {
|
|
116
|
+
question,
|
|
117
|
+
header,
|
|
118
|
+
multiSelect,
|
|
119
|
+
...(title ? { title } : {}),
|
|
120
|
+
...(preview ? { preview } : {}),
|
|
121
|
+
...(recommended ? { recommended } : {}),
|
|
122
|
+
options,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function parseAskFormParams(root: Record<string, unknown>): QuestionParams {
|
|
127
|
+
rejectUnknownFields(root, ["v", "mode", "qs"], "Emma ask payload");
|
|
128
|
+
if (!Array.isArray(root.qs) || root.qs.length < 1 || root.qs.length > MAX_QUESTIONS)
|
|
129
|
+
throw new Error(`Invalid Emma questionnaire format. ${ASK_PAYLOAD_FORMAT}`);
|
|
130
|
+
return { questions: root.qs.map((rawQuestion, index) => parseAskQuestion(rawQuestion, index)) };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Document mode is one synthesized question: the decision markdown becomes the question-level
|
|
135
|
+
* preview and the actions become its options, so it rides the same questionnaire pipeline as a
|
|
136
|
+
* form and only the presentation differs.
|
|
137
|
+
*/
|
|
138
|
+
function parseAskDocumentParams(root: Record<string, unknown>): QuestionParams {
|
|
139
|
+
rejectUnknownFields(root, ["v", "mode", "p", "o"], "Emma ask payload");
|
|
140
|
+
if (!Array.isArray(root.o) || root.o.length < 1 || root.o.length > MAX_OPTIONS)
|
|
141
|
+
throw new Error(`Emma document mode requires 1-${MAX_OPTIONS} actions`);
|
|
142
|
+
const title = t("gate.title", "Emma · Next step");
|
|
143
|
+
return {
|
|
144
|
+
questions: [{
|
|
145
|
+
question: t("gate.question", "Choose the next step."),
|
|
146
|
+
header: title.slice(0, MAX_HEADER_LENGTH),
|
|
147
|
+
title,
|
|
148
|
+
preview: nonEmptyString(root.p, "Emma document markdown"),
|
|
149
|
+
multiSelect: false,
|
|
150
|
+
options: root.o.map((rawOption, index) => parseAskOption(rawOption, "document", index)),
|
|
151
|
+
}],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Decode the model-facing ask payload into questionnaire params. `mode` is explicit when
|
|
157
|
+
* present; otherwise a `qs` array means a question form and a `p`/`o` pair means a document
|
|
158
|
+
* decision, so the two shapes can never be confused with one another.
|
|
159
|
+
*/
|
|
160
|
+
export function parseAskPayload(payload: unknown, maxPayloadLength = MAX_ASK_PAYLOAD): ParsedAsk {
|
|
161
|
+
const root = decodeQuestionnairePayload(payload, maxPayloadLength);
|
|
162
|
+
if (root.v !== undefined && root.v !== 2)
|
|
163
|
+
throw new Error(`Invalid Emma questionnaire version. ${ASK_PAYLOAD_FORMAT}`);
|
|
164
|
+
const mode = root.mode ?? (Array.isArray(root.qs) ? "form" : "document");
|
|
165
|
+
if (mode !== "form" && mode !== "document")
|
|
166
|
+
throw new Error(`Invalid Emma questionnaire mode. ${ASK_PAYLOAD_FORMAT}`);
|
|
167
|
+
return mode === "form"
|
|
168
|
+
? { mode, params: parseAskFormParams(root) }
|
|
169
|
+
: { mode, params: parseAskDocumentParams(root) };
|
|
170
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 juicesharp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Embedded questionnaire: upstream baseline and our deltas
|
|
2
|
+
|
|
3
|
+
`vc-ask` was extracted from the questionnaire in Emma (`2cdc923`, `emma/runtime/questionnaire/`).
|
|
4
|
+
The notes below describe that original embedded baseline and its deltas. The standalone package
|
|
5
|
+
preserves the original license and event contract; its optional timeout policy lives in `timeout.ts`.
|
|
6
|
+
|
|
7
|
+
Emma's `emma/runtime/questionnaire/` began as an embedded copy of the published package
|
|
8
|
+
`@juicesharp/rpiv-ask-user-question` (see `LICENSE.ask-user-question`) and has since diverged in
|
|
9
|
+
both directions. This file records the baseline we embed against, the deltas we deliberately keep,
|
|
10
|
+
and the procedure for taking a newer upstream version. Rebase, do not hand-merge blindly: the
|
|
11
|
+
comparison includes intentional differences.
|
|
12
|
+
|
|
13
|
+
## Baseline
|
|
14
|
+
|
|
15
|
+
| | |
|
|
16
|
+
|---|---|
|
|
17
|
+
| Package | `@juicesharp/rpiv-ask-user-question` |
|
|
18
|
+
| Version | **2.13.9** |
|
|
19
|
+
| Fetched | `npm pack` (see the script below) |
|
|
20
|
+
| Source fix port | [`d3c6f0812140605a4e55e0a660eb83edc12abbc5`](https://github.com/juicesharp/rpiv-mono/commit/d3c6f0812140605a4e55e0a660eb83edc12abbc5), checked 2026-10-19 |
|
|
21
|
+
| Local root | `emma/runtime/questionnaire/` |
|
|
22
|
+
|
|
23
|
+
Anchor the version here before rebasing, and update it in the same commit that moves it.
|
|
24
|
+
|
|
25
|
+
## Comparison tool
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
node scripts/sync-questionnaire-upstream.mjs [version]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Report-only. It fetches the version, normalizes the `.ts` → `.js` import style that only differs
|
|
32
|
+
because we embed, and prints: files only upstream has, files only we have, and files both have that
|
|
33
|
+
differ (with changed-line counts). It never merges or writes.
|
|
34
|
+
|
|
35
|
+
Historical snapshot before the presentation port: 17 upstream-only, 13 embedded-only, 38 differing.
|
|
36
|
+
The script defaults to the pinned npm baseline, not GitHub HEAD; inspect newer source commits separately.
|
|
37
|
+
|
|
38
|
+
- **Only upstream:** `README.md`, `ask-user-question.ts`, `docs/*`, `index.ts`, `package.json`,
|
|
39
|
+
`reconcile.ts`, `rpc-fallback.ts`, `state/i18n-bridge.ts`,
|
|
40
|
+
`view/component-binding.ts`, `view/dialog-copy.ts`, `view/scroll-window.ts`.
|
|
41
|
+
- **Only embedded:** `execute.ts`, `i18n.ts`, `inline-entry.ts`, `question-preview.ts`, `rpc.ts`,
|
|
42
|
+
`state/geometry.ts`, `state/panel-router.ts`, `state/vertical.ts`, `view/card-theme.ts`,
|
|
43
|
+
`view/document-theme.ts`, `view/document-view.ts`, `view/panel-chrome.ts`,
|
|
44
|
+
`view/vertical-view.ts`.
|
|
45
|
+
- **Differing:** the shared state machine, reducers, preview views, locales and tool layer. Port
|
|
46
|
+
upstream changes into these by hand and re-apply the deltas below.
|
|
47
|
+
|
|
48
|
+
## Deltas we keep
|
|
49
|
+
|
|
50
|
+
1. **Vertical question list** (`state/vertical.ts`, `view/vertical-view.ts`) — upstream pages
|
|
51
|
+
questions across tabs; we stack every question in the docked panel with a single submit row.
|
|
52
|
+
Carries our own `VerticalAction` set and focus model. Descriptions remain visible; the focused
|
|
53
|
+
question/option preview uses the upstream Markdown cache. At 90+ columns questions and preview
|
|
54
|
+
share left/right columns; narrower terminals stack them with independent Ctrl+PageUp/PageDown
|
|
55
|
+
preview paging. Question-level preview takes precedence, including on multi-select questions.
|
|
56
|
+
2. **Review screen and global note** (`review_enter` / `review_focus` / `review_exit`, the review
|
|
57
|
+
body in `vertical-view.ts`) — the vertical equivalent of upstream's Submit tab: answers, the
|
|
58
|
+
unanswered list, a whole-questionnaire note, then submit or cancel. Single-question and document
|
|
59
|
+
asks skip it.
|
|
60
|
+
3. **Document view** (`view/document-view.ts`, `view/document-theme.ts`, `question-preview.ts`) —
|
|
61
|
+
the decision/plan surface with its action row; upstream renders the same material through the
|
|
62
|
+
generic preview pane.
|
|
63
|
+
4. **Panel geometry and routing** (`state/geometry.ts`, `state/panel-router.ts`,
|
|
64
|
+
`view/panel-chrome.ts`, `view/card-theme.ts`) — dock/float placement, resize, drag and the
|
|
65
|
+
card accent. Floating cards render only their local rectangle; native overlays own placement.
|
|
66
|
+
Drag/resize geometry stays inside the viewport to match host bounds. The dock still uses our
|
|
67
|
+
45% row budget rather than upstream's 70%; this deliberately reserves more transcript space.
|
|
68
|
+
5. **Embedded runtime layer** (`execute.ts`, `inline-entry.ts`, `rpc.ts`, `i18n.ts`,
|
|
69
|
+
`answer-channel.ts`, `tool/response-envelope.ts`, `tool/normalize-params.ts`,
|
|
70
|
+
`tool/external-answer.ts`, `events.ts`) — no rpiv runtime imports or service bridge, our own
|
|
71
|
+
locale dictionaries, our own `emma:ask-user:*` event channels, and a plain-text answer envelope.
|
|
72
|
+
6. **Model-facing protocol** (owned by `emma/runtime/extension.ts`) — one `ask` tool with
|
|
73
|
+
`{v:2,mode:"form"|"document",...}` payloads, no ids, and envelope output.
|
|
74
|
+
|
|
75
|
+
## Invariants to re-check after every port
|
|
76
|
+
|
|
77
|
+
- The embedded tree imports no rpiv runtime package and no service bridge.
|
|
78
|
+
- `MAX_QUESTIONS` is 12 (upstream allows 4); `MinimumOptions` may be 1 for stage actions.
|
|
79
|
+
- `QuestionData` keeps `preview` (question-level) and `recommended` (preselected option indexes).
|
|
80
|
+
- Option previews are allowed on multi-select questions in our payload; upstream restricts them to
|
|
81
|
+
single-select.
|
|
82
|
+
- The envelope never echoes a chosen option's `preview` back to the model.
|
|
83
|
+
- Stage confirmation (`shape_align` / `build_gate` / `hunt_align`) reads
|
|
84
|
+
`parseStageActionPayload` + `compactGateResult` internally — the model never authors action ids.
|
|
85
|
+
- Shape and Hunt action buttons disable option notes through the internal `allowNotes: false` flag;
|
|
86
|
+
free-text feedback remains available. Other questionnaires keep notes enabled by default.
|
|
87
|
+
|
|
88
|
+
## Outstanding work from the rebase plan
|
|
89
|
+
|
|
90
|
+
- `presentation.ts` now adapts the upstream inline-slot claim/release and capturing-overlay
|
|
91
|
+
fallback (#253), including the latest #313 distinction: a passive `nonCapturing` HUD never
|
|
92
|
+
forces an inline questionnaire into a focused overlay. Host-allocated row markers and
|
|
93
|
+
`hasOverlay()` compatibility fallback are preserved. Emma keeps its own row budget and
|
|
94
|
+
model-facing protocol, event channels and close/abort handling. Native floating-card geometry
|
|
95
|
+
is an Emma adaptation, not an upstream implementation.
|
|
96
|
+
- Source patch #313 changes presentation detection and docs/tests only; its behavior is covered
|
|
97
|
+
by `emma-questionnaire-preview-layout.test.mjs` and `emma-questionnaire-host-layout.test.mjs`.
|
|
98
|
+
Core regression coverage also checks default vertical question descriptions, both preview
|
|
99
|
+
levels, multi-select, narrow fallback, paging, and untouched live terminal background.
|
|
100
|
+
- `reconcile.ts` (strip the tool in non-interactive runs) is not embedded; the questionnaire
|
|
101
|
+
currently answers without UI through its own failure envelope.
|
|
102
|
+
- `config.ts` takes `guidance.{description,promptSnippet,promptGuidelines}`, `collapseKey`,
|
|
103
|
+
`locale`, `cardAccent` and the panel size from `vibe-emma/questionnaire.json`; upstream's
|
|
104
|
+
rpiv-config loading and legacy fallback path are intentionally not taken.
|