@mrclrchtr/supi-ask-user 11.4.0 → 13.0.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/CHANGELOG.md +5 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +3 -1
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -0
- package/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +22 -3
- package/node_modules/@mrclrchtr/supi-core/src/retired-packages.ts +152 -0
- package/node_modules/@mrclrchtr/supi-core/src/session.ts +1 -0
- package/node_modules/@mrclrchtr/supi-core/src/shell-hints.ts +46 -0
- package/node_modules/@mrclrchtr/supi-core/src/spill.ts +93 -0
- package/package.json +2 -2
- package/src/schema.ts +66 -54
- package/src/tool/ask_user/spec.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [12.0.0]
|
|
4
|
+
|
|
5
|
+
- **Breaking:** `ask_user` rejects unknown fields on the form, its questions, and their options instead of ignoring them.
|
|
6
|
+
- `ask_user` now declares read-only tool annotations, so permission extensions that read `pi.getAllTools()` do not ask for confirmation before showing a form ([#582](https://github.com/mrclrchtr/supi/issues/582)).
|
|
7
|
+
|
|
3
8
|
## [11.4.0]
|
|
4
9
|
|
|
5
10
|
- Overlay forms now report Pi as waiting for your answer on terminals that show program status, like inline forms.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
4
4
|
"description": "Shared settings, configuration, reporting, and session infrastructure",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -63,8 +63,10 @@
|
|
|
63
63
|
"./project": "./src/project.ts",
|
|
64
64
|
"./prompt-surface": "./src/prompt-surface.ts",
|
|
65
65
|
"./report": "./src/report.ts",
|
|
66
|
+
"./retired-packages": "./src/retired-packages.ts",
|
|
66
67
|
"./session": "./src/session.ts",
|
|
67
68
|
"./settings": "./src/settings.ts",
|
|
69
|
+
"./spill": "./src/spill.ts",
|
|
68
70
|
"./spinner-frames": "./src/spinner-frames.ts",
|
|
69
71
|
"./status-spinner": "./src/status-spinner.ts",
|
|
70
72
|
"./terminal": "./src/terminal.ts",
|
|
@@ -29,10 +29,14 @@ export * from "./prompt-surface.ts";
|
|
|
29
29
|
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
30
30
|
export * from "./report.ts";
|
|
31
31
|
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
32
|
+
export * from "./retired-packages.ts";
|
|
33
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
32
34
|
export * from "./session.ts";
|
|
33
35
|
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
34
36
|
export * from "./settings.ts";
|
|
35
37
|
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
38
|
+
export * from "./spill.ts";
|
|
39
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
36
40
|
export * from "./spinner-frames.ts";
|
|
37
41
|
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
38
42
|
export * from "./status-spinner.ts";
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Wrap content in an `<extension-context>` XML tag.
|
|
10
10
|
*
|
|
11
|
-
* @param source - Extension identifier (e.g. "supi-
|
|
11
|
+
* @param source - Extension identifier (e.g. "supi-lsp")
|
|
12
12
|
* @param content - The text content to wrap
|
|
13
13
|
* @param attrs - Optional additional attributes (rendered as key="value")
|
|
14
14
|
* @returns Formatted XML string
|
|
@@ -18,6 +18,12 @@ export interface DebugRegistryConfig {
|
|
|
18
18
|
agentRunRetrospectivesEnabled: boolean;
|
|
19
19
|
/** Maximum number of session-local events to keep in memory. */
|
|
20
20
|
maxEvents: number;
|
|
21
|
+
/**
|
|
22
|
+
* Minimum level forwarded to persistence sinks. Lower-level events stay in the
|
|
23
|
+
* live retained buffer only, so high-volume `debug` telemetry does not grow
|
|
24
|
+
* session files.
|
|
25
|
+
*/
|
|
26
|
+
persistLevel: DebugLevel;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
export const DEBUG_REGISTRY_DEFAULTS: DebugRegistryConfig = {
|
|
@@ -25,8 +31,11 @@ export const DEBUG_REGISTRY_DEFAULTS: DebugRegistryConfig = {
|
|
|
25
31
|
agentAccess: "sanitized",
|
|
26
32
|
agentRunRetrospectivesEnabled: false,
|
|
27
33
|
maxEvents: 100,
|
|
34
|
+
persistLevel: "info",
|
|
28
35
|
};
|
|
29
36
|
|
|
37
|
+
const DEBUG_LEVEL_RANK: Record<DebugLevel, number> = { debug: 0, info: 1, warning: 2, error: 3 };
|
|
38
|
+
|
|
30
39
|
export interface DebugEventInput {
|
|
31
40
|
/** Opaque identity for events directly owned by one public Tool call. */
|
|
32
41
|
operationId?: string;
|
|
@@ -150,6 +159,10 @@ export function isDebugLevel(value: unknown): value is DebugLevel {
|
|
|
150
159
|
return value === "debug" || value === "info" || value === "warning" || value === "error";
|
|
151
160
|
}
|
|
152
161
|
|
|
162
|
+
function shouldPersist(state: DebugRegistryState, level: DebugLevel): boolean {
|
|
163
|
+
return DEBUG_LEVEL_RANK[level] >= DEBUG_LEVEL_RANK[state.config.persistLevel];
|
|
164
|
+
}
|
|
165
|
+
|
|
153
166
|
/** Return whether a value has the exact 16-byte base64url Debug Operation ID form. */
|
|
154
167
|
export function isDebugOperationId(value: unknown): value is string {
|
|
155
168
|
return typeof value === "string" && DEBUG_OPERATION_ID_RE.test(value);
|
|
@@ -194,6 +207,9 @@ export function configureDebugRegistry(config: Partial<DebugRegistryConfig>): De
|
|
|
194
207
|
...state.config,
|
|
195
208
|
...config,
|
|
196
209
|
maxEvents: normalizeMaxEvents(config.maxEvents ?? state.config.maxEvents),
|
|
210
|
+
persistLevel: isDebugLevel(config.persistLevel)
|
|
211
|
+
? config.persistLevel
|
|
212
|
+
: state.config.persistLevel,
|
|
197
213
|
};
|
|
198
214
|
trimToMaxEvents(state);
|
|
199
215
|
return getDebugRegistryConfig();
|
|
@@ -211,14 +227,16 @@ export function isDebugRegistryEnabled(): boolean {
|
|
|
211
227
|
|
|
212
228
|
/**
|
|
213
229
|
* Return whether a retrospective can be captured: Debug and its explicit opt-in
|
|
214
|
-
* must be enabled,
|
|
230
|
+
* must be enabled, at least one persistence sink must be registered, and the
|
|
231
|
+
* persistence threshold must admit `info` events.
|
|
215
232
|
*/
|
|
216
233
|
export function canRecordAgentRunRetrospective(): boolean {
|
|
217
234
|
const state = getState();
|
|
218
235
|
return (
|
|
219
236
|
state.config.enabled &&
|
|
220
237
|
state.config.agentRunRetrospectivesEnabled &&
|
|
221
|
-
state.persistenceSinks.size > 0
|
|
238
|
+
state.persistenceSinks.size > 0 &&
|
|
239
|
+
shouldPersist(state, "info")
|
|
222
240
|
);
|
|
223
241
|
}
|
|
224
242
|
|
|
@@ -283,7 +301,8 @@ export function recordDebugEvent(input: DebugEventInput): DebugEvent | null {
|
|
|
283
301
|
// Debug-event consumers must not alter producer behavior.
|
|
284
302
|
}
|
|
285
303
|
}
|
|
286
|
-
|
|
304
|
+
const sinks = shouldPersist(state, event.level) ? state.persistenceSinks : [];
|
|
305
|
+
for (const sink of sinks) {
|
|
287
306
|
try {
|
|
288
307
|
sink(toSanitizedView(event));
|
|
289
308
|
} catch {
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// supi-core retired-packages domain — warn when a retired SuPi package is still declared.
|
|
2
|
+
//
|
|
3
|
+
// Retired packages keep loading after an upgrade until the user removes them, and their
|
|
4
|
+
// surfaces can shadow the package that absorbed them. Detection reads the declared Pi
|
|
5
|
+
// packages per scope, the same view `pi remove` acts on, and never infers identity from paths.
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
ExtensionAPI,
|
|
9
|
+
ExtensionContext,
|
|
10
|
+
PackageSource,
|
|
11
|
+
} from "@earendil-works/pi-coding-agent";
|
|
12
|
+
import { SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import { recordDebugEvent } from "./debug-registry.ts";
|
|
14
|
+
|
|
15
|
+
/** A retired npm package and the package that now ships its features. */
|
|
16
|
+
export interface RetiredPackage {
|
|
17
|
+
/** npm package name, e.g. `"@mrclrchtr/supi-cache"`. */
|
|
18
|
+
name: string;
|
|
19
|
+
/** npm package name that absorbed it, e.g. `"@mrclrchtr/supi-debug"`. */
|
|
20
|
+
replacement: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Pi settings scope of a package declaration. */
|
|
24
|
+
export type PackageDeclarationScope = "user" | "project";
|
|
25
|
+
|
|
26
|
+
/** One declaration of a retired package found in Pi settings. */
|
|
27
|
+
export interface RetiredPackageDeclaration {
|
|
28
|
+
package: RetiredPackage;
|
|
29
|
+
scope: PackageDeclarationScope;
|
|
30
|
+
/** Exact command that removes this declaration. */
|
|
31
|
+
removeCommand: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Declared Pi packages per scope. Omit `project` when the project is not trusted. */
|
|
35
|
+
export interface DeclaredPackages {
|
|
36
|
+
user: readonly PackageSource[];
|
|
37
|
+
project?: readonly PackageSource[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Options for {@link warnRetiredPackages}. */
|
|
41
|
+
export interface WarnRetiredPackagesOptions {
|
|
42
|
+
/** Debug event source, e.g. `"supi-debug"`. */
|
|
43
|
+
source: string;
|
|
44
|
+
/** Override Pi's agent directory (tests). */
|
|
45
|
+
agentDir?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const WARNED_KEY = Symbol.for("@mrclrchtr/supi-core/retired-packages-warned");
|
|
49
|
+
const NPM_PREFIX = "npm:";
|
|
50
|
+
const NPM_NAME_RE = /^(@[^/\s]+\/[^@\s]+|[^@\s]+)(?:@.+)?$/;
|
|
51
|
+
|
|
52
|
+
/** npm package name of a Pi package source, ignoring version pins; `undefined` for non-npm sources. */
|
|
53
|
+
export function npmPackageName(source: PackageSource): string | undefined {
|
|
54
|
+
const value = (typeof source === "string" ? source : source.source).trim();
|
|
55
|
+
if (!value.startsWith(NPM_PREFIX)) return undefined;
|
|
56
|
+
return NPM_NAME_RE.exec(value.slice(NPM_PREFIX.length).trim())?.[1];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Find declarations of retired packages, project scope first (Pi's load precedence). */
|
|
60
|
+
export function findRetiredPackageDeclarations(
|
|
61
|
+
declared: DeclaredPackages,
|
|
62
|
+
retired: readonly RetiredPackage[],
|
|
63
|
+
): RetiredPackageDeclaration[] {
|
|
64
|
+
const scopes: Array<[PackageDeclarationScope, readonly PackageSource[] | undefined]> = [
|
|
65
|
+
["project", declared.project],
|
|
66
|
+
["user", declared.user],
|
|
67
|
+
];
|
|
68
|
+
const found: RetiredPackageDeclaration[] = [];
|
|
69
|
+
for (const [scope, sources] of scopes) {
|
|
70
|
+
const names = new Set((sources ?? []).map(npmPackageName));
|
|
71
|
+
for (const pkg of retired) {
|
|
72
|
+
if (!names.has(pkg.name)) continue;
|
|
73
|
+
const local = scope === "project" ? " --local" : "";
|
|
74
|
+
found.push({ package: pkg, scope, removeCommand: `pi remove npm:${pkg.name}${local}` });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return found;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Format one bounded, actionable warning for one retired package. */
|
|
81
|
+
export function formatRetiredPackageWarning(
|
|
82
|
+
pkg: RetiredPackage,
|
|
83
|
+
declarations: readonly RetiredPackageDeclaration[],
|
|
84
|
+
): string {
|
|
85
|
+
const commands = declarations.map((declaration) => ` ${declaration.removeCommand}`);
|
|
86
|
+
return [
|
|
87
|
+
`${pkg.name} is retired; ${pkg.replacement} now ships its features, and the old package can override them. Remove it:`,
|
|
88
|
+
...commands,
|
|
89
|
+
].join("\n");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function warnedNames(): Set<string> {
|
|
93
|
+
const store = globalThis as Record<symbol, Set<string> | undefined>;
|
|
94
|
+
store[WARNED_KEY] ??= new Set();
|
|
95
|
+
return store[WARNED_KEY];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readDeclaredPackages(
|
|
99
|
+
ctx: Pick<ExtensionContext, "cwd" | "isProjectTrusted">,
|
|
100
|
+
agentDir: string | undefined,
|
|
101
|
+
): DeclaredPackages {
|
|
102
|
+
const projectTrusted = ctx.isProjectTrusted();
|
|
103
|
+
const settings = SettingsManager.create(ctx.cwd, agentDir, { projectTrusted });
|
|
104
|
+
return {
|
|
105
|
+
user: settings.getGlobalSettings().packages ?? [],
|
|
106
|
+
...(projectTrusted ? { project: settings.getProjectSettings().packages ?? [] } : {}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Warn once per Pi process for each retired package that is still declared in user or
|
|
112
|
+
* trusted project settings. Shows a UI warning, or writes to stderr without UI, and records
|
|
113
|
+
* a `retired-package` Debug event. Never throws; unreadable settings skip the check.
|
|
114
|
+
*/
|
|
115
|
+
export function warnRetiredPackages(
|
|
116
|
+
pi: ExtensionAPI,
|
|
117
|
+
retired: readonly RetiredPackage[],
|
|
118
|
+
options: WarnRetiredPackagesOptions,
|
|
119
|
+
): void {
|
|
120
|
+
pi.on("session_start", (_event, ctx) => {
|
|
121
|
+
const warned = warnedNames();
|
|
122
|
+
const pending = retired.filter((pkg) => !warned.has(pkg.name));
|
|
123
|
+
if (pending.length === 0) return;
|
|
124
|
+
|
|
125
|
+
let declarations: RetiredPackageDeclaration[];
|
|
126
|
+
try {
|
|
127
|
+
declarations = findRetiredPackageDeclarations(
|
|
128
|
+
readDeclaredPackages(ctx, options.agentDir),
|
|
129
|
+
pending,
|
|
130
|
+
);
|
|
131
|
+
} catch {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
for (const pkg of pending) {
|
|
136
|
+
const matches = declarations.filter((declaration) => declaration.package === pkg);
|
|
137
|
+
if (matches.length === 0) continue;
|
|
138
|
+
warned.add(pkg.name);
|
|
139
|
+
const message = formatRetiredPackageWarning(pkg, matches);
|
|
140
|
+
if (ctx.hasUI) ctx.ui.notify(message, "warning");
|
|
141
|
+
else process.stderr.write(`${message}\n`);
|
|
142
|
+
recordDebugEvent({
|
|
143
|
+
source: options.source,
|
|
144
|
+
level: "warning",
|
|
145
|
+
category: "retired-package",
|
|
146
|
+
message: `${pkg.name} is retired but still declared`,
|
|
147
|
+
cwd: ctx.cwd,
|
|
148
|
+
data: { name: pkg.name, replacement: pkg.replacement, scopes: matches.map((m) => m.scope) },
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Shell hints — explain BSD sed script errors once per session.
|
|
2
|
+
//
|
|
3
|
+
// On macOS, `sed` is BSD sed: `-i` requires a backup-suffix argument and script errors read
|
|
4
|
+
// `sed: 1: "...": ...`. Agents trained on GNU sed retry the same shape repeatedly. This hook adds
|
|
5
|
+
// one hint to the first matching bash result in a session. It costs no context until it fires.
|
|
6
|
+
|
|
7
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
|
|
9
|
+
/** Marker that identifies the hint in tool results and on the session branch. */
|
|
10
|
+
export const BSD_SED_HINT_MARKER = "[supi shell hint]";
|
|
11
|
+
|
|
12
|
+
/** Text appended to the first BSD sed script error in a session. */
|
|
13
|
+
export const BSD_SED_HINT = `${BSD_SED_HINT_MARKER} This is BSD sed (macOS): \`sed -i\` needs a suffix argument (\`sed -i '' ...\`), and the substitute delimiter must not occur in the pattern. Prefer the edit tool for file changes when it is available, or \`gsed\` if installed.`;
|
|
14
|
+
|
|
15
|
+
const BSD_SED_ERROR = /^sed: (?:\d+: |-i may not be used|-I or -i may not be used)/m;
|
|
16
|
+
|
|
17
|
+
function resultText(content: readonly { type: string; text?: string }[]): string {
|
|
18
|
+
return content.map((part) => (part.type === "text" ? (part.text ?? "") : "")).join("\n");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hintAlreadyShown(ctx: ExtensionContext): boolean {
|
|
22
|
+
return ctx.sessionManager
|
|
23
|
+
.getBranch()
|
|
24
|
+
.some(
|
|
25
|
+
(entry) =>
|
|
26
|
+
entry.type === "message" &&
|
|
27
|
+
entry.message.role === "toolResult" &&
|
|
28
|
+
JSON.stringify(entry.message.content).includes(BSD_SED_HINT_MARKER),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Register a `tool_result` hook that appends {@link BSD_SED_HINT} to the first bash result in a
|
|
34
|
+
* session that contains a BSD sed script error. Safe to register from several extensions: the hook
|
|
35
|
+
* skips results that already carry the hint and sessions whose branch already shows it.
|
|
36
|
+
* Usable directly as a child-session extension factory.
|
|
37
|
+
*/
|
|
38
|
+
export function registerShellHints(pi: ExtensionAPI): void {
|
|
39
|
+
pi.on("tool_result", (event, ctx) => {
|
|
40
|
+
if (event.toolName !== "bash") return;
|
|
41
|
+
const text = resultText(event.content);
|
|
42
|
+
if (!BSD_SED_ERROR.test(text) || text.includes(BSD_SED_HINT_MARKER)) return;
|
|
43
|
+
if (hintAlreadyShown(ctx)) return;
|
|
44
|
+
return { content: [...event.content, { type: "text", text: BSD_SED_HINT }] };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// supi-core spill domain — create-only temp files for full tool output (#597).
|
|
2
|
+
//
|
|
3
|
+
// SuPi never deletes spill files. Instead, it writes few of them: one private base directory per
|
|
4
|
+
// user, content-addressed names, and reuse for identical content. The OS temp purge owns their
|
|
5
|
+
// lifetime, so paths returned to the model stay readable for the session.
|
|
6
|
+
|
|
7
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
8
|
+
import { lstatSync, mkdirSync, mkdtempSync, renameSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { extname, join } from "node:path";
|
|
11
|
+
|
|
12
|
+
/** Input for {@link writeSpillFile}. */
|
|
13
|
+
export interface SpillFileOptions {
|
|
14
|
+
/** Producer id used as sub-directory, e.g. `"agent"`. Lowercase letters, digits, and dashes. */
|
|
15
|
+
owner: string;
|
|
16
|
+
/** Descriptive file name, e.g. `"snapshot.md"`. The content hash is inserted before the extension. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Full content to persist. */
|
|
19
|
+
content: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const SEGMENT = /^[a-z0-9][a-z0-9-]*$/;
|
|
23
|
+
const FILE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Persist full output that did not fit inline and return its absolute path.
|
|
27
|
+
*
|
|
28
|
+
* Layout: `$TMPDIR/supi-<uid>/<owner>/<stem>-<sha256 prefix><ext>`. Identical content maps to the
|
|
29
|
+
* same file, which is reused. Both directories must be real directories owned by the current
|
|
30
|
+
* user without group/other access; otherwise the file falls back to a fresh `mkdtemp`
|
|
31
|
+
* directory, as before. Files are created with mode `0600` and published atomically by rename.
|
|
32
|
+
*/
|
|
33
|
+
export function writeSpillFile({ owner, name, content }: SpillFileOptions): string {
|
|
34
|
+
if (!SEGMENT.test(owner)) throw new Error(`Invalid spill owner: ${owner}`);
|
|
35
|
+
if (!FILE_NAME.test(name)) throw new Error(`Invalid spill file name: ${name}`);
|
|
36
|
+
const extension = extname(name);
|
|
37
|
+
const stem = name.slice(0, name.length - extension.length);
|
|
38
|
+
const hash = createHash("sha256").update(content).digest("hex").slice(0, 32);
|
|
39
|
+
const fileName = `${stem}-${hash}${extension}`;
|
|
40
|
+
|
|
41
|
+
const directory = privateSpillDirectory(owner);
|
|
42
|
+
if (!directory) {
|
|
43
|
+
const fallback = join(mkdtempSync(join(tmpdir(), `supi-${owner}-`)), fileName);
|
|
44
|
+
writeFileSync(fallback, content, { encoding: "utf8", mode: 0o600, flag: "wx" });
|
|
45
|
+
return fallback;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const target = join(directory, fileName);
|
|
49
|
+
if (isRegularFile(target)) return target;
|
|
50
|
+
const staging = join(directory, `.${fileName}.${process.pid}.${randomBytes(4).toString("hex")}`);
|
|
51
|
+
writeFileSync(staging, content, { encoding: "utf8", mode: 0o600, flag: "wx" });
|
|
52
|
+
// Atomic publish; a concurrent writer of the same hash replaces it with identical bytes.
|
|
53
|
+
renameSync(staging, target);
|
|
54
|
+
return target;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Return the validated private spill directory for `owner`, or undefined when it is unsafe. */
|
|
58
|
+
function privateSpillDirectory(owner: string): string | undefined {
|
|
59
|
+
const uid = process.getuid?.();
|
|
60
|
+
const base = join(tmpdir(), uid === undefined ? "supi" : `supi-${uid}`);
|
|
61
|
+
if (!ensurePrivateDirectory(base, uid)) return undefined;
|
|
62
|
+
const directory = join(base, owner);
|
|
63
|
+
return ensurePrivateDirectory(directory, uid) ? directory : undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Create `path` with mode `0700` if missing, then accept it only when it is a real directory
|
|
68
|
+
* (not a symlink) owned by `uid` with no group/other permissions. Never modifies or removes an
|
|
69
|
+
* existing entry. Ownership and mode checks are skipped where POSIX ids are unavailable.
|
|
70
|
+
*/
|
|
71
|
+
function ensurePrivateDirectory(path: string, uid: number | undefined): boolean {
|
|
72
|
+
try {
|
|
73
|
+
mkdirSync(path, { mode: 0o700 });
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") return false;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const stats = lstatSync(path);
|
|
79
|
+
if (!stats.isDirectory() || stats.isSymbolicLink()) return false;
|
|
80
|
+
if (uid === undefined) return true;
|
|
81
|
+
return stats.uid === uid && (stats.mode & 0o077) === 0;
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function isRegularFile(path: string): boolean {
|
|
88
|
+
try {
|
|
89
|
+
return lstatSync(path).isFile();
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-ask-user",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
4
4
|
"description": "Structured choice and text forms for agent-user decisions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"!__tests__"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@mrclrchtr/supi-core": "
|
|
36
|
+
"@mrclrchtr/supi-core": "13.0.0"
|
|
37
37
|
},
|
|
38
38
|
"bundledDependencies": [
|
|
39
39
|
"@mrclrchtr/supi-core"
|
package/src/schema.ts
CHANGED
|
@@ -3,21 +3,24 @@
|
|
|
3
3
|
import { type Static, Type } from "typebox";
|
|
4
4
|
import { ASK_USER_LIMITS } from "./types.ts";
|
|
5
5
|
|
|
6
|
-
const OptionSchema = Type.Object(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Type.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Type.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
const OptionSchema = Type.Object(
|
|
7
|
+
{
|
|
8
|
+
value: Type.String({ description: "Unique returned id" }),
|
|
9
|
+
label: Type.String({ description: "Displayed label" }),
|
|
10
|
+
description: Type.Optional(
|
|
11
|
+
Type.String({
|
|
12
|
+
description: "Optional helper text",
|
|
13
|
+
}),
|
|
14
|
+
),
|
|
15
|
+
details: Type.Optional(
|
|
16
|
+
Type.String({
|
|
17
|
+
description:
|
|
18
|
+
"Extended details shown when focused — trade-offs, code snippets, or consequences",
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
},
|
|
22
|
+
{ additionalProperties: false },
|
|
23
|
+
);
|
|
21
24
|
|
|
22
25
|
const ChoiceOptionCount = {
|
|
23
26
|
minItems: ASK_USER_LIMITS.minChoiceOptions,
|
|
@@ -28,51 +31,60 @@ const QuestionCount = {
|
|
|
28
31
|
maxItems: ASK_USER_LIMITS.maxQuestions,
|
|
29
32
|
} as const;
|
|
30
33
|
|
|
31
|
-
const ChoiceQuestionSchema = Type.Object(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
multi: Type.Optional(
|
|
41
|
-
Type.Boolean({
|
|
42
|
-
default: false,
|
|
43
|
-
description: "Allow multiple selections",
|
|
44
|
-
}),
|
|
45
|
-
),
|
|
46
|
-
recommendation: Type.Optional(
|
|
47
|
-
Type.Union([Type.String(), Type.Array(Type.String())], {
|
|
48
|
-
description: "Recommended value(s): single string, multi array",
|
|
34
|
+
const ChoiceQuestionSchema = Type.Object(
|
|
35
|
+
{
|
|
36
|
+
type: Type.Literal("choice"),
|
|
37
|
+
id: Type.String({ description: "Unique question id" }),
|
|
38
|
+
header: Type.String({ description: "Short label" }),
|
|
39
|
+
prompt: Type.String({ description: "Question text" }),
|
|
40
|
+
options: Type.Array(OptionSchema, {
|
|
41
|
+
description: "Each option requires `label` (shown text) and a unique `value` (returned id).",
|
|
42
|
+
...ChoiceOptionCount,
|
|
49
43
|
}),
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
multi: Type.Optional(
|
|
45
|
+
Type.Boolean({
|
|
46
|
+
default: false,
|
|
47
|
+
description: "Allow multiple selections",
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
recommendation: Type.Optional(
|
|
51
|
+
Type.Union([Type.String(), Type.Array(Type.String())], {
|
|
52
|
+
description: "Recommended value(s): single string, multi array",
|
|
53
|
+
}),
|
|
54
|
+
),
|
|
55
|
+
},
|
|
56
|
+
{ additionalProperties: false },
|
|
57
|
+
);
|
|
52
58
|
|
|
53
|
-
const TextQuestionSchema = Type.Object(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})
|
|
59
|
+
const TextQuestionSchema = Type.Object(
|
|
60
|
+
{
|
|
61
|
+
type: Type.Literal("text"),
|
|
62
|
+
id: Type.String({ description: "Unique question id" }),
|
|
63
|
+
header: Type.String({ description: "Short label" }),
|
|
64
|
+
prompt: Type.String({ description: "Question text" }),
|
|
65
|
+
recommendation: Type.Optional(Type.String({ description: "Suggested text" })),
|
|
66
|
+
placeholder: Type.Optional(Type.String({ description: "Editor placeholder" })),
|
|
67
|
+
},
|
|
68
|
+
{ additionalProperties: false },
|
|
69
|
+
);
|
|
61
70
|
|
|
62
71
|
const QuestionSchema = Type.Union([ChoiceQuestionSchema, TextQuestionSchema]);
|
|
63
72
|
|
|
64
|
-
export const AskUserParamsSchema = Type.Object(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Type.
|
|
68
|
-
|
|
73
|
+
export const AskUserParamsSchema = Type.Object(
|
|
74
|
+
{
|
|
75
|
+
title: Type.Optional(Type.String({ description: "Optional title" })),
|
|
76
|
+
intro: Type.Optional(
|
|
77
|
+
Type.String({
|
|
78
|
+
description: "Optional context",
|
|
79
|
+
}),
|
|
80
|
+
),
|
|
81
|
+
questions: Type.Array(QuestionSchema, {
|
|
82
|
+
description: "1-10 related questions for one decision",
|
|
83
|
+
...QuestionCount,
|
|
69
84
|
}),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
...QuestionCount,
|
|
74
|
-
}),
|
|
75
|
-
});
|
|
85
|
+
},
|
|
86
|
+
{ additionalProperties: false },
|
|
87
|
+
);
|
|
76
88
|
|
|
77
89
|
export type AskUserParams = Static<typeof AskUserParamsSchema>;
|
|
78
90
|
export type ExternalQuestion = Static<typeof QuestionSchema>;
|
|
@@ -7,6 +7,12 @@ export const ASK_USER_TOOL_LABEL = "Ask User";
|
|
|
7
7
|
export const askUserSpec = {
|
|
8
8
|
name: ASK_USER_TOOL_NAME,
|
|
9
9
|
label: ASK_USER_TOOL_LABEL,
|
|
10
|
+
annotations: {
|
|
11
|
+
readOnlyHint: true,
|
|
12
|
+
destructiveHint: false,
|
|
13
|
+
idempotentHint: true,
|
|
14
|
+
openWorldHint: false,
|
|
15
|
+
},
|
|
10
16
|
parameters: AskUserParamsSchema,
|
|
11
17
|
// Keep user forms out of nested tool calls.
|
|
12
18
|
exposure: "model-only",
|