@stravica-ai/digital-operator-pa 0.1.13 → 0.1.16
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/README.md +18 -5
- package/dist/engineering-pa-cli/scripts/migrate-doc-paths.mjs +418 -0
- package/dist/engineering-pa-cli/src/agent/audit.mjs +77 -0
- package/dist/engineering-pa-cli/src/agent/cli.mjs +266 -0
- package/dist/engineering-pa-cli/src/agent/probes.mjs +236 -0
- package/dist/engineering-pa-cli/src/autonomy/cli.mjs +1 -1
- package/dist/engineering-pa-cli/src/autonomy/envelope.mjs +19 -300
- package/dist/engineering-pa-cli/src/pa/cli.mjs +8 -0
- package/dist/engineering-pa-cli/src/pa/doc-path.mjs +125 -0
- package/dist/engineering-pa-cli/src/pa/project-cli.mjs +12 -0
- package/dist/engineering-pa-cli/src/pa/projects.mjs +15 -2
- package/dist/engineering-pa-cli/src/pa/workstreams.mjs +22 -4
- package/dist/engineering-pa-core/index.mjs +13 -0
- package/dist/engineering-pa-core/knowledge/scaffold/README.md +66 -0
- package/dist/engineering-pa-core/knowledge/scaffold/agent-baseline.json +132 -0
- package/dist/engineering-pa-core/knowledge/scaffold/agent-baseline.schema.json +146 -0
- package/dist/engineering-pa-core/src/agent-baseline/manifest.mjs +139 -0
- package/dist/engineering-pa-core/src/autonomy/envelope.mjs +301 -0
- package/dist/engineering-pa-scaffold/package.json +3 -0
- package/dist/engineering-pa-scaffold/src/generator.mjs +23 -0
- package/dist/engineering-pa-workspace/app/index.html +8 -3
- package/dist/engineering-pa-workspace/src/api.mjs +11 -1
- package/package.json +2 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# scaffold — baseline manifest + scaffold seeds
|
|
2
|
+
|
|
3
|
+
Machine-readable baselines that shape every fresh PA and every audit against a running one.
|
|
4
|
+
|
|
5
|
+
## `agent-baseline.json`
|
|
6
|
+
|
|
7
|
+
The list of capabilities every operator PA is expected to carry. Each entry is a mechanical presence-probe: `pa agent audit` (packages/cli/src/agent/) diffs an agent estate against this file and reports gaps.
|
|
8
|
+
|
|
9
|
+
Two failure classes it covers, in priority order:
|
|
10
|
+
|
|
11
|
+
1. **Drift** — the platform grows a capability, existing agents never adopt. This is the motivating case. Boot-slice shipped in core 0.1.7, one estate adopted, another never noticed for months. The audit turns adoption into a generated to-do instead of a memory test.
|
|
12
|
+
2. **Creation-time gaps** — a new agent scaffolded by `pa-init` boots missing standard kit. `packages/scaffold/test/manifest-coverage.test.mjs` runs the manifest against the pa-init plan and fails the build if any agents-local capability with a static-path probe is uncovered.
|
|
13
|
+
|
|
14
|
+
### Version-coupling convention
|
|
15
|
+
|
|
16
|
+
Every capability entry carries a `sinceVersion` (the `@stravica-ai/engineering-pa-core` release that introduced it) and the manifest as a whole carries a `manifestVersion` integer.
|
|
17
|
+
|
|
18
|
+
**When a new capability lands:**
|
|
19
|
+
|
|
20
|
+
1. Add the entry to `agent-baseline.json`.
|
|
21
|
+
2. Bump `manifestVersion` by 1.
|
|
22
|
+
3. Set the entry's `sinceVersion` to the core version the change ships in.
|
|
23
|
+
4. Note the manifest bump in `CHANGELOG.md` under the release (line pattern: `agent-baseline: added <capability-id> at manifestVersion N`).
|
|
24
|
+
|
|
25
|
+
**When a capability is removed** (rare — retired platform feature): bump `manifestVersion` and note the removal in the changelog. Never rename an `id` — retire and add.
|
|
26
|
+
|
|
27
|
+
### Probe types (v1)
|
|
28
|
+
|
|
29
|
+
Each probe carries a `type` and its own required fields (see `agent-baseline.schema.json`):
|
|
30
|
+
|
|
31
|
+
| Type | Purpose |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `file-exists` | File at `path` exists. `{paName}` token substituted. |
|
|
34
|
+
| `directory-exists` | Directory at `path` exists (must be a dir, not a file). |
|
|
35
|
+
| `knowledge-doc-exists` | Semantic alias for `file-exists` on `operator/knowledge/**/*.md`. Kept as its own type so future extensions (graph presence, non-orphan) can enrich the check. |
|
|
36
|
+
| `staging-recent-write` | Directory exists AND has a non-hidden entry younger than `maxAgeDays`. Fails only if the newest entry is older than the window. Use with `severity: warn` — a quiet week is not a broken agent. |
|
|
37
|
+
| `schedule-defined` | A JSON file under `path` (typically `schedules/`) whose `command` includes ALL of `commandIncludes` and (if given) AT LEAST ONE of `commandIncludesAny`, and is not `enabled: false`. Host-pinned schedules produce `unverified-here` when the audited host doesn't match. Use with `hostDependent: true`. |
|
|
38
|
+
| `json-field-includes` | Open a JSON file at `path`, check that top-level `field` is an array containing `expectedValue` (token-substituted). Optional `requiredTool` gates the probe: absent tool = `unverified-here`. |
|
|
39
|
+
|
|
40
|
+
### Outcome ladder
|
|
41
|
+
|
|
42
|
+
| Rendered status | When |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `pass` | Probe matched. |
|
|
45
|
+
| `warn` | Probe failed AND capability has `severity: warn` — informational, never gates `--strict`. |
|
|
46
|
+
| `fail` | Probe failed AND capability has `severity: fail` (default). Gates `--strict`. |
|
|
47
|
+
| `unverified-here` | Mechanically indeterminate on this host — host-pinned capability declared for another host, required tool absent from the estate, probe threw. Never a false pass, never a false fail. |
|
|
48
|
+
|
|
49
|
+
### Named defaults (ratified with the operator on approval)
|
|
50
|
+
|
|
51
|
+
- `pa agent audit` exit code default = 0 (informational tool). `--strict` opts into CI-gating exit 2 on any `fail`.
|
|
52
|
+
- `staging-recent-write` window = 7 days, severity `warn` (quiet-week tolerance).
|
|
53
|
+
- Host-dependent probes report `unverified-here`, never `fail`. Precision over noise.
|
|
54
|
+
- Manifest ships in `packages/core/knowledge/scaffold/` (single-bundled via `packages/engineering-pa/build.mjs`), not a separate schema package.
|
|
55
|
+
- Cache path `.session/agent-audit.json`, mirroring `pa environment`'s `.session/environment.json`.
|
|
56
|
+
- `sinceVersion` is the `@stravica-ai/engineering-pa-core` version, not the platform tarball version (manifest lives in core).
|
|
57
|
+
|
|
58
|
+
### Consumers
|
|
59
|
+
|
|
60
|
+
- **`pa agent audit`** — session-boot drift detection. Reads the cache; auto-refreshes on stale.
|
|
61
|
+
- **`pa-init`** (via `manifest-coverage.test.mjs`) — creation-time coverage guard. New capabilities that CAN be scaffolded MUST be scaffolded, or the test fails and forces the scaffold plan update at the same time as the manifest bump.
|
|
62
|
+
- **Future: `boot-context`** — the session-boot hook can surface a one-liner (`3/11 capabilities need adoption`) into the injected workState block.
|
|
63
|
+
|
|
64
|
+
## `domains.json`
|
|
65
|
+
|
|
66
|
+
The base set of knowledge domains seeded into every fresh PA — unchanged by this pass.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./agent-baseline.schema.json",
|
|
3
|
+
"schemaVersion": "1.0",
|
|
4
|
+
"manifestVersion": 1,
|
|
5
|
+
"description": "Baseline capabilities every operator PA agent is expected to carry. Each entry is a mechanical presence-probe: `pa agent audit` diffs an agent estate against this manifest and reports gaps. New capabilities land here at the same time as the platform release that ships them, so drift becomes a generated to-do instead of a memory test. Version-coupling convention: bump `manifestVersion` whenever a new capability entry lands; set the capability's `sinceVersion` to the @stravica-ai/engineering-pa-core release that introduced it. Host-dependent probes MUST carry `hostDependent:true` so a mismatched host is reported as `unverified-here`, not a false fail.",
|
|
6
|
+
"capabilities": [
|
|
7
|
+
{
|
|
8
|
+
"id": "spawn-log",
|
|
9
|
+
"label": "Spawn-log JSON present",
|
|
10
|
+
"sinceVersion": "0.1.0",
|
|
11
|
+
"rationale": "Every dispatch must leave a trail; the spawn-log is the machine-readable record the librarian sweeps.",
|
|
12
|
+
"probe": {
|
|
13
|
+
"type": "file-exists",
|
|
14
|
+
"path": "agents/{paName}/spawn-log.json"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "journal",
|
|
19
|
+
"label": "Self-improvement journal present",
|
|
20
|
+
"sinceVersion": "0.1.0",
|
|
21
|
+
"rationale": "Every PA keeps a journal — the substrate for the librarian's distillation pass.",
|
|
22
|
+
"probe": {
|
|
23
|
+
"type": "file-exists",
|
|
24
|
+
"path": "agents/{paName}/journal.md"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "next-session",
|
|
29
|
+
"label": "Next-session handover file present",
|
|
30
|
+
"sinceVersion": "0.1.0",
|
|
31
|
+
"rationale": "Session-boundary continuity — the top of the file is operator-facing.",
|
|
32
|
+
"probe": {
|
|
33
|
+
"type": "file-exists",
|
|
34
|
+
"path": "agents/{paName}/next-session.md"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"id": "autonomy-envelope",
|
|
39
|
+
"label": "Autonomy-envelope file present",
|
|
40
|
+
"sinceVersion": "0.1.0",
|
|
41
|
+
"rationale": "Per-task-type approval state — the durable record the PA checks when the reflex is unclear.",
|
|
42
|
+
"probe": {
|
|
43
|
+
"type": "file-exists",
|
|
44
|
+
"path": "agents/{paName}/autonomy-envelope.md"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"id": "staging-dir",
|
|
49
|
+
"label": "Staging directory present",
|
|
50
|
+
"sinceVersion": "0.1.0",
|
|
51
|
+
"rationale": "Real-time observation staging — the librarian's inbox. Absent staging dir means the PA has no place to write in-session observations.",
|
|
52
|
+
"probe": {
|
|
53
|
+
"type": "directory-exists",
|
|
54
|
+
"path": "agents/{paName}/staging"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "staging-recent-write",
|
|
59
|
+
"label": "Staging directory has a recent write",
|
|
60
|
+
"sinceVersion": "0.1.0",
|
|
61
|
+
"rationale": "Warns (never fails) if the staging dir has been quiet for longer than the tolerated window — a signal that real-time staging discipline has drifted, but tolerant of legitimate quiet weeks.",
|
|
62
|
+
"severity": "warn",
|
|
63
|
+
"probe": {
|
|
64
|
+
"type": "staging-recent-write",
|
|
65
|
+
"path": "agents/{paName}/staging",
|
|
66
|
+
"maxAgeDays": 7
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "session-end-sop-overlay",
|
|
71
|
+
"label": "Session-boot-and-end SOP overlay present",
|
|
72
|
+
"sinceVersion": "0.1.0",
|
|
73
|
+
"rationale": "The estate-side SOP that layers over the core session-end routine — its absence means the PA is running on the core baseline only, with no estate customisation applied.",
|
|
74
|
+
"probe": {
|
|
75
|
+
"type": "knowledge-doc-exists",
|
|
76
|
+
"path": "operator/knowledge/operator-interface/session-boot-and-end.md"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "boot-slice-job",
|
|
81
|
+
"label": "Boot-slice schedule + output file",
|
|
82
|
+
"sinceVersion": "0.1.7",
|
|
83
|
+
"rationale": "The lightweight boot slice is what the PA loads on every session boot instead of the full profile. Its regeneration is scheduled on a profile-bearing host; the output file must exist somewhere in the estate.",
|
|
84
|
+
"hostDependent": true,
|
|
85
|
+
"probe": {
|
|
86
|
+
"type": "schedule-defined",
|
|
87
|
+
"path": "schedules",
|
|
88
|
+
"commandIncludes": ["slice generate"],
|
|
89
|
+
"outputPathHints": ["operator/profile/slices/"]
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "library-sync-up",
|
|
94
|
+
"label": "Library-sync up-path scheduled",
|
|
95
|
+
"sinceVersion": "0.1.5",
|
|
96
|
+
"rationale": "Fresh estate content must reach canonical on every device that authors it; a missing up-path is the mechanism that produced the 2026-07-14 stale-clobber family.",
|
|
97
|
+
"hostDependent": true,
|
|
98
|
+
"probe": {
|
|
99
|
+
"type": "schedule-defined",
|
|
100
|
+
"path": "schedules",
|
|
101
|
+
"commandIncludes": ["library-sync"],
|
|
102
|
+
"commandIncludesAny": ["--up", "library-sync-cycle"]
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": "library-sync-down",
|
|
107
|
+
"label": "Library-sync down-path scheduled",
|
|
108
|
+
"sinceVersion": "0.1.5",
|
|
109
|
+
"rationale": "Every device must materialise the freshest canonical content. On devices that use the cycle orchestrator the down leg is embedded; standalone down-only schedules also satisfy this probe.",
|
|
110
|
+
"hostDependent": true,
|
|
111
|
+
"probe": {
|
|
112
|
+
"type": "schedule-defined",
|
|
113
|
+
"path": "schedules",
|
|
114
|
+
"commandIncludes": ["library-sync"],
|
|
115
|
+
"commandIncludesAny": ["--down", "library-sync-cycle", "library-sync-refresh"]
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"id": "relay-agent-registration",
|
|
120
|
+
"label": "Agent id registered in claude-relay config",
|
|
121
|
+
"sinceVersion": "0.1.0",
|
|
122
|
+
"rationale": "Cross-agent transport requires the agent id to appear in `operator/extensions/tools/claude-relay/config.json:agents`; absence means no cross-machine relay traffic can address this PA.",
|
|
123
|
+
"probe": {
|
|
124
|
+
"type": "json-field-includes",
|
|
125
|
+
"path": "operator/extensions/tools/claude-relay/config.json",
|
|
126
|
+
"field": "agents",
|
|
127
|
+
"expectedValue": "{paName}",
|
|
128
|
+
"requiredTool": "claude-relay"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Agent Baseline Manifest",
|
|
4
|
+
"description": "Machine-readable baseline of capabilities every operator PA is expected to carry. Consumed by `pa agent audit` and by `pa-init` at scaffold time.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["schemaVersion", "manifestVersion", "capabilities"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": { "type": "string" },
|
|
9
|
+
"schemaVersion": { "type": "string", "const": "1.0" },
|
|
10
|
+
"manifestVersion": {
|
|
11
|
+
"type": "integer",
|
|
12
|
+
"minimum": 1,
|
|
13
|
+
"description": "Monotonic manifest version. Bump on every capability addition/removal so an audit can detect its own manifest is behind."
|
|
14
|
+
},
|
|
15
|
+
"description": { "type": "string" },
|
|
16
|
+
"capabilities": {
|
|
17
|
+
"type": "array",
|
|
18
|
+
"items": { "$ref": "#/definitions/capability" }
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"definitions": {
|
|
22
|
+
"capability": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"required": ["id", "label", "sinceVersion", "rationale", "probe"],
|
|
25
|
+
"additionalProperties": false,
|
|
26
|
+
"properties": {
|
|
27
|
+
"id": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"pattern": "^[a-z0-9][a-z0-9-]*[a-z0-9]$",
|
|
30
|
+
"description": "Stable capability id — kebab-case, referenced in audit output. Never renamed once shipped."
|
|
31
|
+
},
|
|
32
|
+
"label": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "Human-facing one-liner rendered in audit summaries."
|
|
35
|
+
},
|
|
36
|
+
"sinceVersion": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
|
39
|
+
"description": "@stravica-ai/engineering-pa-core version that introduced this capability."
|
|
40
|
+
},
|
|
41
|
+
"rationale": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"description": "Why this capability exists in the baseline. Renders in --verbose audit output."
|
|
44
|
+
},
|
|
45
|
+
"severity": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"enum": ["fail", "warn"],
|
|
48
|
+
"default": "fail",
|
|
49
|
+
"description": "How a missing/failing probe is reported. `warn` never contributes to a non-zero --strict exit."
|
|
50
|
+
},
|
|
51
|
+
"hostDependent": {
|
|
52
|
+
"type": "boolean",
|
|
53
|
+
"default": false,
|
|
54
|
+
"description": "Declares the capability lives on a specific host or subset of hosts. The audit's fail-vs-unverified-here treatment is probe-specific: only `schedule-defined` currently reads host-shape (via each schedule's `host` field) and upgrades a matching-schedule-on-wrong-host outcome to `unverified-here`. For all other probe types, `hostDependent:true` is documentary metadata only — a mechanical fail (missing file, missing directory, missing field) is reported as `fail`, because a missing artefact is missing on every host, not just this one. The upgrade is deliberately kept probe-local: a generic 'hostDependent+fail → unverified-here' fold would silence genuine estate-wide gaps that no host has."
|
|
55
|
+
},
|
|
56
|
+
"probe": {
|
|
57
|
+
"oneOf": [
|
|
58
|
+
{ "$ref": "#/definitions/probeFileExists" },
|
|
59
|
+
{ "$ref": "#/definitions/probeDirectoryExists" },
|
|
60
|
+
{ "$ref": "#/definitions/probeStagingRecentWrite" },
|
|
61
|
+
{ "$ref": "#/definitions/probeKnowledgeDocExists" },
|
|
62
|
+
{ "$ref": "#/definitions/probeScheduleDefined" },
|
|
63
|
+
{ "$ref": "#/definitions/probeJsonFieldIncludes" }
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"probeFileExists": {
|
|
69
|
+
"type": "object",
|
|
70
|
+
"required": ["type", "path"],
|
|
71
|
+
"additionalProperties": false,
|
|
72
|
+
"properties": {
|
|
73
|
+
"type": { "const": "file-exists" },
|
|
74
|
+
"path": { "type": "string", "description": "Path relative to repo root. Tokens: {paName}." }
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"probeDirectoryExists": {
|
|
78
|
+
"type": "object",
|
|
79
|
+
"required": ["type", "path"],
|
|
80
|
+
"additionalProperties": false,
|
|
81
|
+
"properties": {
|
|
82
|
+
"type": { "const": "directory-exists" },
|
|
83
|
+
"path": { "type": "string" }
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"probeKnowledgeDocExists": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"required": ["type", "path"],
|
|
89
|
+
"additionalProperties": false,
|
|
90
|
+
"properties": {
|
|
91
|
+
"type": { "const": "knowledge-doc-exists" },
|
|
92
|
+
"path": { "type": "string" }
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"probeStagingRecentWrite": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"required": ["type", "path", "maxAgeDays"],
|
|
98
|
+
"additionalProperties": false,
|
|
99
|
+
"properties": {
|
|
100
|
+
"type": { "const": "staging-recent-write" },
|
|
101
|
+
"path": { "type": "string" },
|
|
102
|
+
"maxAgeDays": { "type": "number", "minimum": 1 }
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"probeScheduleDefined": {
|
|
106
|
+
"type": "object",
|
|
107
|
+
"required": ["type", "path", "commandIncludes"],
|
|
108
|
+
"additionalProperties": false,
|
|
109
|
+
"properties": {
|
|
110
|
+
"type": { "const": "schedule-defined" },
|
|
111
|
+
"path": { "type": "string", "description": "Directory containing schedule JSON files (typically `schedules`)." },
|
|
112
|
+
"commandIncludes": {
|
|
113
|
+
"type": "array",
|
|
114
|
+
"items": { "type": "string" },
|
|
115
|
+
"minItems": 1,
|
|
116
|
+
"description": "Substrings that MUST all appear (AND) in a schedule's `command` field."
|
|
117
|
+
},
|
|
118
|
+
"commandIncludesAny": {
|
|
119
|
+
"type": "array",
|
|
120
|
+
"items": { "type": "string" },
|
|
121
|
+
"description": "Substrings where AT LEAST ONE (OR) must appear in the same schedule's command."
|
|
122
|
+
},
|
|
123
|
+
"outputPathHints": {
|
|
124
|
+
"type": "array",
|
|
125
|
+
"items": { "type": "string" },
|
|
126
|
+
"description": "Optional path substrings that, if present in the estate, corroborate the schedule's declared output."
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"probeJsonFieldIncludes": {
|
|
131
|
+
"type": "object",
|
|
132
|
+
"required": ["type", "path", "field", "expectedValue"],
|
|
133
|
+
"additionalProperties": false,
|
|
134
|
+
"properties": {
|
|
135
|
+
"type": { "const": "json-field-includes" },
|
|
136
|
+
"path": { "type": "string" },
|
|
137
|
+
"field": { "type": "string", "description": "Top-level JSON field name (dot-path not supported in v1)." },
|
|
138
|
+
"expectedValue": { "type": "string", "description": "Value expected in the field's array. Tokens: {paName}." },
|
|
139
|
+
"requiredTool": {
|
|
140
|
+
"type": "string",
|
|
141
|
+
"description": "If set, the probe is skipped (unverified-here) when the named tool directory is absent under operator/extensions/tools/."
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// manifest.mjs — loader for the agent baseline manifest.
|
|
2
|
+
//
|
|
3
|
+
// The manifest itself lives at
|
|
4
|
+
// packages/core/knowledge/scaffold/agent-baseline.json
|
|
5
|
+
// and is shipped inside the core package (single-bundled by
|
|
6
|
+
// packages/engineering-pa/build.mjs at publish time). Downstream code
|
|
7
|
+
// resolves the on-disk path via `bundledManifestPath()` — no hard-coded
|
|
8
|
+
// consumer paths.
|
|
9
|
+
|
|
10
|
+
import { readFile } from 'node:fs/promises';
|
|
11
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
12
|
+
import { dirname, resolve } from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Absolute path to the manifest shipped inside this package. Resolves both
|
|
19
|
+
* in the dev workspace (packages/core/knowledge/scaffold/agent-baseline.json)
|
|
20
|
+
* and in the published tarball (dist/engineering-pa-core/knowledge/scaffold/agent-baseline.json).
|
|
21
|
+
*/
|
|
22
|
+
export function bundledManifestPath() {
|
|
23
|
+
return resolve(__dirname, '..', '..', 'knowledge', 'scaffold', 'agent-baseline.json');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Load the bundled manifest synchronously. Throws with a clear diagnostic
|
|
28
|
+
* if the file is missing or malformed — callers surface that via exit
|
|
29
|
+
* code 2 (unresolvable state).
|
|
30
|
+
*/
|
|
31
|
+
export function loadBundledManifestSync() {
|
|
32
|
+
const path = bundledManifestPath();
|
|
33
|
+
if (!existsSync(path)) {
|
|
34
|
+
const err = new Error(`agent baseline manifest missing at ${path}`);
|
|
35
|
+
err.exitCode = 2;
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
const raw = readFileSync(path, 'utf8');
|
|
39
|
+
return parseManifest(raw, path);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Async loader for the bundled manifest. Same contract as the sync form.
|
|
44
|
+
*/
|
|
45
|
+
export async function loadBundledManifest() {
|
|
46
|
+
const path = bundledManifestPath();
|
|
47
|
+
const raw = await readFile(path, 'utf8');
|
|
48
|
+
return parseManifest(raw, path);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parse + shape-validate a raw manifest string. Rejects obvious structural
|
|
53
|
+
* corruption (missing capabilities array, empty ids, unknown probe types)
|
|
54
|
+
* — a false PASS at boot time would be worse than a loud crash.
|
|
55
|
+
*/
|
|
56
|
+
export function parseManifest(raw, sourcePath = '<manifest>') {
|
|
57
|
+
let doc;
|
|
58
|
+
try {
|
|
59
|
+
doc = JSON.parse(raw);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
const wrapped = new Error(`agent baseline manifest at ${sourcePath} is not valid JSON: ${err.message}`);
|
|
62
|
+
wrapped.exitCode = 2;
|
|
63
|
+
throw wrapped;
|
|
64
|
+
}
|
|
65
|
+
if (!doc || typeof doc !== 'object') {
|
|
66
|
+
throw shapeError(`manifest ${sourcePath}: not an object`);
|
|
67
|
+
}
|
|
68
|
+
if (doc.schemaVersion !== '1.0') {
|
|
69
|
+
throw shapeError(`manifest ${sourcePath}: schemaVersion must be "1.0" (got ${JSON.stringify(doc.schemaVersion)})`);
|
|
70
|
+
}
|
|
71
|
+
if (typeof doc.manifestVersion !== 'number' || !Number.isInteger(doc.manifestVersion) || doc.manifestVersion < 1) {
|
|
72
|
+
throw shapeError(`manifest ${sourcePath}: manifestVersion must be a positive integer`);
|
|
73
|
+
}
|
|
74
|
+
if (!Array.isArray(doc.capabilities)) {
|
|
75
|
+
throw shapeError(`manifest ${sourcePath}: capabilities must be an array`);
|
|
76
|
+
}
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
for (const cap of doc.capabilities) {
|
|
79
|
+
validateCapability(cap, sourcePath, seen);
|
|
80
|
+
}
|
|
81
|
+
return doc;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function validateCapability(cap, sourcePath, seen) {
|
|
85
|
+
if (!cap || typeof cap !== 'object') {
|
|
86
|
+
throw shapeError(`manifest ${sourcePath}: capability entry is not an object`);
|
|
87
|
+
}
|
|
88
|
+
for (const field of ['id', 'label', 'sinceVersion', 'rationale']) {
|
|
89
|
+
if (typeof cap[field] !== 'string' || cap[field].length === 0) {
|
|
90
|
+
throw shapeError(`manifest ${sourcePath}: capability missing required string field '${field}'`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(cap.id)) {
|
|
94
|
+
throw shapeError(`manifest ${sourcePath}: capability id ${JSON.stringify(cap.id)} is not kebab-case`);
|
|
95
|
+
}
|
|
96
|
+
if (seen.has(cap.id)) {
|
|
97
|
+
throw shapeError(`manifest ${sourcePath}: duplicate capability id ${JSON.stringify(cap.id)}`);
|
|
98
|
+
}
|
|
99
|
+
seen.add(cap.id);
|
|
100
|
+
if (cap.severity && cap.severity !== 'fail' && cap.severity !== 'warn') {
|
|
101
|
+
throw shapeError(`manifest ${sourcePath}: capability ${cap.id} has invalid severity ${JSON.stringify(cap.severity)}`);
|
|
102
|
+
}
|
|
103
|
+
if (!cap.probe || typeof cap.probe !== 'object' || typeof cap.probe.type !== 'string') {
|
|
104
|
+
throw shapeError(`manifest ${sourcePath}: capability ${cap.id} has no probe.type`);
|
|
105
|
+
}
|
|
106
|
+
const supported = new Set([
|
|
107
|
+
'file-exists',
|
|
108
|
+
'directory-exists',
|
|
109
|
+
'staging-recent-write',
|
|
110
|
+
'knowledge-doc-exists',
|
|
111
|
+
'schedule-defined',
|
|
112
|
+
'json-field-includes',
|
|
113
|
+
]);
|
|
114
|
+
if (!supported.has(cap.probe.type)) {
|
|
115
|
+
throw shapeError(`manifest ${sourcePath}: capability ${cap.id} declares unknown probe.type ${JSON.stringify(cap.probe.type)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function shapeError(msg) {
|
|
120
|
+
const err = new Error(msg);
|
|
121
|
+
err.exitCode = 2;
|
|
122
|
+
return err;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Substitute {paName} tokens in a path template. Extend here if new tokens
|
|
127
|
+
* land — kept small on purpose (path templates are configuration, not code).
|
|
128
|
+
*/
|
|
129
|
+
export function expandTemplate(str, tokens) {
|
|
130
|
+
if (typeof str !== 'string') return str;
|
|
131
|
+
return str.replaceAll('{paName}', tokens.paName);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Derive the effective severity of a capability (default: fail).
|
|
136
|
+
*/
|
|
137
|
+
export function capabilitySeverity(cap) {
|
|
138
|
+
return cap.severity ?? 'fail';
|
|
139
|
+
}
|