pi-arsenal 0.2.0 → 0.2.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.
|
@@ -152,8 +152,10 @@ function splash(theme: Theme, width: number): string[] {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
export default function startupSplash(pi: ExtensionAPI) {
|
|
155
|
-
|
|
155
|
+
const setHeader = (ctx: { mode: string; ui: { setHeader: (factory: Parameters<typeof ctx.ui.setHeader>[0]) => void } }) => {
|
|
156
156
|
if (ctx.mode !== "tui") return;
|
|
157
157
|
ctx.ui.setHeader((_tui, theme) => ({ invalidate() {}, render(width: number): string[] { return splash(theme, width); } }));
|
|
158
|
-
}
|
|
158
|
+
};
|
|
159
|
+
pi.on("session_start", async (_event, ctx) => setHeader(ctx));
|
|
160
|
+
pi.on("session_tree", async (_event, ctx) => setHeader(ctx));
|
|
159
161
|
}
|
package/extensions/task-panel.ts
CHANGED
|
@@ -87,6 +87,17 @@ function approvalFromChoices(event: { toolName: string; content: Array<{ type: s
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// Shared mutable state so the /task command can read it.
|
|
91
|
+
let _steps: PlanStep[] = [];
|
|
92
|
+
let _cancelPlan: (() => void) | undefined;
|
|
93
|
+
|
|
94
|
+
export function getActivePlan(): PlanStep[] { return _steps; }
|
|
95
|
+
export function cancelActivePlan(): boolean {
|
|
96
|
+
if (!_steps.some((s) => s.status !== "completed")) return false;
|
|
97
|
+
if (_cancelPlan) _cancelPlan();
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
90
101
|
export default function taskPanel(pi: ExtensionAPI) {
|
|
91
102
|
let steps: PlanStep[] = [];
|
|
92
103
|
let planChangeAuthorized = false;
|
|
@@ -113,6 +124,7 @@ export default function taskPanel(pi: ExtensionAPI) {
|
|
|
113
124
|
|
|
114
125
|
function restore(ctx: ExtensionContext): void {
|
|
115
126
|
steps = restoreSteps(ctx.sessionManager.getBranch());
|
|
127
|
+
_steps = steps;
|
|
116
128
|
planChangeAuthorized = false;
|
|
117
129
|
planChangeChoiceCallId = undefined;
|
|
118
130
|
render(ctx);
|
|
@@ -146,6 +158,35 @@ export default function taskPanel(pi: ExtensionAPI) {
|
|
|
146
158
|
const next = parseSteps((event.args as { steps?: unknown } | undefined)?.steps);
|
|
147
159
|
if (!next) return;
|
|
148
160
|
steps = next;
|
|
161
|
+
_steps = steps;
|
|
149
162
|
render(ctx);
|
|
150
163
|
});
|
|
164
|
+
|
|
165
|
+
// /task command: show current plan and optionally cancel it.
|
|
166
|
+
_cancelPlan = () => {
|
|
167
|
+
steps = steps.map((s) => s.status === "completed" ? s : { ...s, status: "completed" as const });
|
|
168
|
+
_steps = steps;
|
|
169
|
+
};
|
|
170
|
+
pi.registerCommand("task", {
|
|
171
|
+
description: "Show current plan and cancel if needed",
|
|
172
|
+
handler: async (_args, ctx) => {
|
|
173
|
+
if (ctx.mode !== "tui") return;
|
|
174
|
+
if (!isActivePlan(steps)) { ctx.ui.notify("No active plan.", "info"); return; }
|
|
175
|
+
const statusIcon = (s: PlanStep) => s.status === "completed" ? "✓" : s.status === "in_progress" ? "●" : "○";
|
|
176
|
+
const preview = steps.map((s, i) => `${i + 1}. ${statusIcon(s)} ${s.goal}`).join("\n");
|
|
177
|
+
const choice = await ctx.ui.select(
|
|
178
|
+
`Active plan (${steps.filter((s) => s.status === "completed").length}/${steps.length} done)\n\n${preview}`,
|
|
179
|
+
["Keep current plan", "Cancel this plan"],
|
|
180
|
+
);
|
|
181
|
+
if (choice === "Cancel this plan") {
|
|
182
|
+
const confirmed = await ctx.ui.confirm("Cancel plan?", "Mark all remaining steps completed so the model is free to start a new plan.");
|
|
183
|
+
if (confirmed) {
|
|
184
|
+
steps = steps.map((s) => ({ ...s, status: "completed" as const }));
|
|
185
|
+
_steps = steps;
|
|
186
|
+
render(ctx);
|
|
187
|
+
ctx.ui.notify("Plan cancelled. The model may now start a new plan.", "info");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
});
|
|
151
192
|
}
|
|
@@ -21,6 +21,8 @@ const HIDDEN_NAMES = new Set([".git", "node_modules", ".venv", "__pycache__"]);
|
|
|
21
21
|
const LIST_PAGE_SIZE = 16;
|
|
22
22
|
const DIAGRAM_PAGE_SIZE = 8;
|
|
23
23
|
const NOTES_FILENAME = ".pi/workspace-notes.md";
|
|
24
|
+
const NOTES_CTX_FILE = join(ROOT, ".pi", "agent", "workspace-notes-context.json");
|
|
25
|
+
const APPROVAL_LOG_FILE = join(ROOT, ".pi", "agent", "destructive-operation-guard.jsonl");
|
|
24
26
|
const DIAGRAM_STARTER = "Draw a system architecture diagram for this project.";
|
|
25
27
|
|
|
26
28
|
type Workspace = { name: string; path: string };
|
|
@@ -40,12 +42,13 @@ type ResourceLabels = { displayName?: string; note?: string };
|
|
|
40
42
|
type ResourceMetadata = { skills?: Record<string, ResourceLabels>; mcp?: Record<string, ResourceLabels> };
|
|
41
43
|
type TranslationStudioBridge = { version: 1; open(ctx: ExtensionCommandContext): Promise<void> };
|
|
42
44
|
type EnvItem = { label: string; status: "ok" | "warn" | "info"; detail: string };
|
|
45
|
+
type ApprovalEntry = { timestamp: string; operation: string; tool: string; approval: string; approved: boolean };
|
|
43
46
|
type Result =
|
|
44
47
|
| { type: "close" }
|
|
45
48
|
| { type: "workspace"; workspace: Workspace }
|
|
46
49
|
| { type: "view-diagram"; diagram: Diagram }
|
|
47
50
|
| { type: "diagram-starter" }
|
|
48
|
-
| { type: "sessions" | "translation" | "search-sessions" }
|
|
51
|
+
| { type: "sessions" | "translation" | "search-sessions" | "clean-sessions" | "approval-log" | "toggle-notes-context" }
|
|
49
52
|
| { type: "edit-label"; kind: "skills" | "mcp"; key: string; fallback: string; field: "displayName" | "note" }
|
|
50
53
|
| { type: "use-skill"; canonicalName: string }
|
|
51
54
|
| { type: "organize-skills" }
|
|
@@ -134,6 +137,27 @@ function saveWorkspaceNotes(workspacePath: string, text: string): void {
|
|
|
134
137
|
writeFileSync(file, text, "utf8");
|
|
135
138
|
}
|
|
136
139
|
|
|
140
|
+
function notesContextEnabled(workspacePath: string): boolean {
|
|
141
|
+
try {
|
|
142
|
+
const data = JSON.parse(readFileSync(NOTES_CTX_FILE, "utf8")) as Record<string, boolean>;
|
|
143
|
+
return data[workspacePath] === true;
|
|
144
|
+
} catch { return false; }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function saveNotesContext(workspacePath: string, enabled: boolean): void {
|
|
148
|
+
let data: Record<string, boolean> = {};
|
|
149
|
+
try { data = JSON.parse(readFileSync(NOTES_CTX_FILE, "utf8")) as Record<string, boolean>; } catch { /* First write. */ }
|
|
150
|
+
if (enabled) data[workspacePath] = true; else delete data[workspacePath];
|
|
151
|
+
mkdirSync(dirname(NOTES_CTX_FILE), { recursive: true });
|
|
152
|
+
writeFileSync(NOTES_CTX_FILE, `${JSON.stringify(data, null, 2)}\n`, "utf8");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function readApprovalLog(): ApprovalEntry[] {
|
|
156
|
+
try {
|
|
157
|
+
return readFileSync(APPROVAL_LOG_FILE, "utf8").trim().split("\n").filter(Boolean).map((line) => JSON.parse(line) as ApprovalEntry).reverse();
|
|
158
|
+
} catch { return []; }
|
|
159
|
+
}
|
|
160
|
+
|
|
137
161
|
function buildEnvItems(ctx: ExtensionCommandContext, hasTranslation: boolean, hasChoices: boolean): EnvItem[] {
|
|
138
162
|
const items: EnvItem[] = [];
|
|
139
163
|
// Local extensions
|
|
@@ -360,6 +384,7 @@ class WorkspaceDrawer implements Focusable {
|
|
|
360
384
|
|
|
361
385
|
private homeItems(): Array<{ label: string; view?: View; result?: Result["type"] }> {
|
|
362
386
|
const hasNotes = workspaceNotes(this.workspace.path).trim().length > 0;
|
|
387
|
+
const notesInCtx = notesContextEnabled(this.workspace.path);
|
|
363
388
|
return [
|
|
364
389
|
{ label: "📁 Projects", view: "projects" },
|
|
365
390
|
{ label: "🖥️ Browse computer…", view: "browser" },
|
|
@@ -367,10 +392,13 @@ class WorkspaceDrawer implements Focusable {
|
|
|
367
392
|
{ label: "🗺️ Diagram Gallery", view: "diagrams" },
|
|
368
393
|
{ label: "🕘 Session Library", result: "sessions" },
|
|
369
394
|
{ label: "🔎 Search sessions…", result: "search-sessions" },
|
|
395
|
+
{ label: "🧹 Clean up sessions…", result: "clean-sessions" },
|
|
370
396
|
...(this.hasTranslationStudio ? [{ label: "🌐 Translation Studio", result: "translation" as const }] : []),
|
|
371
397
|
{ label: `📌 Workspace Notes${hasNotes ? " ·" : ""}`, view: "notes" as View },
|
|
398
|
+
{ label: `${notesInCtx ? "📌" : "○"} Include notes in context`, result: "toggle-notes-context" as Result["type"] },
|
|
372
399
|
{ label: "✨ Skill Library", view: "skills" },
|
|
373
400
|
{ label: "🔌 MCP Servers", view: "mcp" },
|
|
401
|
+
{ label: "🛡 Approval Log", result: "approval-log" as Result["type"] },
|
|
374
402
|
{ label: "🔍 Environment Check", view: "env-check" as View },
|
|
375
403
|
];
|
|
376
404
|
}
|
|
@@ -502,7 +530,8 @@ class WorkspaceDrawer implements Focusable {
|
|
|
502
530
|
|
|
503
531
|
if (this.view === "home") {
|
|
504
532
|
const hasNotes = workspaceNotes(this.workspace.path).trim().length > 0;
|
|
505
|
-
|
|
533
|
+
const notesInCtx = notesContextEnabled(this.workspace.path);
|
|
534
|
+
lines.push(row(` ${th.fg("accent", "◈")} ${th.bold(this.workspace.name)}${hasNotes ? ` ${th.fg("warning", "📌")}` : ""}${notesInCtx ? ` ${th.fg("success", "→ctx")}` : ""}`));
|
|
506
535
|
lines.push(row(` ${th.fg("dim", this.workspace.path)}`));
|
|
507
536
|
lines.push(row(""));
|
|
508
537
|
for (const [i, item] of this.homeItems().entries()) lines.push(row(` ${marker(i)} ${th.fg("text", item.label)}`));
|
|
@@ -712,8 +741,10 @@ export default function workspaceDrawer(pi: ExtensionAPI) {
|
|
|
712
741
|
pi.on("session_tree", async (_event, ctx) => restore(ctx));
|
|
713
742
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
714
743
|
const root = active(ctx);
|
|
744
|
+
const notes = notesContextEnabled(root.path) ? workspaceNotes(root.path).trim() : "";
|
|
745
|
+
const notesSection = notes ? `\n\nWorkspace Notes (personal reminders from the user — read-only context, do not modify):\n${notes}` : "";
|
|
715
746
|
return {
|
|
716
|
-
systemPrompt: `${event.systemPrompt}\n\nActive Workspace: ${root.path}\nInterpret relative file paths, project files, and project commands as referring to this workspace by default. Use paths under it for native file tools and run project shell commands from it. An explicit user-provided absolute path overrides this default.\n\nDiagram Gallery contract: Do not create or register diagrams unless the user explicitly asks you to generate a diagram, chart, architecture view, flowchart, or node graph. For such a request, create Mermaid flowchart/graph source under <Active Workspace>/.pi/diagrams/<stable-id>.mmd and create or update <Active Workspace>/.pi/diagrams/gallery.json in this exact shape: {"diagrams":[{"id":"stable-id","title":"Human title","file":"stable-id.mmd","type":"mermaid","createdAt":"ISO-8601 timestamp","summary":"short description"}]}. The TUI Gallery only displays manifest entries and previews .mmd Mermaid sources; never infer or auto-register existing files
|
|
747
|
+
systemPrompt: `${event.systemPrompt}\n\nActive Workspace: ${root.path}\nInterpret relative file paths, project files, and project commands as referring to this workspace by default. Use paths under it for native file tools and run project shell commands from it. An explicit user-provided absolute path overrides this default.\n\nDiagram Gallery contract: Do not create or register diagrams unless the user explicitly asks you to generate a diagram, chart, architecture view, flowchart, or node graph. For such a request, create Mermaid flowchart/graph source under <Active Workspace>/.pi/diagrams/<stable-id>.mmd and create or update <Active Workspace>/.pi/diagrams/gallery.json in this exact shape: {"diagrams":[{"id":"stable-id","title":"Human title","file":"stable-id.mmd","type":"mermaid","createdAt":"ISO-8601 timestamp","summary":"short description"}]}. The TUI Gallery only displays manifest entries and previews .mmd Mermaid sources; never infer or auto-register existing files.${notesSection}\n`,
|
|
717
748
|
};
|
|
718
749
|
});
|
|
719
750
|
const open = async (ctx: ExtensionCommandContext): Promise<void> => {
|
|
@@ -744,6 +775,48 @@ export default function workspaceDrawer(pi: ExtensionAPI) {
|
|
|
744
775
|
ctx.ui.notify(next.trim() ? "Notes saved." : "Notes cleared.", "info");
|
|
745
776
|
}
|
|
746
777
|
}
|
|
778
|
+
else if (result.type === "clean-sessions") {
|
|
779
|
+
const currentPath = ctx.sessionManager.getSessionFile();
|
|
780
|
+
const all = await listSessions();
|
|
781
|
+
const nonCurrent = all.filter((s) => s.path !== currentPath);
|
|
782
|
+
if (!nonCurrent.length) { ctx.ui.notify("No other sessions to clean up.", "info"); return; }
|
|
783
|
+
const strategy = await ctx.ui.select(
|
|
784
|
+
`Clean up sessions (${nonCurrent.length} available, current is protected)`,
|
|
785
|
+
["Keep newest 10, delete the rest", "Keep newest 20, delete the rest", "Delete sessions older than 7 days", "Delete sessions older than 30 days", "Cancel"],
|
|
786
|
+
);
|
|
787
|
+
if (!strategy || strategy === "Cancel") return;
|
|
788
|
+
const now = Date.now();
|
|
789
|
+
const toDelete = strategy.startsWith("Keep newest")
|
|
790
|
+
? nonCurrent.slice(Number(strategy.includes("10") ? 10 : 20))
|
|
791
|
+
: nonCurrent.filter((s) => (now - s.modified.getTime()) > (strategy.includes("7") ? 7 : 30) * 86400000);
|
|
792
|
+
if (!toDelete.length) { ctx.ui.notify("No sessions match the criteria.", "info"); return; }
|
|
793
|
+
const preview = toDelete.slice(0, 5).map((s) => `• ${sessionTitle(s)} (${relativeTime(s.modified)})`).join("\n");
|
|
794
|
+
const more = toDelete.length > 5 ? `\n… and ${toDelete.length - 5} more` : "";
|
|
795
|
+
const confirmed = await ctx.ui.confirm(`Delete ${toDelete.length} session${toDelete.length === 1 ? "" : "s"}?`, `${preview}${more}\n\nThis cannot be undone.`);
|
|
796
|
+
if (!confirmed) return;
|
|
797
|
+
let deleted = 0;
|
|
798
|
+
for (const s of toDelete) { try { const { rmSync } = await import("node:fs"); rmSync(s.path); deleted++; } catch { /* Skip undeletable sessions. */ } }
|
|
799
|
+
ctx.ui.notify(`Deleted ${deleted} session${deleted === 1 ? "" : "s"}.`, "info");
|
|
800
|
+
}
|
|
801
|
+
else if (result.type === "toggle-notes-context") {
|
|
802
|
+
const enabled = notesContextEnabled(current.path);
|
|
803
|
+
const next = !enabled;
|
|
804
|
+
saveNotesContext(current.path, next);
|
|
805
|
+
ctx.ui.notify(next ? "📌 Notes will be included in context from the next message." : "Notes removed from context.", "info");
|
|
806
|
+
}
|
|
807
|
+
else if (result.type === "approval-log") {
|
|
808
|
+
const entries = readApprovalLog();
|
|
809
|
+
if (!entries.length) { ctx.ui.notify("No approval log entries yet.", "info"); return; }
|
|
810
|
+
const today = new Date().toDateString();
|
|
811
|
+
const todayEntries = entries.filter((e) => new Date(e.timestamp).toDateString() === today);
|
|
812
|
+
const rows = (todayEntries.length ? todayEntries : entries.slice(0, 20)).map((e) => {
|
|
813
|
+
const time = new Date(e.timestamp).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
814
|
+
const verdict = e.approved ? (e.approval === "deny" ? "deny" : "allow") : "deny";
|
|
815
|
+
return `${time} ${verdict.padEnd(5)} ${e.operation} (${e.tool})`;
|
|
816
|
+
});
|
|
817
|
+
const header = todayEntries.length ? `Today's approvals (${todayEntries.length})` : `Recent approvals (${rows.length})`;
|
|
818
|
+
await ctx.ui.select(header + "\n\nTime Verdict Operation (tool)\n" + rows.join("\n"), ["Close"]);
|
|
819
|
+
}
|
|
747
820
|
else if (result.type === "organize-skills") { await organizeSkillFolders(ctx); await open(ctx); }
|
|
748
821
|
else if (result.type === "use-skill") {
|
|
749
822
|
ctx.ui.setEditorText(`/skill:${result.canonicalName} `);
|