pi-better-server 0.3.0 → 0.4.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/package.json +4 -1
- package/scripts/measure-shared-reads.mjs +25 -5
- package/scripts/test-on-pi.sh +3 -2
- package/src/daemon-owner.ts +2 -1
- package/src/handshake.ts +1 -1
- package/src/protocol.ts +2 -0
- package/src/runtime/background.ts +12 -3
- package/src/runtime/cancellation.ts +10 -6
- package/src/runtime/catalog-admission.ts +50 -0
- package/src/runtime/catalog.ts +133 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +18 -1
- package/src/runtime/domain/catalog/agent-session-settings.d.mts +30 -0
- package/src/runtime/domain/catalog/agent-session-settings.mjs +112 -0
- package/src/runtime/domain/catalog/catalog-overlay.d.mts +3 -0
- package/src/runtime/domain/catalog/catalog-overlay.mjs +9 -0
- package/src/runtime/domain/catalog/catalog-preferences.d.mts +17 -0
- package/src/runtime/domain/catalog/catalog-preferences.mjs +164 -0
- package/src/runtime/domain/catalog/catalog-schema.d.mts +265 -0
- package/src/runtime/domain/catalog/catalog-schema.mjs +1331 -0
- package/src/runtime/domain/catalog/catalog-skill-edits.d.mts +42 -0
- package/src/runtime/domain/catalog/catalog-skill-edits.mjs +95 -0
- package/src/runtime/domain/catalog/catalog-store.d.mts +126 -0
- package/src/runtime/domain/catalog/catalog-store.mjs +810 -0
- package/src/runtime/domain/catalog/roles/role.architect.md +13 -0
- package/src/runtime/domain/catalog/roles/role.developer.md +16 -0
- package/src/runtime/domain/catalog/roles/role.explorer.md +13 -0
- package/src/runtime/domain/catalog/roles/role.product-manager.md +13 -0
- package/src/runtime/domain/catalog/roles/role.researcher.md +13 -0
- package/src/runtime/domain/catalog/roles/role.reviewer.md +13 -0
- package/src/runtime/domain/catalog/roles/role.writer.md +12 -0
- package/src/runtime/domain/catalog/thinking.d.mts +8 -0
- package/src/runtime/domain/catalog/thinking.mjs +22 -0
- package/src/runtime/domain/coordinator/src/discovery.mjs +9 -0
- package/src/runtime/domain/coordinator/src/operations.mjs +5 -3
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +101 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +17 -1
- package/src/runtime/domain/coordinator/src/store.mjs +11 -1
- package/src/runtime/mutation-store.ts +34 -0
- package/src/runtime/query-executor.ts +58 -9
- package/src/runtime/query-worker.mjs +3 -2
- package/src/runtime/read-model.ts +111 -59
- package/src/runtime/result-supervision.ts +63 -0
- package/src/runtime/work-client.d.mts +1 -0
- package/src/runtime/work-client.mjs +16 -2
- package/src/server.ts +66 -5
- package/src/version.ts +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Generated from packages/pi-better-subagents/catalog-overlay.ts. Do not edit directly.
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
/** Canonical host/server credential binding for branch-local Catalog preferences. */
|
|
4
|
+
export function overlayDigest(value = {}) {
|
|
5
|
+
const canonical = Object.fromEntries(Object.keys(value).sort().map(id => [id,
|
|
6
|
+
Object.fromEntries(Object.entries(value[id]).sort(([a], [b]) => a.localeCompare(b))),
|
|
7
|
+
]));
|
|
8
|
+
return createHash("sha256").update(JSON.stringify(canonical)).digest("hex");
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ThinkingLevel } from "./thinking.mjs";
|
|
2
|
+
export type CatalogPreference = Readonly<{
|
|
3
|
+
bundled?: true;
|
|
4
|
+
model?: string | null;
|
|
5
|
+
effort?: ThinkingLevel | null;
|
|
6
|
+
}>;
|
|
7
|
+
export type CatalogPreferences = Readonly<Record<string, CatalogPreference>>;
|
|
8
|
+
export declare function readCatalogPreferences(root: string): {
|
|
9
|
+
settings: CatalogPreferences;
|
|
10
|
+
digest: string;
|
|
11
|
+
};
|
|
12
|
+
/** Replace only this id's own preferences; null explicitly clears a definition value. */
|
|
13
|
+
export declare function writeCatalogPreferences(root: string, id: string, value: CatalogPreference | ((current: CatalogPreference) => CatalogPreference)): {
|
|
14
|
+
path: string;
|
|
15
|
+
settings: CatalogPreferences;
|
|
16
|
+
digest: string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Generated from packages/pi-better-subagents/catalog-preferences.ts. Do not edit directly.
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { closeSync, constants, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
import { THINKING_LEVELS } from "./thinking.mjs";
|
|
7
|
+
const ID = /^(role|agent)\.[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
|
|
8
|
+
const MODEL = /^[a-z0-9][a-z0-9._-]*\/[A-Za-z0-9][A-Za-z0-9._+-]*$/;
|
|
9
|
+
function object(value, label) {
|
|
10
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
11
|
+
throw new Error(`${label} must be a JSON object.`);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function preferences(id, value) {
|
|
15
|
+
if (typeof id !== "string" || !ID.test(id))
|
|
16
|
+
throw new Error(`Invalid catalog id ${JSON.stringify(id)}.`);
|
|
17
|
+
const record = object(value, `Preferences for ${id}`);
|
|
18
|
+
for (const [key, item] of Object.entries(record)) {
|
|
19
|
+
if (key !== "bundled" && key !== "model" && key !== "effort")
|
|
20
|
+
throw new Error(`Unknown preference ${key} for ${id}.`);
|
|
21
|
+
if (key === "bundled" ? item !== true : item !== null && (typeof item !== "string" || (key === "model" ? !MODEL.test(item)
|
|
22
|
+
: !THINKING_LEVELS.includes(item)))) {
|
|
23
|
+
throw new Error(`Invalid ${key} preference for ${id}: ${JSON.stringify(item)}.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
...(Object.hasOwn(record, "bundled") ? { bundled: true } : {}),
|
|
28
|
+
...(Object.hasOwn(record, "model") ? { model: record.model } : {}),
|
|
29
|
+
...(Object.hasOwn(record, "effort") ? { effort: record.effort } : {}),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function snapshot(values) {
|
|
33
|
+
const settings = Object.freeze(Object.fromEntries(Object.keys(values).sort().map(id => [id, values[id]])));
|
|
34
|
+
return { settings, digest: createHash("sha256").update(JSON.stringify(settings)).digest("hex") };
|
|
35
|
+
}
|
|
36
|
+
function stat(path) {
|
|
37
|
+
try {
|
|
38
|
+
return lstatSync(path);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error.code === "ENOENT")
|
|
42
|
+
return undefined;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function checkRoot(root) {
|
|
47
|
+
const info = stat(root);
|
|
48
|
+
if (!info)
|
|
49
|
+
return false;
|
|
50
|
+
if (info.isSymbolicLink())
|
|
51
|
+
throw new Error(`Refusing symlink catalog directory ${root}.`);
|
|
52
|
+
if (!info.isDirectory())
|
|
53
|
+
throw new Error(`Catalog root ${root} must be a directory.`);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
function checkFile(path) {
|
|
57
|
+
const info = stat(path);
|
|
58
|
+
if (!info)
|
|
59
|
+
return false;
|
|
60
|
+
if (info.isSymbolicLink())
|
|
61
|
+
throw new Error(`Refusing symlink catalog settings file ${path}.`);
|
|
62
|
+
if (!info.isFile())
|
|
63
|
+
throw new Error(`Catalog settings ${path} must be a regular file.`);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
export function readCatalogPreferences(root) {
|
|
67
|
+
root = resolve(root);
|
|
68
|
+
const path = join(root, "settings.json");
|
|
69
|
+
try {
|
|
70
|
+
if (!checkRoot(root) || !checkFile(path))
|
|
71
|
+
return snapshot({});
|
|
72
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
73
|
+
let data;
|
|
74
|
+
try {
|
|
75
|
+
if (!fstatSync(fd).isFile())
|
|
76
|
+
throw new Error("Settings must be a regular file.");
|
|
77
|
+
data = object(JSON.parse(readFileSync(fd, "utf8")), "Catalog settings");
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
closeSync(fd);
|
|
81
|
+
}
|
|
82
|
+
if (data.version !== 1 || !Object.hasOwn(data, "defaults") ||
|
|
83
|
+
Object.keys(data).some(key => key !== "version" && key !== "defaults")) {
|
|
84
|
+
throw new Error("Expected only version: 1 and defaults in catalog settings.");
|
|
85
|
+
}
|
|
86
|
+
const settings = Object.fromEntries(Object.entries(object(data.defaults, "Catalog defaults"))
|
|
87
|
+
.map(([id, value]) => [id, preferences(id, value)]));
|
|
88
|
+
return snapshot(settings);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new Error(`Cannot read catalog preferences at ${path}: ${error.message}`, { cause: error });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function acquire(path) {
|
|
95
|
+
// Read-only catalog consumers (including the portable CLI) need no lock adapter.
|
|
96
|
+
const lockfile = createRequire(import.meta.url)("proper-lockfile");
|
|
97
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
98
|
+
try {
|
|
99
|
+
return lockfile.lockSync(path, { realpath: false });
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error.code !== "ELOCKED" || attempt === 99)
|
|
103
|
+
throw error;
|
|
104
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
throw new Error(`Cannot lock catalog settings at ${path}.`);
|
|
108
|
+
}
|
|
109
|
+
/** Replace only this id's own preferences; null explicitly clears a definition value. */
|
|
110
|
+
export function writeCatalogPreferences(root, id, value) {
|
|
111
|
+
// Validate literal input before touching disk; updater callbacks run under the lock.
|
|
112
|
+
const selected = typeof value === "function" ? (preferences(id, {}), undefined) : preferences(id, value);
|
|
113
|
+
root = resolve(root);
|
|
114
|
+
const path = join(root, "settings.json");
|
|
115
|
+
let release;
|
|
116
|
+
let pending;
|
|
117
|
+
try {
|
|
118
|
+
if (!checkRoot(root)) {
|
|
119
|
+
// Do not create the caller's user/project configuration directories.
|
|
120
|
+
try {
|
|
121
|
+
mkdirSync(root, { mode: 0o700 });
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error.code !== "EEXIST")
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
checkRoot(root);
|
|
128
|
+
}
|
|
129
|
+
checkFile(path);
|
|
130
|
+
release = acquire(path);
|
|
131
|
+
const settings = { ...readCatalogPreferences(root).settings };
|
|
132
|
+
const next = selected ?? preferences(id, value(settings[id] ?? Object.freeze({})));
|
|
133
|
+
if (Object.keys(next).length)
|
|
134
|
+
settings[id] = next;
|
|
135
|
+
else
|
|
136
|
+
delete settings[id];
|
|
137
|
+
const result = snapshot(settings);
|
|
138
|
+
pending = join(root, `.settings.json.${randomUUID()}.tmp`);
|
|
139
|
+
const fd = openSync(pending, "wx", 0o600);
|
|
140
|
+
try {
|
|
141
|
+
writeFileSync(fd, `${JSON.stringify({ version: 1, defaults: result.settings }, null, 2)}\n`);
|
|
142
|
+
fsyncSync(fd);
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
closeSync(fd);
|
|
146
|
+
}
|
|
147
|
+
checkRoot(root);
|
|
148
|
+
checkFile(path);
|
|
149
|
+
renameSync(pending, path);
|
|
150
|
+
return { path, ...result };
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
throw new Error(`Cannot save catalog preferences at ${path}: ${error.message}`, { cause: error });
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
try {
|
|
157
|
+
if (pending)
|
|
158
|
+
rmSync(pending, { force: true });
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
release?.();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { type ThinkingLevel } from "./thinking.mjs";
|
|
2
|
+
export type { ThinkingLevel };
|
|
3
|
+
export declare const CATALOG_SCHEMA_VERSION: "pi-agent/v1";
|
|
4
|
+
export type CatalogSchemaVersion = typeof CATALOG_SCHEMA_VERSION;
|
|
5
|
+
export type CatalogKind = "role" | "agent";
|
|
6
|
+
export type InstructionMode = "add" | "replace";
|
|
7
|
+
export type CatalogScope = "project" | "user" | "bundled";
|
|
8
|
+
export type PreferenceKey = "model" | "effort" | "tier";
|
|
9
|
+
export type DiagnosticSeverity = "error" | "warning" | "info";
|
|
10
|
+
export declare const PREFERENCE_KEYS: ["model", "effort", "tier"];
|
|
11
|
+
/**
|
|
12
|
+
* Every key `defaults` (roles) and `overrides` (agents) may carry. `skills` is
|
|
13
|
+
* added here but is not a `PreferenceKey`: model resolution consumes preferences,
|
|
14
|
+
* while skill exposure is reproduced by the launcher from the definition.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFINITION_PREFERENCE_KEYS: readonly ["model", "effort", "tier", "skills"];
|
|
17
|
+
/** Closed set of thinking levels shared with the existing subagent parser. */
|
|
18
|
+
export declare const EFFORT_LEVELS: any;
|
|
19
|
+
/**
|
|
20
|
+
* Top-level keys that describe host execution. The catalog preserves them and
|
|
21
|
+
* blocks launch; it never treats them as enforced permissions or tool presets.
|
|
22
|
+
*/
|
|
23
|
+
export declare const HOST_EXECUTION_CONTROL_KEYS: readonly ["sandbox", "sandbox_mode", "sandboxMode", "tools", "tool", "toolPreset", "toolsPreset", "permissions", "permission", "mcp", "mcpServers", "extensions", "network", "filesystem", "cwd", "workspace", "allow_nested", "nested", "env", "environment"];
|
|
24
|
+
export declare const PARSER_LIMITS: {
|
|
25
|
+
readonly maxFileBytes: number;
|
|
26
|
+
readonly maxFrontmatterBytes: number;
|
|
27
|
+
readonly maxBodyBytes: number;
|
|
28
|
+
readonly maxAliasCount: 50;
|
|
29
|
+
readonly maxNodes: 2000;
|
|
30
|
+
readonly maxDepth: 32;
|
|
31
|
+
readonly maxIdLength: 128;
|
|
32
|
+
readonly maxNameLength: 120;
|
|
33
|
+
readonly maxDescriptionLength: 2000;
|
|
34
|
+
readonly maxStringLength: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Approved bundled-role defaults from DEV-23. Short model names in the product
|
|
38
|
+
* table are OpenAI model ids; stored values use the provider/model form the
|
|
39
|
+
* runtime already uses. Tiers are catalog policy, not benchmark rankings.
|
|
40
|
+
*/
|
|
41
|
+
export declare const APPROVED_ROLE_DEFAULTS: readonly [{
|
|
42
|
+
readonly id: "role.researcher";
|
|
43
|
+
readonly name: "Researcher";
|
|
44
|
+
readonly model: "openai/gpt-6.1-terra";
|
|
45
|
+
readonly effort: "medium";
|
|
46
|
+
readonly tier: "balanced";
|
|
47
|
+
}, {
|
|
48
|
+
readonly id: "role.explorer";
|
|
49
|
+
readonly name: "Explorer";
|
|
50
|
+
readonly model: "openai/gpt-6-luna";
|
|
51
|
+
readonly effort: "medium";
|
|
52
|
+
readonly tier: "efficient";
|
|
53
|
+
}, {
|
|
54
|
+
readonly id: "role.product-manager";
|
|
55
|
+
readonly name: "Product Manager";
|
|
56
|
+
readonly model: "openai/gpt-6.1-sol";
|
|
57
|
+
readonly effort: "medium";
|
|
58
|
+
readonly tier: "balanced";
|
|
59
|
+
}, {
|
|
60
|
+
readonly id: "role.developer";
|
|
61
|
+
readonly name: "Developer";
|
|
62
|
+
readonly model: "openai/gpt-6.1-sol";
|
|
63
|
+
readonly effort: "high";
|
|
64
|
+
readonly tier: "balanced";
|
|
65
|
+
}, {
|
|
66
|
+
readonly id: "role.reviewer";
|
|
67
|
+
readonly name: "Reviewer";
|
|
68
|
+
readonly model: "openai/gpt-6-astra";
|
|
69
|
+
readonly effort: "medium";
|
|
70
|
+
readonly tier: "frontier";
|
|
71
|
+
}, {
|
|
72
|
+
readonly id: "role.architect";
|
|
73
|
+
readonly name: "Architect";
|
|
74
|
+
readonly model: "openai/gpt-6-astra";
|
|
75
|
+
readonly effort: "high";
|
|
76
|
+
readonly tier: "frontier";
|
|
77
|
+
}, {
|
|
78
|
+
readonly id: "role.writer";
|
|
79
|
+
readonly name: "Writer";
|
|
80
|
+
readonly model: "openai/gpt-6.1-terra";
|
|
81
|
+
readonly effort: "medium";
|
|
82
|
+
readonly tier: undefined;
|
|
83
|
+
}];
|
|
84
|
+
export declare const DiagnosticCodes: {
|
|
85
|
+
readonly malformedFrontmatter: "malformed-frontmatter";
|
|
86
|
+
readonly parserLimit: "parser-limit";
|
|
87
|
+
readonly duplicateKey: "duplicate-key";
|
|
88
|
+
readonly invalidSchema: "invalid-schema";
|
|
89
|
+
readonly invalidKind: "invalid-kind";
|
|
90
|
+
readonly invalidId: "invalid-id";
|
|
91
|
+
readonly duplicateId: "duplicate-id";
|
|
92
|
+
readonly invalidField: "invalid-field";
|
|
93
|
+
readonly invalidInstructionMode: "invalid-instruction-mode";
|
|
94
|
+
readonly emptyReplacement: "empty-replacement";
|
|
95
|
+
readonly multipleBaseRoles: "multiple-base-roles";
|
|
96
|
+
readonly missingRole: "missing-role";
|
|
97
|
+
readonly unusableRole: "unusable-role";
|
|
98
|
+
readonly unknownAgent: "unknown-agent";
|
|
99
|
+
readonly unknownRole: "unknown-role";
|
|
100
|
+
readonly ambiguousSelector: "ambiguous-selector";
|
|
101
|
+
readonly missingSelector: "missing-selector";
|
|
102
|
+
readonly invalidShadow: "invalid-shadow";
|
|
103
|
+
readonly unsupportedExecutionRestriction: "unsupported-execution-restriction";
|
|
104
|
+
readonly projectCatalogSuppressed: "project-catalog-suppressed";
|
|
105
|
+
readonly symlinkIgnored: "symlink-ignored";
|
|
106
|
+
readonly credentialMaterial: "credential-material";
|
|
107
|
+
readonly cosmeticMetadata: "cosmetic-metadata";
|
|
108
|
+
readonly untrustedWrite: "untrusted-write";
|
|
109
|
+
readonly immutableScope: "immutable-scope";
|
|
110
|
+
readonly definitionExists: "definition-exists";
|
|
111
|
+
readonly pathEscape: "path-escape";
|
|
112
|
+
readonly notLaunchable: "not-launchable";
|
|
113
|
+
readonly kindDirectoryMismatch: "kind-directory-mismatch";
|
|
114
|
+
readonly bundledMissing: "bundled-missing";
|
|
115
|
+
readonly ioError: "io-error";
|
|
116
|
+
readonly unsafeConfigDir: "unsafe-config-dir";
|
|
117
|
+
};
|
|
118
|
+
export type DiagnosticCode = (typeof DiagnosticCodes)[keyof typeof DiagnosticCodes];
|
|
119
|
+
export interface Diagnostic {
|
|
120
|
+
severity: DiagnosticSeverity;
|
|
121
|
+
code: DiagnosticCode | string;
|
|
122
|
+
message: string;
|
|
123
|
+
id?: string;
|
|
124
|
+
scope?: CatalogScope;
|
|
125
|
+
path?: string;
|
|
126
|
+
field?: string;
|
|
127
|
+
/** Prevents launch of this identity. Does not hide unrelated identities. */
|
|
128
|
+
blocking: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* The file is not a trustworthy whole definition. A higher-priority
|
|
131
|
+
* structural failure occupies its id and blocks lower-priority sources.
|
|
132
|
+
*/
|
|
133
|
+
structural: boolean;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Model, effort, tier, and skill exposure. Absence inherits; null is an explicit value.
|
|
137
|
+
*
|
|
138
|
+
* `skills` is the one launch value here that changes what the child can see
|
|
139
|
+
* rather than how the model is chosen. It stays a definition-owned preference
|
|
140
|
+
* because the launcher reproduces it exactly (`--no-skills` plus `--skill`), the
|
|
141
|
+
* same way it reproduces model and effort, and because it grants nothing: a
|
|
142
|
+
* skill list narrows prompt exposure and cannot add a tool or a permission.
|
|
143
|
+
*/
|
|
144
|
+
export interface PortablePreferences {
|
|
145
|
+
model?: string | null;
|
|
146
|
+
effort?: ThinkingLevel | null;
|
|
147
|
+
tier?: string | null;
|
|
148
|
+
skills?: string[] | null;
|
|
149
|
+
}
|
|
150
|
+
export interface Provenance {
|
|
151
|
+
origin: "local" | "imported";
|
|
152
|
+
format?: string;
|
|
153
|
+
/** Original source label. Not a live sync handle and not a secret. */
|
|
154
|
+
sourceRef?: string;
|
|
155
|
+
importedAt?: string;
|
|
156
|
+
note?: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A required execution restriction the catalog does not enforce.
|
|
160
|
+
* `honored: true` in a file is not proof of enforcement and does not unblock launch.
|
|
161
|
+
*/
|
|
162
|
+
export interface ExecutionRestriction {
|
|
163
|
+
name: string;
|
|
164
|
+
value: unknown;
|
|
165
|
+
required: boolean;
|
|
166
|
+
honored: boolean;
|
|
167
|
+
reason?: string;
|
|
168
|
+
}
|
|
169
|
+
interface DefinitionBase {
|
|
170
|
+
schema: CatalogSchemaVersion;
|
|
171
|
+
id: string;
|
|
172
|
+
name: string;
|
|
173
|
+
description?: string;
|
|
174
|
+
provenance?: Provenance;
|
|
175
|
+
executionRestrictions: ExecutionRestriction[];
|
|
176
|
+
/** Explicit metadata object from the file. Cosmetic unless it hides a secret. */
|
|
177
|
+
metadata?: Record<string, unknown>;
|
|
178
|
+
/** Unknown non-execution frontmatter, preserved so writes do not drop it. */
|
|
179
|
+
extensions?: Record<string, unknown>;
|
|
180
|
+
/** Host execution keys preserved verbatim (secrets redacted) and not enforced. */
|
|
181
|
+
preservedExecutionControls?: Record<string, unknown>;
|
|
182
|
+
body: string;
|
|
183
|
+
}
|
|
184
|
+
export interface RoleDefinition extends DefinitionBase {
|
|
185
|
+
kind: "role";
|
|
186
|
+
defaults: PortablePreferences;
|
|
187
|
+
}
|
|
188
|
+
export interface AgentDefinition extends DefinitionBase {
|
|
189
|
+
kind: "agent";
|
|
190
|
+
/** Exactly one base role. Executable-role memberships are not additional parents. */
|
|
191
|
+
roleId: string;
|
|
192
|
+
instructionMode: InstructionMode;
|
|
193
|
+
/** Explicit values only. Missing keys inherit and must not be backfilled. */
|
|
194
|
+
overrides: PortablePreferences;
|
|
195
|
+
}
|
|
196
|
+
export type CatalogDefinition = RoleDefinition | AgentDefinition;
|
|
197
|
+
export interface ParseResult {
|
|
198
|
+
/** True when the file is a trustworthy whole definition. Blocking diagnostics may still prevent launch. */
|
|
199
|
+
ok: boolean;
|
|
200
|
+
definition?: CatalogDefinition;
|
|
201
|
+
/** Set when this file should occupy an id even though it is not ok. */
|
|
202
|
+
occupantId?: string;
|
|
203
|
+
diagnostics: Diagnostic[];
|
|
204
|
+
}
|
|
205
|
+
export interface SerializeResult {
|
|
206
|
+
ok: boolean;
|
|
207
|
+
markdown?: string;
|
|
208
|
+
diagnostics: Diagnostic[];
|
|
209
|
+
}
|
|
210
|
+
export declare function formatDiagnostic(diagnostic: Diagnostic): string;
|
|
211
|
+
export declare function hasBlockingDiagnostic(diagnostics: readonly Diagnostic[]): boolean;
|
|
212
|
+
export declare function kindForId(id: string): CatalogKind | undefined;
|
|
213
|
+
/** Prefix every role id carries. Stored ids and files keep it; people type and read the short name. */
|
|
214
|
+
export declare const ROLE_ID_PREFIX = "role.";
|
|
215
|
+
/** Short, user-facing role name: `role.developer` becomes `developer`. Any other id is returned unchanged. */
|
|
216
|
+
export declare function shortRoleName(id: string): string;
|
|
217
|
+
/**
|
|
218
|
+
* Canonical role id for a value typed into a `role` field. Trimmed and
|
|
219
|
+
* lowercased; a bare name gains the `role.` prefix, so `Developer` becomes
|
|
220
|
+
* `role.developer`. The result always starts with `role.`, so a role field
|
|
221
|
+
* can never select an `agent.*` named agent.
|
|
222
|
+
*/
|
|
223
|
+
export declare function canonicalRoleId(value: string): string;
|
|
224
|
+
/** Canonical named-agent id: trimmed and lowercased, since ids are lowercase-only. */
|
|
225
|
+
export declare function canonicalAgentId(value: string): string;
|
|
226
|
+
/**
|
|
227
|
+
* Canonical id for a field that takes either kind, such as `agents_catalog`
|
|
228
|
+
* inspect. An `agent.` id (any case) is lowercased; anything else is read as a role.
|
|
229
|
+
*/
|
|
230
|
+
export declare function canonicalCatalogId(value: string): string;
|
|
231
|
+
export declare function isPreferenceKey(value: string): value is PreferenceKey;
|
|
232
|
+
/** Explicit override. Null is stored; it does not mean "inherit". */
|
|
233
|
+
export declare function setAgentOverride(agent: AgentDefinition, key: "model", value: string | null): AgentDefinition;
|
|
234
|
+
export declare function setAgentOverride(agent: AgentDefinition, key: "effort", value: ThinkingLevel | null): AgentDefinition;
|
|
235
|
+
export declare function setAgentOverride(agent: AgentDefinition, key: "tier", value: string | null): AgentDefinition;
|
|
236
|
+
/** Delete one override key so the next resolution inherits that field again. */
|
|
237
|
+
export declare function removeAgentOverride(agent: AgentDefinition, key: PreferenceKey): AgentDefinition;
|
|
238
|
+
export declare function updateAgentOverrides(agent: AgentDefinition, patch: {
|
|
239
|
+
set?: Partial<PortablePreferences>;
|
|
240
|
+
remove?: readonly (PreferenceKey | "skills")[];
|
|
241
|
+
}): AgentDefinition;
|
|
242
|
+
/**
|
|
243
|
+
* One `/agents` skill edit. `inherit` removes the definition's own key,
|
|
244
|
+
* `none` writes `[]`, and `explicit` writes the absolute paths.
|
|
245
|
+
*
|
|
246
|
+
* `explicit` with no paths is rejected on purpose: an empty selected list must
|
|
247
|
+
* not become `[]` (which means "none") or absence (which means discovery).
|
|
248
|
+
*/
|
|
249
|
+
export type SkillExposureEdit = {
|
|
250
|
+
mode: "inherit";
|
|
251
|
+
} | {
|
|
252
|
+
mode: "none";
|
|
253
|
+
} | {
|
|
254
|
+
mode: "explicit";
|
|
255
|
+
paths: readonly string[];
|
|
256
|
+
};
|
|
257
|
+
/** The definition's own skill value: undefined inherits, null suppresses, `[]` is none. */
|
|
258
|
+
export declare function definitionSkillPreference(definition: CatalogDefinition): string[] | null | undefined;
|
|
259
|
+
/** Absolute definition paths, with the empty selection rejected rather than stored as "none". */
|
|
260
|
+
export declare function definitionSkillPaths(paths: readonly string[]): string[];
|
|
261
|
+
/** Apply one edit without flattening inherited values or touching other fields. */
|
|
262
|
+
export declare function applySkillExposure<T extends CatalogDefinition>(definition: T, edit: SkillExposureEdit): T;
|
|
263
|
+
export declare function parseDefinition(markdown: string, sourcePath?: string): ParseResult;
|
|
264
|
+
export declare function validateDefinition(definition: CatalogDefinition): ParseResult;
|
|
265
|
+
export declare function serializeDefinition(definition: CatalogDefinition): SerializeResult;
|