@iseoane/agent-depot 0.3.0 → 0.4.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/CHANGELOG.md +18 -0
- package/README.md +87 -3
- package/dist/src/app-flow.js +12 -5
- package/dist/src/cli.js +5 -0
- package/dist/src/profile-cli.js +88 -0
- package/dist/src/profile-export.js +135 -0
- package/dist/src/profile-import.js +218 -0
- package/dist/src/profile.js +130 -0
- package/dist/src/project-manifest.js +6 -0
- package/dist/src/tui/app-actions.js +3 -3
- package/dist/src/tui/app.js +10 -4
- package/dist/src/tui/profile-view.js +249 -0
- package/dist/src/tui/sources-recipes.js +216 -0
- package/dist/src/tui/sources-view.js +16 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.4.1] - 2026-10-01
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- CI uses `actions/checkout@v7`, `actions/setup-node@v7` and `pnpm/action-setup@v6`, which run on Node.js 24 instead of the deprecated Node.js 20.
|
|
13
|
+
- The App and Profile modules are assigned to dependency-boundary zones, so `pnpm audit:dead-code` passes again.
|
|
14
|
+
- README: the Usage block lists the `app`, `export` and `import` commands, and Static analysis documents the `tui` and `tooling` zones.
|
|
15
|
+
|
|
16
|
+
## [0.4.0] - 2026-10-01
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- **Profiles**: a portable, versioned `agent-depot-profile/v1` JSON file to carry a user-global setup to another Agent Depot installation (ADR 0008). It holds Git Sources, user-global Skill selections (Source, path, version policy, Hosts, methods) and App recipe contents, plus the producing `agentDepotVersion`. Local-path and built-in Sources, unmanaged and App-owned Skills, approvals and installed state are never exported; credentials in URLs and absolute paths are rejected, and output is canonically ordered.
|
|
21
|
+
- `agent-depot export [--out <file>]` with `--no-sources`, `--no-skills`, `--no-apps` and repeatable `--source`, `--skill`, `--app`; refuses an existing output file and an empty selection.
|
|
22
|
+
- `agent-depot import <file> [--yes]`: an add-only plan (add / same / conflict with per-field differences) that never removes or changes anything present. Without `--yes` nothing is written and every Skill's Hosts, version policy and method argv are shown. Imported App recipes arrive unapproved and Apps are never installed; a recipe conflicts only with a same-name recipe whose platform overlaps.
|
|
23
|
+
- TUI: a fifth tab **5 Import/Export** with checklists for both directions, previews, y/n confirmation and per-item results.
|
|
24
|
+
- TUI: an **App recipes** section in Sources (`Tab` to switch) lists every recipe with its status (approved, needs approval, invalid, not applicable), previews and approves it with Enter, and `n` shows how to add one: install the `agent-depot-apprecipe` skill from the TUI and paste the suggested prompt, or write the recipe by hand in the shown `apps/` directory.
|
|
25
|
+
|
|
8
26
|
## [0.3.0] - 2026-10-01
|
|
9
27
|
|
|
10
28
|
### Added
|
package/README.md
CHANGED
|
@@ -75,6 +75,11 @@ agent-depot uninstall --cli
|
|
|
75
75
|
agent-depot uninstall --skills --yes
|
|
76
76
|
agent-depot uninstall --unmanaged-skill <exact-global-path> --yes
|
|
77
77
|
agent-depot uninstall --data --yes
|
|
78
|
+
agent-depot app list
|
|
79
|
+
agent-depot app approve <name> --yes
|
|
80
|
+
agent-depot app install <name> --yes
|
|
81
|
+
agent-depot export --out profile.json
|
|
82
|
+
agent-depot import profile.json --yes
|
|
78
83
|
agent-depot tui
|
|
79
84
|
agent-depot --version
|
|
80
85
|
```
|
|
@@ -380,7 +385,7 @@ agent-depot tui
|
|
|
380
385
|
The TUI is an [Ink](https://github.com/vadimdemedes/ink) (React for terminals)
|
|
381
386
|
front end over the same operations as the CLI. It needs Node.js >= 24 and an
|
|
382
387
|
interactive terminal; otherwise `tui` fails with an error. Switch views with
|
|
383
|
-
`1`-`
|
|
388
|
+
`1`-`5`, quit with `q` (not while a prompt is open). Every list scrolls when it is
|
|
384
389
|
taller than the terminal. `j`/`k` or the arrow keys move.
|
|
385
390
|
|
|
386
391
|
| View | Purpose |
|
|
@@ -389,6 +394,7 @@ taller than the terminal. `j`/`k` or the arrow keys move.
|
|
|
389
394
|
| 2 Catalog | Skills that can be installed: those not installed yet, as Source, then Skills. |
|
|
390
395
|
| 3 Installations | What is on disk: managed installations (user-global and project) and unmanaged user-global skills. |
|
|
391
396
|
| 4 Updates | Managed skills with a newer version available, for user-global and project scope. |
|
|
397
|
+
| 5 Import/Export | Transfer portable user-global Source choices, Skill selections and App recipes. |
|
|
392
398
|
|
|
393
399
|
Keys per view (prompts also accept `Esc` to cancel and `y`/`n` to confirm):
|
|
394
400
|
|
|
@@ -399,6 +405,8 @@ Keys per view (prompts also accept `Esc` to cancel and `y`/`n` to confirm):
|
|
|
399
405
|
| Installations | `Enter`/arrows expand and collapse, `u` uninstall (all Hosts or chosen Hosts) or remove an unmanaged skill, `h` or `i` add Hosts to an installation, `A` or `Enter` adopt an unmanaged skill, `space` marks a leaf and `a` marks all visible leaves: with marks, `u` and `h` act on all of them with one combined preview and one confirmation (project installations are skipped with a reason) |
|
|
400
406
|
| Updates | `space` mark, `a` mark all, `t`/`p`/`g` show all, project or user-global, `Enter` preview the marks, `r` check again, arrows fold the "cannot assess" line |
|
|
401
407
|
|
|
408
|
+
| Import/Export | `e` export, `i` import; enter a file path, `space` toggle choices, `a` toggle all, `Enter` preview, `y` apply; `j`/`k` scroll previews and results |
|
|
409
|
+
|
|
402
410
|
Safety model:
|
|
403
411
|
|
|
404
412
|
- Nothing is written before a preview and an explicit `y`. Exposing a skill to an
|
|
@@ -456,8 +464,11 @@ node dist/src/cli.js --version
|
|
|
456
464
|
|
|
457
465
|
[Fallow](https://docs.fallow.tools) 3.30.0 runs through `npx --yes fallow@3.30.0`
|
|
458
466
|
(pinned, no dependency installed) and reads `.fallowrc.json`, which defines the
|
|
459
|
-
entry points and the module-layer boundaries (`cli` -> `
|
|
460
|
-
-> `infrastructure`; imports may only point downward
|
|
467
|
+
entry points and the module-layer boundaries (`cli` -> `tui` -> `application`
|
|
468
|
+
-> `core` -> `infrastructure`; imports may only point downward, and `cli` may
|
|
469
|
+
also use the lower layers directly). `scripts/**` forms an isolated `tooling`
|
|
470
|
+
zone. Every source file must belong to a zone; App and Profile modules sit in
|
|
471
|
+
`application`, except `atomic-file.ts` in `infrastructure`.
|
|
461
472
|
|
|
462
473
|
- `pnpm audit:dead-code`: unused files, exports and dependencies, plus
|
|
463
474
|
boundary violations. Must be clean.
|
|
@@ -577,3 +588,76 @@ are previewed before execution; each Host gets an outcome and failures do not st
|
|
|
577
588
|
remaining Hosts. For manual completion, rerun the selected Host with
|
|
578
589
|
`--manual-done --yes`. This checks the App version, not Host wiring. Host actions
|
|
579
590
|
never change installed-App tracking.
|
|
591
|
+
|
|
592
|
+
## Export a user-global Profile
|
|
593
|
+
|
|
594
|
+
Export portable choices to another machine or keep them in git:
|
|
595
|
+
|
|
596
|
+
```sh
|
|
597
|
+
agent-depot export > profile.json
|
|
598
|
+
agent-depot export --out profile.json
|
|
599
|
+
agent-depot export --no-apps --source <source-id> --skill doctor-md-agents
|
|
600
|
+
agent-depot export --no-sources --no-skills --app my-tool --app another-tool
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
Everything portable is selected by default. `--no-sources`, `--no-skills` and
|
|
604
|
+
`--no-apps` exclude blocks; repeatable `--source <id|url>`, `--skill <path|name>`
|
|
605
|
+
and `--app <name>` restrict each block independently. Unknown selections and
|
|
606
|
+
combining a block's inclusion filter with its `--no-*` flag are errors.
|
|
607
|
+
|
|
608
|
+
Stdout contains JSON only; stderr shows the preview and exclusion reasons.
|
|
609
|
+
`--out` requires a new file (existing files and symlinks are not replaced).
|
|
610
|
+
Profiles contain canonical Git URLs with discovery inclusion, recorded Skill
|
|
611
|
+
version policies/Hosts/user methods, and complete App recipes, including recipes
|
|
612
|
+
for other platforms. CLI export always writes `included: true`; discovery choices are transient, while
|
|
613
|
+
the TUI may pass explicit inclusion choices to the shared export core.
|
|
614
|
+
Export neither refreshes Sources nor runs App commands.
|
|
615
|
+
|
|
616
|
+
Local paths and obvious credentials are not portable. Nonportable/invalid items
|
|
617
|
+
are excluded with reasons, as are unmanaged/App-owned and project Skills,
|
|
618
|
+
installation locations/evidence, approval receipts, installed-App state and
|
|
619
|
+
pending updates. Free-text recipe portability checks are conservative; review
|
|
620
|
+
profiles before sharing them—arbitrary secrets cannot be detected automatically.
|
|
621
|
+
|
|
622
|
+
## Import a user-global Profile
|
|
623
|
+
|
|
624
|
+
Preview first, then explicitly confirm the same selection:
|
|
625
|
+
|
|
626
|
+
```sh
|
|
627
|
+
agent-depot import profile.json
|
|
628
|
+
agent-depot import profile.json --yes
|
|
629
|
+
agent-depot import profile.json --no-apps --skill doctor-md-agents --yes
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
Import uses the same independent block/name filters as export. It reports **add**,
|
|
633
|
+
**same** (skipped), and **conflict** (difference shown, skipped). Without `--yes`,
|
|
634
|
+
nothing is written. Existing choices and conflicting files are never replaced.
|
|
635
|
+
A profile produced by a newer Agent Depot version gives a warning, not an error.
|
|
636
|
+
|
|
637
|
+
Confirmed additions run in order: Source registration, user-global Skills through
|
|
638
|
+
normal refreshed install previews and safety checks, then App recipes. Recorded
|
|
639
|
+
Hosts, version policies and user methods are retained. Even without `--yes`,
|
|
640
|
+
each add-Skill preview shows its Source, Hosts, version policy and full argv for
|
|
641
|
+
every user-provided method, marked as running only after confirmation. The normal
|
|
642
|
+
install preview still appears before execution. Each failure is reported independently and remaining items
|
|
643
|
+
continue; any failed item makes the command exit non-zero.
|
|
644
|
+
|
|
645
|
+
Recipes, including those for other platforms, arrive **unapproved** in `apps/`.
|
|
646
|
+
A same-name destination recipe blocks import only when its platform overlaps the
|
|
647
|
+
incoming recipe: equal platforms overlap, and a missing platform overlaps every
|
|
648
|
+
platform. Disjoint platform recipes can both be added. Invalid recipe JSON uses
|
|
649
|
+
its raw name and platform for the same check; unknown-name files are reported
|
|
650
|
+
with read/parse details without blocking unrelated Apps. A profile cannot contain
|
|
651
|
+
same-name recipes whose platform applicability overlaps. Import never installs Apps or runs
|
|
652
|
+
recipe commands. Review and approve applicable
|
|
653
|
+
recipes with `agent-depot app approve <name> --yes` before using their lifecycle
|
|
654
|
+
commands. Source discovery inclusion remains a transient frontend choice, not a
|
|
655
|
+
persisted change to an existing Source. Skills carry their own Source identity,
|
|
656
|
+
so omitting their Source block does not force registration; the preview names
|
|
657
|
+
unregistered Sources that will be fetched without registering. Existing Source
|
|
658
|
+
rows explain when discovery inclusion differs but is not imported.
|
|
659
|
+
|
|
660
|
+
The **5 Import/Export** TUI tab offers grouped checklists and the same shared-core
|
|
661
|
+
previews as the CLI. Exclusions and conflicts cannot be selected. Export creates
|
|
662
|
+
a new file only; empty exports write nothing (CLI reports an error). Import adds missing choices without replacing existing ones.
|
|
663
|
+
Imported recipes remain unapproved and Apps are never installed by import.
|
package/dist/src/app-flow.js
CHANGED
|
@@ -137,7 +137,8 @@ export function createAppOperations(environment = {}) {
|
|
|
137
137
|
await chmod(receipts, 0o700);
|
|
138
138
|
await writeFileAtomically(receiptPath(entry), JSON.stringify({ hash: entry.hash }), { mode: 0o600 });
|
|
139
139
|
}
|
|
140
|
-
|
|
140
|
+
/** Reads recipe identity and approval receipts only; never resolves or runs commands. */
|
|
141
|
+
async function approvalStatus(entry) {
|
|
141
142
|
if (entry.error || !entry.recipe)
|
|
142
143
|
return { status: "invalid", reason: entry.error };
|
|
143
144
|
if (!entry.applicable)
|
|
@@ -154,11 +155,17 @@ export function createAppOperations(environment = {}) {
|
|
|
154
155
|
if (error.code !== "ENOENT")
|
|
155
156
|
throw error;
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
+
return { status: approved ? "approved" : "needs approval" };
|
|
159
|
+
}
|
|
160
|
+
async function approvalProblem(entry) {
|
|
161
|
+
const approval = await approvalStatus(entry);
|
|
162
|
+
if (approval.status === "approved")
|
|
163
|
+
return undefined;
|
|
164
|
+
if (approval.status === "needs approval") {
|
|
158
165
|
const { executable } = await resolve(entry.recipe.version.argv[0]);
|
|
159
|
-
return { status:
|
|
166
|
+
return { status: approval.status, reason: approval.reason, executable };
|
|
160
167
|
}
|
|
161
|
-
return
|
|
168
|
+
return { status: approval.status, reason: approval.reason };
|
|
162
169
|
}
|
|
163
170
|
/** A supplied cache checks recipe approval without running version; omit it for a live check. */
|
|
164
171
|
async function inspect(entry, cached) {
|
|
@@ -440,7 +447,7 @@ export function createAppOperations(environment = {}) {
|
|
|
440
447
|
throw error;
|
|
441
448
|
});
|
|
442
449
|
}
|
|
443
|
-
return { checkUpdate, load, preview, approve, inspect, planLifecycle, executeLifecycle, completeManual, cancelManual, trackedApps, previewForget, forgetApp };
|
|
450
|
+
return { directory, approvalStatus, checkUpdate, load, preview, approve, inspect, planLifecycle, executeLifecycle, completeManual, cancelManual, trackedApps, previewForget, forgetApp };
|
|
444
451
|
}
|
|
445
452
|
/** Concurrent independent checks; one broken App must not hide the rest of a batch. */
|
|
446
453
|
export async function checkAppUpdates(apps) {
|
package/dist/src/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { checkAppUpdates, createAppOperations } from "./app-flow.js";
|
|
7
7
|
import { describeAppResult, describeManualCompletion, runAppCommand } from "./app-cli.js";
|
|
8
|
+
import { EXPORT_USAGE, IMPORT_USAGE, runProfileExport, runProfileImport } from "./profile-cli.js";
|
|
8
9
|
import { pathsOverlap } from "./path-safety.js";
|
|
9
10
|
import { skillTreeBaseline } from "./skill-discovery.js";
|
|
10
11
|
import { BuiltInSourceError, createSourceOperations, resolveProjectSource, SourceMetadataError, SourceNotFoundError, } from "./sources.js";
|
|
@@ -41,6 +42,8 @@ const USAGE = [
|
|
|
41
42
|
" agent-depot app approve <name> [--yes]",
|
|
42
43
|
" agent-depot app install|update|uninstall <name> [--yes] [--manual-done]",
|
|
43
44
|
" agent-depot app uninstall <name> --forget [--yes]",
|
|
45
|
+
` ${EXPORT_USAGE}`,
|
|
46
|
+
` ${IMPORT_USAGE}`,
|
|
44
47
|
" agent-depot tui",
|
|
45
48
|
" agent-depot --version",
|
|
46
49
|
].join("\n");
|
|
@@ -68,6 +71,8 @@ const SOURCE_SUBCOMMANDS = new Map([
|
|
|
68
71
|
["migrate", (values, { operations, dependencies, output }) => runSourceMigration(values, operations, dependencies, output)],
|
|
69
72
|
]);
|
|
70
73
|
const COMMANDS = new Map([
|
|
74
|
+
["import", (values, { operations, dependencies, output }) => runProfileImport(values, operations, dependencies.appOperations ?? createAppOperations({ homeDirectory: dependencies.homeDirectory }), output, dependencies)],
|
|
75
|
+
["export", (values, { operations, dependencies, output }) => runProfileExport(values, operations, dependencies.appOperations ?? createAppOperations({ homeDirectory: dependencies.homeDirectory }), output, dependencies.stderr ?? (line => console.error(line)), dependencies.homeDirectory)],
|
|
71
76
|
["app", (values, { dependencies, output }) => runAppCommand(values, dependencies.appOperations ?? createAppOperations({ homeDirectory: dependencies.homeDirectory }), output)],
|
|
72
77
|
["install", async (values, { operations, dependencies, output }) => {
|
|
73
78
|
await runInstall(values, operations, dependencies, output);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { buildProfileExport, requireProfileExportSelection, writeProfileExport } from "./profile-export.js";
|
|
3
|
+
import { applyProfileImport, buildProfileImport } from "./profile-import.js";
|
|
4
|
+
import { serializeProfile } from "./profile.js";
|
|
5
|
+
import { CliUsageError } from "./usage-error.js";
|
|
6
|
+
export const EXPORT_USAGE = "agent-depot export [--out <file>] [--no-sources] [--no-skills] [--no-apps] [--source <id|url>...] [--skill <path|name>...] [--app <name>...]";
|
|
7
|
+
export const IMPORT_USAGE = "agent-depot import <file> [--yes] [--no-sources] [--no-skills] [--no-apps] [--source <id|url>...] [--skill <path|name>...] [--app <name>...]";
|
|
8
|
+
export async function runProfileExport(values, operations, apps, output, diagnostic, homeDirectory) {
|
|
9
|
+
const { filters, out } = parseProfileOptions(values, false);
|
|
10
|
+
const plan = await buildProfileExport(operations, apps, { ...filters, homeDirectory });
|
|
11
|
+
for (const line of plan.preview)
|
|
12
|
+
diagnostic(line);
|
|
13
|
+
requireProfileExportSelection(plan.profile);
|
|
14
|
+
const content = serializeProfile(plan.profile);
|
|
15
|
+
if (out === undefined)
|
|
16
|
+
output(content.trimEnd());
|
|
17
|
+
else {
|
|
18
|
+
await writeProfileExport(out, plan.profile);
|
|
19
|
+
diagnostic(`Exported profile to ${out}`);
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
function parseProfileOptions(values, importing) {
|
|
24
|
+
const sources = [], skills = [], appNames = [];
|
|
25
|
+
const filters = { sources, skills, apps: appNames };
|
|
26
|
+
let out;
|
|
27
|
+
let confirmed = false;
|
|
28
|
+
for (let index = 0; index < values.length; index++) {
|
|
29
|
+
const option = values[index];
|
|
30
|
+
if (option === "--yes" && importing) {
|
|
31
|
+
if (confirmed)
|
|
32
|
+
throw new CliUsageError("Duplicate --yes");
|
|
33
|
+
confirmed = true;
|
|
34
|
+
}
|
|
35
|
+
else if (option === "--no-sources")
|
|
36
|
+
filters.noSources = true;
|
|
37
|
+
else if (option === "--no-skills")
|
|
38
|
+
filters.noSkills = true;
|
|
39
|
+
else if (option === "--no-apps")
|
|
40
|
+
filters.noApps = true;
|
|
41
|
+
else if (["--out", "--source", "--skill", "--app"].includes(option)) {
|
|
42
|
+
const value = values[++index];
|
|
43
|
+
if (!value || value.startsWith("--"))
|
|
44
|
+
throw new CliUsageError(`${option} requires a value`);
|
|
45
|
+
if (option === "--out") {
|
|
46
|
+
if (importing)
|
|
47
|
+
throw new CliUsageError(`Usage: ${IMPORT_USAGE}`);
|
|
48
|
+
if (out !== undefined)
|
|
49
|
+
throw new CliUsageError("Duplicate --out");
|
|
50
|
+
out = value;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const names = option === "--source" ? sources : option === "--skill" ? skills : appNames;
|
|
54
|
+
if (names.includes(value))
|
|
55
|
+
throw new CliUsageError(`Duplicate ${option} ${JSON.stringify(value)}`);
|
|
56
|
+
names.push(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
throw new CliUsageError(`Usage: ${importing ? IMPORT_USAGE : EXPORT_USAGE}`);
|
|
61
|
+
}
|
|
62
|
+
return { filters, out, confirmed };
|
|
63
|
+
}
|
|
64
|
+
export async function runProfileImport(values, operations, apps, output, environment = {}) {
|
|
65
|
+
const file = values[0];
|
|
66
|
+
if (!file || file.startsWith("--"))
|
|
67
|
+
throw new CliUsageError(`Usage: ${IMPORT_USAGE}`);
|
|
68
|
+
const { filters, confirmed } = parseProfileOptions(values.slice(1), true);
|
|
69
|
+
const content = await readFile(file, "utf8");
|
|
70
|
+
let input;
|
|
71
|
+
try {
|
|
72
|
+
input = JSON.parse(content);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new Error(`${file}: invalid JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
76
|
+
}
|
|
77
|
+
const plan = await buildProfileImport(input, operations, apps, filters);
|
|
78
|
+
for (const line of plan.preview)
|
|
79
|
+
output(line);
|
|
80
|
+
if (!confirmed) {
|
|
81
|
+
output("Import not confirmed; rerun with --yes. Nothing was written.");
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
const results = await applyProfileImport(plan, operations, apps, confirmed, output, environment);
|
|
85
|
+
for (const result of results)
|
|
86
|
+
output(`${result.status}: ${result.item.label}${result.detail ? `; ${result.detail}` : ""}`);
|
|
87
|
+
return results.some(result => result.status === "failed") ? 1 : 0;
|
|
88
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { loadAppOwnedSkillFilter } from "./app-owned-skills.js";
|
|
4
|
+
import { sourceIdForUrl } from "./git-source.js";
|
|
5
|
+
import { AGENT_DEPOT_PACKAGE_VERSION } from "./project-manifest.js";
|
|
6
|
+
import { parseProfile, PROFILE_FORMAT, serializeProfile } from "./profile.js";
|
|
7
|
+
import { scanUserGlobalSkillInventory } from "./user-global-skill-inventory.js";
|
|
8
|
+
export function selectProfileItems(items, requested, disabled, names, block) {
|
|
9
|
+
if (disabled && requested?.length)
|
|
10
|
+
throw new Error(`${block}: filters cannot be combined with --no-${block}`);
|
|
11
|
+
for (const name of requested ?? []) {
|
|
12
|
+
if (!items.some(item => names(item).includes(name)))
|
|
13
|
+
throw new Error(`${block}: unknown selection ${JSON.stringify(name)}`);
|
|
14
|
+
}
|
|
15
|
+
return disabled ? [] : items.filter(item => !requested?.length || names(item).some(name => requested.includes(name)));
|
|
16
|
+
}
|
|
17
|
+
function validateOne(block, item) {
|
|
18
|
+
const profile = parseProfile({ format: PROFILE_FORMAT, agentDepotVersion: AGENT_DEPOT_PACKAGE_VERSION,
|
|
19
|
+
sources: [], skills: [], apps: [], [block]: [item] });
|
|
20
|
+
return profile[block][0];
|
|
21
|
+
}
|
|
22
|
+
/** Read-only export plan shared by terminal frontends; never refreshes Sources or executes recipes. */
|
|
23
|
+
export async function buildProfileExport(operations, apps, options = {}) {
|
|
24
|
+
if (!operations.listUserGlobalInstallations)
|
|
25
|
+
throw new Error("Profile export requires user-global installation listing");
|
|
26
|
+
if (!AGENT_DEPOT_PACKAGE_VERSION)
|
|
27
|
+
throw new Error("Unable to determine the Agent Depot package version");
|
|
28
|
+
const diagnostics = [];
|
|
29
|
+
const exclude = (block, label, reason) => {
|
|
30
|
+
diagnostics.push({ block, label, reason });
|
|
31
|
+
};
|
|
32
|
+
const warn = (message) => diagnostics.push({ kind: "load", message });
|
|
33
|
+
const sources = selectProfileItems(await operations.listSources(), options.sources, options.noSources, source => source.kind === "git" ? [source.id, source.url] : [source.id], "sources");
|
|
34
|
+
const allInstallations = await operations.listUserGlobalInstallations();
|
|
35
|
+
const installations = selectProfileItems(allInstallations, options.skills, options.noSkills, skill => [skill.path, path.posix.basename(skill.path)], "skills");
|
|
36
|
+
const entries = selectProfileItems(await apps.load(), options.apps, options.noApps, entry => [entry.recipe?.name ?? path.basename(entry.file)], "apps");
|
|
37
|
+
const owned = await loadAppOwnedSkillFilter({ appEnvironment: { recipesDirectory: apps.directory },
|
|
38
|
+
reportWarning: warn });
|
|
39
|
+
const portableSources = [];
|
|
40
|
+
for (const source of sources) {
|
|
41
|
+
if (source.kind === "builtin") {
|
|
42
|
+
exclude("sources", "built-in Source", "always present (built-in Skill selections remain portable)");
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
portableSources.push(validateOne("sources", {
|
|
47
|
+
url: source.url, included: options.includedSourceIds?.includes(source.id) ?? true,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
exclude("sources", `Source ${source.id}`, `local-path or invalid Source, not portable (${error instanceof Error ? error.message : String(error)})`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const skills = [];
|
|
55
|
+
for (const skill of installations) {
|
|
56
|
+
if (owned(path.posix.basename(skill.installation?.path ?? skill.path))) {
|
|
57
|
+
exclude("skills", `Skill ${skill.path}`, "App-owned");
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const { source, path: skillPath, version, hosts, methods } = skill;
|
|
61
|
+
const selection = { source, path: skillPath, version, hosts, ...(methods ? { methods } : {}) };
|
|
62
|
+
try {
|
|
63
|
+
skills.push(validateOne("skills", selection));
|
|
64
|
+
if (skill.installation)
|
|
65
|
+
exclude("skills", `installation location and version evidence for Skill ${skill.path}`, "machine-specific");
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
exclude("skills", `Skill ${skill.path}`, `not portable (${error instanceof Error ? error.message : String(error)})`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const recipes = [];
|
|
72
|
+
for (const entry of entries) {
|
|
73
|
+
try {
|
|
74
|
+
if (entry.error)
|
|
75
|
+
throw new Error(entry.error);
|
|
76
|
+
recipes.push(validateOne("apps", entry.recipe));
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
exclude("apps", `App recipe ${path.basename(entry.file)}`, error instanceof Error ? error.message : String(error));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!options.noSkills) {
|
|
83
|
+
const inventory = await scanUserGlobalSkillInventory({
|
|
84
|
+
homeDirectory: options.homeDirectory, managedInstallations: allInstallations,
|
|
85
|
+
appEnvironment: { recipesDirectory: apps.directory }, reportWarning: warn,
|
|
86
|
+
});
|
|
87
|
+
for (const name of new Set([...inventory.unmanaged, ...inventory.symlinks].map(skill => skill.name))) {
|
|
88
|
+
exclude("skills", `unmanaged Skill ${name}`, "not tracked");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const profile = parseProfile({ format: PROFILE_FORMAT, agentDepotVersion: AGENT_DEPOT_PACKAGE_VERSION,
|
|
92
|
+
sources: portableSources, skills, apps: recipes });
|
|
93
|
+
return {
|
|
94
|
+
profile,
|
|
95
|
+
exclusions: diagnostics.filter((item) => "block" in item),
|
|
96
|
+
warnings: [...diagnostics.filter((item) => "kind" in item), ...sourceWarnings(profile)],
|
|
97
|
+
preview: profileExportPreview(profile, diagnostics),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function sourceWarnings(profile) {
|
|
101
|
+
return profile.skills.flatMap(skill => {
|
|
102
|
+
const identity = skill.source;
|
|
103
|
+
if (identity.kind === "external" && "url" in identity && !profile.sources.some(source => source.url === identity.url)) {
|
|
104
|
+
return [{ kind: "source", message: `WARNING: Skill ${skill.path} references Source ${identity.url} not included in profile` }];
|
|
105
|
+
}
|
|
106
|
+
return [];
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** Shared preview for a frontend-selected subset; Source warnings are recomputed. */
|
|
110
|
+
export function profileExportPreview(profile, diagnostics = []) {
|
|
111
|
+
return ["Preview: export portable user-global profile",
|
|
112
|
+
...profile.sources.map(source => `Source ${sourceIdForUrl(source.url)} ${source.url} (included: ${source.included})`),
|
|
113
|
+
...profile.skills.map(skill => `Skill ${skill.path} [${skill.hosts.join(", ")}] (${skill.version.policy})`),
|
|
114
|
+
...profile.apps.map(recipe => `App recipe ${recipe.name} (${recipe.platform ?? "all platforms"}; no approval)`),
|
|
115
|
+
...diagnostics.flatMap(item => "block" in item ? [`Excluded ${item.label}: ${item.reason}`] : item.kind === "load" ? [item.message] : []),
|
|
116
|
+
...sourceWarnings(profile).map(warning => warning.message)];
|
|
117
|
+
}
|
|
118
|
+
/** Empty profiles are valid to parse, but are not useful export artifacts. */
|
|
119
|
+
export function requireProfileExportSelection(profile) {
|
|
120
|
+
if (!profile.sources.length && !profile.skills.length && !profile.apps.length) {
|
|
121
|
+
throw new Error("Nothing selected; nothing written.");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Exclusively create an export artifact; never replace a file or follow a symlink. */
|
|
125
|
+
export async function writeProfileExport(file, profile) {
|
|
126
|
+
requireProfileExportSelection(profile);
|
|
127
|
+
try {
|
|
128
|
+
await writeFile(file, serializeProfile(profile), { encoding: "utf8", flag: "wx" });
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error.code === "EEXIST")
|
|
132
|
+
throw new Error(`${file} already exists; choose another path`);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|