@cleocode/cleo-os 2026.4.64 → 2026.4.66

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/dist/cli.js CHANGED
@@ -13,6 +13,8 @@
13
13
  import { existsSync, readFileSync } from 'node:fs';
14
14
  import { dirname, join } from 'node:path';
15
15
  import { fileURLToPath } from 'node:url';
16
+ import { AgentRegistry } from './registry/agent-registry.js';
17
+ import { ProviderMatrix } from './registry/provider-matrix.js';
16
18
  import { resolveCleoOsPaths } from './xdg.js';
17
19
  const __dirname = dirname(fileURLToPath(import.meta.url));
18
20
  /**
@@ -61,6 +63,55 @@ function handleVersionFlags(args) {
61
63
  }
62
64
  return false;
63
65
  }
66
+ /**
67
+ * Handle CleoOS sovereignty-surface diagnostic flags before delegating to Pi.
68
+ *
69
+ * These flags surface the harness sovereignty modules (ADR-050) without
70
+ * requiring a full Pi startup — useful for scripts, CI probes, and the
71
+ * future `cleo-os doctor` command.
72
+ *
73
+ * - `--providers` / `cleoos providers`: prints the provider matrix (which of
74
+ * the 9 adapters are installed, have spawn implementations, and their
75
+ * hook-event counts).
76
+ * - `--agents` / `cleoos agents`: prints the agent registry (seed agents
77
+ * bundled with CleoOS + user agents discovered in provider paths).
78
+ *
79
+ * @param args - User-supplied CLI arguments.
80
+ * @returns `true` if a diagnostic flag was handled, `false` otherwise.
81
+ */
82
+ async function handleDiagnosticsFlags(args) {
83
+ const wantProviders = args.includes('--providers') || args[0] === 'providers';
84
+ const wantAgents = args.includes('--agents') || args[0] === 'agents';
85
+ if (wantProviders) {
86
+ const matrix = new ProviderMatrix();
87
+ const rows = await matrix.getMatrix();
88
+ console.log('CleoOS Provider Matrix (ADR-050)');
89
+ console.log('═══════════════════════════════════════════════════════════');
90
+ console.log(` ${'provider'.padEnd(18)} ${'installed'.padEnd(10)} ${'spawn'.padEnd(7)} ${'hooks'.padEnd(5)} adapter`);
91
+ console.log(' ─────────────────────────────────────────────────────────');
92
+ for (const r of rows) {
93
+ const installed = r.installed ? 'yes' : 'no';
94
+ const spawn = r.spawnImplemented ? 'yes' : 'stub';
95
+ console.log(` ${r.providerId.padEnd(18)} ${installed.padEnd(10)} ${spawn.padEnd(7)} ${String(r.hookSupport).padEnd(5)} ${r.adapterClass}`);
96
+ }
97
+ return true;
98
+ }
99
+ if (wantAgents) {
100
+ const registry = new AgentRegistry();
101
+ const agents = await registry.listAll();
102
+ console.log('CleoOS Agent Registry (ADR-050)');
103
+ console.log('═══════════════════════════════════════════════════════════');
104
+ if (agents.length === 0) {
105
+ console.log(' (no agents found — run `cleo admin install-global` to seed)');
106
+ return true;
107
+ }
108
+ for (const a of agents) {
109
+ console.log(` [${a.source.padEnd(4)}] ${a.id.padEnd(28)} ${a.provider.padEnd(14)} ${a.name}`);
110
+ }
111
+ return true;
112
+ }
113
+ return false;
114
+ }
64
115
  /**
65
116
  * Collect CleoOS extension paths that exist on disk.
66
117
  *
@@ -128,6 +179,11 @@ async function main() {
128
179
  if (handleVersionFlags(userArgs)) {
129
180
  return;
130
181
  }
182
+ // Intercept sovereignty diagnostic flags (ADR-050) before touching Pi.
183
+ // These surface the CleoOS-specific harness layer without a Pi startup.
184
+ if (await handleDiagnosticsFlags(userArgs)) {
185
+ return;
186
+ }
131
187
  // Dynamically import Pi — it's a peerDependency, may not be installed
132
188
  let piMain;
133
189
  try {
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,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jF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * CleoOS Memory Policy — governs what gets written to `brain.db`.
3
+ *
4
+ * Enforces owner learning L-fe4ba2dc: *"Chat logs are NOT memory. Real memory
5
+ * is extracted artifacts — patterns, decisions, learnings. Raw conversation
6
+ * history should never be stored directly in brain.db."*
7
+ *
8
+ * The default policy allows structured memory types (`observation`, `decision`,
9
+ * `pattern`, `learning`) and rejects raw transcript types (`chatlog`,
10
+ * `transcript`). The policy is configurable via `MemoryPolicyConfig` for
11
+ * extension without adding feature toggles to the skeleton.
12
+ *
13
+ * @see ADR-050 — CleoOS Sovereign Harness: Distribution Binding Charter
14
+ * @see D008 — 7-technique memory architecture (owner decision 2026-04-13)
15
+ * @see L-fe4ba2dc — Chat logs are NOT memory
16
+ * @task T640
17
+ * @epic T636
18
+ * @packageDocumentation
19
+ */
20
+ /**
21
+ * Discriminated union of memory item types recognised by the CleoOS memory gate.
22
+ *
23
+ * @remarks
24
+ * The `chatlog` and `transcript` variants exist to allow callers to explicitly
25
+ * pass raw conversation data through the policy — which will then be rejected
26
+ * with a human-readable reason. This makes the rejection point observable
27
+ * rather than silent.
28
+ */
29
+ export type MemoryItemType = 'observation' | 'decision' | 'pattern' | 'learning' | 'chatlog' | 'transcript';
30
+ /**
31
+ * A candidate item for storage in `brain.db`.
32
+ *
33
+ * The `type` field is the primary discriminant used by `MemoryPolicy.shouldStore()`.
34
+ * The `text` field is the raw content. `metadata` carries any supplementary
35
+ * structured data (source, confidence, timestamps, etc.).
36
+ */
37
+ export interface MemoryItem {
38
+ /** Semantic classification of this memory item. */
39
+ type: MemoryItemType;
40
+ /** Raw text content of the memory item. */
41
+ text: string;
42
+ /**
43
+ * Optional supplementary metadata.
44
+ *
45
+ * Callers may include fields such as `source`, `confidence`, `taskId`, or
46
+ * `timestamp`. The policy does not inspect metadata when making its decision —
47
+ * type and text alone are sufficient for the current skeleton.
48
+ */
49
+ metadata?: Record<string, unknown>;
50
+ }
51
+ /**
52
+ * Configuration object for `MemoryPolicy`.
53
+ *
54
+ * All fields are optional; the default values implement the owner-mandated
55
+ * L-fe4ba2dc rule. Override only when a specific distribution profile needs
56
+ * different behaviour (e.g. a development harness that stores transcripts for
57
+ * debugging — explicitly opt-in, not on by default).
58
+ */
59
+ export interface MemoryPolicyConfig {
60
+ /**
61
+ * Set of `MemoryItemType` values that are ALLOWED through the gate.
62
+ *
63
+ * Defaults to `['observation', 'decision', 'pattern', 'learning']`.
64
+ * Items whose type is NOT in this set are rejected.
65
+ */
66
+ allowedTypes: ReadonlySet<MemoryItemType>;
67
+ /**
68
+ * Minimum character length for `item.text` to be stored.
69
+ *
70
+ * Items with text shorter than this threshold are rejected as likely noise.
71
+ * Defaults to `10`.
72
+ */
73
+ minTextLength: number;
74
+ }
75
+ /**
76
+ * Gate that decides whether a memory item should be written to `brain.db`.
77
+ *
78
+ * @remarks
79
+ * Owner learning L-fe4ba2dc (2026-04-13):
80
+ * *"Chat logs are NOT memory. Real memory is extracted artifacts — patterns,
81
+ * decisions, learnings. Raw conversation history should never be stored
82
+ * directly in brain.db. The extraction pipeline (extraction→consolidation→
83
+ * retrieval) must transform raw transcripts into structured knowledge before
84
+ * storage."*
85
+ *
86
+ * The default configuration enforces this rule. Override via
87
+ * `MemoryPolicyConfig` for specialised distribution profiles.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const policy = new MemoryPolicy();
92
+ *
93
+ * const obs: MemoryItem = { type: 'observation', text: 'File walker now handles symlinks' };
94
+ * policy.shouldStore(obs); // true
95
+ *
96
+ * const log: MemoryItem = { type: 'chatlog', text: 'User: how does this work?' };
97
+ * policy.shouldStore(log); // false
98
+ * policy.reason(log); // "chatlog items are excluded: store extracted artifacts, not raw chat history"
99
+ * ```
100
+ */
101
+ export declare class MemoryPolicy {
102
+ private readonly config;
103
+ /**
104
+ * Construct a `MemoryPolicy` with optional configuration overrides.
105
+ *
106
+ * @param config - Partial overrides merged with {@link DEFAULT_POLICY_CONFIG}.
107
+ * Omitted fields retain their defaults.
108
+ */
109
+ constructor(config?: Partial<MemoryPolicyConfig>);
110
+ /**
111
+ * Return `true` if `item` should be stored in `brain.db`.
112
+ *
113
+ * Applies two checks in order:
114
+ * 1. **Type gate** — item type must be in `config.allowedTypes`.
115
+ * 2. **Length gate** — `item.text.length` must meet `config.minTextLength`.
116
+ *
117
+ * Both checks must pass for `shouldStore` to return `true`.
118
+ *
119
+ * @param item - Candidate memory item to evaluate.
120
+ * @returns Whether the item passes the memory gate.
121
+ */
122
+ shouldStore(item: MemoryItem): boolean;
123
+ /**
124
+ * Return a human-readable explanation of the policy decision for `item`.
125
+ *
126
+ * Always returns a string — callers can surface this in logs or diagnostic
127
+ * output regardless of whether `shouldStore` returned `true` or `false`.
128
+ *
129
+ * @param item - Memory item to explain the policy decision for.
130
+ * @returns Human-readable rationale string.
131
+ */
132
+ reason(item: MemoryItem): string;
133
+ }
134
+ //# sourceMappingURL=memory-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-policy.d.ts","sourceRoot":"","sources":["../../src/policies/memory-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GACtB,aAAa,GACb,UAAU,GACV,SAAS,GACT,UAAU,GACV,SAAS,GACT,YAAY,CAAC;AAEjB;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,IAAI,EAAE,cAAc,CAAC;IACrB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,YAAY,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C;;;;;OAKG;gBACS,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;IAOhD;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO;IAUtC;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;CAejC"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * CleoOS Memory Policy — governs what gets written to `brain.db`.
3
+ *
4
+ * Enforces owner learning L-fe4ba2dc: *"Chat logs are NOT memory. Real memory
5
+ * is extracted artifacts — patterns, decisions, learnings. Raw conversation
6
+ * history should never be stored directly in brain.db."*
7
+ *
8
+ * The default policy allows structured memory types (`observation`, `decision`,
9
+ * `pattern`, `learning`) and rejects raw transcript types (`chatlog`,
10
+ * `transcript`). The policy is configurable via `MemoryPolicyConfig` for
11
+ * extension without adding feature toggles to the skeleton.
12
+ *
13
+ * @see ADR-050 — CleoOS Sovereign Harness: Distribution Binding Charter
14
+ * @see D008 — 7-technique memory architecture (owner decision 2026-04-13)
15
+ * @see L-fe4ba2dc — Chat logs are NOT memory
16
+ * @task T640
17
+ * @epic T636
18
+ * @packageDocumentation
19
+ */
20
+ // ---------------------------------------------------------------------------
21
+ // Default configuration
22
+ // ---------------------------------------------------------------------------
23
+ /**
24
+ * Default memory policy configuration.
25
+ *
26
+ * @remarks
27
+ * Implements owner learning L-fe4ba2dc: chat logs and transcripts are
28
+ * categorically excluded from `brain.db`. Only extracted, typed memory
29
+ * artifacts pass through.
30
+ */
31
+ const DEFAULT_POLICY_CONFIG = {
32
+ allowedTypes: new Set(['observation', 'decision', 'pattern', 'learning']),
33
+ minTextLength: 10,
34
+ };
35
+ // ---------------------------------------------------------------------------
36
+ // MemoryPolicy
37
+ // ---------------------------------------------------------------------------
38
+ /**
39
+ * Gate that decides whether a memory item should be written to `brain.db`.
40
+ *
41
+ * @remarks
42
+ * Owner learning L-fe4ba2dc (2026-04-13):
43
+ * *"Chat logs are NOT memory. Real memory is extracted artifacts — patterns,
44
+ * decisions, learnings. Raw conversation history should never be stored
45
+ * directly in brain.db. The extraction pipeline (extraction→consolidation→
46
+ * retrieval) must transform raw transcripts into structured knowledge before
47
+ * storage."*
48
+ *
49
+ * The default configuration enforces this rule. Override via
50
+ * `MemoryPolicyConfig` for specialised distribution profiles.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const policy = new MemoryPolicy();
55
+ *
56
+ * const obs: MemoryItem = { type: 'observation', text: 'File walker now handles symlinks' };
57
+ * policy.shouldStore(obs); // true
58
+ *
59
+ * const log: MemoryItem = { type: 'chatlog', text: 'User: how does this work?' };
60
+ * policy.shouldStore(log); // false
61
+ * policy.reason(log); // "chatlog items are excluded: store extracted artifacts, not raw chat history"
62
+ * ```
63
+ */
64
+ export class MemoryPolicy {
65
+ config;
66
+ /**
67
+ * Construct a `MemoryPolicy` with optional configuration overrides.
68
+ *
69
+ * @param config - Partial overrides merged with {@link DEFAULT_POLICY_CONFIG}.
70
+ * Omitted fields retain their defaults.
71
+ */
72
+ constructor(config) {
73
+ this.config = {
74
+ allowedTypes: config?.allowedTypes ?? DEFAULT_POLICY_CONFIG.allowedTypes,
75
+ minTextLength: config?.minTextLength ?? DEFAULT_POLICY_CONFIG.minTextLength,
76
+ };
77
+ }
78
+ /**
79
+ * Return `true` if `item` should be stored in `brain.db`.
80
+ *
81
+ * Applies two checks in order:
82
+ * 1. **Type gate** — item type must be in `config.allowedTypes`.
83
+ * 2. **Length gate** — `item.text.length` must meet `config.minTextLength`.
84
+ *
85
+ * Both checks must pass for `shouldStore` to return `true`.
86
+ *
87
+ * @param item - Candidate memory item to evaluate.
88
+ * @returns Whether the item passes the memory gate.
89
+ */
90
+ shouldStore(item) {
91
+ if (!this.config.allowedTypes.has(item.type)) {
92
+ return false;
93
+ }
94
+ if (item.text.length < this.config.minTextLength) {
95
+ return false;
96
+ }
97
+ return true;
98
+ }
99
+ /**
100
+ * Return a human-readable explanation of the policy decision for `item`.
101
+ *
102
+ * Always returns a string — callers can surface this in logs or diagnostic
103
+ * output regardless of whether `shouldStore` returned `true` or `false`.
104
+ *
105
+ * @param item - Memory item to explain the policy decision for.
106
+ * @returns Human-readable rationale string.
107
+ */
108
+ reason(item) {
109
+ if (!this.config.allowedTypes.has(item.type)) {
110
+ return (`${item.type} items are excluded: store extracted artifacts, not raw ` +
111
+ `${item.type === 'chatlog' || item.type === 'transcript' ? 'chat history' : 'unstructured content'}`);
112
+ }
113
+ if (item.text.length < this.config.minTextLength) {
114
+ return (`text too short (${item.text.length} chars < minimum ${this.config.minTextLength}): ` +
115
+ `likely noise or empty observation`);
116
+ }
117
+ return `${item.type} item accepted (${item.text.length} chars)`;
118
+ }
119
+ }
120
+ //# sourceMappingURL=memory-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-policy.js","sourceRoot":"","sources":["../../src/policies/memory-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAsEH,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,qBAAqB,GAAuB;IAChD,YAAY,EAAE,IAAI,GAAG,CAAiB,CAAC,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IACzF,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,YAAY;IACN,MAAM,CAAqB;IAE5C;;;;;OAKG;IACH,YAAY,MAAoC;QAC9C,IAAI,CAAC,MAAM,GAAG;YACZ,YAAY,EAAE,MAAM,EAAE,YAAY,IAAI,qBAAqB,CAAC,YAAY;YACxE,aAAa,EAAE,MAAM,EAAE,aAAa,IAAI,qBAAqB,CAAC,aAAa;SAC5E,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,IAAgB;QAC1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YACjD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAgB;QACrB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,OAAO,CACL,GAAG,IAAI,CAAC,IAAI,0DAA0D;gBACtE,GAAG,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,sBAAsB,EAAE,CACrG,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YACjD,OAAO,CACL,mBAAmB,IAAI,CAAC,IAAI,CAAC,MAAM,oBAAoB,IAAI,CAAC,MAAM,CAAC,aAAa,KAAK;gBACrF,mCAAmC,CACpC,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,IAAI,CAAC,IAAI,mBAAmB,IAAI,CAAC,IAAI,CAAC,MAAM,SAAS,CAAC;IAClE,CAAC;CACF"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * CleoOS Agent Registry — catalog of installed agents across all provider adapters.
3
+ *
4
+ * Discovers agents from two sources:
5
+ * 1. **Seed agents** — bundled with CleoOS in `packages/cleo-os/seed-agents/`.
6
+ * 2. **User agents** — installed by individual provider adapters into their
7
+ * provider-specific agent directories (e.g. `~/.claude/agents/`).
8
+ *
9
+ * This module is read-only. It does not install, remove, or modify agents.
10
+ * Provider adapter logic stays in `packages/adapters/`. CleoOS consumes the
11
+ * filesystem artifacts that adapters produce.
12
+ *
13
+ * @remarks
14
+ * Long-term: `loadUserAgents()` should call `adapter.paths?.getAgentInstallDir()`
15
+ * dynamically once T639 exposes the provider-folder contract. For now the 9 paths
16
+ * are hard-coded from each provider's `AdapterPathProvider` defaults.
17
+ *
18
+ * @see ADR-050 — CleoOS Sovereign Harness: Distribution Binding Charter
19
+ * @task T640
20
+ * @epic T636
21
+ * @packageDocumentation
22
+ */
23
+ /**
24
+ * A single agent known to the CleoOS agent catalog.
25
+ *
26
+ * Agents are discovered at runtime from seed directories and provider-specific
27
+ * agent installation folders. The `source` discriminant distinguishes bundled
28
+ * agents from user-installed ones.
29
+ */
30
+ export interface AgentDefinition {
31
+ /** Stable unique identifier for this agent (derived from file name sans extension). */
32
+ id: string;
33
+ /** Human-readable display name (defaults to `id` when no metadata is available). */
34
+ name: string;
35
+ /**
36
+ * Provider that manages this agent's execution context.
37
+ *
38
+ * One of the 9 known CLEO provider IDs: `"claude-code"`, `"claude-sdk"`,
39
+ * `"codex"`, `"cursor"`, `"gemini-cli"`, `"kimi"`, `"openai-sdk"`,
40
+ * `"opencode"`, `"pi"`. Seed agents use `"cleo-os"`.
41
+ */
42
+ provider: string;
43
+ /** Absolute path to the agent definition file on disk. */
44
+ path: string;
45
+ /**
46
+ * Free-form capability tags describing what this agent can do.
47
+ *
48
+ * Common values: `"spawn"`, `"orchestrate"`, `"memory"`, `"review"`, `"test"`.
49
+ * May be empty when no metadata file is available.
50
+ */
51
+ capabilities: string[];
52
+ /**
53
+ * Origin of this agent definition.
54
+ *
55
+ * - `"seed"` — bundled with CleoOS under `packages/cleo-os/seed-agents/`
56
+ * - `"user"` — installed by a provider adapter into its agent directory
57
+ */
58
+ source: 'seed' | 'user';
59
+ }
60
+ /**
61
+ * Read-only catalog of CleoOS agents discovered across all provider adapters.
62
+ *
63
+ * Combines seed agents (bundled with CleoOS) with user-installed agents from
64
+ * each of the 9 provider adapter directories. Results are deduplicated by
65
+ * `path` — a path present in both sources appears once as `"seed"`.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const registry = new AgentRegistry();
70
+ * const all = await registry.listAll();
71
+ * console.log(all.length, 'agents discovered');
72
+ * ```
73
+ */
74
+ export declare class AgentRegistry {
75
+ /**
76
+ * Load seed agents bundled with CleoOS.
77
+ *
78
+ * Reads `packages/cleo-os/seed-agents/` and returns one `AgentDefinition`
79
+ * per agent file found. Returns an empty array when the directory is absent
80
+ * or empty (the directory is created during T640 but initially unpopulated).
81
+ *
82
+ * @returns Array of seed agent definitions; empty if none are installed.
83
+ */
84
+ loadSeedAgents(): Promise<AgentDefinition[]>;
85
+ /**
86
+ * Load user-installed agents from all known provider agent directories.
87
+ *
88
+ * Iterates the 9 provider adapter directories and returns one
89
+ * `AgentDefinition` per agent file found. Directories that do not exist
90
+ * or are unreadable are silently skipped.
91
+ *
92
+ * @returns Array of user agent definitions across all providers.
93
+ */
94
+ loadUserAgents(): Promise<AgentDefinition[]>;
95
+ /**
96
+ * Return all known agents — seed agents followed by user-installed agents.
97
+ *
98
+ * Seed agents take precedence: if the same absolute path appears in both
99
+ * sources (uncommon but possible in development), the seed entry wins and
100
+ * the user entry is omitted.
101
+ *
102
+ * @returns Deduplicated array of all discovered agent definitions.
103
+ */
104
+ listAll(): Promise<AgentDefinition[]>;
105
+ }
106
+ //# sourceMappingURL=agent-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-registry.d.ts","sourceRoot":"","sources":["../../src/registry/agent-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAcH;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,uFAAuF;IACvF,EAAE,EAAE,MAAM,CAAC;IACX,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAuFD;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAa;IACxB;;;;;;;;OAQG;IACG,cAAc,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAelD;;;;;;;;OAQG;IACG,cAAc,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAqBlD;;;;;;;;OAQG;IACG,OAAO,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAY5C"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * CleoOS Agent Registry — catalog of installed agents across all provider adapters.
3
+ *
4
+ * Discovers agents from two sources:
5
+ * 1. **Seed agents** — bundled with CleoOS in `packages/cleo-os/seed-agents/`.
6
+ * 2. **User agents** — installed by individual provider adapters into their
7
+ * provider-specific agent directories (e.g. `~/.claude/agents/`).
8
+ *
9
+ * This module is read-only. It does not install, remove, or modify agents.
10
+ * Provider adapter logic stays in `packages/adapters/`. CleoOS consumes the
11
+ * filesystem artifacts that adapters produce.
12
+ *
13
+ * @remarks
14
+ * Long-term: `loadUserAgents()` should call `adapter.paths?.getAgentInstallDir()`
15
+ * dynamically once T639 exposes the provider-folder contract. For now the 9 paths
16
+ * are hard-coded from each provider's `AdapterPathProvider` defaults.
17
+ *
18
+ * @see ADR-050 — CleoOS Sovereign Harness: Distribution Binding Charter
19
+ * @task T640
20
+ * @epic T636
21
+ * @packageDocumentation
22
+ */
23
+ import { existsSync } from 'node:fs';
24
+ import { readdir } from 'node:fs/promises';
25
+ import { homedir } from 'node:os';
26
+ import { dirname, join } from 'node:path';
27
+ import { fileURLToPath } from 'node:url';
28
+ const __dirname = dirname(fileURLToPath(import.meta.url));
29
+ // ---------------------------------------------------------------------------
30
+ // Internal helpers
31
+ // ---------------------------------------------------------------------------
32
+ /**
33
+ * Absolute path to the CleoOS seed-agents directory.
34
+ *
35
+ * Located at `packages/cleo-os/seed-agents/` relative to this source file's
36
+ * compiled output (`dist/registry/`), so we go up two levels from `__dirname`.
37
+ */
38
+ const SEED_AGENTS_DIR = join(__dirname, '..', '..', 'seed-agents');
39
+ /**
40
+ * Known provider IDs and their default agent installation directories.
41
+ *
42
+ * Derived from each provider's `AdapterPathProvider.getAgentInstallDir()` defaults.
43
+ * Update here when a provider changes its agent directory structure.
44
+ *
45
+ * @remarks
46
+ * Long-term replacement: call `adapter.paths?.getAgentInstallDir()` once T639
47
+ * exposes the provider-folder contract via a dynamic registry surface.
48
+ */
49
+ const PROVIDER_AGENT_DIRS = [
50
+ { providerId: 'claude-code', dir: join(homedir(), '.claude', 'agents') },
51
+ { providerId: 'claude-sdk', dir: join(homedir(), '.claude', 'agents') },
52
+ { providerId: 'codex', dir: join(homedir(), '.codex', 'agents') },
53
+ { providerId: 'cursor', dir: join(homedir(), '.cursor', 'agents') },
54
+ { providerId: 'gemini-cli', dir: join(homedir(), '.gemini', 'agents') },
55
+ { providerId: 'kimi', dir: join(homedir(), '.kimi', 'agents') },
56
+ { providerId: 'openai-sdk', dir: join(homedir(), '.openai', 'agents') },
57
+ { providerId: 'opencode', dir: join(homedir(), '.opencode', 'agents') },
58
+ { providerId: 'pi', dir: join(homedir(), '.pi', 'agents') },
59
+ ];
60
+ /**
61
+ * File extensions recognised as agent definition files.
62
+ *
63
+ * Excludes README.md and other documentation files in seed-agents/.
64
+ */
65
+ const AGENT_EXTENSIONS = new Set(['.md', '.json', '.yaml', '.yml', '.ts', '.js']);
66
+ /**
67
+ * Derive a stable agent `id` from a file name by stripping the extension.
68
+ *
69
+ * @param fileName - Base file name (e.g. `"cleo-prime.md"`).
70
+ * @returns ID string (e.g. `"cleo-prime"`).
71
+ */
72
+ function idFromFileName(fileName) {
73
+ const dot = fileName.lastIndexOf('.');
74
+ return dot > 0 ? fileName.slice(0, dot) : fileName;
75
+ }
76
+ /**
77
+ * Read agent file names from a directory, returning an empty array when the
78
+ * directory does not exist or cannot be read.
79
+ *
80
+ * Filters to known agent file extensions and skips `README` files.
81
+ *
82
+ * @param dir - Absolute path to the directory to scan.
83
+ * @returns Array of base file names matching the agent extension filter.
84
+ */
85
+ async function readAgentFileNames(dir) {
86
+ if (!existsSync(dir)) {
87
+ return [];
88
+ }
89
+ try {
90
+ const entries = await readdir(dir, { withFileTypes: true });
91
+ return entries
92
+ .filter((e) => e.isFile())
93
+ .map((e) => e.name)
94
+ .filter((name) => {
95
+ const dot = name.lastIndexOf('.');
96
+ if (dot < 0)
97
+ return false;
98
+ const ext = name.slice(dot);
99
+ return AGENT_EXTENSIONS.has(ext) && !name.toLowerCase().startsWith('readme');
100
+ });
101
+ }
102
+ catch {
103
+ return [];
104
+ }
105
+ }
106
+ // ---------------------------------------------------------------------------
107
+ // AgentRegistry
108
+ // ---------------------------------------------------------------------------
109
+ /**
110
+ * Read-only catalog of CleoOS agents discovered across all provider adapters.
111
+ *
112
+ * Combines seed agents (bundled with CleoOS) with user-installed agents from
113
+ * each of the 9 provider adapter directories. Results are deduplicated by
114
+ * `path` — a path present in both sources appears once as `"seed"`.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const registry = new AgentRegistry();
119
+ * const all = await registry.listAll();
120
+ * console.log(all.length, 'agents discovered');
121
+ * ```
122
+ */
123
+ export class AgentRegistry {
124
+ /**
125
+ * Load seed agents bundled with CleoOS.
126
+ *
127
+ * Reads `packages/cleo-os/seed-agents/` and returns one `AgentDefinition`
128
+ * per agent file found. Returns an empty array when the directory is absent
129
+ * or empty (the directory is created during T640 but initially unpopulated).
130
+ *
131
+ * @returns Array of seed agent definitions; empty if none are installed.
132
+ */
133
+ async loadSeedAgents() {
134
+ const fileNames = await readAgentFileNames(SEED_AGENTS_DIR);
135
+ return fileNames.map((fileName) => {
136
+ const id = idFromFileName(fileName);
137
+ return {
138
+ id,
139
+ name: id,
140
+ provider: 'cleo-os',
141
+ path: join(SEED_AGENTS_DIR, fileName),
142
+ capabilities: [],
143
+ source: 'seed',
144
+ };
145
+ });
146
+ }
147
+ /**
148
+ * Load user-installed agents from all known provider agent directories.
149
+ *
150
+ * Iterates the 9 provider adapter directories and returns one
151
+ * `AgentDefinition` per agent file found. Directories that do not exist
152
+ * or are unreadable are silently skipped.
153
+ *
154
+ * @returns Array of user agent definitions across all providers.
155
+ */
156
+ async loadUserAgents() {
157
+ const results = [];
158
+ for (const { providerId, dir } of PROVIDER_AGENT_DIRS) {
159
+ const fileNames = await readAgentFileNames(dir);
160
+ for (const fileName of fileNames) {
161
+ const id = idFromFileName(fileName);
162
+ results.push({
163
+ id,
164
+ name: id,
165
+ provider: providerId,
166
+ path: join(dir, fileName),
167
+ capabilities: [],
168
+ source: 'user',
169
+ });
170
+ }
171
+ }
172
+ return results;
173
+ }
174
+ /**
175
+ * Return all known agents — seed agents followed by user-installed agents.
176
+ *
177
+ * Seed agents take precedence: if the same absolute path appears in both
178
+ * sources (uncommon but possible in development), the seed entry wins and
179
+ * the user entry is omitted.
180
+ *
181
+ * @returns Deduplicated array of all discovered agent definitions.
182
+ */
183
+ async listAll() {
184
+ const [seed, user] = await Promise.all([this.loadSeedAgents(), this.loadUserAgents()]);
185
+ const seenPaths = new Set(seed.map((a) => a.path));
186
+ const deduped = user.filter((a) => {
187
+ if (seenPaths.has(a.path))
188
+ return false;
189
+ seenPaths.add(a.path);
190
+ return true;
191
+ });
192
+ return [...seed, ...deduped];
193
+ }
194
+ }
195
+ //# sourceMappingURL=agent-registry.js.map