@astrosheep/pi-context 0.6.0 → 0.6.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 +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -21
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ The nine Codex History/Notes actions are flattened because Pi tools have one glo
|
|
|
46
46
|
|
|
47
47
|
`notes_*` stores operation entries in the same append-only Pi session under `pi-context/note`. They are session-scoped, survive JSONL reload, never enter provider context, and use safe relative virtual paths only (no absolute paths, `..`, `.`, empty components, or backslashes). Searches are literal and case-sensitive. `notes_read_file` accepts inclusive 1-based line ranges; negative line numbers count from the last line. Writes are capped at 1,000,000 UTF-8 bytes.
|
|
48
48
|
|
|
49
|
-
Pi has no
|
|
49
|
+
Unlike Codex, the history tools do not advertise `agent_name`: Pi has no cross-agent session routing, so the parameter is omitted from the schemas entirely (strict `additionalProperties: false` still rejects it) instead of costing schema tokens on every request.
|
|
50
50
|
|
|
51
51
|
Two extra controls compose Pi public APIs:
|
|
52
52
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -42,7 +42,6 @@ type HistoryItem = {
|
|
|
42
42
|
type HistoryWindow = { windowId: string; createdAt?: string; items: HistoryItem[] };
|
|
43
43
|
|
|
44
44
|
type HistoryFilter = {
|
|
45
|
-
agent_name?: string | null;
|
|
46
45
|
window_id?: string | null;
|
|
47
46
|
role?: HistoryItem["role"] | null;
|
|
48
47
|
tool_namespace?: string | null;
|
|
@@ -58,12 +57,6 @@ function output(value: unknown, details: unknown = value, terminate = false) {
|
|
|
58
57
|
return { content: [{ type: "text" as const, text: json(value) }], details, terminate };
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
function unsupportedAgent(agentName: string | null | undefined) {
|
|
62
|
-
return agentName !== undefined && agentName !== null
|
|
63
|
-
? { error: "Pi 0.85.1 exposes no cross-agent session routing; agent_name is unsupported and was not aliased to this session." }
|
|
64
|
-
: undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
60
|
function isTextContent(part: unknown): part is TextContent {
|
|
68
61
|
return typeof part === "object" && part !== null && (part as TextContent).type === "text" && typeof (part as TextContent).text === "string";
|
|
69
62
|
}
|
|
@@ -160,9 +153,7 @@ function allItems(ctx: ExtensionContext) {
|
|
|
160
153
|
return historyFromSession(ctx).flatMap((window) => window.items);
|
|
161
154
|
}
|
|
162
155
|
|
|
163
|
-
function filteredItems(ctx: ExtensionContext, params: HistoryFilter): HistoryItem[]
|
|
164
|
-
const agentError = unsupportedAgent(params.agent_name);
|
|
165
|
-
if (agentError) return agentError;
|
|
156
|
+
function filteredItems(ctx: ExtensionContext, params: HistoryFilter): HistoryItem[] {
|
|
166
157
|
let items = allItems(ctx);
|
|
167
158
|
if (typeof params.window_id === "string") items = items.filter((item) => item.windowId === params.window_id);
|
|
168
159
|
if (typeof params.role === "string") items = items.filter((item) => item.role === params.role);
|
|
@@ -319,11 +310,9 @@ export default function piContext(pi: ExtensionAPI) {
|
|
|
319
310
|
pi.registerTool(defineTool({
|
|
320
311
|
name: "history_list_windows",
|
|
321
312
|
label: "History list windows",
|
|
322
|
-
description: "List durable Pi session-history windows.
|
|
323
|
-
parameters: Type.Object({ limit: positiveInteger(),
|
|
313
|
+
description: "List durable Pi session-history windows.",
|
|
314
|
+
parameters: Type.Object({ limit: positiveInteger(), recent_first: Type.Optional(Type.Boolean()) }, { additionalProperties: false }),
|
|
324
315
|
async execute(_id, params, _signal, _update, ctx) {
|
|
325
|
-
const agentError = unsupportedAgent(params.agent_name);
|
|
326
|
-
if (agentError) return output(agentError);
|
|
327
316
|
let windows = historyFromSession(ctx);
|
|
328
317
|
if (params.recent_first) windows = [...windows].reverse();
|
|
329
318
|
const limit = params.limit ?? windows.length;
|
|
@@ -335,10 +324,9 @@ export default function piContext(pi: ExtensionAPI) {
|
|
|
335
324
|
name: "history_list_items",
|
|
336
325
|
label: "History list items",
|
|
337
326
|
description: "List durable session items, including items before compaction, using opaque item and window IDs.",
|
|
338
|
-
parameters: Type.Object({ limit: positiveInteger(), recent_first: Type.Optional(Type.Boolean()), tool_namespace: nullableString(), role: Type.Optional(role),
|
|
327
|
+
parameters: Type.Object({ limit: positiveInteger(), recent_first: Type.Optional(Type.Boolean()), tool_namespace: nullableString(), role: Type.Optional(role), tool_name: nullableString(), window_id: nullableString(), max_chars_per_item: positiveInteger() }, { additionalProperties: false }),
|
|
339
328
|
async execute(_id, params, _signal, _update, ctx) {
|
|
340
329
|
const items = filteredItems(ctx, params);
|
|
341
|
-
if ("error" in items) return output(items);
|
|
342
330
|
return output({ items: items.slice(0, params.limit ?? items.length).map((item) => visibleItem(item, params.max_chars_per_item ?? 1200)) });
|
|
343
331
|
},
|
|
344
332
|
}));
|
|
@@ -347,10 +335,8 @@ export default function piContext(pi: ExtensionAPI) {
|
|
|
347
335
|
name: "history_read_item",
|
|
348
336
|
label: "History read item",
|
|
349
337
|
description: "Read a bounded character range from one durable session item.",
|
|
350
|
-
parameters: Type.Object({
|
|
338
|
+
parameters: Type.Object({ item_id: Type.String(), offset_chars: Type.Optional(Type.Integer({ minimum: 0 })), limit_chars: positiveInteger(), window_id: Type.String() }, { additionalProperties: false }),
|
|
351
339
|
async execute(_id, params, _signal, _update, ctx) {
|
|
352
|
-
const agentError = unsupportedAgent(params.agent_name);
|
|
353
|
-
if (agentError) return output(agentError);
|
|
354
340
|
const item = allItems(ctx).find((candidate) => candidate.windowId === params.window_id && candidate.itemId === params.item_id);
|
|
355
341
|
if (!item) return output({ error: "unknown item_id or window_id" });
|
|
356
342
|
const chars = Array.from(item.content);
|
|
@@ -364,10 +350,9 @@ export default function piContext(pi: ExtensionAPI) {
|
|
|
364
350
|
name: "history_search_contents",
|
|
365
351
|
label: "History search",
|
|
366
352
|
description: "Case-sensitive literal substring search over durable Pi session history; no semantic search.",
|
|
367
|
-
parameters: Type.Object({ limit: positiveInteger(), query: Type.String(), recent_first: Type.Optional(Type.Boolean()), tool_namespace: nullableString(), role: Type.Optional(role),
|
|
353
|
+
parameters: Type.Object({ limit: positiveInteger(), query: Type.String(), recent_first: Type.Optional(Type.Boolean()), tool_namespace: nullableString(), role: Type.Optional(role), tool_name: nullableString(), window_id: nullableString() }, { additionalProperties: false }),
|
|
368
354
|
async execute(_id, params, _signal, _update, ctx) {
|
|
369
355
|
const items = filteredItems(ctx, params);
|
|
370
|
-
if ("error" in items) return output(items);
|
|
371
356
|
const matching = items.filter((item) => item.content.includes(params.query));
|
|
372
357
|
return output({ items: matching.slice(0, params.limit ?? matching.length).map((item) => visibleItem(item)) });
|
|
373
358
|
},
|