pi-usereq 0.61.0 → 0.63.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/README.md +1 -1
- package/package.json +1 -1
- package/src/core/prompt-command-state.ts +46 -0
- package/src/core/prompts.ts +18 -6
- package/src/index.ts +12 -6
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -209,3 +209,49 @@ export function restorePersistedPromptCommandRuntimeStateForSession(
|
|
|
209
209
|
}
|
|
210
210
|
return undefined;
|
|
211
211
|
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @brief Describes the loosely-typed extension-api surface persisted for model re-application.
|
|
215
|
+
* @details Stores only the session-scoped model appliers plus thinking-level probe needed to re-apply one captured selection after session replacement. The structural shape avoids importing concrete pi SDK types into this process-scoped module. The interface is compile-time only and introduces no runtime cost.
|
|
216
|
+
* @satisfies REQ-367, REQ-368, REQ-369
|
|
217
|
+
*/
|
|
218
|
+
export interface PersistedPromptCommandRuntimeApi {
|
|
219
|
+
setModel?: (model: unknown) => unknown;
|
|
220
|
+
setThinkingLevel?: (level: unknown) => unknown;
|
|
221
|
+
getThinkingLevel?: () => unknown;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @brief Defines the global property used for latest live extension-api persistence.
|
|
226
|
+
* @details The property lives on `globalThis` because pi invalidates the extension api captured by one session's extension instance whenever that session is replaced and reloads the extension against the replacement session while the host process persists. Access complexity is O(1).
|
|
227
|
+
*/
|
|
228
|
+
const PI_USEREQ_PROMPT_COMMAND_RUNTIME_API_KEY = "__piUsereqPromptCommandRuntimeApi";
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @brief Writes the latest live extension api into process-scoped persistence.
|
|
232
|
+
* @details Replaces the stored loosely-typed model-api surface so model re-application helpers always bind to the extension instance of the currently active session runner and never to an api invalidated by session replacement. Runtime is O(1). Side effect: mutates process-scoped state.
|
|
233
|
+
* @param[in] runtimeApi {PersistedPromptCommandRuntimeApi | undefined} Latest extension-api surface written at extension bind time, or undefined to clear the stored surface.
|
|
234
|
+
* @return {void} No return value.
|
|
235
|
+
* @satisfies REQ-367, REQ-368, REQ-369
|
|
236
|
+
*/
|
|
237
|
+
export function writePersistedPromptCommandRuntimeApi(
|
|
238
|
+
runtimeApi: PersistedPromptCommandRuntimeApi | undefined,
|
|
239
|
+
): void {
|
|
240
|
+
const globalState = globalThis as typeof globalThis & {
|
|
241
|
+
__piUsereqPromptCommandRuntimeApi?: PersistedPromptCommandRuntimeApi | undefined;
|
|
242
|
+
};
|
|
243
|
+
globalState[PI_USEREQ_PROMPT_COMMAND_RUNTIME_API_KEY] = runtimeApi;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @brief Reads the latest live extension api from process-scoped persistence.
|
|
248
|
+
* @details Returns the extension-api surface written by the most recent extension bind so post-switch model re-application uses a session-scoped api that remains valid after session replacement, returning undefined so callers degrade to their own captured api. Runtime is O(1). No external state is mutated.
|
|
249
|
+
* @return {PersistedPromptCommandRuntimeApi | undefined} Latest stored extension-api surface, or undefined when no extension has bound in this process.
|
|
250
|
+
* @satisfies REQ-367, REQ-368, REQ-369
|
|
251
|
+
*/
|
|
252
|
+
export function readPersistedPromptCommandRuntimeApi(): PersistedPromptCommandRuntimeApi | undefined {
|
|
253
|
+
const globalState = globalThis as typeof globalThis & {
|
|
254
|
+
__piUsereqPromptCommandRuntimeApi?: PersistedPromptCommandRuntimeApi | undefined;
|
|
255
|
+
};
|
|
256
|
+
return globalState[PI_USEREQ_PROMPT_COMMAND_RUNTIME_API_KEY];
|
|
257
|
+
}
|
package/src/core/prompts.ts
CHANGED
|
@@ -81,16 +81,28 @@ const PI_DEV_CODING_AGENT_DOCS_PROMPT_PATH = `${PI_DEV_DOCS_PROMPT_PATH}/coding-
|
|
|
81
81
|
* @details Prompt guidance cites this directory when requiring read-only validation against the pi client implementation. Lookup complexity is O(1).
|
|
82
82
|
*/
|
|
83
83
|
const PI_DEV_SOURCE_PROMPT_PATH = "pi.dev-src/pi-mono";
|
|
84
|
+
/**
|
|
85
|
+
* @brief Stores the repository-relative root directory of the pi CLI client sources.
|
|
86
|
+
* @details Prompt guidance cites this directory when declaring the permanently read-only pi CLI client reference and source-of-truth mandates for new implementations, source-code modifications, and bug fixes. Lookup complexity is O(1).
|
|
87
|
+
*/
|
|
88
|
+
const PI_DEV_SOURCE_ROOT_PROMPT_PATH = "pi.dev-src";
|
|
84
89
|
/**
|
|
85
90
|
* @brief Defines the injected pi.dev governance guidance block.
|
|
86
|
-
* @details The block requires read-only handling for documentation and pi client sources, coding-agent-document review, coding-agent-document compliance, optional manifest-referenced document handling, and pi client source validation for ambiguous or bug-fix interface work. Construction happens once at module load. Access complexity is O(1).
|
|
87
|
-
* @satisfies REQ-033, REQ-034, REQ-108, REQ-273, REQ-274, REQ-275
|
|
91
|
+
* @details The block requires read-only handling for documentation and pi client sources, mandatory read-only pi CLI client reference usage plus source-of-truth handling for new implementations, source-code modifications, and bug fixes, coding-agent-document review, coding-agent-document compliance, optional manifest-referenced document handling, and pi client source validation for ambiguous or bug-fix interface work. Construction happens once at module load. Access complexity is O(1).
|
|
92
|
+
* @satisfies CTN-017, CTN-023, CTN-024, REQ-033, REQ-034, REQ-108, REQ-273, REQ-274, REQ-275, REQ-378
|
|
88
93
|
*/
|
|
89
94
|
const PI_DEV_CONFORMANCE_BLOCK = [
|
|
90
95
|
"- Treat every path under `docs/` as read-only; do NOT modify "
|
|
91
96
|
+ "any documentation file, including those under `docs/pi.dev/`.",
|
|
92
97
|
"- Treat every path under `pi.dev-src/` as read-only; do NOT modify "
|
|
93
98
|
+ `\`${PI_DEV_SOURCE_PROMPT_PATH}\` or any other pi client source.`,
|
|
99
|
+
`- Every file under \`${PI_DEV_SOURCE_ROOT_PROMPT_PATH}/\` is a pi CLI client `
|
|
100
|
+
+ "source: it MAY and MUST be used as read-only reference material "
|
|
101
|
+
+ "during analysis, implementation, verification, and bug fixing.",
|
|
102
|
+
`- Treat \`${PI_DEV_SOURCE_ROOT_PROMPT_PATH}/\` as the source-of-truth (SoT) `
|
|
103
|
+
+ "for new implementations, source-code modifications, and bug fixes; "
|
|
104
|
+
+ "derive pi-client-facing behavior from it without modifying it "
|
|
105
|
+
+ "in any way.",
|
|
94
106
|
"- If the task creates or modifies software that interfaces with the "
|
|
95
107
|
+ `pi.dev CLI, review \`${PI_DEV_CODING_AGENT_DOCS_PROMPT_PATH}/\` `
|
|
96
108
|
+ "before analysis, implementation, verification, or bug fixing.",
|
|
@@ -110,11 +122,11 @@ const PI_DEV_CONFORMANCE_BLOCK = [
|
|
|
110
122
|
|
|
111
123
|
/**
|
|
112
124
|
* @brief Builds the conditional pi.dev governance block for one rendered prompt.
|
|
113
|
-
* @details Emits the coding-agent-document-driven governance rules only when the selected bundled prompt can analyze or mutate source code and the project root contains the `docs/pi.dev/coding-agent-docs/` directory; the manifest file is optional and its absence does not suppress the block. Time complexity O(1). No filesystem writes.
|
|
125
|
+
* @details Emits the coding-agent-document-driven governance rules only when the selected bundled prompt can analyze or mutate source code and the project root contains the `docs/pi.dev/coding-agent-docs/` directory; the manifest file is optional and its absence does not suppress the block. The emitted rules declare `pi.dev-src/` the permanently read-only pi CLI client reference and source-of-truth for new implementations, source-code modifications, and bug fixes. Time complexity O(1). No filesystem writes.
|
|
114
126
|
* @param[in] promptName {string} Bundled prompt identifier.
|
|
115
127
|
* @param[in] projectBase {string} Absolute project root used for coding-agent-docs directory existence checks.
|
|
116
128
|
* @return {string} Markdown bullet block or the empty string when injection is not applicable.
|
|
117
|
-
* @satisfies REQ-032, REQ-033, REQ-034, REQ-108, REQ-273, REQ-274, REQ-275
|
|
129
|
+
* @satisfies CTN-023, CTN-024, REQ-032, REQ-033, REQ-034, REQ-108, REQ-273, REQ-274, REQ-275, REQ-378
|
|
118
130
|
*/
|
|
119
131
|
function buildPiDevConformanceBlock(promptName: string, projectBase: string): string {
|
|
120
132
|
if (!PI_DEV_AWARE_PROMPT_NAMES.has(promptName)) {
|
|
@@ -134,7 +146,7 @@ function buildPiDevConformanceBlock(promptName: string, projectBase: string): st
|
|
|
134
146
|
* @param[in] promptName {string} Bundled prompt identifier.
|
|
135
147
|
* @param[in] projectBase {string} Absolute project root used for coding-agent-docs directory existence checks.
|
|
136
148
|
* @return {string} Prompt markdown with zero or one injected conformance block.
|
|
137
|
-
* @satisfies REQ-032, REQ-033, REQ-034, REQ-108, REQ-273, REQ-274, REQ-275
|
|
149
|
+
* @satisfies REQ-032, REQ-033, REQ-034, REQ-108, REQ-273, REQ-274, REQ-275, REQ-378
|
|
138
150
|
*/
|
|
139
151
|
function injectPiDevConformanceBlock(text: string, promptName: string, projectBase: string): string {
|
|
140
152
|
const block = buildPiDevConformanceBlock(promptName, projectBase);
|
|
@@ -326,7 +338,7 @@ function renderBundledCommitInstruction(
|
|
|
326
338
|
* @param[in] config {UseReqConfig} Effective project configuration used for path substitutions.
|
|
327
339
|
* @param[in] executionPlan {PromptCommandExecutionPlan | undefined} Optional prompt-command execution plan used for injected runtime guidance.
|
|
328
340
|
* @return {string} Fully rendered prompt markdown ready for `pi.sendUserMessage(...)`.
|
|
329
|
-
* @satisfies REQ-002, REQ-003, REQ-032, REQ-033, REQ-034, REQ-108, REQ-200, REQ-201, REQ-202, REQ-206, REQ-207, REQ-208, REQ-209, REQ-211, REQ-213, REQ-214, REQ-273, REQ-274, REQ-275, REQ-329, REQ-330, REQ-331, REQ-332
|
|
341
|
+
* @satisfies REQ-002, REQ-003, REQ-032, REQ-033, REQ-034, REQ-108, REQ-200, REQ-201, REQ-202, REQ-206, REQ-207, REQ-208, REQ-209, REQ-211, REQ-213, REQ-214, REQ-273, REQ-274, REQ-275, REQ-378, REQ-329, REQ-330, REQ-331, REQ-332
|
|
330
342
|
*/
|
|
331
343
|
export function renderPrompt(
|
|
332
344
|
promptName: string,
|
package/src/index.ts
CHANGED
|
@@ -145,8 +145,11 @@ import { PROMPT_COMMAND_NAMES } from "./core/prompt-command-catalog.js";
|
|
|
145
145
|
import { resolveRuntimeGitPath } from "./core/runtime-project-paths.js";
|
|
146
146
|
import {
|
|
147
147
|
clearPersistedPromptCommandRuntimeState,
|
|
148
|
+
readPersistedPromptCommandRuntimeApi,
|
|
148
149
|
readPersistedPromptCommandRuntimeState,
|
|
150
|
+
writePersistedPromptCommandRuntimeApi,
|
|
149
151
|
writePersistedPromptCommandRuntimeState,
|
|
152
|
+
type PersistedPromptCommandRuntimeApi,
|
|
150
153
|
} from "./core/prompt-command-state.js";
|
|
151
154
|
import { ensureBundledResourcesAccessible, readBundledPromptDescription } from "./core/resources.js";
|
|
152
155
|
import { ReqError } from "./core/errors.js";
|
|
@@ -3148,8 +3151,8 @@ function resolveCurrentThinkingLevel(pi: ExtensionAPI, ctx: unknown): string | u
|
|
|
3148
3151
|
|
|
3149
3152
|
/**
|
|
3150
3153
|
* @brief Builds the loosely-typed model-selection surface from the runtime API plus context.
|
|
3151
|
-
* @details Wraps `setModel` and `setThinkingLevel` with defensive function probes so the surface only exposes appliers the running host actually implements, and copies the context model, thinking level, and model registry used by the guarded re-apply comparison. Returns undefined when no context is available so re-application degrades to a not-attempted skip. Runtime is O(1). No external state is mutated.
|
|
3152
|
-
* @param[in] pi {ExtensionAPI}
|
|
3154
|
+
* @details Wraps `setModel` and `setThinkingLevel` with defensive function probes so the surface only exposes appliers the running host actually implements, and copies the context model, thinking level, and model registry used by the guarded re-apply comparison. The supplied api MUST be the latest live extension api bound to the active session runner because pi invalidates captured extension apis after session replacement. Returns undefined when no context is available so re-application degrades to a not-attempted skip. Runtime is O(1). No external state is mutated.
|
|
3155
|
+
* @param[in] pi {ExtensionAPI} Latest live extension api instance supplying the session-scoped model appliers; after session replacement callers pass the rebound api rather than a captured pre-switch api.
|
|
3153
3156
|
* @param[in] ctx {unknown} Active extension or command context supplying model probes.
|
|
3154
3157
|
* @return {PromptCommandModelSelectionSurface | undefined} Re-apply surface, or undefined when no context exists.
|
|
3155
3158
|
* @satisfies REQ-367, REQ-370, REQ-371
|
|
@@ -3182,10 +3185,10 @@ function resolvePromptCommandModelSurface(
|
|
|
3182
3185
|
|
|
3183
3186
|
/**
|
|
3184
3187
|
* @brief Re-applies one captured model selection onto the active post-switch session.
|
|
3185
|
-
* @details Builds the guarded re-apply surface from the
|
|
3188
|
+
* @details Builds the guarded re-apply surface from the latest process-scoped extension api plus context, preferring the api written by the most recent extension bind because pi invalidates the api captured before session replacement, and falls back to the caller-supplied api for hosts that do not rebind. Forwards the captured selection plus thinking level into `reapplyPromptCommandSessionSelection(...)` and routes every warning through `notifyContextSafely(...)` so stale replacement contexts after session replacement never abort orchestration. Runtime is O(1) plus one awaited model mutation. Side effects include session-scoped model and thinking-level mutation plus stale-safe warning notifications.
|
|
3186
3189
|
* @param[in] selection {PromptCommandModelSelection | undefined} Captured model provider plus identifier.
|
|
3187
3190
|
* @param[in] thinkingLevel {string | undefined} Captured thinking level.
|
|
3188
|
-
* @param[in] pi {ExtensionAPI}
|
|
3191
|
+
* @param[in] pi {ExtensionAPI} Extension api captured by the running handler, used only as fallback when no rebound api is stored.
|
|
3189
3192
|
* @param[in] ctx {unknown} Active extension or command context used for probes and warning delivery.
|
|
3190
3193
|
* @return {Promise<void>} Promise resolved once the guarded re-application completed.
|
|
3191
3194
|
* @satisfies REQ-367, REQ-368, REQ-369, REQ-370, REQ-371, REQ-372
|
|
@@ -3196,10 +3199,12 @@ async function reapplyCapturedPromptModelSelection(
|
|
|
3196
3199
|
pi: ExtensionAPI,
|
|
3197
3200
|
ctx: unknown,
|
|
3198
3201
|
): Promise<void> {
|
|
3202
|
+
const liveApi = readPersistedPromptCommandRuntimeApi();
|
|
3203
|
+
const activeApi = liveApi ?? pi;
|
|
3199
3204
|
await reapplyPromptCommandSessionSelection({
|
|
3200
3205
|
selection,
|
|
3201
3206
|
thinkingLevel,
|
|
3202
|
-
surface: resolvePromptCommandModelSurface(
|
|
3207
|
+
surface: resolvePromptCommandModelSurface(activeApi as ExtensionAPI, ctx),
|
|
3203
3208
|
notifyWarning: (message) => {
|
|
3204
3209
|
notifyContextSafely(ctx as ExtensionContext, message, "error");
|
|
3205
3210
|
},
|
|
@@ -5132,12 +5137,13 @@ function registerConfigCommands(
|
|
|
5132
5137
|
|
|
5133
5138
|
/**
|
|
5134
5139
|
* @brief Registers the complete pi-usereq extension.
|
|
5135
|
-
* @details
|
|
5140
|
+
* @details Persists the live extension api into process-scoped storage on every bind so model re-application after session replacement binds to the api of the currently active session runner instead of an invalidated captured api, then validates installation-owned bundled resources, registers the specialized `req-reset` and `req-references` commands plus bundled prompt-backed commands and agent tools, conditionally registers config-gated debug tool wrapper commands when the current project enables them, registers configuration commands, registers the configurable notification-sound shortcut when the runtime supports shortcuts, and installs shared wrappers for all supported pi lifecycle hooks so status telemetry, context usage, prompt timing, cumulative runtime, prompt-specific Pushover metadata, tool-result debug logging, and prompt-orchestration effects remain synchronized with runtime events. Runtime is O(h) in hook count during registration. Side effects include filesystem reads, command/tool/shortcut registration, UI updates, active-tool changes, process-scoped extension-api persistence, optional debug-log writes, and timer scheduling.
|
|
5136
5141
|
* @param[in] pi {ExtensionAPI} Active extension API instance.
|
|
5137
5142
|
* @return {void} No return value.
|
|
5138
5143
|
* @satisfies DES-002, DES-015, REQ-004, REQ-005, REQ-009, REQ-044, REQ-067, REQ-068, REQ-109, REQ-111, REQ-112, REQ-113, REQ-114, REQ-115, REQ-116, REQ-117, REQ-118, REQ-119, REQ-120, REQ-121, REQ-122, REQ-123, REQ-124, REQ-125, REQ-126, REQ-127, REQ-128, REQ-131, REQ-132, REQ-133, REQ-134, REQ-137, REQ-159, REQ-163, REQ-164, REQ-165, REQ-166, REQ-167, REQ-168, REQ-169, REQ-172, REQ-174, REQ-179, REQ-180, REQ-184, REQ-188, REQ-190, REQ-191, REQ-192, REQ-193, REQ-194, REQ-195, REQ-196, REQ-197, REQ-236, REQ-237, REQ-238, REQ-239, REQ-240, REQ-241, REQ-242, REQ-243, REQ-244, REQ-245, REQ-246, REQ-247, REQ-298, REQ-299, REQ-300, REQ-301, REQ-302, REQ-303, REQ-304, REQ-305, REQ-306, REQ-312, REQ-313, REQ-323, REQ-324, REQ-325, REQ-326, REQ-327
|
|
5139
5144
|
*/
|
|
5140
5145
|
export default function piUsereqExtension(pi: ExtensionAPI): void {
|
|
5146
|
+
writePersistedPromptCommandRuntimeApi(pi as unknown as PersistedPromptCommandRuntimeApi);
|
|
5141
5147
|
const statusController = createPiUsereqStatusController();
|
|
5142
5148
|
ensureBundledResourcesAccessible();
|
|
5143
5149
|
registerReqResetCommand(pi, statusController);
|