@descent-vtt/spec-harness 0.8.0 → 0.9.1

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.
@@ -10,7 +10,7 @@
10
10
  "name": "spec-harness",
11
11
  "source": "./",
12
12
  "description": "Rounds of agent work under a brief.",
13
- "version": "0.8.0"
13
+ "version": "0.9.1"
14
14
  }
15
15
  ]
16
16
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-harness",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Rounds of agent work under a brief: context, a guard on every write, escalations a person signs, an audit at the end. Needs Claude Code 2.1.139 or later, and @descent-vtt/spec-harness and @descent-vtt/spec-brief 0.2.0 or later installed in the project.",
5
5
  "author": {
6
6
  "name": "DescentVTT",
package/CHANGELOG.md CHANGED
@@ -9,6 +9,47 @@ only fixes, reports less or documents, so `^0.7.0` takes only releases that
9
9
  cannot turn a run red. The family's policy is
10
10
  [spec-core's ADR-0009](https://github.com/DescentVTT/spec-core/blob/main/docs/adr/0009-versions-before-1-0.md).
11
11
 
12
+ ## 0.9.1
13
+
14
+ A command or a JUnit entity named `constructor`, `toString` or `__proto__`
15
+ is the unknown name it is, and the suite now runs against the siblings' newest
16
+ releases and, in CI, their minimums.
17
+
18
+ ### Fixed
19
+
20
+ - A command named as something every JavaScript object answers to -
21
+ `spec-harness constructor`, `toString`, `__proto__` - is the unknown
22
+ command it is: `unknown command "constructor"; see spec-harness --help`
23
+ with exit 2, where it ended on a stack trace with exit 1.
24
+ - `probe` leaves an entity of such a name in a JUnit report as written, as
25
+ it leaves any entity XML does not name: `&constructor;` or `&toString;` in
26
+ a test's name, its class or a failure's message was replaced with the
27
+ source of a function, so a probe's `test:` could not name that test.
28
+ - `formatSarif`, called with a finding whose rule is so named, describes the
29
+ rule by its name, as it does any rule the audit does not have; the
30
+ description had no text. No command makes such a finding.
31
+
32
+ ## 0.9.0
33
+
34
+ spec-harness refuses sibling JSON of a shape it does not read, with exit 2,
35
+ where it stopped with a stack trace or read the document halfway, and two
36
+ messages name what is really missing.
37
+
38
+ ### Fixed
39
+
40
+ - On a branch with nothing committed yet, `audit`, `context`, `doctor`
41
+ and the MCP tools say HEAD names no commit, where they said the base named
42
+ none.
43
+ - When spec-brief exits 2 while listing the briefs and says nothing, the
44
+ error ends in `exit 2`, where it ended with the colon before a reason.
45
+ - When spec-guard or spec-brief prints JSON of a shape spec-harness does
46
+ not read - `results` that is not a list, a result whose `ok` is not true
47
+ or false, an archive reason of a severity it does not know - `audit` and
48
+ `premises` exit 2 naming the tool and the field, where they stopped with
49
+ a stack trace or read the document halfway; `context` says the rules could
50
+ not be read and why, as it does for spec-guard output that is not JSON
51
+ ([ADR-0002](https://github.com/DescentVTT/spec-harness/blob/main/docs/adr/0002-siblings-through-their-command-lines.md)).
52
+
12
53
  ## 0.8.0
13
54
 
14
55
  The context packet names front matter lines it could not read, `doctor`
@@ -0,0 +1,54 @@
1
+ /**
2
+ * What spec-guard and spec-brief answer in JSON, besides the brief list
3
+ * briefs.ts reads: a query's rules, a run's results and errors, and an
4
+ * archive's plan. Each is checked for the fields the harness reads, with the
5
+ * types it reads them as, and a document of another shape is an error that
6
+ * names the tool and the field (ADR-0002): the command that asked stops with
7
+ * exit 2, as for any sibling that printed something it cannot read, rather
8
+ * than crash halfway through the document or count what it could not read as
9
+ * clean. Fields the harness does not read are not checked, so a sibling may
10
+ * add to its documents freely.
11
+ */
12
+ import type { ArchiveReason } from './audit.js';
13
+ /** Where spec-guard places a directive. */
14
+ export interface Spec {
15
+ readonly file: string;
16
+ readonly line: number;
17
+ }
18
+ export interface QueryRule {
19
+ readonly document: string;
20
+ readonly line: number;
21
+ readonly kind: string;
22
+ readonly description: string;
23
+ readonly reason: string | null;
24
+ /** Absent from a document that says nothing of it, which is in force. */
25
+ readonly inForce: boolean;
26
+ }
27
+ /** The rules in each of the results of `spec-guard query --json`, in order. */
28
+ export declare function readQueryRules(document: unknown): QueryRule[][];
29
+ export interface GuardResult {
30
+ readonly ok: boolean;
31
+ readonly description: string;
32
+ readonly message: string;
33
+ readonly spec?: Spec | undefined;
34
+ }
35
+ export interface GuardError {
36
+ readonly message: string;
37
+ readonly raw: string;
38
+ readonly spec?: Spec | undefined;
39
+ }
40
+ /** The results and the unreadable directives of a spec-guard run over briefs, `--json`. */
41
+ export declare function readGuardRun(document: unknown): {
42
+ results: GuardResult[];
43
+ errors: GuardError[];
44
+ };
45
+ /**
46
+ * What `spec-brief archive --dry-run --format json` would refuse and warn
47
+ * about. A document with no plan plans nothing to refuse. spec-brief gives a
48
+ * reason without a hint where it has no next step, and the reason is carried
49
+ * as it gave it: a field it left out is undefined, which JSON leaves out too.
50
+ */
51
+ export declare function readArchivePlan(document: unknown): {
52
+ blocking: ArchiveReason[];
53
+ warnings: ArchiveReason[];
54
+ };
@@ -0,0 +1,139 @@
1
+ /**
2
+ * What spec-guard and spec-brief answer in JSON, besides the brief list
3
+ * briefs.ts reads: a query's rules, a run's results and errors, and an
4
+ * archive's plan. Each is checked for the fields the harness reads, with the
5
+ * types it reads them as, and a document of another shape is an error that
6
+ * names the tool and the field (ADR-0002): the command that asked stops with
7
+ * exit 2, as for any sibling that printed something it cannot read, rather
8
+ * than crash halfway through the document or count what it could not read as
9
+ * clean. Fields the harness does not read are not checked, so a sibling may
10
+ * add to its documents freely.
11
+ */
12
+ import { SiblingOutputError } from './briefs.js';
13
+ function isObject(value) {
14
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
15
+ }
16
+ /** Reads fields of one document, naming the tool, its command and the field in every refusal. */
17
+ function reader(printer) {
18
+ const refuse = (where, expected) => {
19
+ throw new SiblingOutputError(`${printer} printed ${where} that is not ${expected}`);
20
+ };
21
+ return {
22
+ object(value, where) {
23
+ return isObject(value) ? value : refuse(where, 'an object');
24
+ },
25
+ /** A list that is absent is an empty one. */
26
+ list(value, where) {
27
+ if (value === undefined)
28
+ return [];
29
+ return Array.isArray(value) ? value : refuse(where, 'a list');
30
+ },
31
+ text(value, where) {
32
+ return typeof value === 'string' ? value : refuse(where, 'text');
33
+ },
34
+ optionalText(value, where) {
35
+ return value === undefined ? undefined : typeof value === 'string' ? value : refuse(where, 'text');
36
+ },
37
+ number(value, where) {
38
+ return typeof value === 'number' ? value : refuse(where, 'a number');
39
+ },
40
+ optionalNumber(value, where) {
41
+ return value === undefined ? undefined : typeof value === 'number' ? value : refuse(where, 'a number');
42
+ },
43
+ flag(value, where) {
44
+ return typeof value === 'boolean' ? value : refuse(where, 'true or false');
45
+ },
46
+ refuse,
47
+ };
48
+ }
49
+ /** The rules in each of the results of `spec-guard query --json`, in order. */
50
+ export function readQueryRules(document) {
51
+ const read = reader('spec-guard query');
52
+ const top = read.object(document, 'a document');
53
+ return read.list(top['results'], 'results').map((value, index) => {
54
+ const result = read.object(value, `results[${index}]`);
55
+ return read.list(result['rules'], `results[${index}].rules`).map((ruleValue, at) => {
56
+ const where = `results[${index}].rules[${at}]`;
57
+ const rule = read.object(ruleValue, where);
58
+ const reason = rule['reason'];
59
+ if (reason !== undefined && reason !== null && typeof reason !== 'string')
60
+ read.refuse(`${where}.reason`, 'text or null');
61
+ const inForce = rule['inForce'];
62
+ return {
63
+ document: read.text(rule['document'], `${where}.document`),
64
+ line: read.number(rule['line'], `${where}.line`),
65
+ kind: read.text(rule['kind'], `${where}.kind`),
66
+ description: read.text(rule['description'], `${where}.description`),
67
+ reason: typeof reason === 'string' ? reason : null,
68
+ inForce: inForce === undefined ? true : read.flag(inForce, `${where}.inForce`),
69
+ };
70
+ });
71
+ });
72
+ }
73
+ /** The results and the unreadable directives of a spec-guard run over briefs, `--json`. */
74
+ export function readGuardRun(document) {
75
+ const read = reader('spec-guard');
76
+ const top = read.object(document, 'a document');
77
+ const spec = (value, where) => {
78
+ if (value === undefined)
79
+ return undefined;
80
+ const placed = read.object(value, where);
81
+ return { file: read.text(placed['file'], `${where}.file`), line: read.number(placed['line'], `${where}.line`) };
82
+ };
83
+ const results = read.list(top['results'], 'results').map((value, index) => {
84
+ const where = `results[${index}]`;
85
+ const result = read.object(value, where);
86
+ return {
87
+ ok: read.flag(result['ok'], `${where}.ok`),
88
+ description: read.text(result['description'], `${where}.description`),
89
+ message: read.text(result['message'], `${where}.message`),
90
+ spec: spec(result['spec'], `${where}.spec`),
91
+ };
92
+ });
93
+ const errors = read.list(top['errors'], 'errors').map((value, index) => {
94
+ const where = `errors[${index}]`;
95
+ const error = read.object(value, where);
96
+ return {
97
+ message: read.text(error['message'], `${where}.message`),
98
+ raw: read.optionalText(error['raw'], `${where}.raw`) ?? '',
99
+ spec: spec(error['spec'], `${where}.spec`),
100
+ };
101
+ });
102
+ return { results, errors };
103
+ }
104
+ const SEVERITIES = ['error', 'warning', 'note'];
105
+ /**
106
+ * What `spec-brief archive --dry-run --format json` would refuse and warn
107
+ * about. A document with no plan plans nothing to refuse. spec-brief gives a
108
+ * reason without a hint where it has no next step, and the reason is carried
109
+ * as it gave it: a field it left out is undefined, which JSON leaves out too.
110
+ */
111
+ export function readArchivePlan(document) {
112
+ const read = reader('spec-brief archive');
113
+ const top = read.object(document, 'a document');
114
+ if (top['plan'] === undefined)
115
+ return { blocking: [], warnings: [] };
116
+ const plan = read.object(top['plan'], 'plan');
117
+ const reasons = (key) => read.list(plan[key], `plan.${key}`).map((value, index) => {
118
+ const where = `plan.${key}[${index}]`;
119
+ const reason = read.object(value, where);
120
+ const severity = read.text(reason['severity'], `${where}.severity`);
121
+ if (!SEVERITIES.includes(severity))
122
+ read.refuse(`${where}.severity`, 'error, warning or note');
123
+ const hint = read.optionalText(reason['hint'], `${where}.hint`);
124
+ const file = read.optionalText(reason['file'], `${where}.file`);
125
+ const line = read.optionalNumber(reason['line'], `${where}.line`);
126
+ const path = read.optionalText(reason['path'], `${where}.path`);
127
+ return {
128
+ rule: read.text(reason['rule'], `${where}.rule`),
129
+ severity: severity,
130
+ message: read.text(reason['message'], `${where}.message`),
131
+ hint,
132
+ file,
133
+ line,
134
+ path,
135
+ };
136
+ });
137
+ return { blocking: reasons('blocking'), warnings: reasons('warnings') };
138
+ }
139
+ //# sourceMappingURL=answers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answers.js","sourceRoot":"","sources":["../src/answers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIjD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,iGAAiG;AACjG,SAAS,MAAM,CAAC,OAAe;IAC7B,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAS,EAAE;QACxD,MAAM,IAAI,kBAAkB,CAAC,GAAG,OAAO,YAAY,KAAK,gBAAgB,QAAQ,EAAE,CAAC,CAAC;IACtF,CAAC,CAAC;IACF,OAAO;QACL,MAAM,CAAC,KAAc,EAAE,KAAa;YAClC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAC9D,CAAC;QACD,6CAA6C;QAC7C,IAAI,CAAC,KAAc,EAAE,KAAa;YAChC,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,EAAE,CAAC;YACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC/E,CAAC;QACD,IAAI,CAAC,KAAc,EAAE,KAAa;YAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACnE,CAAC;QACD,YAAY,CAAC,KAAc,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,GAAG,KAAK,UAAU,CAAC;YACzD,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;SACY,CAAC;IACrB,CAAC,CAAC,CAAC;IACL,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * What spec-guard and spec-brief answer in JSON, besides the brief list\n * briefs.ts reads: a query's rules, a run's results and errors, and an\n * archive's plan. Each is checked for the fields the harness reads, with the\n * types it reads them as, and a document of another shape is an error that\n * names the tool and the field (ADR-0002): the command that asked stops with\n * exit 2, as for any sibling that printed something it cannot read, rather\n * than crash halfway through the document or count what it could not read as\n * clean. Fields the harness does not read are not checked, so a sibling may\n * add to its documents freely.\n */\n\nimport type { ArchiveReason } from './audit.js';\nimport { SiblingOutputError } from './briefs.js';\n\ntype Json = Record<string, unknown>;\n\nfunction isObject(value: unknown): value is Json {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Reads fields of one document, naming the tool, its command and the field in every refusal. */\nfunction reader(printer: string) {\n const refuse = (where: string, expected: string): never => {\n throw new SiblingOutputError(`${printer} printed ${where} that is not ${expected}`);\n };\n return {\n object(value: unknown, where: string): Json {\n return isObject(value) ? value : refuse(where, 'an object');\n },\n /** A list that is absent is an empty one. */\n list(value: unknown, where: string): unknown[] {\n if (value === undefined) return [];\n return Array.isArray(value) ? (value as unknown[]) : refuse(where, 'a list');\n },\n text(value: unknown, where: string): string {\n return typeof value === 'string' ? value : refuse(where, 'text');\n },\n optionalText(value: unknown, where: string): string | undefined {\n return value === undefined ? undefined : typeof value === 'string' ? value : refuse(where, 'text');\n },\n number(value: unknown, where: string): number {\n return typeof value === 'number' ? value : refuse(where, 'a number');\n },\n optionalNumber(value: unknown, where: string): number | undefined {\n return value === undefined ? undefined : typeof value === 'number' ? value : refuse(where, 'a number');\n },\n flag(value: unknown, where: string): boolean {\n return typeof value === 'boolean' ? value : refuse(where, 'true or false');\n },\n refuse,\n };\n}\n\n/** Where spec-guard places a directive. */\nexport interface Spec {\n readonly file: string;\n readonly line: number;\n}\n\nexport interface QueryRule {\n readonly document: string;\n readonly line: number;\n readonly kind: string;\n readonly description: string;\n readonly reason: string | null;\n /** Absent from a document that says nothing of it, which is in force. */\n readonly inForce: boolean;\n}\n\n/** The rules in each of the results of `spec-guard query --json`, in order. */\nexport function readQueryRules(document: unknown): QueryRule[][] {\n const read = reader('spec-guard query');\n const top = read.object(document, 'a document');\n return read.list(top['results'], 'results').map((value, index) => {\n const result = read.object(value, `results[${index}]`);\n return read.list(result['rules'], `results[${index}].rules`).map((ruleValue, at) => {\n const where = `results[${index}].rules[${at}]`;\n const rule = read.object(ruleValue, where);\n const reason = rule['reason'];\n if (reason !== undefined && reason !== null && typeof reason !== 'string') read.refuse(`${where}.reason`, 'text or null');\n const inForce = rule['inForce'];\n return {\n document: read.text(rule['document'], `${where}.document`),\n line: read.number(rule['line'], `${where}.line`),\n kind: read.text(rule['kind'], `${where}.kind`),\n description: read.text(rule['description'], `${where}.description`),\n reason: typeof reason === 'string' ? reason : null,\n inForce: inForce === undefined ? true : read.flag(inForce, `${where}.inForce`),\n };\n });\n });\n}\n\nexport interface GuardResult {\n readonly ok: boolean;\n readonly description: string;\n readonly message: string;\n readonly spec?: Spec | undefined;\n}\n\nexport interface GuardError {\n readonly message: string;\n readonly raw: string;\n readonly spec?: Spec | undefined;\n}\n\n/** The results and the unreadable directives of a spec-guard run over briefs, `--json`. */\nexport function readGuardRun(document: unknown): { results: GuardResult[]; errors: GuardError[] } {\n const read = reader('spec-guard');\n const top = read.object(document, 'a document');\n const spec = (value: unknown, where: string): Spec | undefined => {\n if (value === undefined) return undefined;\n const placed = read.object(value, where);\n return { file: read.text(placed['file'], `${where}.file`), line: read.number(placed['line'], `${where}.line`) };\n };\n const results = read.list(top['results'], 'results').map((value, index) => {\n const where = `results[${index}]`;\n const result = read.object(value, where);\n return {\n ok: read.flag(result['ok'], `${where}.ok`),\n description: read.text(result['description'], `${where}.description`),\n message: read.text(result['message'], `${where}.message`),\n spec: spec(result['spec'], `${where}.spec`),\n };\n });\n const errors = read.list(top['errors'], 'errors').map((value, index) => {\n const where = `errors[${index}]`;\n const error = read.object(value, where);\n return {\n message: read.text(error['message'], `${where}.message`),\n raw: read.optionalText(error['raw'], `${where}.raw`) ?? '',\n spec: spec(error['spec'], `${where}.spec`),\n };\n });\n return { results, errors };\n}\n\nconst SEVERITIES: readonly string[] = ['error', 'warning', 'note'];\n\n/**\n * What `spec-brief archive --dry-run --format json` would refuse and warn\n * about. A document with no plan plans nothing to refuse. spec-brief gives a\n * reason without a hint where it has no next step, and the reason is carried\n * as it gave it: a field it left out is undefined, which JSON leaves out too.\n */\nexport function readArchivePlan(document: unknown): { blocking: ArchiveReason[]; warnings: ArchiveReason[] } {\n const read = reader('spec-brief archive');\n const top = read.object(document, 'a document');\n if (top['plan'] === undefined) return { blocking: [], warnings: [] };\n const plan = read.object(top['plan'], 'plan');\n const reasons = (key: 'blocking' | 'warnings'): ArchiveReason[] =>\n read.list(plan[key], `plan.${key}`).map((value, index) => {\n const where = `plan.${key}[${index}]`;\n const reason = read.object(value, where);\n const severity = read.text(reason['severity'], `${where}.severity`);\n if (!SEVERITIES.includes(severity)) read.refuse(`${where}.severity`, 'error, warning or note');\n const hint = read.optionalText(reason['hint'], `${where}.hint`);\n const file = read.optionalText(reason['file'], `${where}.file`);\n const line = read.optionalNumber(reason['line'], `${where}.line`);\n const path = read.optionalText(reason['path'], `${where}.path`);\n return {\n rule: read.text(reason['rule'], `${where}.rule`),\n severity: severity as ArchiveReason['severity'],\n message: read.text(reason['message'], `${where}.message`),\n hint,\n file,\n line,\n path,\n } as ArchiveReason;\n });\n return { blocking: reasons('blocking'), warnings: reasons('warnings') };\n}\n"]}
package/dist/branch.d.ts CHANGED
@@ -29,8 +29,8 @@ export declare function ciBranch(env: Readonly<Record<string, string | undefined
29
29
  readonly branch: string;
30
30
  readonly source: string;
31
31
  } | null;
32
- /** The first template that yields an id, in order. */
33
- export declare function briefIdFromBranch(templates: readonly string[], name: string): string | null;
32
+ /** The first template that yields an id, in order; `null` for a head on no branch, which names no brief. */
33
+ export declare function briefIdFromBranch(templates: readonly string[], name: string | null): string | null;
34
34
  /**
35
35
  * Whether two ids name the same brief: equal as written, or equal as numbers
36
36
  * when both are all digits, since a branch says `brief/12` of a brief whose
package/dist/branch.js CHANGED
@@ -97,8 +97,10 @@ export function ciBranch(env) {
97
97
  named('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME') ??
98
98
  named('CI_COMMIT_BRANCH'));
99
99
  }
100
- /** The first template that yields an id, in order. */
100
+ /** The first template that yields an id, in order; `null` for a head on no branch, which names no brief. */
101
101
  export function briefIdFromBranch(templates, name) {
102
+ if (name === null)
103
+ return null;
102
104
  for (const template of templates) {
103
105
  const id = idFromBranch(template, name);
104
106
  if (id !== null)
@@ -1 +1 @@
1
- {"version":3,"file":"branch.js","sourceRoot":"","sources":["../src/branch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEjD,SAAS,QAAQ,CAAC,EAAU;IAC1B,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,MAAc,EAAE,IAAY;IAC9C,6DAA6D;IAC7D,IAAI,KAAK,GAAc,IAAI,KAAK,CAAU,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,IAAI,KAAK,CAAU,IAAI,CAAC,M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EAAE,CAAC;IAC/D,CAAC,CAAC;IACF,OAAO,CACL,KAAK,CAAC,iBAAiB,CAAC;QACxB,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACvE,KAAK,CAAC,qCAAqC,CAAC;QAC5C,KAAK,CAAC,kBAAkB,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,iBAAiB,CAAC,SAA4B,EAAE,IAAY;IAC1E,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,EAAE,GAAG,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,EAAE,KAAK,IAAI;YAAE,OAAO,EAAE,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/**\n * Which brief a branch is working on, read from its name.\n *\n * A round runs on a branch, and naming the branch after the brief is the one\n * convention every repository that runs agents on briefs already has. Reading\n * it from there keeps the harness stateless: no file says which brief is\n * active, so no file can say it wrongly (ADR-0004).\n *\n * A template is a branch name with `{id}` where the id goes and `*` for any\n * run of characters other than `/`: `brief/{id}`, `*\\/brief-{id}`. The id is\n * the longest run of letters and digits at that point, and must be followed\n * by the end of the name or a separator - so `brief/012-rotate-tokens` names\n * 012, and `brief/012x` names 012x, never 012.\n */\n\nconst SEPARATORS = new Set(['-', '_', '/', '.']);\n\nfunction isIdChar(ch: string): boolean {\n return /^[A-Za-z0-9]$/.test(ch);\n}\n\n/**\n * The offsets in `name` at which a template prefix can end, by dynamic\n * programming over prefix and name, so a template of many stars costs their\n * product and never an exponent.\n */\nfunction prefixEnds(prefix: string, name: string): number[] {\n // reach[j]: the prefix read so far can end at name offset j.\n let reach: boolean[] = new Array<boolean>(name.length + 1).fill(false);\n reach[0] = true;\n for (const token of prefix) {\n const next = new Array<boolean>(name.length + 1).fill(false);\n if (token === '*') {\n let open = false;\n for (let j = 0; j <= name.length; j += 1) {\n if (reach[j]) open = true;\n if (open) next[j] = true;\n if (name.charAt(j) === '/') open = false;\n }\n } else {\n for (let j = 0; j < name.length; j += 1) if (reach[j] && name.charAt(j) === token) next[j + 1] = true;\n }\n reach = next;\n }\n const ends: number[] = [];\n reach.forEach((ok, j) => {\n if (ok) ends.push(j);\n });\n return ends;\n}\n\n/** Why a template cannot be used, or `null`. */\nexport function templateError(template: string): string | null {\n const count = template.split('{id}').length - 1;\n if (count !== 1) return `\"${template}\" must contain {id} exactly once`;\n if (!template.endsWith('{id}')) return `\"${template}\" must end with {id}; whatever follows the id is the branch's own`;\n return null;\n}\n\n/** The brief id a branch name carries under one template, or `null`. */\nexport function idFromBranch(template: string, name: string): string | null {\n if (templateError(template) !== null) return null;\n const prefix = template.slice(0, -'{id}'.length);\n for (const start of prefixEnds(prefix, name)) {\n let end = start;\n while (end < name.length && isIdChar(name.charAt(end))) end += 1;\n if (end === start) continue;\n if (end < name.length && !SEPARATORS.has(name.charAt(end))) continue;\n return name.slice(start, end);\n }\n return null;\n}\n\n/**\n * The branch a CI run is building, as the forge names it, for a checkout on\n * no branch: CI checks out a commit, and without the branch a round's own\n * run would name no brief. In order: a GitHub pull request's head branch; the\n * branch a GitHub push built; a GitLab merge request's source branch; the\n * branch a GitLab pipeline built. Each is set only where it names a branch -\n * GitHub's `GITHUB_REF_NAME` names a tag too, so only when `GITHUB_REF_TYPE`\n * says `branch` - and an empty one is not set. `null` outside CI.\n */\nexport function ciBranch(env: Readonly<Record<string, string | undefined>>): { readonly branch: string; readonly source: string } | null {\n const named = (name: string): { branch: string; source: string } | null => {\n const value = env[name]?.trim() ?? '';\n return value === '' ? null : { branch: value, source: name };\n };\n return (\n named('GITHUB_HEAD_REF') ??\n (env['GITHUB_REF_TYPE'] === 'branch' ? named('GITHUB_REF_NAME') : null) ??\n named('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME') ??\n named('CI_COMMIT_BRANCH')\n );\n}\n\n/** The first template that yields an id, in order. */\nexport function briefIdFromBranch(templates: readonly string[], name: string): string | null {\n for (const template of templates) {\n const id = idFromBranch(template, name);\n if (id !== null) return id;\n }\n return null;\n}\n\n/**\n * Whether two ids name the same brief: equal as written, or equal as numbers\n * when both are all digits, since a branch says `brief/12` of a brief whose\n * file says `012`.\n */\nexport function sameId(a: string, b: string): boolean {\n if (a === b) return true;\n return /^\\d+$/.test(a) && /^\\d+$/.test(b) && BigInt(a) === BigInt(b);\n}\n"]}
1
+ {"version":3,"file":"branch.js","sourceRoot":"","sources":["../src/branch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEjD,SAAS,QAAQ,CAAC,EAAU;IAC1B,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,MAAc,EAAE,IAAY;IAC9C,6DAA6D;IAC7D,IAAI,KAAK,GAAc,IAAI,KAAK,CAAU,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,IAAI,KA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AAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC/D,CAAC,CAAC;IACF,OAAO,CACL,KAAK,CAAC,iBAAiB,CAAC;QACxB,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACvE,KAAK,CAAC,qCAAqC,CAAC;QAC5C,KAAK,CAAC,kBAAkB,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,iBAAiB,CAAC,SAA4B,EAAE,IAAmB;IACjF,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,EAAE,GAAG,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,EAAE,KAAK,IAAI;YAAE,OAAO,EAAE,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/**\n * Which brief a branch is working on, read from its name.\n *\n * A round runs on a branch, and naming the branch after the brief is the one\n * convention every repository that runs agents on briefs already has. Reading\n * it from there keeps the harness stateless: no file says which brief is\n * active, so no file can say it wrongly (ADR-0004).\n *\n * A template is a branch name with `{id}` where the id goes and `*` for any\n * run of characters other than `/`: `brief/{id}`, `*\\/brief-{id}`. The id is\n * the longest run of letters and digits at that point, and must be followed\n * by the end of the name or a separator - so `brief/012-rotate-tokens` names\n * 012, and `brief/012x` names 012x, never 012.\n */\n\nconst SEPARATORS = new Set(['-', '_', '/', '.']);\n\nfunction isIdChar(ch: string): boolean {\n return /^[A-Za-z0-9]$/.test(ch);\n}\n\n/**\n * The offsets in `name` at which a template prefix can end, by dynamic\n * programming over prefix and name, so a template of many stars costs their\n * product and never an exponent.\n */\nfunction prefixEnds(prefix: string, name: string): number[] {\n // reach[j]: the prefix read so far can end at name offset j.\n let reach: boolean[] = new Array<boolean>(name.length + 1).fill(false);\n reach[0] = true;\n for (const token of prefix) {\n const next = new Array<boolean>(name.length + 1).fill(false);\n if (token === '*') {\n let open = false;\n for (let j = 0; j <= name.length; j += 1) {\n if (reach[j]) open = true;\n if (open) next[j] = true;\n if (name.charAt(j) === '/') open = false;\n }\n } else {\n for (let j = 0; j < name.length; j += 1) if (reach[j] && name.charAt(j) === token) next[j + 1] = true;\n }\n reach = next;\n }\n const ends: number[] = [];\n reach.forEach((ok, j) => {\n if (ok) ends.push(j);\n });\n return ends;\n}\n\n/** Why a template cannot be used, or `null`. */\nexport function templateError(template: string): string | null {\n const count = template.split('{id}').length - 1;\n if (count !== 1) return `\"${template}\" must contain {id} exactly once`;\n if (!template.endsWith('{id}')) return `\"${template}\" must end with {id}; whatever follows the id is the branch's own`;\n return null;\n}\n\n/** The brief id a branch name carries under one template, or `null`. */\nexport function idFromBranch(template: string, name: string): string | null {\n if (templateError(template) !== null) return null;\n const prefix = template.slice(0, -'{id}'.length);\n for (const start of prefixEnds(prefix, name)) {\n let end = start;\n while (end < name.length && isIdChar(name.charAt(end))) end += 1;\n if (end === start) continue;\n if (end < name.length && !SEPARATORS.has(name.charAt(end))) continue;\n return name.slice(start, end);\n }\n return null;\n}\n\n/**\n * The branch a CI run is building, as the forge names it, for a checkout on\n * no branch: CI checks out a commit, and without the branch a round's own\n * run would name no brief. In order: a GitHub pull request's head branch; the\n * branch a GitHub push built; a GitLab merge request's source branch; the\n * branch a GitLab pipeline built. Each is set only where it names a branch -\n * GitHub's `GITHUB_REF_NAME` names a tag too, so only when `GITHUB_REF_TYPE`\n * says `branch` - and an empty one is not set. `null` outside CI.\n */\nexport function ciBranch(env: Readonly<Record<string, string | undefined>>): { readonly branch: string; readonly source: string } | null {\n const named = (name: string): { branch: string; source: string } | null => {\n const value = env[name]?.trim() ?? '';\n return value === '' ? null : { branch: value, source: name };\n };\n return (\n named('GITHUB_HEAD_REF') ??\n (env['GITHUB_REF_TYPE'] === 'branch' ? named('GITHUB_REF_NAME') : null) ??\n named('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME') ??\n named('CI_COMMIT_BRANCH')\n );\n}\n\n/** The first template that yields an id, in order; `null` for a head on no branch, which names no brief. */\nexport function briefIdFromBranch(templates: readonly string[], name: string | null): string | null {\n if (name === null) return null;\n for (const template of templates) {\n const id = idFromBranch(template, name);\n if (id !== null) return id;\n }\n return null;\n}\n\n/**\n * Whether two ids name the same brief: equal as written, or equal as numbers\n * when both are all digits, since a branch says `brief/12` of a brief whose\n * file says `012`.\n */\nexport function sameId(a: string, b: string): boolean {\n if (a === b) return true;\n return /^\\d+$/.test(a) && /^\\d+$/.test(b) && BigInt(a) === BigInt(b);\n}\n"]}
package/dist/cli.js CHANGED
@@ -7,6 +7,7 @@
7
7
  * could not look must never exit as though it looked and found nothing
8
8
  * (spec-core ADR-0005).
9
9
  */
10
+ import { SiblingOutputError } from './briefs.js';
10
11
  import { auditCommand, contextCommand, escalateCommand, probeCommand, ruleCommand, rulingsCommand } from './commands.js';
11
12
  import { ConfigError, SIBLINGS } from './config.js';
12
13
  import { describeBase, describeClaudeCode, describeClaudeRelease, describeGitHook, describePlugin, describeSignerKeys, describeSignerProblem, describeSigners, wiringState, } from './configure.js';
@@ -72,20 +73,20 @@ async function decisionsFor(workspace, options, io, given, cwd) {
72
73
  const active = await activeBrief(workspace, options, io.env);
73
74
  const { brief, note, problem } = describeActive(active);
74
75
  if (problem !== null)
75
- return { decisions: [], problem };
76
- const decisions = await checkPaths(workspace, brief, note, given, cwd, reader, options.base);
77
- return { decisions, problem: null };
76
+ return { problem };
77
+ return { decisions: await checkPaths(workspace, brief, note, given, cwd, reader, options.base) };
78
78
  }
79
79
  const SYMBOL = { allow: 'ok ', warn: 'warning', ask: 'ask ', deny: 'refused' };
80
80
  async function guardCommand(options, io) {
81
81
  if (options.positionals.length === 0)
82
82
  throw new UsageError('guard needs at least one path');
83
83
  const workspace = await openWorkspace(options, io);
84
- const { decisions, problem } = await decisionsFor(workspace, options, io, options.positionals, io.cwd);
85
- if (problem !== null) {
86
- io.stderr.write(`spec-harness: ${problem}\n`);
84
+ const decided = await decisionsFor(workspace, options, io, options.positionals, io.cwd);
85
+ if ('problem' in decided) {
86
+ io.stderr.write(`spec-harness: ${decided.problem}\n`);
87
87
  return EXIT_ERROR;
88
88
  }
89
+ const { decisions } = decided;
89
90
  if (options.format === 'json') {
90
91
  io.stdout.write(json('guard', { decisions }));
91
92
  }
@@ -102,6 +103,9 @@ async function guardCommand(options, io) {
102
103
  }
103
104
  /* -------------------------------------------------------------------- hook */
104
105
  async function readStdin(io) {
106
+ // Only the built command line reads process.stdin, and the suite spawns it
107
+ // from dist/, outside the sweep (tests/integration/claude-code.test.ts): the
108
+ // lines below survive it untested in-process.
105
109
  if (io.stdin !== undefined)
106
110
  return io.stdin();
107
111
  const chunks = [];
@@ -132,13 +136,13 @@ async function hookCommand(options, io) {
132
136
  throw error;
133
137
  }
134
138
  try {
135
- const { decisions, problem } = await decisionsFor(workspace, options, io, request.paths, cwd);
136
- if (problem !== null) {
139
+ const decided = await decisionsFor(workspace, options, io, request.paths, cwd);
140
+ if ('problem' in decided) {
137
141
  // Exit 2 blocks the tool call, and its stderr reaches the model.
138
- io.stderr.write(`spec-harness: ${problem}. Fix the brief or the branch before writing.\n`);
142
+ io.stderr.write(`spec-harness: ${decided.problem}. Fix the brief or the branch before writing.\n`);
139
143
  return EXIT_ERROR;
140
144
  }
141
- const response = claudeResponse(request.event, decisions);
145
+ const response = claudeResponse(request.event, decided.decisions);
142
146
  io.stdout.write(response.stdout);
143
147
  return response.exitCode;
144
148
  }
@@ -157,12 +161,12 @@ async function hookCommand(options, io) {
157
161
  const paths = staged.flatMap((change) => (change.from === undefined ? [change.path] : [change.from, change.path]));
158
162
  if (paths.length === 0)
159
163
  return EXIT_OK;
160
- const { decisions, problem } = await decisionsFor(workspace, options, io, paths, workspace.root);
161
- if (problem !== null) {
162
- io.stderr.write(`spec-harness: ${problem}\n`);
164
+ const decided = await decisionsFor(workspace, options, io, paths, workspace.root);
165
+ if ('problem' in decided) {
166
+ io.stderr.write(`spec-harness: ${decided.problem}\n`);
163
167
  return EXIT_ERROR;
164
168
  }
165
- const response = gitResponse(decisions);
169
+ const response = gitResponse(decided.decisions);
166
170
  io.stderr.write(response.text);
167
171
  return response.exitCode;
168
172
  }
@@ -240,7 +244,7 @@ async function doctorCommand(options, io) {
240
244
  `root ${workspace.root}`,
241
245
  `branch ${branch}`,
242
246
  `brief ${named ?? '(none named)'}`,
243
- `base ${describeBase(base.kind === 'resolved' ? base : { reason: base.reason })}`,
247
+ `base ${describeBase(base)}`,
244
248
  `signers ${signers}`,
245
249
  ...more(signerNotes),
246
250
  `plugin ${describePlugin(plugin)}`,
@@ -265,20 +269,26 @@ async function doctorCommand(options, io) {
265
269
  return outdated || !usable || claude === 'both' || tooOld || untold ? EXIT_FAILED : EXIT_OK;
266
270
  }
267
271
  /* ---------------------------------------------------------------- dispatch */
268
- const COMMANDS = {
269
- guard: guardCommand,
270
- hook: hookCommand,
271
- context: contextCommand,
272
- audit: auditCommand,
273
- escalate: escalateCommand,
274
- rule: ruleCommand,
275
- rulings: rulingsCommand,
276
- probe: probeCommand,
277
- premises: premisesCommand,
278
- init: initCommand,
279
- mcp: mcpCommand,
280
- doctor: doctorCommand,
281
- };
272
+ /**
273
+ * A map, because the command is the first word a person types and an object
274
+ * answers to more names than it was given: `spec-harness constructor` ran
275
+ * `Object` as a command and ended on a stack trace, where `spec-harness
276
+ * construct` is an unknown command with exit 2.
277
+ */
278
+ const COMMANDS = new Map([
279
+ ['guard', guardCommand],
280
+ ['hook', hookCommand],
281
+ ['context', contextCommand],
282
+ ['audit', auditCommand],
283
+ ['escalate', escalateCommand],
284
+ ['rule', ruleCommand],
285
+ ['rulings', rulingsCommand],
286
+ ['probe', probeCommand],
287
+ ['premises', premisesCommand],
288
+ ['init', initCommand],
289
+ ['mcp', mcpCommand],
290
+ ['doctor', doctorCommand],
291
+ ]);
282
292
  export async function run(argv, io) {
283
293
  let options;
284
294
  try {
@@ -294,9 +304,9 @@ export async function run(argv, io) {
294
304
  }
295
305
  if (options.help || options.command === undefined) {
296
306
  io.stdout.write(HELP);
297
- return options.command === undefined && !options.help ? EXIT_ERROR : EXIT_OK;
307
+ return options.help ? EXIT_OK : EXIT_ERROR;
298
308
  }
299
- const command = COMMANDS[options.command];
309
+ const command = COMMANDS.get(options.command);
300
310
  if (command === undefined) {
301
311
  io.stderr.write(`spec-harness: unknown command "${options.command}"; see spec-harness --help\n`);
302
312
  return EXIT_ERROR;
@@ -305,13 +315,18 @@ export async function run(argv, io) {
305
315
  return await command(options, io);
306
316
  }
307
317
  catch (error) {
308
- if (error instanceof UsageError || error instanceof ConfigError || error instanceof SiblingError) {
318
+ // A sibling's document of a shape the harness does not read is a sibling
319
+ // that printed something it cannot read (answers.ts): exit 2.
320
+ if (error instanceof UsageError || error instanceof ConfigError || error instanceof SiblingError || error instanceof SiblingOutputError) {
309
321
  io.stderr.write(`spec-harness: ${error.message}\n`);
310
322
  return EXIT_ERROR;
311
323
  }
312
324
  throw error;
313
325
  }
314
326
  }
327
+ // What bin/spec-harness.js runs; the suite spawns the built one, from dist/,
328
+ // outside the sweep (tests/integration/cli.test.ts), so it survives untested
329
+ // in-process.
315
330
  export async function main(argv = process.argv.slice(2)) {
316
331
  return run(argv, { stdout: process.stdout, stderr: process.stderr, cwd: process.cwd(), env: process.env });
317
332
  }