@astralyn/pi 0.81.1-1 → 0.81.1-2

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.
@@ -1,140 +1,140 @@
1
- # SDK Examples
2
-
3
- Programmatic usage of pi-coding-agent via `createAgentSession()` and `createAgentSessionRuntime()`.
4
-
5
- The runtime example shows how to build a recreate function that closes over process-global fixed inputs and recreates cwd-bound services and sessions as the active session cwd changes.
6
-
7
- ## Examples
8
-
9
- | File | Description |
10
- |------|-------------|
11
- | `01-minimal.ts` | Simplest usage with all defaults |
12
- | `02-custom-model.ts` | Select model and thinking level |
13
- | `03-custom-prompt.ts` | Replace or modify system prompt |
14
- | `04-skills.ts` | Discover, filter, or replace skills |
15
- | `05-tools.ts` | Built-in tool allowlists |
16
- | `06-extensions.ts` | Logging, blocking, result modification |
17
- | `07-context-files.ts` | AGENTS.md context files |
18
- | `08-slash-commands.ts` | File-based slash commands |
19
- | `09-api-keys-and-oauth.ts` | API key resolution, OAuth config |
20
- | `10-settings.ts` | Override compaction, retry, terminal settings |
21
- | `11-sessions.ts` | In-memory, persistent, continue, list sessions |
22
- | `12-full-control.ts` | Replace everything, no discovery |
23
- | `13-session-runtime.ts` | Manage runtime-backed session replacement |
24
-
25
- ## Running
26
-
27
- ```bash
28
- cd packages/coding-agent
29
- npx tsx examples/sdk/01-minimal.ts
30
- ```
31
-
32
- ## Quick Reference
33
-
34
- ```typescript
35
- import { getModel } from "@earendil-works/pi-ai";
36
- import {
37
- createAgentSession,
38
- DefaultResourceLoader,
39
- ModelRuntime,
40
- SessionManager,
41
- SettingsManager,
42
- } from "@astralyn/pi";
43
-
44
- const modelRuntime = await ModelRuntime.create();
45
-
46
- // Minimal
47
- const { session } = await createAgentSession({ modelRuntime });
48
-
49
- // Custom model
50
- const model = getModel("anthropic", "claude-opus-4-5");
51
- const { session } = await createAgentSession({ model, thinkingLevel: "high", modelRuntime });
52
-
53
- // Modify prompt
54
- const loader = new DefaultResourceLoader({
55
- systemPromptOverride: (base) => `${base}\n\nBe concise.`,
56
- });
57
- await loader.reload();
58
- const { session } = await createAgentSession({ resourceLoader: loader, modelRuntime });
59
-
60
- // Read-only
61
- const { session } = await createAgentSession({ tools: ["read", "grep", "find", "ls"], modelRuntime });
62
-
63
- // In-memory
64
- const { session } = await createAgentSession({
65
- sessionManager: SessionManager.inMemory(),
66
- modelRuntime,
67
- });
68
-
69
- // Full control
70
- const customRuntime = await ModelRuntime.create({
71
- authPath: "/my/app/auth.json",
72
- modelsPath: "/my/app/models.json",
73
- });
74
- customRuntime.setRuntimeApiKey("anthropic", process.env.MY_KEY!);
75
-
76
- const resourceLoader = new DefaultResourceLoader({
77
- systemPromptOverride: () => "You are helpful.",
78
- extensionFactories: [myExtension],
79
- skillsOverride: () => ({ skills: [], diagnostics: [] }),
80
- agentsFilesOverride: () => ({ agentsFiles: [] }),
81
- promptsOverride: () => ({ prompts: [], diagnostics: [] }),
82
- });
83
- await resourceLoader.reload();
84
-
85
- const { session } = await createAgentSession({
86
- model,
87
- modelRuntime: customRuntime,
88
- resourceLoader,
89
- tools: ["read", "bash", "my_tool"],
90
- customTools: [myTool],
91
- sessionManager: SessionManager.inMemory(),
92
- settingsManager: SettingsManager.inMemory(),
93
- });
94
-
95
- // Run prompts
96
- session.subscribe((event) => {
97
- if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
98
- process.stdout.write(event.assistantMessageEvent.delta);
99
- }
100
- });
101
- await session.prompt("Hello");
102
- ```
103
-
104
- ## Options
105
-
106
- | Option | Default | Description |
107
- |--------|---------|-------------|
108
- | `modelRuntime` | Runtime using `agentDir/auth.json` and `models.json` | Canonical model and authentication runtime |
109
- | `cwd` | `process.cwd()` | Working directory |
110
- | `agentDir` | `~/.pi/agent` | Config directory |
111
- | `model` | From settings/first available | Model to use |
112
- | `thinkingLevel` | From settings/"off" | off, low, medium, high |
113
- | `tools` | `["read", "bash", "edit", "write"]` built-ins | Allowlist tool names across built-in, extension, and custom tools |
114
- | `customTools` | `[]` | Additional tool definitions |
115
- | `resourceLoader` | DefaultResourceLoader | Resource loader for extensions, skills, prompts, themes, and context files |
116
- | `sessionManager` | `SessionManager.create(cwd)` | Persistence |
117
- | `settingsManager` | `SettingsManager.create(cwd, agentDir)` | Settings overrides |
118
-
119
- ## Events
120
-
121
- ```typescript
122
- session.subscribe((event) => {
123
- switch (event.type) {
124
- case "message_update":
125
- if (event.assistantMessageEvent.type === "text_delta") {
126
- process.stdout.write(event.assistantMessageEvent.delta);
127
- }
128
- break;
129
- case "tool_execution_start":
130
- console.log(`Tool: ${event.toolName}`);
131
- break;
132
- case "tool_execution_end":
133
- console.log(`Result: ${event.result}`);
134
- break;
135
- case "agent_end":
136
- console.log("Done");
137
- break;
138
- }
139
- });
140
- ```
1
+ # SDK Examples
2
+
3
+ Programmatic usage of pi-coding-agent via `createAgentSession()` and `createAgentSessionRuntime()`.
4
+
5
+ The runtime example shows how to build a recreate function that closes over process-global fixed inputs and recreates cwd-bound services and sessions as the active session cwd changes.
6
+
7
+ ## Examples
8
+
9
+ | File | Description |
10
+ |------|-------------|
11
+ | `01-minimal.ts` | Simplest usage with all defaults |
12
+ | `02-custom-model.ts` | Select model and thinking level |
13
+ | `03-custom-prompt.ts` | Replace or modify system prompt |
14
+ | `04-skills.ts` | Discover, filter, or replace skills |
15
+ | `05-tools.ts` | Built-in tool allowlists |
16
+ | `06-extensions.ts` | Logging, blocking, result modification |
17
+ | `07-context-files.ts` | AGENTS.md context files |
18
+ | `08-slash-commands.ts` | File-based slash commands |
19
+ | `09-api-keys-and-oauth.ts` | API key resolution, OAuth config |
20
+ | `10-settings.ts` | Override compaction, retry, terminal settings |
21
+ | `11-sessions.ts` | In-memory, persistent, continue, list sessions |
22
+ | `12-full-control.ts` | Replace everything, no discovery |
23
+ | `13-session-runtime.ts` | Manage runtime-backed session replacement |
24
+
25
+ ## Running
26
+
27
+ ```bash
28
+ cd packages/coding-agent
29
+ npx tsx examples/sdk/01-minimal.ts
30
+ ```
31
+
32
+ ## Quick Reference
33
+
34
+ ```typescript
35
+ import { getModel } from "@earendil-works/pi-ai";
36
+ import {
37
+ createAgentSession,
38
+ DefaultResourceLoader,
39
+ ModelRuntime,
40
+ SessionManager,
41
+ SettingsManager,
42
+ } from "@astralyn/pi";
43
+
44
+ const modelRuntime = await ModelRuntime.create();
45
+
46
+ // Minimal
47
+ const { session } = await createAgentSession({ modelRuntime });
48
+
49
+ // Custom model
50
+ const model = getModel("anthropic", "claude-opus-4-5");
51
+ const { session } = await createAgentSession({ model, thinkingLevel: "high", modelRuntime });
52
+
53
+ // Modify prompt
54
+ const loader = new DefaultResourceLoader({
55
+ systemPromptOverride: (base) => `${base}\n\nBe concise.`,
56
+ });
57
+ await loader.reload();
58
+ const { session } = await createAgentSession({ resourceLoader: loader, modelRuntime });
59
+
60
+ // Read-only
61
+ const { session } = await createAgentSession({ tools: ["read", "grep", "find", "ls"], modelRuntime });
62
+
63
+ // In-memory
64
+ const { session } = await createAgentSession({
65
+ sessionManager: SessionManager.inMemory(),
66
+ modelRuntime,
67
+ });
68
+
69
+ // Full control
70
+ const customRuntime = await ModelRuntime.create({
71
+ authPath: "/my/app/auth.json",
72
+ modelsPath: "/my/app/models.json",
73
+ });
74
+ customRuntime.setRuntimeApiKey("anthropic", process.env.MY_KEY!);
75
+
76
+ const resourceLoader = new DefaultResourceLoader({
77
+ systemPromptOverride: () => "You are helpful.",
78
+ extensionFactories: [myExtension],
79
+ skillsOverride: () => ({ skills: [], diagnostics: [] }),
80
+ agentsFilesOverride: () => ({ agentsFiles: [] }),
81
+ promptsOverride: () => ({ prompts: [], diagnostics: [] }),
82
+ });
83
+ await resourceLoader.reload();
84
+
85
+ const { session } = await createAgentSession({
86
+ model,
87
+ modelRuntime: customRuntime,
88
+ resourceLoader,
89
+ tools: ["read", "bash", "my_tool"],
90
+ customTools: [myTool],
91
+ sessionManager: SessionManager.inMemory(),
92
+ settingsManager: SettingsManager.inMemory(),
93
+ });
94
+
95
+ // Run prompts
96
+ session.subscribe((event) => {
97
+ if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
98
+ process.stdout.write(event.assistantMessageEvent.delta);
99
+ }
100
+ });
101
+ await session.prompt("Hello");
102
+ ```
103
+
104
+ ## Options
105
+
106
+ | Option | Default | Description |
107
+ |--------|---------|-------------|
108
+ | `modelRuntime` | Runtime using `agentDir/auth.json` and `models.json` | Canonical model and authentication runtime |
109
+ | `cwd` | `process.cwd()` | Working directory |
110
+ | `agentDir` | `~/.pi/agent` | Config directory |
111
+ | `model` | From settings/first available | Model to use |
112
+ | `thinkingLevel` | From settings/"off" | off, low, medium, high |
113
+ | `tools` | `["read", "bash", "edit", "write"]` built-ins | Allowlist tool names across built-in, extension, and custom tools |
114
+ | `customTools` | `[]` | Additional tool definitions |
115
+ | `resourceLoader` | DefaultResourceLoader | Resource loader for extensions, skills, prompts, themes, and context files |
116
+ | `sessionManager` | `SessionManager.create(cwd)` | Persistence |
117
+ | `settingsManager` | `SettingsManager.create(cwd, agentDir)` | Settings overrides |
118
+
119
+ ## Events
120
+
121
+ ```typescript
122
+ session.subscribe((event) => {
123
+ switch (event.type) {
124
+ case "message_update":
125
+ if (event.assistantMessageEvent.type === "text_delta") {
126
+ process.stdout.write(event.assistantMessageEvent.delta);
127
+ }
128
+ break;
129
+ case "tool_execution_start":
130
+ console.log(`Tool: ${event.toolName}`);
131
+ break;
132
+ case "tool_execution_end":
133
+ console.log(`Result: ${event.result}`);
134
+ break;
135
+ case "agent_end":
136
+ console.log("Done");
137
+ break;
138
+ }
139
+ });
140
+ ```
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@astralyn/pi",
3
- "version": "0.81.1-1",
3
+ "version": "0.81.1-2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@astralyn/pi",
9
- "version": "0.81.1-1",
9
+ "version": "0.81.1-2",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@earendil-works/pi-agent-core": "^0.81.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astralyn/pi",
3
- "version": "0.81.1-1",
3
+ "version": "0.81.1-2",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -89,6 +89,11 @@
89
89
  ],
90
90
  "author": "Astralyn",
91
91
  "license": "MIT",
92
+ "repository": {
93
+ "type": "git",
94
+ "url": "https://github.com/ming-kang/pi",
95
+ "directory": "packages/coding-agent"
96
+ },
92
97
  "publishConfig": {
93
98
  "access": "public",
94
99
  "tag": "latest"