@youngjurry/pi-agents 0.9.0 → 0.10.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/CHANGELOG.md +7 -0
- package/README.md +107 -3
- package/control.ts +5 -53
- package/index.ts +3 -13
- package/package.json +1 -1
- package/settings.ts +8 -16
- package/storage.ts +0 -74
- package/types.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0 - 2026-09-10
|
|
4
|
+
|
|
5
|
+
- Remove all automatic compatibility, path translation, and file-moving logic for legacy Agent storage.
|
|
6
|
+
- Standardize storage, settings, custom-entry identifiers, widget keys, and status keys on the `pi-agents` name.
|
|
7
|
+
- Document an explicit, collision-safe one-time command for users who need to migrate pre-0.10.0 sessions manually.
|
|
8
|
+
- Keep fresh installations free of redundant legacy checks and writes.
|
|
9
|
+
|
|
3
10
|
## 0.9.0 - 2026-09-10
|
|
4
11
|
|
|
5
12
|
- Render `/agent-usage` directly in the normal TUI transcript through Pi's TUI-only custom-entry API instead of opening an overlay.
|
package/README.md
CHANGED
|
@@ -189,10 +189,8 @@ The settings file is optional, but spawning requires a model from either the tas
|
|
|
189
189
|
- Child sessions persist under `~/.pi/agent/pi-agents/roots/<root-session-id>/sessions/` and reload lazily
|
|
190
190
|
- Full final answers persist under `~/.pi/agent/pi-agents/roots/<root-session-id>/results/`
|
|
191
191
|
- Each root storage group records its owning main-session file in `owner.json`
|
|
192
|
-
- The
|
|
192
|
+
- The extension reads and writes only `~/.pi/agent/pi-agents/` and `settings.json`; it contains no automatic legacy migration, archival, or deletion logic
|
|
193
193
|
- Resuming an existing main session removes groups whose owning main-session file has been deleted; new sessions and `/reload` do not trigger grouped cleanup
|
|
194
|
-
- Referenced legacy flat child files are migrated when their main session is resumed
|
|
195
|
-
- The extension never automatically archives or deletes legacy flat files
|
|
196
194
|
- Parents receive a compact completion notice instead of the full answer; use `list_agents(view="results")` or read the result file on demand
|
|
197
195
|
- Notices to a busy agent are queued safely: `wait_agent` returns them in its own result, and any leftovers are delivered right after a successful recipient turn
|
|
198
196
|
- `wait_agent` sends only newly queued mailbox notices to the model; its child status tree excludes the active caller, is folded in the TUI by default, and can be toggled with `Ctrl+O`
|
|
@@ -207,3 +205,109 @@ The settings file is optional, but spawning requires a model from either the tas
|
|
|
207
205
|
- All agents share the same cwd and filesystem
|
|
208
206
|
|
|
209
207
|
Use `/agents` to browse the tree and inspect read-only child transcripts. A compact live tree appears below the editor while child agents exist and shows each active agent's `provider/model` identifier and effective thinking level.
|
|
208
|
+
|
|
209
|
+
## Manual migration from versions before 0.10.0
|
|
210
|
+
|
|
211
|
+
Version 0.10.0 removes all runtime compatibility code for the former `codex-agents` names. Existing users who cannot see an old Agent tree, or who still have `~/.pi/agent/codex-agents/` or `agents-setting.json`, should **close every Pi process first** and run the following command once. It renames the storage/settings paths and updates the old custom-entry identifiers and persisted file paths in main and child session JSONL files. It refuses to merge conflicting old and new paths automatically.
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
python3 - <<'PY'
|
|
215
|
+
from pathlib import Path
|
|
216
|
+
import json
|
|
217
|
+
import os
|
|
218
|
+
import stat
|
|
219
|
+
|
|
220
|
+
agent_dir = Path.home() / ".pi" / "agent"
|
|
221
|
+
old_root = agent_dir / "codex-agents"
|
|
222
|
+
new_root = agent_dir / "pi-agents"
|
|
223
|
+
|
|
224
|
+
if old_root.exists():
|
|
225
|
+
if new_root.exists():
|
|
226
|
+
raise SystemExit(
|
|
227
|
+
f"Refusing to merge because both {old_root} and {new_root} exist. "
|
|
228
|
+
"Back them up and reconcile them manually first."
|
|
229
|
+
)
|
|
230
|
+
old_root.rename(new_root)
|
|
231
|
+
|
|
232
|
+
old_settings = new_root / "agents-setting.json"
|
|
233
|
+
new_settings = new_root / "settings.json"
|
|
234
|
+
if old_settings.exists():
|
|
235
|
+
if new_settings.exists():
|
|
236
|
+
raise SystemExit(
|
|
237
|
+
f"Refusing to overwrite {new_settings}; reconcile it with {old_settings} manually."
|
|
238
|
+
)
|
|
239
|
+
old_settings.rename(new_settings)
|
|
240
|
+
|
|
241
|
+
custom_types = {
|
|
242
|
+
"codex-agents": "pi-agents",
|
|
243
|
+
"codex-agents-state": "pi-agents-state",
|
|
244
|
+
"codex-agents-child-meta": "pi-agents-child-meta",
|
|
245
|
+
"codex-agents-fork-context": "pi-agents-fork-context",
|
|
246
|
+
}
|
|
247
|
+
old_prefix = str(old_root)
|
|
248
|
+
new_prefix = str(new_root)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def migrate(value):
|
|
252
|
+
changed = False
|
|
253
|
+
if isinstance(value, dict):
|
|
254
|
+
output = {}
|
|
255
|
+
for key, child in value.items():
|
|
256
|
+
if key == "customType" and isinstance(child, str) and child in custom_types:
|
|
257
|
+
output[key] = custom_types[child]
|
|
258
|
+
changed = True
|
|
259
|
+
elif key in {"sessionFile", "resultFile"} and isinstance(child, str) and (
|
|
260
|
+
child == old_prefix or child.startswith(old_prefix + os.sep)
|
|
261
|
+
):
|
|
262
|
+
output[key] = new_prefix + child[len(old_prefix):]
|
|
263
|
+
changed = True
|
|
264
|
+
else:
|
|
265
|
+
output[key], child_changed = migrate(child)
|
|
266
|
+
changed |= child_changed
|
|
267
|
+
return output, changed
|
|
268
|
+
if isinstance(value, list):
|
|
269
|
+
output = []
|
|
270
|
+
for child in value:
|
|
271
|
+
migrated, child_changed = migrate(child)
|
|
272
|
+
output.append(migrated)
|
|
273
|
+
changed |= child_changed
|
|
274
|
+
return output, changed
|
|
275
|
+
return value, False
|
|
276
|
+
|
|
277
|
+
files = set((agent_dir / "sessions").rglob("*.jsonl"))
|
|
278
|
+
if new_root.exists():
|
|
279
|
+
files.update(new_root.rglob("*.jsonl"))
|
|
280
|
+
|
|
281
|
+
changed_files = 0
|
|
282
|
+
for file in sorted(files):
|
|
283
|
+
temporary = file.with_name(file.name + ".pi-agents-migrate")
|
|
284
|
+
touched = False
|
|
285
|
+
try:
|
|
286
|
+
with file.open("r", encoding="utf-8") as source, temporary.open("w", encoding="utf-8") as target:
|
|
287
|
+
for line in source:
|
|
288
|
+
try:
|
|
289
|
+
value = json.loads(line)
|
|
290
|
+
except json.JSONDecodeError:
|
|
291
|
+
target.write(line)
|
|
292
|
+
continue
|
|
293
|
+
value, line_changed = migrate(value)
|
|
294
|
+
target.write(
|
|
295
|
+
json.dumps(value, ensure_ascii=False, separators=(",", ":")) + "\n"
|
|
296
|
+
if line_changed else line
|
|
297
|
+
)
|
|
298
|
+
touched |= line_changed
|
|
299
|
+
if touched:
|
|
300
|
+
os.chmod(temporary, stat.S_IMODE(file.stat().st_mode))
|
|
301
|
+
os.replace(temporary, file)
|
|
302
|
+
changed_files += 1
|
|
303
|
+
else:
|
|
304
|
+
temporary.unlink()
|
|
305
|
+
except BaseException:
|
|
306
|
+
temporary.unlink(missing_ok=True)
|
|
307
|
+
raise
|
|
308
|
+
|
|
309
|
+
print(f"Migration complete: updated {changed_files} JSONL file(s). Restart Pi or run /reload.")
|
|
310
|
+
PY
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Fresh installations do not need this command.
|
package/control.ts
CHANGED
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
type PersistedTreeState,
|
|
57
57
|
type RootBinding,
|
|
58
58
|
} from "./types.ts";
|
|
59
|
-
import { getAgentStorageDirectory
|
|
59
|
+
import { getAgentStorageDirectory } from "./storage.ts";
|
|
60
60
|
|
|
61
61
|
const DEFAULT_WAIT_TIMEOUT_MS = 30_000;
|
|
62
62
|
const MIN_WAIT_TIMEOUT_MS = 10_000;
|
|
@@ -364,28 +364,6 @@ export class AgentControl {
|
|
|
364
364
|
session.extensionRunner.setUIContext(proxiedUi, root.ctx.mode);
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
private migrateStoredFile(file: string | undefined, directory: string): { path: string | undefined; migrated: boolean } {
|
|
368
|
-
if (!file) return { path: undefined, migrated: false };
|
|
369
|
-
const original = path.resolve(file);
|
|
370
|
-
const source = resolveMigratedStoragePath(original);
|
|
371
|
-
const translated = source !== original;
|
|
372
|
-
const destinationDirectory = path.resolve(directory);
|
|
373
|
-
if (path.dirname(source) === destinationDirectory) return { path: source, migrated: translated };
|
|
374
|
-
const target = path.join(destinationDirectory, path.basename(source));
|
|
375
|
-
try {
|
|
376
|
-
fs.mkdirSync(destinationDirectory, { recursive: true });
|
|
377
|
-
if (fs.existsSync(source)) {
|
|
378
|
-
if (fs.existsSync(target)) throw new Error(`agent storage migration target already exists: ${target}`);
|
|
379
|
-
fs.renameSync(source, target);
|
|
380
|
-
return { path: target, migrated: true };
|
|
381
|
-
}
|
|
382
|
-
if (fs.existsSync(target)) return { path: target, migrated: true };
|
|
383
|
-
} catch {
|
|
384
|
-
// Keep the original path and fail safely during lazy loading if it becomes unavailable.
|
|
385
|
-
}
|
|
386
|
-
return { path: source, migrated: false };
|
|
387
|
-
}
|
|
388
|
-
|
|
389
367
|
private configureRootStorage(ctx: ExtensionContext, sessionId: string): void {
|
|
390
368
|
const safeSessionId = sessionId.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
391
369
|
const rootDirectory = path.join(this.rootStorageDirectory, safeSessionId);
|
|
@@ -1230,7 +1208,7 @@ export class AgentControl {
|
|
|
1230
1208
|
for (const record of this.agentsByPath.values()) {
|
|
1231
1209
|
try {
|
|
1232
1210
|
const liveManager = record.session?.sessionManager;
|
|
1233
|
-
const storedFile = record.sessionFile
|
|
1211
|
+
const storedFile = record.sessionFile;
|
|
1234
1212
|
if (!liveManager && (!storedFile || !fs.existsSync(storedFile))) {
|
|
1235
1213
|
unreadableSubagents++;
|
|
1236
1214
|
continue;
|
|
@@ -1398,20 +1376,14 @@ export class AgentControl {
|
|
|
1398
1376
|
if (entry.type === "custom" && entry.customType === STATE_ENTRY_TYPE && isPersistedState(entry.data)) latest = entry.data;
|
|
1399
1377
|
}
|
|
1400
1378
|
if (!latest || latest.rootSessionId !== ctx.sessionManager.getSessionId()) return;
|
|
1401
|
-
let migratedAnyFile = false;
|
|
1402
1379
|
for (const persisted of latest.agents) {
|
|
1403
1380
|
const status: AgentLifecycleStatus = persisted.status === "queued" || (persisted.status === "pending_init" && Boolean(persisted.queuedMessage))
|
|
1404
1381
|
? "queued"
|
|
1405
1382
|
: persisted.status === "running" || persisted.status === "pending_init"
|
|
1406
1383
|
? "interrupted"
|
|
1407
1384
|
: persisted.status;
|
|
1408
|
-
const migratedSession = this.migrateStoredFile(persisted.sessionFile, this.childSessionDirectory);
|
|
1409
|
-
const migratedResult = this.migrateStoredFile(persisted.resultFile, this.agentResultDirectory);
|
|
1410
|
-
migratedAnyFile ||= migratedSession.migrated || migratedResult.migrated;
|
|
1411
1385
|
const record: AgentRecord = {
|
|
1412
1386
|
...persisted,
|
|
1413
|
-
sessionFile: migratedSession.path,
|
|
1414
|
-
resultFile: migratedResult.path,
|
|
1415
1387
|
status,
|
|
1416
1388
|
statusMessage: status === "queued"
|
|
1417
1389
|
? "waiting for an execution slot"
|
|
@@ -1426,7 +1398,6 @@ export class AgentControl {
|
|
|
1426
1398
|
this.pathBySessionId.set(record.id, record.path);
|
|
1427
1399
|
if (record.nickname) this.usedNicknames.add(record.nickname);
|
|
1428
1400
|
}
|
|
1429
|
-
if (migratedAnyFile) this.persistState();
|
|
1430
1401
|
}
|
|
1431
1402
|
|
|
1432
1403
|
private forkContextFromSessionManager(sessionManager: SessionManager): AgentMessage[] {
|
|
@@ -1449,29 +1420,10 @@ export class AgentControl {
|
|
|
1449
1420
|
if (!record.sessionFile) throw new Error(`agent ${record.path} has no persisted session file`);
|
|
1450
1421
|
if (!this.root) throw new Error("root session is not bound");
|
|
1451
1422
|
await this.evictForResidency(record.path);
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
record.sessionFile = migratedSessionFile;
|
|
1455
|
-
this.persistState();
|
|
1456
|
-
}
|
|
1457
|
-
let sessionManager: SessionManager;
|
|
1458
|
-
if (fs.existsSync(record.sessionFile)) {
|
|
1459
|
-
sessionManager = SessionManager.open(record.sessionFile);
|
|
1460
|
-
} else {
|
|
1461
|
-
// Older queue releases persisted only a future path. Recreate a durable
|
|
1462
|
-
// session with the recorded identity; its lost fork context is unrecoverable.
|
|
1463
|
-
sessionManager = SessionManager.create(this.root.cwd, this.childSessionDirectory, { id: record.id });
|
|
1464
|
-
sessionManager.appendCustomEntry(CHILD_META_ENTRY_TYPE, {
|
|
1465
|
-
path: record.path,
|
|
1466
|
-
parentPath: record.parentPath,
|
|
1467
|
-
rootSessionId: this.root.sessionId,
|
|
1468
|
-
role: record.role,
|
|
1469
|
-
});
|
|
1470
|
-
sessionManager.appendCustomEntry(FORK_CONTEXT_ENTRY_TYPE, { messages: [] });
|
|
1471
|
-
record.sessionFile = this.persistQueuedSession(sessionManager);
|
|
1472
|
-
this.persistState();
|
|
1473
|
-
sessionManager = SessionManager.open(record.sessionFile);
|
|
1423
|
+
if (!fs.existsSync(record.sessionFile)) {
|
|
1424
|
+
throw new Error(`agent ${record.path} session file does not exist: ${record.sessionFile}`);
|
|
1474
1425
|
}
|
|
1426
|
+
const sessionManager = SessionManager.open(record.sessionFile);
|
|
1475
1427
|
const forkContext = this.forkContextFromSessionManager(sessionManager);
|
|
1476
1428
|
const role = resolveRole(this.root.cwd, this.root.ctx.isProjectTrusted(), record.role);
|
|
1477
1429
|
const settingsManager = SettingsManager.create(this.root.cwd, getAgentDir());
|
package/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
|
5
5
|
import { AgentControl } from "./control.ts";
|
|
6
6
|
import { getAgentSettingsPath, loadAgentSettings, resolveAgentLimits } from "./settings.ts";
|
|
7
7
|
import { createCollaborationTools } from "./tools.ts";
|
|
8
|
-
import { migrateLegacyAgentStorage } from "./storage.ts";
|
|
9
8
|
import {
|
|
10
9
|
EXTENSION_ID,
|
|
11
10
|
ROOT_PATH,
|
|
@@ -17,8 +16,8 @@ import {
|
|
|
17
16
|
import { AgentPickerComponent, AgentTranscriptViewer, formatAgentUsage, renderAgentUsage } from "./viewer.ts";
|
|
18
17
|
|
|
19
18
|
const SELF_PATH = fileURLToPath(import.meta.url);
|
|
20
|
-
const WIDGET_KEY = "
|
|
21
|
-
const STATUS_KEY = "
|
|
19
|
+
const WIDGET_KEY = "pi-agents-tree";
|
|
20
|
+
const STATUS_KEY = "pi-agents";
|
|
22
21
|
const PROMPT_MARKER = "<multi_agent_role>";
|
|
23
22
|
|
|
24
23
|
function statusIcon(status: AgentLifecycleStatus): string {
|
|
@@ -92,8 +91,7 @@ class AgentTreeWidget {
|
|
|
92
91
|
invalidate(): void {}
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
export default function
|
|
96
|
-
const storageMigration = migrateLegacyAgentStorage();
|
|
94
|
+
export default function piAgentsExtension(pi: ExtensionAPI): void {
|
|
97
95
|
const limits = resolveAgentLimits(loadAgentSettings(), getAgentSettingsPath());
|
|
98
96
|
const control = new AgentControl(
|
|
99
97
|
pi,
|
|
@@ -107,7 +105,6 @@ export default function codexAgentsExtension(pi: ExtensionAPI): void {
|
|
|
107
105
|
|
|
108
106
|
let activeContext: ExtensionContext | undefined;
|
|
109
107
|
let widgetTui: { requestRender(): void } | undefined;
|
|
110
|
-
let storageMigrationReported = false;
|
|
111
108
|
|
|
112
109
|
const updateUi = () => {
|
|
113
110
|
const ctx = activeContext;
|
|
@@ -134,13 +131,6 @@ export default function codexAgentsExtension(pi: ExtensionAPI): void {
|
|
|
134
131
|
pi.on("session_start", (event, ctx) => {
|
|
135
132
|
activeContext = ctx;
|
|
136
133
|
control.bindRoot(ctx);
|
|
137
|
-
if (!storageMigrationReported) {
|
|
138
|
-
storageMigrationReported = true;
|
|
139
|
-
if (storageMigration.movedEntries > 0) {
|
|
140
|
-
ctx.ui.notify(`Migrated agent storage to ~/.pi/agent/pi-agents (${storageMigration.movedEntries} entries).`, "info");
|
|
141
|
-
}
|
|
142
|
-
for (const warning of storageMigration.warnings) ctx.ui.notify(`Agent storage migration: ${warning}`, "warning");
|
|
143
|
-
}
|
|
144
134
|
const resumedExistingSession = event.reason === "resume"
|
|
145
135
|
|| (event.reason === "startup" && ctx.sessionManager.getEntries().some((entry) => entry.type === "message"));
|
|
146
136
|
if (resumedExistingSession) {
|
package/package.json
CHANGED
package/settings.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
2
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
4
3
|
import {
|
|
5
4
|
clampThinkingLevel,
|
|
6
5
|
getSupportedThinkingLevels,
|
|
7
6
|
type Model,
|
|
8
7
|
} from "@earendil-works/pi-ai";
|
|
9
|
-
import {
|
|
10
|
-
getAgentSettingsPath as getCurrentAgentSettingsPath,
|
|
11
|
-
getLegacyAgentSettingsPaths,
|
|
12
|
-
} from "./storage.ts";
|
|
8
|
+
import { getAgentSettingsPath as getCurrentAgentSettingsPath } from "./storage.ts";
|
|
13
9
|
|
|
14
10
|
export const DEFAULT_MAX_CONCURRENT_SUBAGENTS = 3;
|
|
15
11
|
export const DEFAULT_MAX_RESIDENT_SUBAGENTS = 3;
|
|
@@ -56,34 +52,30 @@ export function selectAgentThinkingLevel(
|
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
export function loadAgentSettings(filePath = getAgentSettingsPath()): AgentSettings {
|
|
59
|
-
|
|
60
|
-
if (!fs.existsSync(resolvedPath) && path.resolve(filePath) === path.resolve(getAgentSettingsPath())) {
|
|
61
|
-
resolvedPath = getLegacyAgentSettingsPaths().find((candidate) => fs.existsSync(candidate)) ?? resolvedPath;
|
|
62
|
-
}
|
|
63
|
-
if (!fs.existsSync(resolvedPath)) return {};
|
|
55
|
+
if (!fs.existsSync(filePath)) return {};
|
|
64
56
|
|
|
65
57
|
let value: unknown;
|
|
66
58
|
try {
|
|
67
|
-
value = JSON.parse(fs.readFileSync(
|
|
59
|
+
value = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
68
60
|
} catch (error) {
|
|
69
61
|
const message = error instanceof Error ? error.message : String(error);
|
|
70
|
-
throw new Error(`failed to read agent settings at ${
|
|
62
|
+
throw new Error(`failed to read agent settings at ${filePath}: ${message}`);
|
|
71
63
|
}
|
|
72
64
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
73
|
-
throw new Error(`agent settings at ${
|
|
65
|
+
throw new Error(`agent settings at ${filePath} must contain a JSON object`);
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
const raw = value as Record<string, unknown>;
|
|
77
69
|
const settings: AgentSettings = {};
|
|
78
70
|
if (raw.defaultModel !== undefined) {
|
|
79
71
|
if (typeof raw.defaultModel !== "string" || !raw.defaultModel.trim()) {
|
|
80
|
-
throw new Error(`defaultModel in ${
|
|
72
|
+
throw new Error(`defaultModel in ${filePath} must be a non-empty provider/model string`);
|
|
81
73
|
}
|
|
82
74
|
settings.defaultModel = raw.defaultModel.trim();
|
|
83
75
|
}
|
|
84
76
|
if (raw.defaultThinkingLevel !== undefined) {
|
|
85
77
|
if (typeof raw.defaultThinkingLevel !== "string" || !CHILD_THINKING_LEVELS.includes(raw.defaultThinkingLevel as ThinkingLevel)) {
|
|
86
|
-
throw new Error(`defaultThinkingLevel in ${
|
|
78
|
+
throw new Error(`defaultThinkingLevel in ${filePath} must be one of: ${CHILD_THINKING_LEVELS.join(", ")}`);
|
|
87
79
|
}
|
|
88
80
|
settings.defaultThinkingLevel = raw.defaultThinkingLevel as ThinkingLevel;
|
|
89
81
|
}
|
|
@@ -91,7 +83,7 @@ export function loadAgentSettings(filePath = getAgentSettingsPath()): AgentSetti
|
|
|
91
83
|
const limit = raw[key];
|
|
92
84
|
if (limit === undefined) continue;
|
|
93
85
|
if (typeof limit !== "number" || !Number.isSafeInteger(limit) || limit < 1) {
|
|
94
|
-
throw new Error(`${key} in ${
|
|
86
|
+
throw new Error(`${key} in ${filePath} must be a positive integer`);
|
|
95
87
|
}
|
|
96
88
|
settings[key] = limit;
|
|
97
89
|
}
|
package/storage.ts
CHANGED
|
@@ -1,87 +1,13 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
1
|
import * as path from "node:path";
|
|
3
2
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
4
3
|
|
|
5
4
|
const STORAGE_DIRECTORY_NAME = "pi-agents";
|
|
6
|
-
const LEGACY_STORAGE_DIRECTORY_NAME = "codex-agents";
|
|
7
5
|
const SETTINGS_FILE_NAME = "settings.json";
|
|
8
|
-
const LEGACY_SETTINGS_FILE_NAME = "agents-setting.json";
|
|
9
|
-
|
|
10
|
-
export interface StorageMigrationReport {
|
|
11
|
-
movedEntries: number;
|
|
12
|
-
warnings: string[];
|
|
13
|
-
}
|
|
14
6
|
|
|
15
7
|
export function getAgentStorageDirectory(): string {
|
|
16
8
|
return path.join(getAgentDir(), STORAGE_DIRECTORY_NAME);
|
|
17
9
|
}
|
|
18
10
|
|
|
19
|
-
export function getLegacyAgentStorageDirectory(): string {
|
|
20
|
-
return path.join(getAgentDir(), LEGACY_STORAGE_DIRECTORY_NAME);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
11
|
export function getAgentSettingsPath(): string {
|
|
24
12
|
return path.join(getAgentStorageDirectory(), SETTINGS_FILE_NAME);
|
|
25
13
|
}
|
|
26
|
-
|
|
27
|
-
export function getLegacyAgentSettingsPaths(): string[] {
|
|
28
|
-
return [
|
|
29
|
-
path.join(getAgentStorageDirectory(), LEGACY_SETTINGS_FILE_NAME),
|
|
30
|
-
path.join(getLegacyAgentStorageDirectory(), LEGACY_SETTINGS_FILE_NAME),
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function mergeWithoutOverwrite(source: string, destination: string, report: StorageMigrationReport): void {
|
|
35
|
-
if (!fs.existsSync(source)) return;
|
|
36
|
-
if (!fs.existsSync(destination)) {
|
|
37
|
-
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
38
|
-
fs.renameSync(source, destination);
|
|
39
|
-
report.movedEntries++;
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const sourceStat = fs.statSync(source);
|
|
43
|
-
const destinationStat = fs.statSync(destination);
|
|
44
|
-
if (!sourceStat.isDirectory() || !destinationStat.isDirectory()) {
|
|
45
|
-
report.warnings.push(`storage migration left a conflicting path untouched: ${source}`);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
for (const entry of fs.readdirSync(source)) {
|
|
49
|
-
mergeWithoutOverwrite(path.join(source, entry), path.join(destination, entry), report);
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
if (fs.readdirSync(source).length === 0) fs.rmdirSync(source);
|
|
53
|
-
} catch {
|
|
54
|
-
// A partial migration remains readable through the legacy path fallback.
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Preserve the 0.7.x upgrade path. For a fresh installation this is only an
|
|
60
|
-
* existence check and performs no writes.
|
|
61
|
-
*/
|
|
62
|
-
export function migrateLegacyAgentStorage(): StorageMigrationReport {
|
|
63
|
-
const report: StorageMigrationReport = { movedEntries: 0, warnings: [] };
|
|
64
|
-
const source = getLegacyAgentStorageDirectory();
|
|
65
|
-
const destination = getAgentStorageDirectory();
|
|
66
|
-
try {
|
|
67
|
-
mergeWithoutOverwrite(source, destination, report);
|
|
68
|
-
const legacySettings = path.join(destination, LEGACY_SETTINGS_FILE_NAME);
|
|
69
|
-
const settings = getAgentSettingsPath();
|
|
70
|
-
if (fs.existsSync(legacySettings)) mergeWithoutOverwrite(legacySettings, settings, report);
|
|
71
|
-
} catch (error) {
|
|
72
|
-
report.warnings.push(error instanceof Error ? error.message : String(error));
|
|
73
|
-
}
|
|
74
|
-
return report;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Translate paths persisted before the storage directory rename. */
|
|
78
|
-
export function resolveMigratedStoragePath(file: string): string {
|
|
79
|
-
const source = path.resolve(file);
|
|
80
|
-
const legacyRoot = path.resolve(getLegacyAgentStorageDirectory());
|
|
81
|
-
if (source !== legacyRoot && !source.startsWith(`${legacyRoot}${path.sep}`)) return source;
|
|
82
|
-
// A collision-safe merge leaves the legacy source in place. Prefer the exact
|
|
83
|
-
// persisted path instead of shadowing it with a different destination file.
|
|
84
|
-
if (fs.existsSync(source)) return source;
|
|
85
|
-
const translated = path.join(getAgentStorageDirectory(), path.relative(legacyRoot, source));
|
|
86
|
-
return fs.existsSync(translated) ? translated : source;
|
|
87
|
-
}
|
package/types.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { AgentMessage, ThinkingLevel } from "@earendil-works/pi-agent-core"
|
|
|
2
2
|
import type { Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { AgentSession, ExtensionContext, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
|
|
5
|
-
export const EXTENSION_ID = "
|
|
6
|
-
export const STATE_ENTRY_TYPE = "
|
|
7
|
-
export const CHILD_META_ENTRY_TYPE = "
|
|
8
|
-
export const FORK_CONTEXT_ENTRY_TYPE = "
|
|
5
|
+
export const EXTENSION_ID = "pi-agents";
|
|
6
|
+
export const STATE_ENTRY_TYPE = "pi-agents-state";
|
|
7
|
+
export const CHILD_META_ENTRY_TYPE = "pi-agents-child-meta";
|
|
8
|
+
export const FORK_CONTEXT_ENTRY_TYPE = "pi-agents-fork-context";
|
|
9
9
|
export const USAGE_ENTRY_TYPE = "pi-agents-usage";
|
|
10
10
|
export const ROOT_PATH = "/root";
|
|
11
11
|
export const DIRECT_AGENT_TOOL_NAMES = [
|