@gregiteen/ssss-cli 0.7.0 → 0.8.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/CHANGELOG.md +63 -4
- package/README.md +29 -13
- package/VERSION +1 -1
- package/conformance/README.md +17 -11
- package/conformance/fixtures.json +68 -2
- package/conformance/reference-bundle.ucw.json +39 -5
- package/docs/help/bundle.md +6 -2
- package/docs/help/import.md +6 -2
- package/docs/help/leases.md +31 -0
- package/docs/help/localization.md +43 -0
- package/docs/help/overview.md +9 -5
- package/docs/help/portability.md +11 -3
- package/docs/help/runtime.md +3 -3
- package/docs/help/scaffold.md +2 -2
- package/docs/help/semantic.md +37 -0
- package/docs/ssss-spec.md +112 -7
- package/package.json +8 -3
- package/registry/core.json +43 -3
- package/scripts/audit-registry-field-usage.mjs +10 -1
- package/scripts/build-reference-bundle.mjs +25 -2
- package/scripts/cmd-export.mjs +3 -3
- package/scripts/cmd-import.mjs +5 -1
- package/scripts/cmd-localize.mjs +44 -0
- package/scripts/cmd-new.mjs +11 -11
- package/scripts/cmd-semantic.mjs +88 -0
- package/scripts/conformance.mjs +574 -2
- package/scripts/ssss.mjs +6 -2
- package/skills/ssss/SKILL.md +225 -0
- package/skills/ssss/evals/evals.json +37 -0
- package/skills/ssss/references/contract-reference.md +96 -0
- package/skills/ssss/scripts/validate-schema.mjs +258 -0
- package/skills/ssss/subagents/audit-ssss-contract.md +22 -0
- package/src/bundle.mjs +266 -41
- package/src/engine.mjs +78 -4
- package/src/frontmatter.mjs +141 -38
- package/src/registry.mjs +249 -7
- package/src/semantic.mjs +402 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: skill
|
|
3
|
+
title: SSSS System Manager
|
|
4
|
+
name: ssss
|
|
5
|
+
description: "Inspect, validate, implement, or change SSSS primitives, extension registries, operation envelopes, workflow runtimes, semantic search, translation/localization overlays, bundles, projections, and host adapters. Use for SSSS schema changes, registry collisions, conformance failures, portability/privacy questions, or translatable semantic vault work. MANDATORY: Read this file before editing SSSS files or code."
|
|
6
|
+
timestamp: 2026-07-10T00:00:00Z
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# SSSS — Structured Semantic Syntax System Manager
|
|
10
|
+
|
|
11
|
+
SSSS is a vendor-neutral, Markdown-first state and mutation contract. Canonical
|
|
12
|
+
state is typed Markdown plus append-only events. Databases, indexes, queues,
|
|
13
|
+
dashboards, and search stores are host projections unless explicitly documented
|
|
14
|
+
as external resources.
|
|
15
|
+
|
|
16
|
+
## Establish Ground Truth First
|
|
17
|
+
|
|
18
|
+
Do not infer the contract from an installed skill snapshot.
|
|
19
|
+
|
|
20
|
+
1. Find the repository root and inspect `package.json`, `VERSION`,
|
|
21
|
+
`registry/core.json`, and `docs/ssss-spec.md` when they exist.
|
|
22
|
+
2. Treat `registry/core.json` as the machine-readable primitive contract and
|
|
23
|
+
`docs/ssss-spec.md` as the normative explanation.
|
|
24
|
+
3. Treat `src/engine.mjs`, `src/runtime.mjs`, `src/semantic.mjs`,
|
|
25
|
+
`src/bundle.mjs`, `src/registry.mjs`, and `src/frontmatter.mjs` as the
|
|
26
|
+
reference behavior.
|
|
27
|
+
4. Treat host schemas and services as adapters or extension registries. Never
|
|
28
|
+
promote host-only fields into the core standard without an explicit spec and
|
|
29
|
+
registry change.
|
|
30
|
+
5. Read the current package name and version instead of hard-coding an alias.
|
|
31
|
+
In this checkout the published package is `@gregiteen/ssss-cli`; the CLI is
|
|
32
|
+
`ssss`.
|
|
33
|
+
|
|
34
|
+
If those files are absent, inspect the installed
|
|
35
|
+
`@gregiteen/ssss-cli/registry/core.json` export. Use the bundled reference only
|
|
36
|
+
as a fallback and report that the result is snapshot-based.
|
|
37
|
+
|
|
38
|
+
## Authority Order
|
|
39
|
+
|
|
40
|
+
When sources disagree, resolve drift in this order:
|
|
41
|
+
|
|
42
|
+
1. Conformance fixtures and tests for observed executable behavior.
|
|
43
|
+
2. `registry/core.json` for required fields, enums, append behavior, and
|
|
44
|
+
portability.
|
|
45
|
+
3. `docs/ssss-spec.md` for normative semantics.
|
|
46
|
+
4. Reference engine/runtime/bundle code.
|
|
47
|
+
5. Host extension registry and host adapter documentation.
|
|
48
|
+
6. Skills, examples, README prose, and copied mirrors.
|
|
49
|
+
|
|
50
|
+
Do not silently pick one side. Identify the mismatch, decide whether code or
|
|
51
|
+
canon is wrong, update every affected source, and add a regression check.
|
|
52
|
+
|
|
53
|
+
## Document Contract
|
|
54
|
+
|
|
55
|
+
Every SSSS document has YAML frontmatter and a Markdown body. SSSS-managed
|
|
56
|
+
documents require the universal fields:
|
|
57
|
+
|
|
58
|
+
- `type`
|
|
59
|
+
- `title`
|
|
60
|
+
- `description`
|
|
61
|
+
- `timestamp`
|
|
62
|
+
|
|
63
|
+
Primitive-specific required fields are additive. An SSSS-managed skill also
|
|
64
|
+
requires `name`; a schema-v2 memory has knowledge-graph fields; a workflow
|
|
65
|
+
requires `name`.
|
|
66
|
+
|
|
67
|
+
Unknown frontmatter fields must be preserved for forward compatibility. Never
|
|
68
|
+
drop a nested map, array, or unknown field during parse/serialize or patch.
|
|
69
|
+
|
|
70
|
+
Registry declarations are executable contract. Enforce `required_fields`,
|
|
71
|
+
`required_when`, `enums`, `patterns`, `immutable_fields`, `references`,
|
|
72
|
+
`append_only`, and `portability`. Reject malformed extension definitions,
|
|
73
|
+
symlinked registry files, and core or sibling type collisions during load.
|
|
74
|
+
|
|
75
|
+
## Mutation Contract
|
|
76
|
+
|
|
77
|
+
Agent-generated mutations flow through the Operation Contract:
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
validate envelope
|
|
81
|
+
-> verify safe workspace/idempotency/actor identifiers
|
|
82
|
+
-> resolve and contain the target path
|
|
83
|
+
-> replay or reject the idempotency key + request hash
|
|
84
|
+
-> authorize with verified actor identity (fail closed)
|
|
85
|
+
-> validate any active lease (fail closed)
|
|
86
|
+
-> validate universal + primitive-specific content
|
|
87
|
+
-> commit atomically
|
|
88
|
+
-> append the audit event
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The mutation envelopes are:
|
|
92
|
+
|
|
93
|
+
- `operation` — create or fully replace a replace-type document.
|
|
94
|
+
- `patch` — merge an existing replace-type document without changing `type`.
|
|
95
|
+
- `event` — append an immutable event record.
|
|
96
|
+
- `delete` — remove a replace-type document and emit an audit event; reject
|
|
97
|
+
append-type targets.
|
|
98
|
+
|
|
99
|
+
Use `dry_run: true` for model-generated preflight. Idempotency is scoped by the
|
|
100
|
+
effective request, not the key alone: the same request replays, while the same
|
|
101
|
+
workspace/key with a different request hash is a conflict.
|
|
102
|
+
|
|
103
|
+
## Append, Lease, and Path Safety
|
|
104
|
+
|
|
105
|
+
- `conversation` and `run` are append-only. Preserve prior bytes and append new
|
|
106
|
+
records; never rewrite or delete them.
|
|
107
|
+
- Events are immutable.
|
|
108
|
+
- Paths must be relative, contained vault paths. Reject absolute paths,
|
|
109
|
+
backslashes, null bytes, empty segments, `.`/`..`, directory targets, and
|
|
110
|
+
symlink escapes.
|
|
111
|
+
- Leases are actor-owned, operation-linked, expiring locks. Missing, mismatched,
|
|
112
|
+
malformed, or unreadable lease state fails closed.
|
|
113
|
+
- Hosts must overwrite caller-supplied actor data with verified session identity
|
|
114
|
+
before authorization.
|
|
115
|
+
|
|
116
|
+
## Workflow Runtime
|
|
117
|
+
|
|
118
|
+
Workflow frontmatter owns the schedule. Cron, daemon, webhook, file watcher, and
|
|
119
|
+
event-loop processes are wake-up mechanisms, not a second scheduling database.
|
|
120
|
+
|
|
121
|
+
Use `@gregiteen/ssss-cli/runtime` to deterministically derive the trigger event,
|
|
122
|
+
task, and run envelopes. Duplicate ticks must replay idempotently. Queues and
|
|
123
|
+
task dashboards are disposable projections over workflow state and events.
|
|
124
|
+
|
|
125
|
+
## Bundles and Portability
|
|
126
|
+
|
|
127
|
+
Every document primitive resolves to one portability class:
|
|
128
|
+
|
|
129
|
+
- `structural` — reusable model shipped in templates and sale bundles.
|
|
130
|
+
- `tenant_private` — operator/customer runtime data; excluded from template and
|
|
131
|
+
sale exports.
|
|
132
|
+
- `resource_bound` — exported only as a requirement declaration; never leak the
|
|
133
|
+
seller's bound resource value.
|
|
134
|
+
|
|
135
|
+
Bundle paths must be unique, safe, and symlink-free. Validate content hashes,
|
|
136
|
+
required extensions, primitive inventory, core version, parameters, and link
|
|
137
|
+
integrity before import. Preflight the complete plan before the first commit so a
|
|
138
|
+
late invalid envelope cannot leave a partial install. Provisioning produces
|
|
139
|
+
deterministic Operation Contract envelopes; re-import must be a no-op.
|
|
140
|
+
|
|
141
|
+
## Semantic Search and Localization
|
|
142
|
+
|
|
143
|
+
Treat semantic indexes and localized trees as disposable projections. Use
|
|
144
|
+
`@gregiteen/ssss-cli/semantic`, `ssss semantic`, and `ssss localize` for the
|
|
145
|
+
dependency-free reference behavior.
|
|
146
|
+
|
|
147
|
+
- Index only `structural` documents by default. Include `tenant_private` and
|
|
148
|
+
`resource_bound` sources only after an explicit authorized opt-in.
|
|
149
|
+
- Derive stable identity from `semantic_id`, then `resource`, then source path.
|
|
150
|
+
- Build edges from explicit `relations`, wiki links, and Markdown links.
|
|
151
|
+
- Keep projection output outside the source vault; reject symlinks and unsafe paths,
|
|
152
|
+
and stage the complete tree before publishing it.
|
|
153
|
+
- Model localization as a `translation` document pointing to an existing
|
|
154
|
+
structural source and its exact SHA-256 content hash.
|
|
155
|
+
- Translate only `title`, `description`, and body. Preserve types, ids, enums,
|
|
156
|
+
permissions, status, portability, relations, and paths from the source.
|
|
157
|
+
- Apply approved overlays by default. Reject stale hashes, duplicate locale/source
|
|
158
|
+
overlays, recursive translations, private sources, and immutable identity edits.
|
|
159
|
+
|
|
160
|
+
## Scope and Host Adapters
|
|
161
|
+
|
|
162
|
+
The core standard does not collapse host ownership layers. A host may implement
|
|
163
|
+
global/project or system/account/workspace overlays, but must document precedence
|
|
164
|
+
and preserve isolation. Shared system skills should be inherited through an
|
|
165
|
+
overlay rather than copied into every workspace.
|
|
166
|
+
|
|
167
|
+
When working in Total Recall, use its validated-write and memory-validator
|
|
168
|
+
adapter if those modules exist. In another host, locate its extension registry
|
|
169
|
+
and conformance bridge. Do not quote Total Recall paths as universal SSSS
|
|
170
|
+
architecture.
|
|
171
|
+
|
|
172
|
+
## Procedure for Changes
|
|
173
|
+
|
|
174
|
+
1. Classify the change: core primitive, contract behavior, runtime behavior,
|
|
175
|
+
semantic/localization behavior, bundle/provisioning behavior, projection, or
|
|
176
|
+
host extension.
|
|
177
|
+
2. Inspect the registry, spec section, implementation, fixtures, and host bridge
|
|
178
|
+
for that surface.
|
|
179
|
+
3. Make the smallest coherent change across code and canon.
|
|
180
|
+
4. Add positive, negative, replay, and invalid-path cases where applicable.
|
|
181
|
+
5. Run focused validation, then the full conformance gate.
|
|
182
|
+
6. Update skill/reference mirrors only after the executable contract is green.
|
|
183
|
+
|
|
184
|
+
## Validation
|
|
185
|
+
|
|
186
|
+
Validate a Markdown document with the dependency-free skill helper:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
node skills/ssss/scripts/validate-schema.mjs path/to/document.md
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
In the SSSS reference repository, the required gate is:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
npm test
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
It covers registry/engine parity, shipped-skill conformance, Operation Contract
|
|
199
|
+
fixtures, workflow runtime behavior, lease/frontmatter regressions,
|
|
200
|
+
extension-registry hardening, semantic/localization behavior,
|
|
201
|
+
bundle/provisioning round trips, and CLI smoke tests.
|
|
202
|
+
|
|
203
|
+
For host adapters, run the host's named SSSS conformance command as well. Do not
|
|
204
|
+
substitute a loose YAML parse or a generic typecheck for the SSSS gate.
|
|
205
|
+
|
|
206
|
+
## Do Not
|
|
207
|
+
|
|
208
|
+
- Do not treat an installed skill, copied spec, or README as newer than the live
|
|
209
|
+
registry and conformance suite.
|
|
210
|
+
- Do not use raw file writes for agent-generated vault mutations.
|
|
211
|
+
- Do not make a derived database/index/queue the canonical record.
|
|
212
|
+
- Do not add a primitive in prose without registry and fixture coverage.
|
|
213
|
+
- Do not translate symbolic control fields or index private content by default.
|
|
214
|
+
- Do not materialize a projection inside its source vault.
|
|
215
|
+
- Do not mix document primitives with contract envelopes.
|
|
216
|
+
- Do not claim conformance from HTTP success or file creation alone.
|
|
217
|
+
- Do not publish package names, versions, or exporter identities without reading
|
|
218
|
+
them from current package metadata.
|
|
219
|
+
|
|
220
|
+
## References
|
|
221
|
+
|
|
222
|
+
Read `references/contract-reference.md` for the compact topology, primitive
|
|
223
|
+
families, package entry points, and drift checklist. For normative detail, read
|
|
224
|
+
the exact linked section of `docs/ssss-spec.md` rather than loading a stale
|
|
225
|
+
vendored copy.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "ssss-skill-validates-as-primitive",
|
|
4
|
+
"assertion": "SKILL.md includes universal SSSS frontmatter plus type: skill, name: ssss, and a trigger-optimized description.",
|
|
5
|
+
"severity": "error"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "ssss-canon-is-evidence-first",
|
|
9
|
+
"assertion": "The skill tells agents to inspect package metadata, registry, spec, implementation, and conformance instead of trusting a copied snapshot.",
|
|
10
|
+
"severity": "error"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"name": "ssss-validator-is-dependency-free",
|
|
14
|
+
"assertion": "scripts/validate-schema.mjs runs with Node built-ins and validates universal plus primitive-specific fields.",
|
|
15
|
+
"severity": "error"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "ssss-host-boundaries-are-explicit",
|
|
19
|
+
"assertion": "The skill distinguishes the vendor-neutral reference kernel from Total Recall and other host adapters.",
|
|
20
|
+
"severity": "error"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "ssss-full-gate-is-named",
|
|
24
|
+
"assertion": "The skill requires npm test in the reference repository and the host-specific SSSS conformance gate for adapters.",
|
|
25
|
+
"severity": "error"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "ssss-semantic-default-is-private",
|
|
29
|
+
"assertion": "The skill requires structural-only semantic and localization projections by default, with explicit authorization before private or resource-bound indexing.",
|
|
30
|
+
"severity": "error"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "ssss-translations-preserve-controls",
|
|
34
|
+
"assertion": "The skill limits translations to title, description, and body; requires an exact structural source hash; and preserves symbolic control fields.",
|
|
35
|
+
"severity": "error"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# SSSS Contract Reference
|
|
2
|
+
|
|
3
|
+
This is an operational map. The normative source is the current
|
|
4
|
+
`docs/ssss-spec.md`; the machine-readable source is `registry/core.json`.
|
|
5
|
+
|
|
6
|
+
## Reference-kernel topology
|
|
7
|
+
|
|
8
|
+
| Surface | Responsibility |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| `registry/core.json` | Core document/contract primitives, universal fields, enums, portability, bundle/runtime vocabularies. |
|
|
11
|
+
| `registry/extensions/*.json` | Host/application types that cannot redefine core primitives. |
|
|
12
|
+
| `src/engine.mjs` | Operation Contract, validation, authorization, leases, idempotency, atomic commit, audit. |
|
|
13
|
+
| `src/runtime.mjs` | Workflow trigger planning and deterministic event/task/run envelopes. |
|
|
14
|
+
| `src/semantic.mjs` | Deterministic semantic records/edges, localized search, and safe materialization. |
|
|
15
|
+
| `src/bundle.mjs` | Export, validate, provision, import, portability filtering, link/hash integrity. |
|
|
16
|
+
| `src/registry.mjs` | Registry loading and type/portability resolution. |
|
|
17
|
+
| `src/frontmatter.mjs` | Dependency-free parse/serialize with unknown-field preservation. |
|
|
18
|
+
| `conformance/fixtures.json` | Canonical mutation examples and negative cases. |
|
|
19
|
+
| `scripts/conformance.mjs` | Full executable contract gate. |
|
|
20
|
+
|
|
21
|
+
## Package entry points
|
|
22
|
+
|
|
23
|
+
Read the npm package name from `package.json`. The current reference checkout
|
|
24
|
+
uses `@gregiteen/ssss-cli` and exposes `/engine`, `/runtime`, `/semantic`, `/bundle`,
|
|
25
|
+
`/registry`, `/frontmatter`, `/registry/core.json`,
|
|
26
|
+
`/conformance/fixtures.json`, and `/conformance/reference-bundle.ucw.json`.
|
|
27
|
+
The executable command is `ssss`.
|
|
28
|
+
|
|
29
|
+
## Document versus contract primitives
|
|
30
|
+
|
|
31
|
+
Document primitives persist as Markdown and carry universal frontmatter.
|
|
32
|
+
Contract primitives are mutation/concurrency envelopes and are not Markdown
|
|
33
|
+
document types.
|
|
34
|
+
|
|
35
|
+
Current core document families include knowledge (`memory`), capability
|
|
36
|
+
(`skill`, `page`), governance (`rule`, `security_role`), work (`task`,
|
|
37
|
+
`workflow`), actors/catalog (`assistant`, `model`), transcripts (`conversation`,
|
|
38
|
+
`run`), localization (`translation`), and lifecycle/meta (`conflict`, `migration`,
|
|
39
|
+
`release`).
|
|
40
|
+
|
|
41
|
+
The contract primitives are `operation`, `patch`, `event`, `delete`, and
|
|
42
|
+
`lease`.
|
|
43
|
+
|
|
44
|
+
## Required validation dimensions
|
|
45
|
+
|
|
46
|
+
For a document:
|
|
47
|
+
|
|
48
|
+
1. Frontmatter exists and parses.
|
|
49
|
+
2. Universal fields are present and non-empty.
|
|
50
|
+
3. `type` exists in the core or a loaded extension registry.
|
|
51
|
+
4. Primitive-specific required/conditional fields are present.
|
|
52
|
+
5. Enum values are valid.
|
|
53
|
+
6. Pattern constraints match and document references resolve safely.
|
|
54
|
+
7. Immutable fields do not change during replacement or patch.
|
|
55
|
+
8. Append-only behavior is preserved.
|
|
56
|
+
9. Unknown fields survive parse/serialize and patch.
|
|
57
|
+
10. Path and canonical filename rules hold where applicable.
|
|
58
|
+
|
|
59
|
+
For an envelope:
|
|
60
|
+
|
|
61
|
+
1. Envelope type and identifiers are valid.
|
|
62
|
+
2. Target path is relative and contained.
|
|
63
|
+
3. Idempotency replay is bound to the request hash.
|
|
64
|
+
4. Actor identity is verified and authorization fails closed.
|
|
65
|
+
5. Lease state is valid or the write is rejected.
|
|
66
|
+
6. Content validates against universal plus primitive-specific rules.
|
|
67
|
+
7. Commit is atomic and emits an audit event.
|
|
68
|
+
|
|
69
|
+
For a bundle:
|
|
70
|
+
|
|
71
|
+
1. Manifest shape and core version are supported.
|
|
72
|
+
2. Required extensions are loaded.
|
|
73
|
+
3. Paths are safe, unique, and sorted.
|
|
74
|
+
4. Content hash and primitive inventory match.
|
|
75
|
+
5. Portability prevents tenant-private and resource-value leakage.
|
|
76
|
+
6. Parameters/provisioning use registry vocabularies.
|
|
77
|
+
7. Internal links resolve after remapping.
|
|
78
|
+
8. Re-import replays without new commits.
|
|
79
|
+
|
|
80
|
+
For a semantic/localization projection:
|
|
81
|
+
|
|
82
|
+
1. Records and index hashes are deterministic for identical inputs.
|
|
83
|
+
2. Stable identity, tokens, content hashes, portability, and graph edges are retained.
|
|
84
|
+
3. Private and resource-bound documents are excluded unless explicitly authorized.
|
|
85
|
+
4. A translation targets one structural, non-translation source by safe relative path.
|
|
86
|
+
5. The source hash is exact and only natural-language surface fields change.
|
|
87
|
+
6. Duplicate, stale, traversing, symlinked, or recursive overlays fail closed.
|
|
88
|
+
7. Materialization occurs outside the source vault and remains rebuildable.
|
|
89
|
+
|
|
90
|
+
## Drift checklist
|
|
91
|
+
|
|
92
|
+
Compare package/version metadata, spec and registry versions, registry fields
|
|
93
|
+
against engine consumption, `spec_ref` headings, docs/skills against package
|
|
94
|
+
exports, reference-bundle provenance, host extensions against core ownership,
|
|
95
|
+
and generated/symlinked skill copies against tracked sources. Add a deterministic
|
|
96
|
+
check for every drift class that has occurred once.
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const FALLBACK_UNIVERSAL = ['type', 'title', 'description', 'timestamp'];
|
|
8
|
+
const FALLBACK_REQUIRED = {
|
|
9
|
+
memory: ['slug', 'category', 'status', 'schema_version'],
|
|
10
|
+
skill: ['name'],
|
|
11
|
+
rule: ['name'],
|
|
12
|
+
security_role: ['name', 'permissions'],
|
|
13
|
+
task: ['priority', 'category', 'status'],
|
|
14
|
+
assistant: ['name'],
|
|
15
|
+
workflow: ['name'],
|
|
16
|
+
model: ['model_id', 'provider'],
|
|
17
|
+
conversation: ['thread_id'],
|
|
18
|
+
run: ['run_id', 'workflow_id'],
|
|
19
|
+
conflict: ['conflict_id', 'status', 'new_slug', 'existing_slug', 'detected_at'],
|
|
20
|
+
page: ['slug', 'name', 'sandbox_entry'],
|
|
21
|
+
migration: ['migration_id', 'from_version', 'to_version', 'status'],
|
|
22
|
+
release: ['release_id', 'version', 'schema_version', 'summary', 'released_at'],
|
|
23
|
+
translation: ['translation_id', 'source_path', 'source_hash', 'locale', 'status', 'translated_fields'],
|
|
24
|
+
};
|
|
25
|
+
const CONTRACT_TYPES = new Set(['operation', 'patch', 'event', 'delete', 'lease']);
|
|
26
|
+
const APPEND_TYPES = new Set(['conversation', 'run']);
|
|
27
|
+
|
|
28
|
+
function findUp(start, predicate) {
|
|
29
|
+
let dir = path.resolve(start);
|
|
30
|
+
while (true) {
|
|
31
|
+
if (predicate(dir)) return dir;
|
|
32
|
+
const parent = path.dirname(dir);
|
|
33
|
+
if (parent === dir) return null;
|
|
34
|
+
dir = parent;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function findKernelRoot(start) {
|
|
39
|
+
return findUp(start, (dir) =>
|
|
40
|
+
fs.existsSync(path.join(dir, 'registry', 'core.json')) &&
|
|
41
|
+
fs.existsSync(path.join(dir, 'src', 'frontmatter.mjs'))
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function parseScalar(value) {
|
|
46
|
+
const text = value.trim();
|
|
47
|
+
if (!text) return '';
|
|
48
|
+
if ((text.startsWith('"') && text.endsWith('"')) ||
|
|
49
|
+
(text.startsWith("'") && text.endsWith("'"))) return text.slice(1, -1);
|
|
50
|
+
if (text === 'true') return true;
|
|
51
|
+
if (text === 'false') return false;
|
|
52
|
+
if (text === 'null' || text === '~') return null;
|
|
53
|
+
if (/^-?\d+(?:\.\d+)?$/.test(text)) return Number(text);
|
|
54
|
+
if (text.startsWith('[') && text.endsWith(']')) {
|
|
55
|
+
return text.slice(1, -1).split(',').map((item) => parseScalar(item)).filter((item) => item !== '');
|
|
56
|
+
}
|
|
57
|
+
return text;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function parseFallback(raw) {
|
|
61
|
+
const lines = raw.replace(/\r\n/g, '\n').split('\n');
|
|
62
|
+
if (lines[0]?.trim() !== '---') throw new Error('Missing YAML frontmatter block.');
|
|
63
|
+
const close = lines.findIndex((line, index) => index > 0 && line.trim() === '---');
|
|
64
|
+
if (close < 0) throw new Error('Unclosed YAML frontmatter block.');
|
|
65
|
+
const data = {};
|
|
66
|
+
let collectionKey = null;
|
|
67
|
+
for (const line of lines.slice(1, close)) {
|
|
68
|
+
if (!line.trim() || line.trimStart().startsWith('#')) continue;
|
|
69
|
+
const listMatch = line.match(/^\s+-\s+(.+)$/);
|
|
70
|
+
if (listMatch && collectionKey) {
|
|
71
|
+
if (!Array.isArray(data[collectionKey])) data[collectionKey] = [];
|
|
72
|
+
data[collectionKey].push(parseScalar(listMatch[1]));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (/^\s/.test(line)) continue;
|
|
76
|
+
const match = line.match(/^([A-Za-z_][A-Za-z0-9_-]*):\s*(.*)$/);
|
|
77
|
+
if (!match) continue;
|
|
78
|
+
collectionKey = match[1];
|
|
79
|
+
data[collectionKey] = parseScalar(match[2]);
|
|
80
|
+
}
|
|
81
|
+
return { data, body: lines.slice(close + 1).join('\n') };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function parseDocument(raw, kernelRoot) {
|
|
85
|
+
if (!kernelRoot) return parseFallback(raw);
|
|
86
|
+
try {
|
|
87
|
+
const module = await import(pathToFileURL(path.join(kernelRoot, 'src', 'frontmatter.mjs')).href);
|
|
88
|
+
return module.parseDocument(raw);
|
|
89
|
+
} catch {
|
|
90
|
+
return parseFallback(raw);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function loadRegistry(kernelRoot) {
|
|
95
|
+
if (!kernelRoot) return null;
|
|
96
|
+
try {
|
|
97
|
+
return JSON.parse(fs.readFileSync(path.join(kernelRoot, 'registry', 'core.json'), 'utf8'));
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isEmpty(value) {
|
|
104
|
+
return value === undefined || value === null || value === '' ||
|
|
105
|
+
(Array.isArray(value) && value.length === 0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function requiredWhenFields(definition, data) {
|
|
109
|
+
const fields = [];
|
|
110
|
+
for (const [condition, required] of Object.entries(definition?.required_when || {})) {
|
|
111
|
+
const match = condition.match(/^([A-Za-z_][A-Za-z0-9_-]*)==(.+)$/);
|
|
112
|
+
if (match && String(data[match[1]]) === match[2]) fields.push(...required);
|
|
113
|
+
}
|
|
114
|
+
return fields;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function isSafeReferencePath(value) {
|
|
118
|
+
return typeof value === 'string' && value.length > 0 && value.endsWith('.md') &&
|
|
119
|
+
!path.isAbsolute(value) && !value.includes('\\') && !value.includes('\0') &&
|
|
120
|
+
value.split('/').every((segment) => segment && segment !== '.' && segment !== '..');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function inferVaultRoot(target) {
|
|
124
|
+
let cursor = path.dirname(target);
|
|
125
|
+
while (path.dirname(cursor) !== cursor) {
|
|
126
|
+
if (path.basename(cursor) === 'translations') return path.dirname(cursor);
|
|
127
|
+
cursor = path.dirname(cursor);
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function validateTranslationReference(target, data, registry, kernelRoot, errors, warnings) {
|
|
133
|
+
if (data.type !== 'translation' || isEmpty(data.source_path)) return;
|
|
134
|
+
if (!isSafeReferencePath(data.source_path)) {
|
|
135
|
+
errors.push(`Field 'source_path' must be a safe vault-relative Markdown path.`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const vaultRoot = inferVaultRoot(target);
|
|
139
|
+
if (!vaultRoot) {
|
|
140
|
+
warnings.push("Cannot resolve translation source outside the canonical translations/<locale>/ layout.");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const source = path.resolve(vaultRoot, data.source_path);
|
|
144
|
+
const relative = path.relative(vaultRoot, source);
|
|
145
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
146
|
+
errors.push("Translation source_path escapes the vault.");
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (!fs.existsSync(source) || !fs.statSync(source).isFile() || fs.lstatSync(source).isSymbolicLink()) {
|
|
150
|
+
errors.push(`Translation source does not exist as a regular non-symlinked file: ${data.source_path}.`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const raw = fs.readFileSync(source, 'utf8');
|
|
154
|
+
const parsed = await parseDocument(raw, kernelRoot);
|
|
155
|
+
if (parsed.data.type === 'translation') errors.push('Translations may not target another translation.');
|
|
156
|
+
const sourceDefinition = registry?.document_primitives?.[parsed.data.type];
|
|
157
|
+
const portability = parsed.data.x_portability || sourceDefinition?.portability;
|
|
158
|
+
if (portability !== 'structural') errors.push('Translations may target structural documents only.');
|
|
159
|
+
const hash = `sha256:${crypto.createHash('sha256').update(raw).digest('hex')}`;
|
|
160
|
+
if (data.source_hash !== hash) errors.push(`Translation source_hash is stale; expected '${hash}'.`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function validateNode(filePath) {
|
|
164
|
+
const target = path.resolve(filePath);
|
|
165
|
+
const kernelRoot = findKernelRoot(path.dirname(target)) || findKernelRoot(process.cwd());
|
|
166
|
+
const registry = loadRegistry(kernelRoot);
|
|
167
|
+
const raw = fs.readFileSync(target, 'utf8');
|
|
168
|
+
const { data, body } = await parseDocument(raw, kernelRoot);
|
|
169
|
+
const errors = [];
|
|
170
|
+
const warnings = [];
|
|
171
|
+
|
|
172
|
+
if (isEmpty(data.type)) {
|
|
173
|
+
errors.push("Missing required field 'type'.");
|
|
174
|
+
return { valid: false, errors, warnings, file: target, type: null, kernelRoot };
|
|
175
|
+
}
|
|
176
|
+
if (CONTRACT_TYPES.has(data.type)) {
|
|
177
|
+
errors.push(`Type '${data.type}' is a contract envelope, not a Markdown document primitive.`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const definition = registry?.document_primitives?.[data.type] || null;
|
|
181
|
+
if (registry && !definition) errors.push(`Unknown document primitive '${data.type}'.`);
|
|
182
|
+
if (!registry && !FALLBACK_REQUIRED[data.type]) {
|
|
183
|
+
warnings.push(`No live core registry found and no fallback schema exists for '${data.type}'.`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const required = new Set([
|
|
187
|
+
...(registry?.universal_frontmatter?.required || FALLBACK_UNIVERSAL),
|
|
188
|
+
...(definition?.required_fields || FALLBACK_REQUIRED[data.type] || []),
|
|
189
|
+
...requiredWhenFields(definition, data),
|
|
190
|
+
]);
|
|
191
|
+
for (const field of required) {
|
|
192
|
+
if (isEmpty(data[field])) errors.push(`Missing required field '${field}'.`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
for (const [field, allowed] of Object.entries(definition?.enums || {})) {
|
|
196
|
+
const values = Array.isArray(data[field]) ? data[field] : [data[field]];
|
|
197
|
+
if (!isEmpty(data[field]) && values.some((value) => !allowed.includes(value))) {
|
|
198
|
+
errors.push(`Field '${field}' must contain only: ${allowed.join(', ')}.`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for (const [field, source] of Object.entries(definition?.patterns || {})) {
|
|
203
|
+
if (isEmpty(data[field])) continue;
|
|
204
|
+
try {
|
|
205
|
+
if (!(new RegExp(source, 'u')).test(String(data[field]))) {
|
|
206
|
+
errors.push(`Field '${field}' does not match required pattern ${source}.`);
|
|
207
|
+
}
|
|
208
|
+
} catch {
|
|
209
|
+
errors.push(`Registry pattern for '${field}' is invalid.`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
await validateTranslationReference(target, data, registry, kernelRoot, errors, warnings);
|
|
214
|
+
|
|
215
|
+
if (APPEND_TYPES.has(data.type) && body.trim() === '') {
|
|
216
|
+
warnings.push(`Append-only primitive '${data.type}' has an empty body.`);
|
|
217
|
+
}
|
|
218
|
+
if (data.type === 'memory' && target.split(path.sep).includes('memory-vault')) {
|
|
219
|
+
const parent = path.basename(path.dirname(target));
|
|
220
|
+
if (data.category && data.category !== parent) {
|
|
221
|
+
errors.push(`Memory category '${data.category}' does not match parent directory '${parent}'.`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
valid: errors.length === 0,
|
|
227
|
+
errors,
|
|
228
|
+
warnings,
|
|
229
|
+
file: target,
|
|
230
|
+
type: data.type,
|
|
231
|
+
kernelRoot,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function realpath(value) {
|
|
236
|
+
try { return fs.realpathSync(value); } catch { return value; }
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const invoked = process.argv[1] ? realpath(path.resolve(process.argv[1])) : null;
|
|
240
|
+
if (invoked === realpath(fileURLToPath(import.meta.url))) {
|
|
241
|
+
const target = process.argv[2];
|
|
242
|
+
if (!target) {
|
|
243
|
+
console.error('Usage: node validate-schema.mjs <path-to-ssss-document.md>');
|
|
244
|
+
process.exit(2);
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const result = await validateNode(target);
|
|
248
|
+
for (const warning of result.warnings) console.warn(`WARN: ${warning}`);
|
|
249
|
+
if (!result.valid) {
|
|
250
|
+
for (const error of result.errors) console.error(`ERROR: ${error}`);
|
|
251
|
+
process.exit(1);
|
|
252
|
+
}
|
|
253
|
+
console.log(`OK: ${path.basename(result.file)} is a valid '${result.type}' document.`);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error(`ERROR: ${error.message}`);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Role: SSSS Contract Auditor
|
|
2
|
+
|
|
3
|
+
Audit one bounded SSSS surface without editing it.
|
|
4
|
+
|
|
5
|
+
## Inputs
|
|
6
|
+
|
|
7
|
+
- Repository root
|
|
8
|
+
- Surface: primitive, envelope, runtime, bundle, projection, or host adapter
|
|
9
|
+
- Files or symbols in scope
|
|
10
|
+
|
|
11
|
+
## Procedure
|
|
12
|
+
|
|
13
|
+
1. Read the relevant registry entry and exact spec section.
|
|
14
|
+
2. Trace the implementation and every related conformance fixture.
|
|
15
|
+
3. Compare required fields, enums, append behavior, authorization, path safety,
|
|
16
|
+
idempotency, portability, and package identity where relevant.
|
|
17
|
+
4. Report only evidence-backed mismatches with file paths and a proposed test.
|
|
18
|
+
|
|
19
|
+
## Output
|
|
20
|
+
|
|
21
|
+
Return a compact table with `severity`, `contract`, `implementation`, `evidence`,
|
|
22
|
+
and `recommended regression`. Do not modify files.
|