pi-better-server 0.2.4 → 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 +6 -3
- package/scripts/measure-shared-reads/daemon.mjs +7 -0
- package/scripts/measure-shared-reads/probe.mjs +10 -0
- package/scripts/measure-shared-reads.mjs +165 -0
- package/scripts/test-on-pi.sh +21 -3
- package/src/cli.ts +39 -2
- package/src/client.ts +9 -4
- package/src/daemon-owner.ts +48 -6
- package/src/handshake.ts +8 -7
- package/src/lifecycle-config.ts +4 -0
- package/src/paths.ts +1 -11
- package/src/protocol.ts +7 -0
- package/src/registry.ts +2 -1
- package/src/runtime/background-history.ts +241 -0
- package/src/runtime/background.ts +182 -0
- package/src/runtime/cancellation.ts +99 -0
- package/src/runtime/catalog-admission.ts +50 -0
- package/src/runtime/catalog.ts +133 -0
- package/src/runtime/client.ts +111 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -0
- package/src/runtime/domain/assignment-observation.mjs +120 -0
- package/src/runtime/domain/assignment-projection.d.mts +1 -0
- package/src/runtime/domain/assignment-projection.mjs +245 -0
- package/src/runtime/domain/background/conditions.mjs +93 -0
- package/src/runtime/domain/background/process-identity.mjs +110 -0
- package/src/runtime/domain/background/process.mjs +511 -0
- package/src/runtime/domain/background/registry.mjs +374 -0
- package/src/runtime/domain/background/snapshot.mjs +73 -0
- package/src/runtime/domain/background/supervisor/identity.mjs +92 -0
- package/src/runtime/domain/background/supervisor/invocation.mjs +29 -0
- package/src/runtime/domain/background/supervisor/store.mjs +604 -0
- package/src/runtime/domain/background/supervisor/supervisor.mjs +720 -0
- package/src/runtime/domain/background/supervisor/types.mjs +47 -0
- package/src/runtime/domain/background/terminal-publication.mjs +58 -0
- package/src/runtime/domain/background/types.mjs +3 -0
- 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/index.mjs +50 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +160 -0
- package/src/runtime/domain/coordinator/src/discovery.mjs +94 -0
- package/src/runtime/domain/coordinator/src/errors.mjs +12 -0
- package/src/runtime/domain/coordinator/src/operations.mjs +301 -0
- package/src/runtime/domain/coordinator/src/outbox.mjs +282 -0
- package/src/runtime/domain/coordinator/src/recovery.mjs +51 -0
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +101 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +277 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +367 -0
- package/src/runtime/domain/coordinator/src/sqlite.mjs +193 -0
- package/src/runtime/domain/coordinator/src/store.mjs +245 -0
- package/src/runtime/domain/coordinator/src/task-cancellation.mjs +187 -0
- package/src/runtime/domain/coordinator/src/types.mjs +24 -0
- package/src/runtime/domain/coordinator/src/validate.mjs +233 -0
- package/src/runtime/domain/coordinator/src/waits.mjs +850 -0
- package/src/runtime/domain/health-observation.d.mts +3 -0
- package/src/runtime/domain/health-observation.mjs +613 -0
- package/src/runtime/domain/health-surface.mjs +279 -0
- package/src/runtime/domain/log-cursor.mjs +148 -0
- package/src/runtime/domain/log-paths.mjs +13 -0
- package/src/runtime/domain/parse.d.mts +2 -0
- package/src/runtime/domain/parse.mjs +1173 -0
- package/src/runtime/domain/process-status.d.mts +1 -0
- package/src/runtime/domain/process-status.mjs +25 -0
- package/src/runtime/domain/session-store.d.mts +2 -0
- package/src/runtime/domain/session-store.mjs +489 -0
- package/src/runtime/domain/shared-harness-settings.d.mts +1 -0
- package/src/runtime/domain/shared-harness-settings.mjs +126 -0
- package/src/runtime/domain/shared-log-utils.mjs +1223 -0
- package/src/runtime/domain/shared-stall-detector.mjs +37 -0
- package/src/runtime/domain/widget.d.mts +1 -0
- package/src/runtime/domain/widget.mjs +250 -0
- package/src/runtime/guardian.ts +189 -0
- package/src/runtime/health-config.ts +27 -0
- package/src/runtime/local-client.ts +34 -0
- package/src/runtime/mutation-store.ts +34 -0
- package/src/runtime/queries.ts +76 -0
- package/src/runtime/query-executor.ts +277 -0
- package/src/runtime/query-worker.mjs +119 -0
- package/src/runtime/read-model.ts +409 -0
- package/src/runtime/result-supervision.ts +63 -0
- package/src/runtime/root.ts +29 -0
- package/src/runtime/socket.ts +10 -0
- package/src/runtime/status-cli.ts +11 -0
- package/src/runtime/work-client.d.mts +14 -0
- package/src/runtime/work-client.mjs +102 -0
- package/src/server.ts +199 -14
- package/src/session-activity.ts +22 -2
- package/src/startup/activation.ts +32 -5
- package/src/startup/ensure.ts +13 -1
- package/src/startup/install.ts +2 -0
- package/src/version.ts +4 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/agents` skill edits persisted through the catalog's definition save path.
|
|
3
|
+
*
|
|
4
|
+
* Skill exposure belongs to `defaults.skills` (roles) and `overrides.skills`
|
|
5
|
+
* (named agents), so unlike model and effort it is not a settings.json
|
|
6
|
+
* preference: changing it must rewrite that definition through
|
|
7
|
+
* `saveDefinition`. The edit is surgical. The prompt, description, and every
|
|
8
|
+
* other preference stay as they were, and `inherit` deletes the key instead of
|
|
9
|
+
* writing a null or copying an inherited value back into the file.
|
|
10
|
+
*
|
|
11
|
+
* A bundled definition is immutable. Editing its skills writes a personal
|
|
12
|
+
* definition with the bundled content unchanged except for the skill value;
|
|
13
|
+
* that is the catalog's existing whole-definition override mechanism. An
|
|
14
|
+
* untrusted project never reaches this code because its definitions are not
|
|
15
|
+
* loaded at all.
|
|
16
|
+
*/
|
|
17
|
+
import { type SkillExposureEdit } from "./catalog-schema.mjs";
|
|
18
|
+
import { type LoadCatalogInput } from "./catalog-store.mjs";
|
|
19
|
+
export interface SkillDefinitionTarget {
|
|
20
|
+
id: string;
|
|
21
|
+
/** The winning source shown when the screen opened; catches a stale edit. */
|
|
22
|
+
winningSource?: {
|
|
23
|
+
path: string;
|
|
24
|
+
contentDigest: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface SkillSaveResult {
|
|
28
|
+
ok: boolean;
|
|
29
|
+
message: string;
|
|
30
|
+
path?: string;
|
|
31
|
+
scope?: "user" | "project";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Save one skill choice for the definition behind an `/agents` screen.
|
|
35
|
+
*
|
|
36
|
+
* Returns `ok: false` without writing when the screen is stale, the definition
|
|
37
|
+
* is not structurally valid, or the definition save refuses the scope. The
|
|
38
|
+
* caller keeps its screen and reports the message.
|
|
39
|
+
*/
|
|
40
|
+
export declare function saveSkillExposure(input: LoadCatalogInput & {
|
|
41
|
+
entry: SkillDefinitionTarget;
|
|
42
|
+
}, edit: SkillExposureEdit): SkillSaveResult;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Generated from packages/pi-better-subagents/catalog-skill-edits.ts. Do not edit directly.
|
|
2
|
+
/**
|
|
3
|
+
* `/agents` skill edits persisted through the catalog's definition save path.
|
|
4
|
+
*
|
|
5
|
+
* Skill exposure belongs to `defaults.skills` (roles) and `overrides.skills`
|
|
6
|
+
* (named agents), so unlike model and effort it is not a settings.json
|
|
7
|
+
* preference: changing it must rewrite that definition through
|
|
8
|
+
* `saveDefinition`. The edit is surgical. The prompt, description, and every
|
|
9
|
+
* other preference stay as they were, and `inherit` deletes the key instead of
|
|
10
|
+
* writing a null or copying an inherited value back into the file.
|
|
11
|
+
*
|
|
12
|
+
* A bundled definition is immutable. Editing its skills writes a personal
|
|
13
|
+
* definition with the bundled content unchanged except for the skill value;
|
|
14
|
+
* that is the catalog's existing whole-definition override mechanism. An
|
|
15
|
+
* untrusted project never reaches this code because its definitions are not
|
|
16
|
+
* loaded at all.
|
|
17
|
+
*/
|
|
18
|
+
import { applySkillExposure, definitionSkillPreference, } from "./catalog-schema.mjs";
|
|
19
|
+
import { loadCatalog, saveDefinition } from "./catalog-store.mjs";
|
|
20
|
+
function sameSkillValue(left, right) {
|
|
21
|
+
if (left === undefined || right === undefined)
|
|
22
|
+
return left === right;
|
|
23
|
+
if (left === null || right === null)
|
|
24
|
+
return left === right;
|
|
25
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
26
|
+
}
|
|
27
|
+
function actionLabel(edit) {
|
|
28
|
+
if (edit.mode === "inherit")
|
|
29
|
+
return "inherit";
|
|
30
|
+
if (edit.mode === "none")
|
|
31
|
+
return "none (--no-skills)";
|
|
32
|
+
return `${edit.paths.length} selected`;
|
|
33
|
+
}
|
|
34
|
+
function alreadyMessage(definition, edit) {
|
|
35
|
+
if (edit.mode === "inherit") {
|
|
36
|
+
return definition.kind === "role"
|
|
37
|
+
? `Skills already inherit for ${definition.id}; nothing was written.`
|
|
38
|
+
: `Skills already inherit the base role for ${definition.id}; nothing was written.`;
|
|
39
|
+
}
|
|
40
|
+
return `Skills already ${actionLabel(edit)} for ${definition.id}; nothing was written.`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Save one skill choice for the definition behind an `/agents` screen.
|
|
44
|
+
*
|
|
45
|
+
* Returns `ok: false` without writing when the screen is stale, the definition
|
|
46
|
+
* is not structurally valid, or the definition save refuses the scope. The
|
|
47
|
+
* caller keeps its screen and reports the message.
|
|
48
|
+
*/
|
|
49
|
+
export function saveSkillExposure(input, edit) {
|
|
50
|
+
try {
|
|
51
|
+
const snapshot = loadCatalog(input);
|
|
52
|
+
const entry = snapshot.roles.get(input.entry.id) ?? snapshot.agents.get(input.entry.id);
|
|
53
|
+
if (!entry?.definition || !entry.structurallyValid || entry.duplicate) {
|
|
54
|
+
throw new Error(`Cannot save skills for ${input.entry.id}: repair the catalog definition first. Nothing changed.`);
|
|
55
|
+
}
|
|
56
|
+
const source = input.entry.winningSource;
|
|
57
|
+
if (!source)
|
|
58
|
+
throw new Error(`Cannot save skills for ${input.entry.id}: the definition source is unavailable. Reopen its settings.`);
|
|
59
|
+
if (source.path !== entry.path || source.contentDigest !== entry.contentDigest) {
|
|
60
|
+
throw new Error(`${input.entry.id} changed since this screen opened. Reopen its settings. Nothing changed.`);
|
|
61
|
+
}
|
|
62
|
+
const before = definitionSkillPreference(entry.definition);
|
|
63
|
+
const next = applySkillExposure(entry.definition, edit);
|
|
64
|
+
const after = definitionSkillPreference(next);
|
|
65
|
+
if (sameSkillValue(before, after))
|
|
66
|
+
return { ok: true, message: alreadyMessage(entry.definition, edit) };
|
|
67
|
+
const scope = entry.scope === "project" ? "project" : "user";
|
|
68
|
+
const copiedFromBundled = entry.scope === "bundled";
|
|
69
|
+
const saved = saveDefinition({
|
|
70
|
+
...input,
|
|
71
|
+
definition: next,
|
|
72
|
+
scope,
|
|
73
|
+
replace: true,
|
|
74
|
+
});
|
|
75
|
+
if (!saved.ok || !saved.path) {
|
|
76
|
+
throw new Error(saved.diagnostics.map((item) => item.message).join(" ") || `The ${scope} definition was not written.`);
|
|
77
|
+
}
|
|
78
|
+
const reloaded = loadCatalog(input);
|
|
79
|
+
const persisted = reloaded.roles.get(entry.id) ?? reloaded.agents.get(entry.id);
|
|
80
|
+
const reloadedValue = persisted?.definition ? definitionSkillPreference(persisted.definition) : undefined;
|
|
81
|
+
if (!persisted || !persisted.structurallyValid || !sameSkillValue(reloadedValue, after)) {
|
|
82
|
+
throw new Error(`Saved ${saved.path}, but the reloaded catalog did not report that skill value. Reopen its settings before relying on it.`);
|
|
83
|
+
}
|
|
84
|
+
const prefix = copiedFromBundled ? "Personal definition saved" : "Skills saved";
|
|
85
|
+
return {
|
|
86
|
+
ok: true,
|
|
87
|
+
path: saved.path,
|
|
88
|
+
scope: saved.scope,
|
|
89
|
+
message: `${prefix} (${saved.scope}): ${entry.id} · ${actionLabel(edit)}`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { AgentSessionOverrides } from "./agent-session-settings.mjs";
|
|
2
|
+
import { CATALOG_SCHEMA_VERSION, type CatalogDefinition, type AgentDefinition, type CatalogKind, type CatalogScope, type Diagnostic, type ParseResult } from "./catalog-schema.mjs";
|
|
3
|
+
export type { CatalogScope, CatalogKind, CatalogDefinition, Diagnostic, ParseResult };
|
|
4
|
+
export declare const DEFAULT_PROJECT_CONFIG_DIR_NAME = ".pi";
|
|
5
|
+
export declare const SOURCE_PRECEDENCE: readonly ["project", "user", "bundled"];
|
|
6
|
+
export interface LoadCatalogInput {
|
|
7
|
+
cwd: string;
|
|
8
|
+
/** Host trust decision. Untrusted projects do not contribute definitions. */
|
|
9
|
+
projectTrusted: boolean;
|
|
10
|
+
/** Personal root, usually `PI_CODING_AGENT_DIR` or `~/.pi/agent`. Required so tests never scan the real home by accident. */
|
|
11
|
+
userRoot: string;
|
|
12
|
+
/** Directory of bundled role markdown. Defaults to this package's `roles` directory. */
|
|
13
|
+
bundledRoot?: string;
|
|
14
|
+
/** Optional bundled named-agent directory. The package does not ship agents. */
|
|
15
|
+
bundledAgentsRoot?: string;
|
|
16
|
+
/** Single path segment. Pi hosts should pass `CONFIG_DIR_NAME` (default `.pi`). */
|
|
17
|
+
projectConfigDirName?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface SaveDefinitionInput {
|
|
20
|
+
definition: CatalogDefinition;
|
|
21
|
+
/** Defaults to personal storage. `"project"` must be explicit. */
|
|
22
|
+
scope?: "user" | "project";
|
|
23
|
+
cwd: string;
|
|
24
|
+
projectTrusted: boolean;
|
|
25
|
+
userRoot: string;
|
|
26
|
+
projectConfigDirName?: string;
|
|
27
|
+
/** When false, an existing id in that scope is left untouched. */
|
|
28
|
+
replace?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface UnusedSource {
|
|
31
|
+
scope: CatalogScope;
|
|
32
|
+
path: string;
|
|
33
|
+
contentDigest: string;
|
|
34
|
+
id?: string;
|
|
35
|
+
reason: "shadowed-by-whole-definition" | "blocked-by-invalid-higher-priority" | "blocked-by-duplicate-higher-priority";
|
|
36
|
+
}
|
|
37
|
+
export interface CatalogEntry {
|
|
38
|
+
id: string;
|
|
39
|
+
kind: CatalogKind;
|
|
40
|
+
scope: CatalogScope;
|
|
41
|
+
/** Representative path. Duplicate entries also list every competing path. */
|
|
42
|
+
path: string;
|
|
43
|
+
paths: readonly string[];
|
|
44
|
+
contentDigest: string;
|
|
45
|
+
definition?: CatalogDefinition;
|
|
46
|
+
diagnostics: readonly Diagnostic[];
|
|
47
|
+
structurallyValid: boolean;
|
|
48
|
+
/** Trustworthy definition with no blocking diagnostic. Role existence is checked by the resolver. */
|
|
49
|
+
schemaLaunchable: boolean;
|
|
50
|
+
duplicate: boolean;
|
|
51
|
+
unused: readonly UnusedSource[];
|
|
52
|
+
}
|
|
53
|
+
export interface CatalogSnapshot {
|
|
54
|
+
schema: typeof CATALOG_SCHEMA_VERSION;
|
|
55
|
+
/** Hex sha256 of the canonical snapshot. Excludes `loadedAt`. */
|
|
56
|
+
digest: string;
|
|
57
|
+
revision: string;
|
|
58
|
+
loadedAt: string;
|
|
59
|
+
roles: ReadonlyMap<string, CatalogEntry>;
|
|
60
|
+
agents: ReadonlyMap<string, CatalogEntry>;
|
|
61
|
+
/** Same-scope duplicates. They occupy the id without selecting a filesystem-order winner. */
|
|
62
|
+
blocked: readonly CatalogEntry[];
|
|
63
|
+
diagnostics: readonly Diagnostic[];
|
|
64
|
+
/** Immutable, branch-local preferences; never written by loadCatalog. */
|
|
65
|
+
sessionSettings?: AgentSessionOverrides;
|
|
66
|
+
savedSettings?: AgentSessionOverrides;
|
|
67
|
+
preferenceSources?: Readonly<Record<string, Readonly<Partial<Record<"model" | "effort", {
|
|
68
|
+
scope: "user" | "project";
|
|
69
|
+
path: string;
|
|
70
|
+
bundled?: boolean;
|
|
71
|
+
}>>>>>;
|
|
72
|
+
}
|
|
73
|
+
export interface SaveResult {
|
|
74
|
+
/** True when the file was written. Blocking diagnostics can still make that file unlaunchable. */
|
|
75
|
+
ok: boolean;
|
|
76
|
+
path?: string;
|
|
77
|
+
scope?: "user" | "project";
|
|
78
|
+
diagnostics: Diagnostic[];
|
|
79
|
+
}
|
|
80
|
+
/** Rebuild the same immutable domain value after a JSON socket round trip. */
|
|
81
|
+
export declare function catalogSnapshotFromWire(wire: Omit<CatalogSnapshot, "roles" | "agents"> & {
|
|
82
|
+
roles: Iterable<readonly [string, CatalogEntry]>;
|
|
83
|
+
agents: Iterable<readonly [string, CatalogEntry]>;
|
|
84
|
+
}): CatalogSnapshot;
|
|
85
|
+
export declare function defaultUserRoot(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
86
|
+
export declare function bundledRolesRoot(moduleUrl?: string): string;
|
|
87
|
+
export declare function projectCatalogPaths(cwd: string, projectConfigDirName?: string): {
|
|
88
|
+
root: string;
|
|
89
|
+
roles: string;
|
|
90
|
+
agents: string;
|
|
91
|
+
};
|
|
92
|
+
export declare function userCatalogPaths(userRoot: string): {
|
|
93
|
+
root: string;
|
|
94
|
+
roles: string;
|
|
95
|
+
agents: string;
|
|
96
|
+
};
|
|
97
|
+
export declare function contentDigest(raw: string): string;
|
|
98
|
+
/** Import matching needs every source in the destination scope, including shadowed IDs. */
|
|
99
|
+
export declare function listScopedAgents(input: LoadCatalogInput, scope: "user" | "project"): {
|
|
100
|
+
agents: {
|
|
101
|
+
path: string;
|
|
102
|
+
definition: AgentDefinition;
|
|
103
|
+
}[];
|
|
104
|
+
diagnostics: Diagnostic[];
|
|
105
|
+
};
|
|
106
|
+
/** Read every source again. Identical bytes produce the same digest and a new object. */
|
|
107
|
+
export declare function loadCatalog(input: LoadCatalogInput): CatalogSnapshot;
|
|
108
|
+
export declare function refreshCatalog(input: LoadCatalogInput): CatalogSnapshot;
|
|
109
|
+
export declare function createDefinition(input: SaveDefinitionInput): SaveResult;
|
|
110
|
+
type ResetDefinitionInput = LoadCatalogInput & {
|
|
111
|
+
id: string;
|
|
112
|
+
expectedPath: string;
|
|
113
|
+
expectedDigest: string;
|
|
114
|
+
};
|
|
115
|
+
/** Archive one displayed user override, preserving its model and effort preferences. */
|
|
116
|
+
export declare function resetUserDefinition(input: ResetDefinitionInput): SaveResult & {
|
|
117
|
+
backupPath?: string;
|
|
118
|
+
};
|
|
119
|
+
/** Restore bundled defaults, archiving a user definition and clearing only this id's user preferences. */
|
|
120
|
+
export declare function resetToBundled(input: ResetDefinitionInput): SaveResult & {
|
|
121
|
+
backupPath?: string;
|
|
122
|
+
};
|
|
123
|
+
/** Restore bundled model and effort while keeping every Markdown definition intact. */
|
|
124
|
+
export declare function resetRuntimeToBundled(input: ResetDefinitionInput): SaveResult;
|
|
125
|
+
export declare function saveDefinition(input: SaveDefinitionInput): SaveResult;
|
|
126
|
+
export declare function isSafeConfigDirName(name: string): boolean;
|