pi-gentic 0.1.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 ADDED
@@ -0,0 +1,499 @@
1
+ # pi-gentic
2
+
3
+ `pi-gentic` helps Pi work more like a small team.
4
+
5
+ If you do not know Pi yet, picture a coding chat app. You type a request, and the app can read files, use tools, run commands, and help with software work.
6
+
7
+ A Pi session is one conversation in that app.
8
+
9
+ An agent is a role for a conversation. A role can say, "act like a reviewer", "act like a researcher", or "act like a builder". Each role can have its own instructions and its own tools.
10
+
11
+ `pi-gentic` connects those conversations together. One main session can send a task to another session, let it work in the background, then receive the answer when it is done.
12
+
13
+ ```text
14
+ You
15
+ └─ Main Pi session
16
+ ├─ Research session: finds information
17
+ ├─ Review session: checks for mistakes
18
+ └─ Build session: makes code changes
19
+ ```
20
+
21
+ Without `pi-gentic`, you have to remember where each conversation is and what each one is doing. With `pi-gentic`, Pi can show the work as a tree, keep each session's role clear, and send results back to the right place.
22
+
23
+ ---
24
+
25
+ ## The short version
26
+
27
+ `pi-gentic` adds three everyday actions to Pi.
28
+
29
+ | Feature | What it means | Example |
30
+ | --- | --- | --- |
31
+ | `/agent` | Give a session a role with instructions. | `/agent reviewer` makes the current session act like a reviewer. |
32
+ | `/send` | Send a task to another session. | `/send Check this plan --agent reviewer --bg` asks a reviewer session to check the plan in the background. |
33
+ | `agents` tool | Lets the model do the same thing itself. | The model can delegate a task to a researcher without asking you to type the command. |
34
+
35
+ A simple before and after:
36
+
37
+ | Without pi-gentic | With pi-gentic |
38
+ | --- | --- |
39
+ | You ask one long conversation to research, plan, edit, test, and review. | You keep one main conversation and send focused jobs to child sessions. |
40
+ | You manually track which chat had which idea. | The orchestration tree shows the session family. |
41
+ | Background work is easy to lose track of. | Live cards show what is running and where the answer will return. |
42
+
43
+ ---
44
+
45
+ ## Why it's useful
46
+
47
+ Some software tasks have too many moving pieces for one conversation.
48
+
49
+ For example, "improve this package" might really mean:
50
+
51
+ - read the docs
52
+ - inspect the source code
53
+ - make a change
54
+ - test the change
55
+ - review the result
56
+
57
+ A single session can do that, but it gets crowded. `pi-gentic` lets Pi split the task into smaller jobs. Each session keeps its own memory and focus.
58
+
59
+ That gives you a cleaner workflow:
60
+
61
+ ```text
62
+ Main session: decides what needs to happen
63
+ Researcher: finds facts and docs
64
+ Builder: changes files
65
+ Reviewer: checks for mistakes
66
+ Main session: receives the final answer
67
+ ```
68
+
69
+ The main point: you can see who is doing what.
70
+
71
+ ---
72
+
73
+ ## What is an agent?
74
+
75
+ An agent is a named role with instructions.
76
+
77
+ Example roles:
78
+
79
+ ```text
80
+ researcher = find facts and sources
81
+ reviewer = look for bugs and risks
82
+ builder = change the code
83
+ ```
84
+
85
+ An agent can also have permissions. You can choose which tools, skills, prompt files, and other agents it can use.
86
+
87
+ That matters because different jobs need different rules. A reviewer might only need read access. A builder might need file-editing tools. A researcher might need search tools.
88
+
89
+ ---
90
+
91
+ ## What is a session?
92
+
93
+ A session is one Pi conversation.
94
+
95
+ It has its own history, messages, tool calls, model settings, and working directory. If you send more work to the same session later, it remembers what happened before.
96
+
97
+ `pi-gentic` uses sessions as durable workers. They keep their context even when you switch away from them.
98
+
99
+ ---
100
+
101
+ ## How you delegate tasks
102
+
103
+ You delegate tasks with `/send`.
104
+
105
+ ```text
106
+ /send Check this plan for missing edge cases --agent reviewer --bg
107
+ ```
108
+
109
+ That command says:
110
+
111
+ 1. Create a new session.
112
+ 2. Load the `reviewer` role into it.
113
+ 3. Send it the message: `Check this plan for missing edge cases`.
114
+ 4. Let it work in the background because `--bg` was used.
115
+ 5. Bring the final answer back to the original session.
116
+
117
+ Example result:
118
+
119
+ ```text
120
+ Sent message to [reviewer] agent in session 019ed682.
121
+ The agent will return with a full answer once done.
122
+ ```
123
+
124
+ Later, the caller receives something like:
125
+
126
+ ```text
127
+ Message from [reviewer] agent from session 019ed682:
128
+ The plan misses error handling for empty input and cancellation.
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Main commands in detail
134
+
135
+ ### `/agent`
136
+
137
+ Use `/agent` to load a role into a session.
138
+
139
+ ```text
140
+ /agent reviewer
141
+ ```
142
+
143
+ Now the current session behaves like the `reviewer` agent.
144
+
145
+ More examples:
146
+
147
+ ```text
148
+ /agent
149
+ /agent clear
150
+ /agent reviewer --session 019ed682
151
+ ```
152
+
153
+ | Command | What it does |
154
+ | --- | --- |
155
+ | `/agent` | Shows the active agent. |
156
+ | `/agent reviewer` | Loads `reviewer` into the current session. |
157
+ | `/agent clear` | Removes the active agent. |
158
+ | `/agent reviewer --session <id>` | Loads `reviewer` into another session. |
159
+
160
+ When an agent is loaded, `pi-gentic` recalculates the session's tools, skills, agents, prompt files, model, thinking level, and defaults. The UI shows a card that can be expanded to inspect the resolved prompt.
161
+
162
+ <img src="./docs/assets/load-agent.png" alt="Agent load card" width="900">
163
+
164
+ The same card can be expanded to show the final prompt and resolved configuration that the agent receives.
165
+
166
+ ### `/send`
167
+
168
+ Use `/send` to give work to another session.
169
+
170
+ ```text
171
+ /send Review this implementation --agent reviewer --bg
172
+ ```
173
+
174
+ Useful examples:
175
+
176
+ ```text
177
+ /send Find the relevant docs --agent researcher --bg
178
+ /send Continue the previous investigation --session 019ed682
179
+ /send Implement the parser cleanup --agent builder --worktree parser-cleanup
180
+ ```
181
+
182
+ Common flags:
183
+
184
+ | Flag | What it means |
185
+ | --- | --- |
186
+ | `--agent <name>` | Use this agent in the target session. |
187
+ | `--session <id>` | Send to an existing session. |
188
+ | `--bg` | Run in the background and return later. |
189
+ | `--fg` | Wait for the answer now. |
190
+ | `--cwd <dir>` | Use this folder as the target working directory. |
191
+ | `--worktree [branch]` | Create or use a Git worktree for the target session. |
192
+ | `--no-invoke` | Add the answer as context without starting a new caller turn. |
193
+
194
+ Runtime override flags:
195
+
196
+ | Flag | Example |
197
+ | --- | --- |
198
+ | `--model` | `--model openai-codex/gpt-5.4-mini` |
199
+ | `--thinking` | `--thinking high` |
200
+ | `--tools` | `--tools read,grep,agents` |
201
+ | `--agents` | `--agents researcher,reviewer` |
202
+ | `--skills` | `--skills tdd,playwright-cli` |
203
+ | `--theme` | `--theme dark` |
204
+ | `--system-prompt-files` | `--system-prompt-files +local.md,!legacy.md` |
205
+ | `--max-subagent-depth` | `--max-subagent-depth 2` |
206
+
207
+ A foreground send waits for the target session to answer.
208
+
209
+ <img src="./docs/assets/send-foreground.png" alt="Foreground send card" width="900">
210
+
211
+ A background send returns immediately and keeps the delegated task visible.
212
+
213
+ <img src="./docs/assets/send-background.png" alt="Background send card" width="900">
214
+
215
+ ### `/orchestration-tree`
216
+
217
+ Use this command to see the session family tree.
218
+
219
+ ```text
220
+ /orchestration-tree
221
+ ```
222
+
223
+ The tree shows parent sessions, child sessions, agent names, recent messages, running state, and short session ids.
224
+
225
+ <img src="./docs/assets/orchestration-tree.png" alt="Orchestration tree" width="900">
226
+
227
+ ---
228
+
229
+ ## The model can use it too
230
+
231
+ `pi-gentic` registers a model-callable tool named `agents`.
232
+
233
+ That tool lets the model delegate through JSON. For example:
234
+
235
+ ```json
236
+ {
237
+ "action": "send",
238
+ "agent": "reviewer",
239
+ "message": "Review this implementation for regressions.",
240
+ "async": true
241
+ }
242
+ ```
243
+
244
+ This is the tool version of typing:
245
+
246
+ ```text
247
+ /send Review this implementation for regressions. --agent reviewer --bg
248
+ ```
249
+
250
+ Supported actions:
251
+
252
+ | Action | What it does |
253
+ | --- | --- |
254
+ | `list` | List available agents. |
255
+ | `get` | Show one agent definition. |
256
+ | `load` | Load or clear an agent in a session. |
257
+ | `send` | Delegate a task to a child or existing session. |
258
+ | `status` | Check what a session is doing. |
259
+ | `abort` | Stop a running session. |
260
+ | `discoverSessions` | Show nearby sessions. |
261
+
262
+ If a tool action fails, the error is shown as a readable card.
263
+
264
+ <img src="./docs/assets/error-card.png" alt="Error card" width="900">
265
+
266
+ ---
267
+
268
+ ## Git worktrees
269
+
270
+ A Git worktree is a separate working folder for the same repository.
271
+
272
+ That is useful when a delegated session needs to edit files. It can work in its own folder instead of changing the files you are currently looking at.
273
+
274
+ Example:
275
+
276
+ ```text
277
+ /send Build the migration --agent builder --worktree migration-builder
278
+ ```
279
+
280
+ If no folder is given, `pi-gentic` creates one under:
281
+
282
+ ```text
283
+ .agentfiles/worktrees/<generated-name>
284
+ ```
285
+
286
+ Generated session or worktree names are told to stay 3 words long max.
287
+
288
+ ---
289
+
290
+ ## Codebase architecture
291
+
292
+ The extension is organized around one main entrypoint and a small set of focused modules.
293
+
294
+ ```mermaid
295
+ flowchart TD
296
+ Pi[Pi runtime] --> Extension[src/extension.ts]
297
+
298
+ Extension --> Commands[src/commands.ts]
299
+ Extension --> Orchestrator[src/orchestrator.ts]
300
+ Extension --> UI[src/ui.ts]
301
+
302
+ Orchestrator --> Policy[src/policy.ts]
303
+ Orchestrator --> Prompt[src/prompt.ts]
304
+ Orchestrator --> Sessions[src/sessions.ts]
305
+ Orchestrator --> Runtime[src/runtime.ts]
306
+ Orchestrator --> Runs[src/runs.ts]
307
+ Orchestrator --> Worktrees[src/worktrees.ts]
308
+
309
+ Config[src/config.ts] --> Policy
310
+ Config --> Prompt
311
+
312
+ Commands --> Orchestrator
313
+ Sessions --> UI
314
+ Runs --> UI
315
+ Runtime --> Sessions
316
+
317
+ classDef edge fill:#101820,stroke:#79ffe1,color:#ffffff;
318
+ classDef core fill:#251a3f,stroke:#b991ff,color:#ffffff;
319
+ classDef ui fill:#1c2f4a,stroke:#8cc8ff,color:#ffffff;
320
+ classDef data fill:#23351f,stroke:#a6e875,color:#ffffff;
321
+
322
+ class Pi,Extension edge;
323
+ class Orchestrator core;
324
+ class UI ui;
325
+ class Commands,Policy,Prompt,Sessions,Runtime,Runs,Worktrees,Config data;
326
+ ```
327
+
328
+ In plain English:
329
+
330
+ - `extension.ts` connects `pi-gentic` to Pi.
331
+ - `commands.ts` parses `/agent` and `/send`.
332
+ - `orchestrator.ts` decides what should happen.
333
+ - `policy.ts` resolves agent permissions and defaults.
334
+ - `prompt.ts` builds the prompt additions for active agents.
335
+ - `sessions.ts` finds and organizes related sessions.
336
+ - `runtime.ts` tracks live running sessions.
337
+ - `runs.ts` formats run status and return messages.
338
+ - `ui.ts` renders cards and trees.
339
+ - `worktrees.ts` prepares Git worktrees.
340
+
341
+ ---
342
+
343
+ ## Configuration
344
+
345
+ `pi-gentic` reads configuration from user-level files and project-level files.
346
+
347
+ | Order | Path | Meaning |
348
+ | ---: | --- | --- |
349
+ | 1 | `~/.pi/agent/extensions/pi-gentic/settings.json` | Settings for all your projects. |
350
+ | 2 | `~/.pi/agent/extensions/pi-gentic/agents/*.md` | Agents you can reuse everywhere. |
351
+ | 3 | `<workspace>/.pi/extensions/pi-gentic/settings.json` | Settings for one project. |
352
+ | 4 | `<workspace>/.pi/extensions/pi-gentic/agents/*.md` | Agents for one project. |
353
+
354
+ Project settings override user settings.
355
+
356
+ ---
357
+
358
+ ## Example agent file
359
+
360
+ Create this file:
361
+
362
+ ```text
363
+ .pi/extensions/pi-gentic/agents/reviewer.md
364
+ ```
365
+
366
+ ```markdown
367
+ ---
368
+ name: reviewer
369
+ description: Reviews changes, edge cases, and risks.
370
+ tools:
371
+ - read
372
+ - grep
373
+ - bash
374
+ ---
375
+
376
+ Review the requested change for correctness, maintainability, and missed cases.
377
+ Return concise findings with evidence.
378
+ ```
379
+
380
+ Now you can use:
381
+
382
+ ```text
383
+ /agent reviewer
384
+ ```
385
+
386
+ or:
387
+
388
+ ```text
389
+ /send Check this patch --agent reviewer --bg
390
+ ```
391
+
392
+ ---
393
+
394
+ ## Settings example
395
+
396
+ ```json
397
+ {
398
+ "globalMaxSubagentDepth": 6,
399
+ "agentlessSession": {
400
+ "tools": ["read", "grep", "agents"],
401
+ "agentsTool": {
402
+ "async": true,
403
+ "rx": 2,
404
+ "ry": 2
405
+ }
406
+ },
407
+ "agentDefaults": {
408
+ "tools": ["read", "grep", "agents"],
409
+ "skills": ["*"],
410
+ "agentsTool": {
411
+ "async": false,
412
+ "fork": false,
413
+ "invokeMeLater": {
414
+ "async": true,
415
+ "withSession": true
416
+ }
417
+ }
418
+ }
419
+ }
420
+ ```
421
+
422
+ ---
423
+
424
+ ## Agent fields
425
+
426
+ | Field | Meaning |
427
+ | --- | --- |
428
+ | `name` | The agent id, such as `reviewer`. |
429
+ | `description` | A short explanation shown to people and models. |
430
+ | `instructions` | Extra instructions used while the agent is active. |
431
+ | `disabled` | Turns the agent off. |
432
+ | `agents` | Which agents this agent may see. |
433
+ | `tools` | Which tools this agent may use. |
434
+ | `skills` | Which skills this agent may see. |
435
+ | `model` | The model this agent should use by default. |
436
+ | `thinking` | The thinking level this agent should use by default. |
437
+ | `theme` | The Pi theme used while this agent is active. |
438
+ | `systemPromptFiles` | Prompt files to include or exclude. |
439
+ | `maxSubagentDepth` | How many levels of child sessions this agent may create. |
440
+ | `agentsTool.async` | Whether delegated work should run in the background by default. |
441
+ | `agentsTool.fork` | Whether new child sessions should fork the current context by default. |
442
+ | `agentsTool.cwd` | Default working directory for child sessions. |
443
+ | `agentsTool.rx` | Default horizontal search radius for session discovery. |
444
+ | `agentsTool.ry` | Default vertical search radius for session discovery. |
445
+
446
+ ---
447
+
448
+ ## Resource filters
449
+
450
+ Agents can be limited to certain tools, skills, agents, and prompt files.
451
+
452
+ | Pattern | Meaning |
453
+ | --- | --- |
454
+ | `*` | Allow everything. |
455
+ | `pattern` | Allow matching resources. |
456
+ | `!pattern` | Block matching resources. |
457
+ | `+name` | Always allow one exact resource. |
458
+ | `-name` | Always block one exact resource. |
459
+ | `[]` | Allow nothing. |
460
+
461
+ This keeps agents focused. A reviewer can be read-only. A builder can edit files. A researcher can get research tools.
462
+
463
+ ---
464
+
465
+ ## Install
466
+
467
+ Install with Pi:
468
+
469
+ ```bash
470
+ pi install pi-gentic
471
+ ```
472
+
473
+ Or install from a Git repository:
474
+
475
+ ```bash
476
+ pi install git+https://github.com/CodeByPeete/pi-gentic.git#v0.1.0
477
+ ```
478
+
479
+ ---
480
+
481
+ ## Package layout
482
+
483
+ ```text
484
+ pi-gentic/
485
+ ├─ src/ TypeScript source for the Pi extension
486
+ ├─ test/ Node test suite
487
+ ├─ test-ui/ UI rendering captures
488
+ ├─ test-e2e/ terminal E2E captures
489
+ ├─ docs/assets/ README screenshots
490
+ ├─ dist/ build output created by npm run build
491
+ ├─ package.json npm and Pi package manifest
492
+ └─ tsconfig.json TypeScript configuration
493
+ ```
494
+
495
+ ---
496
+
497
+ ## License
498
+
499
+ MIT
@@ -0,0 +1,93 @@
1
+ /** Splits a slash command like a shell, while preserving quoted message text. */
2
+ export declare function tokenizeCommandLine(input: string): string[];
3
+ export declare function parseAgentCommand(input: any): {
4
+ agent: any;
5
+ sessionId: any;
6
+ };
7
+ /** Converts send command text into the same fields accepted by the agents tool. */
8
+ export declare function parseSendCommand(input: string): AnyRecord;
9
+ export declare function normalizeToolInput(input: any): {
10
+ action: string;
11
+ activities?: AnyRecord[];
12
+ agent?: string;
13
+ agentName?: string;
14
+ agents?: AnyRecord[];
15
+ args?: AnyRecord;
16
+ async?: boolean;
17
+ cardId?: string;
18
+ completedAt?: number;
19
+ configuration?: AnyRecord;
20
+ content?: unknown;
21
+ cwd?: string;
22
+ data?: AnyRecord;
23
+ description?: string;
24
+ details?: AnyRecord;
25
+ error?: string;
26
+ firstMessage?: string;
27
+ expanded?: boolean;
28
+ fork?: boolean;
29
+ id?: string;
30
+ inactiveMs?: number;
31
+ isError?: boolean;
32
+ isPartial?: boolean;
33
+ invokeMeLater?: boolean;
34
+ isLast?: boolean;
35
+ kind?: string;
36
+ label?: string;
37
+ lastActivityAt?: string | number | Date;
38
+ lastMessage?: string;
39
+ livePath?: string;
40
+ message?: string;
41
+ modified?: string | number | Date;
42
+ name?: string;
43
+ onRefresh?: (details?: AnyRecord) => void;
44
+ onSettled?: () => void;
45
+ onUpdate?: (update: AnyRecord) => void;
46
+ overrides?: AnyRecord;
47
+ parentSessionPath?: string;
48
+ path?: string;
49
+ resources?: {
50
+ agents?: string[];
51
+ tools?: string[];
52
+ skills?: string[];
53
+ };
54
+ restored?: boolean;
55
+ root?: string;
56
+ running?: boolean;
57
+ rx?: number;
58
+ ry?: number;
59
+ sessionId?: string;
60
+ sessions?: AnyRecord[];
61
+ settings?: AnyRecord;
62
+ shortId?: string;
63
+ signal?: AbortSignal;
64
+ skillRoots?: string[];
65
+ sourcePath?: string;
66
+ startedAt?: number;
67
+ status?: string;
68
+ text?: string;
69
+ tools?: string[];
70
+ systemPrompt?: string;
71
+ updatedAt?: number;
72
+ value?: string;
73
+ };
74
+ export declare function completeAgents(prefix: any, activeAgentName: any, cwd?: string): {
75
+ value: string;
76
+ label: string;
77
+ description: string;
78
+ }[];
79
+ /** Suggests only the values that make sense at the cursor position. */
80
+ type CompletionOptions = string | {
81
+ cwd?: string;
82
+ sessions?: AnyRecord[];
83
+ currentSessionId?: string;
84
+ agents?: AnyRecord[];
85
+ models?: AnyRecord[];
86
+ tools?: string[];
87
+ skills?: string[];
88
+ themes?: string[];
89
+ systemPromptFiles?: string[];
90
+ };
91
+ export declare function completeSend(prefix: string, options?: CompletionOptions): any;
92
+ export declare function isCompletingSendSession(prefix: string): boolean;
93
+ export {};