@abhishek944/pi-decisions0.2.1
Browser questions and visual comparisons with local or here.now delivery for Pi.
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-decisions
A Pi 1.4 ESM extension for fixed single-choice, multiple-choice and review pages. The AI supplies content directly; the extension renders the page, handles media, routes delivery from configuration, and returns the user's feedback through SubmitQuestion and WaitForAnswer.
Install and configure
Build this checkout with npm install --ignore-scripts && npm run build, then load it with pi -e /absolute/path/to/pi-decisions. For a persistent local installation use pi install /absolute/path/to/pi-decisions, then /reload or restart Pi.
Configure delivery in global ~/.pi/agent/settings.json or normal Pi project settings:
{
"pi-decisions": { "backend": "local" }
}
local is the default and serves a loopback-only page. On macOS, local submissions open in the default browser by default only when the current user owns the graphical console, except in SSH, CI or TERM=dumb sessions. Set "autoOpen": false to disable this, or "autoOpen": true to explicitly override those checks. Other platforms do not automatically open; an explicit attempt reports an unsupported-platform error. Set the configuration value to here.now for account-owned hosted delivery. Backend selection is not a tool argument. A question's delivery is pinned when first submitted; configuration changes affect new questions. There is no silent local/cloud fallback.
Privacy: hosted links and their media are public to anyone with the URL. Only submit material approved for public sharing. Anyone with the link can submit a response; this is not authenticated voting or approval for consequential actions. Credentials, private state, source paths and answer archives are not published. Hosted Sites are not automatically deleted.
here.now credentials are read privately at runtime from HERENOW_API_KEY or ~/.herenow/credentials. Credentials are never embedded in the page or passed in command arguments. Anonymous publication is not used because feedback uses account-owned Site Data.
SubmitQuestion
{
questionId: string;
mode: "single" | "multiple" | "review";
question: string;
content?: ContentBlock[];
options?: { id: string; label: string; content?: ContentBlock[] }[];
recommended?: string;
label?: string;
}
This is the only supported input shape. No directory, task folder, active task lookup, options file, HTML or CSS is needed. Media paths must be complete absolute filesystem paths to regular files; sources can be outside the project. Only explicitly referenced and validated media is copied into the public bundle.
| Mode | Controls |
|---|---|
single |
Radio option cards, Clear selection, comments box, Send response |
multiple |
Checkbox option cards, Clear selection, comments box, Send response |
review |
Review textbox and Send review; no option cards or Clear selection |
Choice modes require a nonempty options array with unique IDs and nonempty labels. recommended, if supplied, is an option ID. Review mode omits both options and recommended. Clear selection preserves written comments. A choice or nonblank comments is sufficient in choice modes; review requires nonblank comments. Six cards fit two desktop rows of three, with two/one columns on smaller screens; six is not a quota. Media controls do not select the surrounding option.
questionId is a safe filename component, unique within the current session/project. Identical content reuses its delivery. Changing text, options, media bytes or source references requires a fresh ID, so an old browser tab cannot answer a replacement question. label optionally sets the page display title.
Shared content blocks
Question-level and option-level content are ordered arrays of the same blocks:
type ContentBlock =
| { type: "text"; text: string }
| { type: "image"; path: string; alt: string; caption?: string }
| { type: "video"; path: string; caption?: string }
| { type: "mermaid"; code: string; caption?: string };
text blocks render Markdown: headings, paragraphs, emphasis, ordered and unordered lists, links, inline code, fenced code blocks, blockquotes, horizontal rules, strikethrough and GFM pipe tables. A single newline starts a new line. Raw HTML is escaped as text instead of executed, Markdown image syntax shows only its alt text, and link targets are limited to http:, https: and mailto:. Option labels, captions and the question title stay plain text. Images support PNG/JPEG/GIF/WebP and an accessible expansion dialog. Video supports MP4/WebM with native controls, seeking and download. Prefer H.264 MP4, optionally with AAC audio, for broad browser support. Container headers and types are checked, not complete decoding or codec compatibility. Videos are not transcoded. Mermaid runs in an isolated script-enabled iframe without same-origin privileges and loads Mermaid 11 from jsDelivr, so diagram rendering requires internet access. There is no arbitrary HTML block.
The extension owns spacing, responsive columns, controls and player markup. Blocks can be combined freely. The human response is text and selected IDs, not uploaded media.
Choice example
SubmitQuestion({
questionId: "navigation-choice",
mode: "single", // or "multiple"
question: "Which navigation should we use?",
content: [{ type: "text", text: "Compare discoverability and screen space." }],
options: [
{ id: "A", label: "Sidebar", content: [
{ type: "image", path: "/absolute/path/sidebar.png", alt: "Sidebar navigation" }
] },
{ id: "B", label: "Top navigation", content: [
{ type: "video", path: "/absolute/path/top-navigation.mp4" },
{ type: "mermaid", code: "flowchart LR\nHome --> Settings" }
] }
],
recommended: "A",
taskIds: ["T12", "T18"] // Pi tasks this decision blocks
})
Review example
SubmitQuestion({
questionId: "checkout-review",
mode: "review",
question: "Please review the checkout flow.",
content: [
{ type: "text", text: "Check validation and confirmation." },
{ type: "video", path: "/absolute/path/checkout.mp4", caption: "Checkout recording" }
]
})
Submission returns {questionId, backend, url, responsePath, statePath, status, public, taskIds?, warnings, opened, openError?}. opened indicates whether this local URL was opened by this session, including an identical repeated submission. openError describes a non-fatal opening failure; the URL remains usable. Hosted URLs are never opened. Share the returned URL, then wait for the answer.
WaitForAnswer
WaitForAnswer({ questionId: "checkout-review" })
Only questionId is accepted. An archived answer returns immediately. Otherwise the tool starts/reuses one packaged watcher through pi-loop-monitor's MonitorCreate and returns waiting with its monitor ID. Yield until the watcher wakes Pi; do not repeatedly poll using model turns. The watcher archives a valid response before success. A monitor exit, timeout, cancellation or error is not a human answer. MonitorCreate/MonitorList must be available through pi-loop-monitor. A withdrawn question returns {status: "withdrawn", reason, taskIds?} and never starts a watcher; that is a record disposition, not an answer.
Task links
SubmitQuestion accepts taskIds such as ["T12","T18"]. The link is stored with the question and is never silently replaced: a repeated identical submission may attach links only when the question had none, and a different link set is rejected. Rearm after a reload names each linked task so the agent can reconcile it when the answer is consumed. Several tasks may share one decision; one answer must resolve every linked task in the same turn.
WithdrawQuestion
WithdrawQuestion({ questionId: "checkout-review", reason: "The selected route removed this decision." })
Retire an unanswered page so it stops being awaited and re-announced. The reason is required. Withdrawal is not an answer and never changes a task: update every linked task record in the same turn (return it to active, complete it with evidence, or take it through the human cancellation decision). Local delivery is stopped, so the page can no longer submit; a hosted page cannot be unpublished and simply stops being awaited. An already answered question cannot be withdrawn. If this extension armed a watcher for the question, the tool stops and dismisses that exact monitor before dropping its handle, so it no longer rereads a retired page and no unrelated monitor is touched. A watcher process started by the CLI exits on withdrawal; because a CLI caller has no monitor handle, that external process may still produce its normal watcher-end notification, but it never reports an answer. pi-decisions list and the Decisions pane report withdrawn as its own status.
The normalized answer contains:
{
questionId: string;
revision: string;
mode: "single" | "multiple" | "review";
selectedIds: string[];
selectedLabels: string[];
submissionType: "selection" | "comments-only";
response: string;
timestamp: string;
sessionId: string;
backend: "local" | "here.now";
recordId: string | null;
}
Selections and labels are reconstructed in displayed option order from trusted question data. Comments-only feedback has empty selection arrays and nonblank response. The owner validates question/revision identity, unique known IDs, mode and response text. The first validated archived answer wins. Domain-specific screenshot provenance or implementation contracts belong to the calling workflow and are not tool parameters or browser-supplied authority.
Internal storage and lifecycle
State, response.json and the explicit public bundle live internally under var/<sessionId>/pi-decisions/<questionId>/ in the current project. This storage is private, session-scoped and independent of tasks or media source locations. The first segment follows the repository var/<sessionId>/... artifact shape so every generated entry stays attributable to the real Pi session that produced it; pi-decisions occupies the segment where a Work ID would appear because this tool interface has no Work/Task context and must not invent one. Media is published under content-hashed filenames. Public presentation containing local filesystem paths is rejected; keep source paths only in media path fields.
Withdrawal is recorded in the same state file as withdrawn: {at, reason}; taskIds and withdrawn are optional so existing format-2 records stay readable. The watcher loop treats withdrawal as a terminal outcome and exits rather than polling forever. Only state format 2 is supported. Earlier saved formats are not loaded or migrated. Existing files are never deleted or overwritten to upgrade them; resubmit outstanding questions using fresh IDs. On reload/reopen, a pending reference saved under the legacy layout is translated to its var/ location for the same project root and session once that question has been copied, and is otherwise kept and reported as needing relocation rather than dropped or given a new ID. A stopped local server can be restarted by repeating an identical submission.
Relocating questions saved under .pi/decisions
Earlier releases stored the same files under .pi/decisions/<sessionId>/<questionId>/. A saved state records absolute storageDir, statePath, responsePath and bundleDir values, and the loader accepts only a state whose recorded paths match its canonical location, so moving that directory by hand breaks its identity. migrate copies one question at a time:
node /absolute/path/to/pi-decisions/dist/cli.js migrate \
--state /absolute/project/.pi/decisions/SESSION/QUESTION/state.json
It prints {questionId, from, to, outcome}, where outcome is relocated or already-migrated. It claims the target question directory with the same single exclusive mkdir that SubmitQuestion uses, writes only the bundle files the state declares plus its byte-identical archived answer, and makes the question visible by writing state.json last. An interrupted run can therefore leave a claimed directory without a state; both commands refuse that directory until it is inspected, and no target is ever replaced by a rename. The source files are never deleted, rewritten or moved as a directory — this command is copy-only.
Supported inputs are deliberately narrow: a local question that is ready and already has an archived answer. An unanswered question is refused because a delivery that is already loaded could still archive into the old paths, and a hosted question is refused because it can still be answered through its public link while it is copied. Neither is reported as preserved. A refused loopback connection on the recorded address is only a refusal guard: it does not prove that a process exited or that an accepted handler is not still finishing, so the owning session must confirm quiescence before the copy is trusted. migrate never signals, stops or inspects a process.
Repeating the command reports already-migrated only after re-checking the target's immutable identity and question content, its complete declared bundle metadata and bytes, and its archived answer. A target whose answer is missing or different is refused; a restarted delivery URL, or an answer archived after the copy, is accepted as legitimate runtime change. The same eligibility rules (ready, local, archived answer) apply to an already-active copy, which is validated without any probe. The project and session are read from the saved state, so the working directory of the call does not matter.
Removing the old .pi/decisions files is a separate, explicitly authorized operation. The command never does it, so a completed copy is not by itself a completed relocation out of .pi.
.pi/decisions remains readable only by migrate; the tools and check|watch|stop require the var/ location.
Classic monitors stop on reload, session switch or shutdown. The extension shuts down local delivery children it owns. Keep Pi running while waiting; stopped machines cannot be woken automatically. CLI users must stop unanswered local deliveries they no longer need. There is no separate recovery manager.
Local delivery binds an OS-assigned port on 127.0.0.1, serves only explicit generated bundle files, supports single video byte ranges, and requires exact Origin plus a private per-question capability for submission/stop. It never serves the project or a media source directory.
here.now uses create → presigned PUT uploads → finalize, then authenticated owner Site Data reads with documented pagination. Browser inserts encode selected_ids as a JSON-array string; the adapter strictly decodes it before shared validation. Answer collection is not a new feedback service. Failed/uncertain publishes fail visibly and are not blindly replayed. Provider warnings retain the live URL but must be inspected before collecting answers. Diagnostics redact credentials rather than exposing raw provider response bodies.
Limits
The existing mandatory here.now answer record boundary is 16 KB (16,384 UTF-8 bytes) including the JSON envelope. Oversized feedback is rejected, never truncated. Provider publish/collection quotas and rate limits remain authoritative; owner reads honor Retry-After on rate limiting. See here.now documentation and OpenAPI.
No application option/block/media-size cap is imposed. Asset handling currently uses memory buffers, so actual machine memory/storage and provider upload quotas apply.
Herdr Decisions page
Run pi-decisions install to install the native mod into the active cloned Herdr layout. The installer backs up a changed layout and checks the mod; it refuses to replace differing installed mod files. Switch to the layout again to load the entry. Decisions appears before Stats and its badge counts only live pending local decisions in the focused repository. The page refreshes from the local host, lists decisions across sessions in one scrollable view, and offers a status filter with counts, defaulting to Pending. Open verifies the live loopback delivery's session-bound identity before using the system browser. Reopen restarts an unanswered local delivery only when its saved loopback address definitively refuses connections; ambiguous failures and identity mismatches are reported without restarting. A delivery started by an older version may return the old revision-only health response; it is not trusted or stopped automatically. Its owning Pi session must stop that delivery before it can be reopened. A per-question lock prevents concurrent reopen attempts. If a host process is interrupted while holding the lock, inspect and resolve the remaining .reopen.lock before trying again; it is never removed automatically. Hosted links are never opened by this page.
pi-decisions list --json [--cwd /absolute/repository] reads the repository's session-first storage without publishing or changing answers. It includes only decisions whose question directory creation time (birthtime) is within the last 48 hours; this same window determines the pending count. The directory timestamp persists when state.json is replaced, but copying a question creates a new directory timestamp. It validates ownership and archived answers, omits malformed or unowned records, and emits only question summaries, timestamps, answer text, and verified live loopback URLs. It does not include assets, capabilities, publication credentials, or internal storage paths. Each row has one status: Pending means unanswered with a verified live server; Expired means unanswered with a refused local connection; Answered means a validated response exists; Withdrawn means the page was retired and will not be awaited. Failed and Invalid remain separate; ambiguous health failures and identity mismatches are Invalid rather than Expired. Rows also carry any linked taskIds and a withdrawal reason.
Model-free CLI
The CLI shares the same direct request/core and requires no model call or Pi runtime import:
node /absolute/path/to/pi-decisions/dist/cli.js submit \
--request /absolute/request.json \
--session-id CURRENT_SESSION_ID \
--cwd /absolute/project \
--backend local \
[--task-id T12 --task-id T18]
node /absolute/path/to/pi-decisions/dist/cli.js reopen --cwd /absolute/project --session-id SESSION --question-id QUESTION [--open]
node /absolute/path/to/pi-decisions/dist/cli.js check --state /absolute/state.json
node /absolute/path/to/pi-decisions/dist/cli.js watch --state /absolute/state.json
node /absolute/path/to/pi-decisions/dist/cli.js stop --state /absolute/state.json
node /absolute/path/to/pi-decisions/dist/cli.js withdraw --state /absolute/state.json --reason TEXT
node /absolute/path/to/pi-decisions/dist/cli.js migrate --state /absolute/legacy-state.json
The request JSON contains exactly the direct SubmitQuestion fields above. --backend is standalone CLI configuration (default local), not a property of that request. Use --backend here.now for configured hosted CLI delivery. check returns waiting, withdrawn, or the normalized answer. watch remains alive without a waiting deadline and archives before success. stop closes the owned local server; withdraw retires an unanswered question with its reason and stops local delivery, without deleting a hosted Site or an archived answer. --task-id links the question to Pi tasks for rearm and withdrawal reporting. migrate is the only verb that accepts a .pi/decisions location and only relocates the named question; see Relocating questions. Private credentials, question text and capabilities are not CLI arguments or submission output.
Development verification
npm run typecheck
npm run build
npm run lint
npm pack --dry-run
No unit tests or test-only dependencies are included. Model-free local HTTP integration is suitable for verification. Live browser testing and real here.now publication require explicit authorization and are separate from local build checks.