@descent-vtt/spec-harness 0.14.0 → 0.15.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +34 -0
- package/README.md +8 -1
- package/dist/answers.js +2 -1
- package/dist/answers.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +26 -23
- package/dist/cli.js.map +1 -1
- package/dist/configure.d.ts +58 -2
- package/dist/configure.js +116 -3
- package/dist/configure.js.map +1 -1
- package/dist/context.js +2 -1
- package/dist/context.js.map +1 -1
- package/dist/fs.js +1 -0
- package/dist/fs.js.map +1 -1
- package/dist/git.js +2 -1
- package/dist/git.js.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/host.js.map +1 -1
- package/dist/literal.d.ts +18 -0
- package/dist/literal.js +21 -0
- package/dist/literal.js.map +1 -0
- package/dist/probe.js +1 -1
- package/dist/probe.js.map +1 -1
- package/dist/reader.js +2 -0
- package/dist/reader.js.map +1 -1
- package/dist/round.d.ts +12 -1
- package/dist/round.js +23 -7
- package/dist/round.js.map +1 -1
- package/dist/sandbox.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/setup.js +2 -1
- package/dist/setup.js.map +1 -1
- package/dist/siblings.js +2 -1
- package/dist/siblings.js.map +1 -1
- package/dist/signers.js +5 -0
- package/dist/signers.js.map +1 -1
- package/dist/usage.d.ts +73 -27
- package/dist/usage.js +51 -7
- package/dist/usage.js.map +1 -1
- package/dist/versions.js +3 -0
- package/dist/versions.js.map +1 -1
- package/dist/workspace.js +3 -1
- package/dist/workspace.js.map +1 -1
- package/package.json +3 -3
package/dist/signers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signers.js","sourceRoot":"","sources":["../src/signers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG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AC,SAAS,KAAK,EAAE,CAAC;YAC1C,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,UAAU,EAAE,OAAO,CAAC,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACzG,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,IAAI,CAAC,KAAK;YACnB,GAAG;SACJ,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAiC;IACxD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AACxG,CAAC","sourcesContent":["/**\n * The allowed-signers file, read as OpenSSH reads it (ssh-keygen(1), ALLOWED\n * SIGNERS), to say which signers sign with a key that is not FIDO2.\n *\n * A line is `principals [options] keytype key [comment]`: principals a\n * comma-separated list, which may hold a double-quoted part; options a\n * comma-separated list with no space outside quotes, such as\n * `cert-authority`, `namespaces=\"git\"` or `valid-after=\"20260101\"`, each\n * value in double quotes. The quotes are read as OpenSSH's sshsig.c and\n * misc.c read them, and each function below names the one it follows. A\n * `cert-authority` line holds the key of a certificate authority, not a\n * person's: the keys it certifies are not in the file, so their type cannot\n * be read from it.\n *\n * Pure: doctor reads the file from the base and passes the text.\n */\n\n/** The key types of a FIDO2 security key: a signature needs a touch no process can supply (ADR-0006). */\nexport const FIDO2_KEY_TYPES: readonly string[] = ['sk-ssh-ed25519@openssh.com', 'sk-ecdsa-sha2-nistp256@openssh.com'];\n\nexport interface AllowedSigner {\n /** 1-based. */\n readonly line: number;\n readonly principals: readonly string[];\n /** Whether the key is a certificate authority's. */\n readonly certAuthority: boolean;\n /** The namespaces the key may sign in, or `null` for any. */\n readonly namespaces: readonly string[] | null;\n readonly validAfter: string | null;\n readonly validBefore: string | null;\n readonly keyType: string;\n readonly key: string;\n}\n\nexport interface SignersRead {\n readonly signers: readonly AllowedSigner[];\n /** Lines that are not a signer, with why. */\n readonly problems: readonly { readonly line: number; readonly message: string }[];\n}\n\n/**\n * A key as the file writes it: base64 of the key's wire form, which starts\n * with the four-byte length of its type's name, so with `AAAA`. OpenSSH tells\n * options from a key type by trying to read a key after it; a key type is\n * followed by a key, and options by a key type, which is not one. So a key\n * type OpenSSH adds later is read as one, as OpenSSH reads it.\n */\nconst KEY = /^AAAA[A-Za-z0-9+/]+={0,2}$/;\n\n/** What OpenSSH's `strdelim` skips as whitespace between fields. */\nconst WHITESPACE = /^[ \\t\\r\\n]*/;\n\n/**\n * The principals field, as OpenSSH's `strdelimw` reads it: up to the first\n * whitespace or double quote. A quote there, at the start or in the middle,\n * is taken out with the next one, and the field ends at that one whatever\n * follows it: `a@example.com,\"b@example.com\"` is\n * `a@example.com,b@example.com`, and `\"a\"b` is `a`, with `b` the next field.\n * `null` when the quote is never closed, which makes the line no signer.\n */\nfunction principalsField(text: string): { value: string; rest: string } | null {\n const at = text.search(/[ \\t\\r\\n\"]/);\n if (at === -1) return { value: text, rest: '' };\n if (text.charAt(at) !== '\"') return { value: text.slice(0, at), rest: text.slice(at).replace(WHITESPACE, '') };\n const close = text.indexOf('\"', at + 1);\n if (close === -1) return null;\n return { value: text.slice(0, at) + text.slice(at + 1, close), rest: text.slice(close + 1).replace(WHITESPACE, '') };\n}\n\n/**\n * The options field, as OpenSSH's `sshkey_advance_past_options` finds its\n * end: the first space or tab outside double quotes, where `\\\"` is a quote\n * inside them. `null` when a quote is never closed.\n */\nfunction optionsField(text: string): { value: string; rest: string } | null {\n // Reading one character past the end changes nothing - `charAt` gives the\n // empty string there - so `<=` for `<` is equivalent.\n let quoted = false;\n let i = 0;\n for (; i < text.length && (quoted || (text.charAt(i) !== ' ' && text.charAt(i) !== '\\t')); i += 1) {\n if (text.charAt(i) === '\\\\' && text.charAt(i + 1) === '\"') i += 1;\n else if (text.charAt(i) === '\"') quoted = !quoted;\n }\n if (quoted) return null;\n return { value: text.slice(0, i), rest: text.slice(i).replace(/^[ \\t]*/, '') };\n}\n\n/** A key type or a key: up to the next space or tab. */\nfunction word(text: string): { value: string; rest: string } {\n const [, value, rest] = /^([^ \\t]*)[ \\t]*(.*)$/s.exec(text) as RegExpExecArray;\n return { value: value as string, rest: rest as string };\n}\n\ninterface Options {\n readonly certAuthority: boolean;\n readonly namespaces: string | null;\n readonly validAfter: string | null;\n readonly validBefore: string | null;\n}\n\nconst NO_OPTIONS: Options = { certAuthority: false, namespaces: null, validAfter: null, validBefore: null };\n\n/** The options with a value, each of which OpenSSH takes once. */\nconst VALUED = ['namespaces', 'valid-after', 'valid-before'];\n\n/**\n * The options, as OpenSSH's `sshsigopt_parse` reads them: `cert-authority`\n * alone and `namespaces`, `valid-after` and `valid-before` with a value,\n * separated by commas, a name in any case and a value always in double\n * quotes, `\\\"` a quote inside one (its `opt_dequote`). Anything else - another\n * option, a value without its quotes or given twice, anything but a comma\n * after an option, a comma with nothing after it - makes the line no signer,\n * as it does for OpenSSH. The times are read as written.\n */\nfunction readOptions(text: string): Options | { refused: string } {\n const values = new Map<string, string>();\n let certAuthority = false;\n let at = 0;\n while (at < text.length) {\n const name = (/^[^,=\"]*/.exec(text.slice(at)) as RegExpExecArray)[0];\n const key = name.toLowerCase();\n at += name.length;\n const valued = text.charAt(at) === '=';\n if (key === 'cert-authority' && !valued) {\n certAuthority = true;\n } else if (VALUED.includes(key) && valued) {\n // `optionsField` has refused a quote never closed, so a value that\n // opens one closes it.\n const quoted = /^\"((?:\\\\\"|[^\"])*)\"/.exec(text.slice(at + 1));\n if (quoted === null) return { refused: `the value of ${name} is not in double quotes, as OpenSSH needs: write ${name}=\"...\"` };\n if (values.has(key)) return { refused: `it gives ${key} twice, which OpenSSH refuses` };\n values.set(key, (quoted[1] as string).replace(/\\\\\"/g, '\"'));\n at += 1 + quoted[0].length;\n } else {\n return { refused: 'OpenSSH reads only cert-authority, namespaces=\"...\", valid-after=\"...\" and valid-before=\"...\" as options' };\n }\n if (at === text.length) break;\n if (text.charAt(at) !== ',') return { refused: 'its options are not separated by commas' };\n at += 1;\n if (at === text.length) return { refused: 'its options end in a comma' };\n }\n return { certAuthority, namespaces: values.get('namespaces') ?? null, validAfter: values.get('valid-after') ?? null, validBefore: values.get('valid-before') ?? null };\n}\n\n/** Reads the file's text: every signer, and every line that is not one. */\nexport function readAllowedSigners(text: string): SignersRead {\n const signers: AllowedSigner[] = [];\n const problems: { line: number; message: string }[] = [];\n text.split(/\\r?\\n/).forEach((raw, index) => {\n const line = index + 1;\n const content = raw.trim();\n if (content === '' || content.startsWith('#')) return;\n const refuse = (message: string): void => {\n problems.push({ line, message });\n };\n const principals = principalsField(content);\n if (principals === null) return refuse('its principals open a double quote that is never closed');\n // OpenSSH reads a key where the key type would be, and options when it\n // cannot: a key type is followed by a key, and options are not.\n let type = word(principals.rest);\n let written: string | null = null;\n if (!KEY.test(word(type.rest).value)) {\n const field = optionsField(principals.rest);\n if (field === null) return refuse('its options open a double quote that is never closed');\n written = field.value;\n type = word(field.rest);\n }\n const key = word(type.rest).value;\n // With no key type, nothing follows it either, and no key is a key.\n if (!KEY.test(key)) return refuse('a signer is its principals, any options, a key type and a key');\n // OpenSSH reads the key before the options, and says first what is wrong with it.\n const options = written === null ? NO_OPTIONS : readOptions(written);\n if ('refused' in options) return refuse(options.refused);\n signers.push({\n line,\n // The field keeps no quote, so every comma parts two principals, as\n // OpenSSH's pattern lists read them.\n principals: principals.value\n .split(',')\n .map((principal) => principal.trim())\n .filter((principal) => principal !== ''),\n certAuthority: options.certAuthority,\n namespaces: options.namespaces === null ? null : options.namespaces.split(',').map((name) => name.trim()),\n validAfter: options.validAfter,\n validBefore: options.validBefore,\n keyType: type.value,\n key,\n });\n });\n return { signers, problems };\n}\n\n/**\n * The signers whose own key is not a FIDO2 security key's. A certificate\n * authority's line is left out: the keys it vouches for are not in the file.\n */\nexport function notFido2(signers: readonly AllowedSigner[]): AllowedSigner[] {\n return signers.filter((signer) => !signer.certAuthority && !FIDO2_KEY_TYPES.includes(signer.keyType));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"signers.js","sourceRoot":"","sources":["../src/signers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,yGAAyG;AACzG,MAAM,CAAC,MAAM,eAAe,GAAsB,CAAC,4BAA4B,EAAE,oCAAoC,CAAC,CAAC;AAsBvH;;;;;;GAMG;AACH,MAAM,GAAG,GAAG,4BAA4B,CAAC;AAEzC,oEAAoE;AACpE,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC;;;;;;;GAOG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACrC,IAAI,EAAE,KAAK,CAAC,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAChD,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,GAAG;QAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC;IAC/G,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IACxC,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI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The allowed-signers file, read as OpenSSH reads it (ssh-keygen(1), ALLOWED\n * SIGNERS), to say which signers sign with a key that is not FIDO2.\n *\n * A line is `principals [options] keytype key [comment]`: principals a\n * comma-separated list, which may hold a double-quoted part; options a\n * comma-separated list with no space outside quotes, such as\n * `cert-authority`, `namespaces=\"git\"` or `valid-after=\"20260101\"`, each\n * value in double quotes. The quotes are read as OpenSSH's sshsig.c and\n * misc.c read them, and each function below names the one it follows. A\n * `cert-authority` line holds the key of a certificate authority, not a\n * person's: the keys it certifies are not in the file, so their type cannot\n * be read from it.\n *\n * Pure: doctor reads the file from the base and passes the text.\n */\n\n/** The key types of a FIDO2 security key: a signature needs a touch no process can supply (ADR-0006). */\nexport const FIDO2_KEY_TYPES: readonly string[] = ['sk-ssh-ed25519@openssh.com', 'sk-ecdsa-sha2-nistp256@openssh.com'];\n\nexport interface AllowedSigner {\n /** 1-based. */\n readonly line: number;\n readonly principals: readonly string[];\n /** Whether the key is a certificate authority's. */\n readonly certAuthority: boolean;\n /** The namespaces the key may sign in, or `null` for any. */\n readonly namespaces: readonly string[] | null;\n readonly validAfter: string | null;\n readonly validBefore: string | null;\n readonly keyType: string;\n readonly key: string;\n}\n\nexport interface SignersRead {\n readonly signers: readonly AllowedSigner[];\n /** Lines that are not a signer, with why. */\n readonly problems: readonly { readonly line: number; readonly message: string }[];\n}\n\n/**\n * A key as the file writes it: base64 of the key's wire form, which starts\n * with the four-byte length of its type's name, so with `AAAA`. OpenSSH tells\n * options from a key type by trying to read a key after it; a key type is\n * followed by a key, and options by a key type, which is not one. So a key\n * type OpenSSH adds later is read as one, as OpenSSH reads it.\n */\nconst KEY = /^AAAA[A-Za-z0-9+/]+={0,2}$/;\n\n/** What OpenSSH's `strdelim` skips as whitespace between fields. */\nconst WHITESPACE = /^[ \\t\\r\\n]*/;\n\n/**\n * The principals field, as OpenSSH's `strdelimw` reads it: up to the first\n * whitespace or double quote. A quote there, at the start or in the middle,\n * is taken out with the next one, and the field ends at that one whatever\n * follows it: `a@example.com,\"b@example.com\"` is\n * `a@example.com,b@example.com`, and `\"a\"b` is `a`, with `b` the next field.\n * `null` when the quote is never closed, which makes the line no signer.\n */\nfunction principalsField(text: string): { value: string; rest: string } | null {\n const at = text.search(/[ \\t\\r\\n\"]/);\n if (at === -1) return { value: text, rest: '' };\n if (text.charAt(at) !== '\"') return { value: text.slice(0, at), rest: text.slice(at).replace(WHITESPACE, '') };\n const close = text.indexOf('\"', at + 1);\n if (close === -1) return null;\n return { value: text.slice(0, at) + text.slice(at + 1, close), rest: text.slice(close + 1).replace(WHITESPACE, '') };\n}\n\n/**\n * The options field, as OpenSSH's `sshkey_advance_past_options` finds its\n * end: the first space or tab outside double quotes, where `\\\"` is a quote\n * inside them. `null` when a quote is never closed.\n */\nfunction optionsField(text: string): { value: string; rest: string } | null {\n // Reading one character past the end changes nothing - `charAt` gives the\n // empty string there - so `<=` for `<` is equivalent.\n let quoted = false;\n let i = 0;\n for (; i < text.length && (quoted || (text.charAt(i) !== ' ' && text.charAt(i) !== '\\t')); i += 1) {\n if (text.charAt(i) === '\\\\' && text.charAt(i + 1) === '\"') i += 1;\n else if (text.charAt(i) === '\"') quoted = !quoted;\n }\n if (quoted) return null;\n return { value: text.slice(0, i), rest: text.slice(i).replace(/^[ \\t]*/, '') };\n}\n\n/** A key type or a key: up to the next space or tab. */\nfunction word(text: string): { value: string; rest: string } {\n // Each part of the pattern can match nothing, so it matches any text from\n // its start, and its last part runs to the end: the match is never null,\n // and either anchor is equivalent to its mutant.\n const [, value, rest] = /^([^ \\t]*)[ \\t]*(.*)$/s.exec(text)!;\n return { value: value as string, rest: rest as string };\n}\n\ninterface Options {\n readonly certAuthority: boolean;\n readonly namespaces: string | null;\n readonly validAfter: string | null;\n readonly validBefore: string | null;\n}\n\nconst NO_OPTIONS: Options = { certAuthority: false, namespaces: null, validAfter: null, validBefore: null };\n\n/** The options with a value, each of which OpenSSH takes once. */\nconst VALUED = ['namespaces', 'valid-after', 'valid-before'];\n\n/**\n * The options, as OpenSSH's `sshsigopt_parse` reads them: `cert-authority`\n * alone and `namespaces`, `valid-after` and `valid-before` with a value,\n * separated by commas, a name in any case and a value always in double\n * quotes, `\\\"` a quote inside one (its `opt_dequote`). Anything else - another\n * option, a value without its quotes or given twice, anything but a comma\n * after an option, a comma with nothing after it - makes the line no signer,\n * as it does for OpenSSH. The times are read as written.\n */\nfunction readOptions(text: string): Options | { refused: string } {\n const values = new Map<string, string>();\n let certAuthority = false;\n let at = 0;\n while (at < text.length) {\n // Nothing is a match too, so there is one at the start of any text: the\n // match is never null, and the anchor is equivalent to its mutant.\n const name = /^[^,=\"]*/.exec(text.slice(at))![0];\n const key = name.toLowerCase();\n at += name.length;\n const valued = text.charAt(at) === '=';\n if (key === 'cert-authority' && !valued) {\n certAuthority = true;\n } else if (VALUED.includes(key) && valued) {\n // `optionsField` has refused a quote never closed, so a value that\n // opens one closes it.\n const quoted = /^\"((?:\\\\\"|[^\"])*)\"/.exec(text.slice(at + 1));\n if (quoted === null) return { refused: `the value of ${name} is not in double quotes, as OpenSSH needs: write ${name}=\"...\"` };\n if (values.has(key)) return { refused: `it gives ${key} twice, which OpenSSH refuses` };\n values.set(key, (quoted[1] as string).replace(/\\\\\"/g, '\"'));\n at += 1 + quoted[0].length;\n } else {\n return { refused: 'OpenSSH reads only cert-authority, namespaces=\"...\", valid-after=\"...\" and valid-before=\"...\" as options' };\n }\n if (at === text.length) break;\n if (text.charAt(at) !== ',') return { refused: 'its options are not separated by commas' };\n at += 1;\n if (at === text.length) return { refused: 'its options end in a comma' };\n }\n return { certAuthority, namespaces: values.get('namespaces') ?? null, validAfter: values.get('valid-after') ?? null, validBefore: values.get('valid-before') ?? null };\n}\n\n/** Reads the file's text: every signer, and every line that is not one. */\nexport function readAllowedSigners(text: string): SignersRead {\n const signers: AllowedSigner[] = [];\n const problems: { line: number; message: string }[] = [];\n text.split(/\\r?\\n/).forEach((raw, index) => {\n const line = index + 1;\n const content = raw.trim();\n if (content === '' || content.startsWith('#')) return;\n const refuse = (message: string): void => {\n problems.push({ line, message });\n };\n const principals = principalsField(content);\n if (principals === null) return refuse('its principals open a double quote that is never closed');\n // OpenSSH reads a key where the key type would be, and options when it\n // cannot: a key type is followed by a key, and options are not.\n let type = word(principals.rest);\n let written: string | null = null;\n if (!KEY.test(word(type.rest).value)) {\n const field = optionsField(principals.rest);\n if (field === null) return refuse('its options open a double quote that is never closed');\n written = field.value;\n type = word(field.rest);\n }\n const key = word(type.rest).value;\n // With no key type, nothing follows it either, and no key is a key.\n if (!KEY.test(key)) return refuse('a signer is its principals, any options, a key type and a key');\n // OpenSSH reads the key before the options, and says first what is wrong with it.\n const options = written === null ? NO_OPTIONS : readOptions(written);\n if ('refused' in options) return refuse(options.refused);\n signers.push({\n line,\n // The field keeps no quote, so every comma parts two principals, as\n // OpenSSH's pattern lists read them.\n principals: principals.value\n .split(',')\n .map((principal) => principal.trim())\n .filter((principal) => principal !== ''),\n certAuthority: options.certAuthority,\n namespaces: options.namespaces === null ? null : options.namespaces.split(',').map((name) => name.trim()),\n validAfter: options.validAfter,\n validBefore: options.validBefore,\n keyType: type.value,\n key,\n });\n });\n return { signers, problems };\n}\n\n/**\n * The signers whose own key is not a FIDO2 security key's. A certificate\n * authority's line is left out: the keys it vouches for are not in the file.\n */\nexport function notFido2(signers: readonly AllowedSigner[]): AllowedSigner[] {\n return signers.filter((signer) => !signer.certAuthority && !FIDO2_KEY_TYPES.includes(signer.keyType));\n}\n"]}
|
package/dist/usage.d.ts
CHANGED
|
@@ -44,31 +44,31 @@ declare const VALUED: {
|
|
|
44
44
|
};
|
|
45
45
|
readonly base: {
|
|
46
46
|
readonly of: (line: CommandLine) => readonly string[];
|
|
47
|
-
readonly says:
|
|
47
|
+
readonly says: "names no commit; give it a branch or a commit, or leave it out for the configured base";
|
|
48
48
|
};
|
|
49
49
|
readonly root: {
|
|
50
50
|
readonly of: (line: CommandLine) => readonly string[];
|
|
51
|
-
readonly says:
|
|
51
|
+
readonly says: "names no directory; give it one, or leave it out to run in the current directory";
|
|
52
52
|
};
|
|
53
53
|
readonly path: {
|
|
54
54
|
readonly of: (line: CommandLine) => readonly string[];
|
|
55
|
-
readonly says:
|
|
55
|
+
readonly says: "names no file; give it the path of a file";
|
|
56
56
|
};
|
|
57
57
|
readonly reason: {
|
|
58
58
|
readonly of: (line: CommandLine) => readonly string[];
|
|
59
|
-
readonly says:
|
|
59
|
+
readonly says: "gives no reason; say why the round cannot be done without the file";
|
|
60
60
|
};
|
|
61
61
|
readonly option: {
|
|
62
62
|
readonly of: (line: CommandLine) => readonly string[];
|
|
63
|
-
readonly says:
|
|
63
|
+
readonly says: "names no choice; give it \"<label>: <cost>\", or leave it out";
|
|
64
64
|
};
|
|
65
65
|
readonly recommend: {
|
|
66
66
|
readonly of: (line: CommandLine) => readonly string[];
|
|
67
|
-
readonly says:
|
|
67
|
+
readonly says: "recommends nothing; say which option and why, or leave it out";
|
|
68
68
|
};
|
|
69
69
|
readonly show: {
|
|
70
70
|
readonly of: (line: CommandLine) => readonly string[];
|
|
71
|
-
readonly says:
|
|
71
|
+
readonly says: "names no escalation; give it an id, as spec-harness escalate --list prints them";
|
|
72
72
|
};
|
|
73
73
|
readonly id: {
|
|
74
74
|
readonly of: (line: CommandLine) => readonly string[];
|
|
@@ -96,9 +96,9 @@ declare const SHAPE: {
|
|
|
96
96
|
readonly takes: "one argument at most, a brief's id";
|
|
97
97
|
};
|
|
98
98
|
readonly argument: {
|
|
99
|
-
readonly role:
|
|
99
|
+
readonly role: "the brief";
|
|
100
100
|
readonly instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names";
|
|
101
|
-
readonly option:
|
|
101
|
+
readonly option: "brief";
|
|
102
102
|
};
|
|
103
103
|
readonly options: readonly ["brief", "base", "root", "format"];
|
|
104
104
|
};
|
|
@@ -106,28 +106,28 @@ declare const SHAPE: {
|
|
|
106
106
|
readonly options: readonly ["brief", "base", "root", "format", "strict"];
|
|
107
107
|
readonly limit: null;
|
|
108
108
|
readonly argument: {
|
|
109
|
-
readonly role:
|
|
110
|
-
readonly instead:
|
|
109
|
+
readonly role: "a path";
|
|
110
|
+
readonly instead: "give it the paths the round would write";
|
|
111
111
|
};
|
|
112
112
|
};
|
|
113
113
|
readonly hook: {
|
|
114
114
|
readonly options: readonly ["brief", "base", "root"];
|
|
115
115
|
readonly limit: {
|
|
116
116
|
readonly most: 1;
|
|
117
|
-
readonly takes:
|
|
117
|
+
readonly takes: "one argument, \"claude\" or \"git\"";
|
|
118
118
|
};
|
|
119
119
|
};
|
|
120
120
|
readonly escalate: {
|
|
121
121
|
readonly limit: {
|
|
122
122
|
readonly most: 0;
|
|
123
|
-
readonly takes:
|
|
123
|
+
readonly takes: "no argument";
|
|
124
124
|
};
|
|
125
125
|
readonly options: readonly ["brief", "root", "format", "path", "reason", "option", "recommend", "list", "show"];
|
|
126
126
|
readonly modes: readonly [{
|
|
127
|
-
readonly option:
|
|
127
|
+
readonly option: "list";
|
|
128
128
|
readonly beside: readonly ["root", "format"];
|
|
129
129
|
}, {
|
|
130
|
-
readonly option:
|
|
130
|
+
readonly option: "show";
|
|
131
131
|
readonly beside: readonly ["root", "format"];
|
|
132
132
|
}];
|
|
133
133
|
};
|
|
@@ -138,8 +138,8 @@ declare const SHAPE: {
|
|
|
138
138
|
readonly takes: "one argument, the escalation's id";
|
|
139
139
|
};
|
|
140
140
|
readonly argument: {
|
|
141
|
-
readonly role:
|
|
142
|
-
readonly instead:
|
|
141
|
+
readonly role: "the escalation";
|
|
142
|
+
readonly instead: "give it an id, as spec-harness escalate --list prints them";
|
|
143
143
|
};
|
|
144
144
|
};
|
|
145
145
|
readonly rulings: {
|
|
@@ -148,9 +148,9 @@ declare const SHAPE: {
|
|
|
148
148
|
readonly takes: "one argument at most, a brief's id";
|
|
149
149
|
};
|
|
150
150
|
readonly argument: {
|
|
151
|
-
readonly role:
|
|
151
|
+
readonly role: "the brief";
|
|
152
152
|
readonly instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names";
|
|
153
|
-
readonly option:
|
|
153
|
+
readonly option: "brief";
|
|
154
154
|
};
|
|
155
155
|
readonly options: readonly ["brief", "base", "root", "format"];
|
|
156
156
|
};
|
|
@@ -160,9 +160,9 @@ declare const SHAPE: {
|
|
|
160
160
|
readonly takes: "one argument at most, a brief's id";
|
|
161
161
|
};
|
|
162
162
|
readonly argument: {
|
|
163
|
-
readonly role:
|
|
163
|
+
readonly role: "the brief";
|
|
164
164
|
readonly instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names";
|
|
165
|
-
readonly option:
|
|
165
|
+
readonly option: "brief";
|
|
166
166
|
};
|
|
167
167
|
readonly options: readonly ["brief", "base", "root", "format", "strict"];
|
|
168
168
|
};
|
|
@@ -172,37 +172,37 @@ declare const SHAPE: {
|
|
|
172
172
|
readonly takes: "one argument at most, a brief's id";
|
|
173
173
|
};
|
|
174
174
|
readonly argument: {
|
|
175
|
-
readonly role:
|
|
175
|
+
readonly role: "the brief";
|
|
176
176
|
readonly instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names";
|
|
177
|
-
readonly option:
|
|
177
|
+
readonly option: "brief";
|
|
178
178
|
};
|
|
179
179
|
readonly options: readonly ["brief", "base", "root", "format", "id", "at"];
|
|
180
180
|
};
|
|
181
181
|
readonly premises: {
|
|
182
182
|
readonly limit: {
|
|
183
183
|
readonly most: 0;
|
|
184
|
-
readonly takes:
|
|
184
|
+
readonly takes: "no argument";
|
|
185
185
|
};
|
|
186
186
|
readonly options: readonly ["brief", "root", "format", "strict"];
|
|
187
187
|
};
|
|
188
188
|
readonly init: {
|
|
189
189
|
readonly limit: {
|
|
190
190
|
readonly most: 0;
|
|
191
|
-
readonly takes:
|
|
191
|
+
readonly takes: "no argument";
|
|
192
192
|
};
|
|
193
193
|
readonly options: readonly ["root", "format", "write", "git-hook"];
|
|
194
194
|
};
|
|
195
195
|
readonly mcp: {
|
|
196
196
|
readonly limit: {
|
|
197
197
|
readonly most: 0;
|
|
198
|
-
readonly takes:
|
|
198
|
+
readonly takes: "no argument";
|
|
199
199
|
};
|
|
200
200
|
readonly options: readonly ["root"];
|
|
201
201
|
};
|
|
202
202
|
readonly doctor: {
|
|
203
203
|
readonly limit: {
|
|
204
204
|
readonly most: 0;
|
|
205
|
-
readonly takes:
|
|
205
|
+
readonly takes: "no argument";
|
|
206
206
|
};
|
|
207
207
|
readonly options: readonly ["brief", "base", "root", "format", "strict"];
|
|
208
208
|
readonly reports: readonly ["brief", "base"];
|
|
@@ -222,6 +222,52 @@ export type Command = keyof typeof SHAPE;
|
|
|
222
222
|
export declare function isClaudeHook(command: string | undefined, argument: string | undefined): boolean;
|
|
223
223
|
/** The words for a `--root` that is a file, or is not there, wherever it is said. */
|
|
224
224
|
export declare function noDirectory(root: string): string;
|
|
225
|
+
/** What is wrong with the line of Claude Code's hook, and what mends it. */
|
|
226
|
+
export interface LineFault {
|
|
227
|
+
readonly wrong: string;
|
|
228
|
+
readonly mend: string;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* What Claude Code's hook does with its own line, as far as the line decides
|
|
232
|
+
* it: it guards, in the root the line gives it where it gives one, or the
|
|
233
|
+
* guard is off, for a fault the hook says with exit 1 and holds no write for
|
|
234
|
+
* (ADR-0005). The hook reads its line through the three functions below, and
|
|
235
|
+
* `doctor` reads a line it finds in Claude Code's settings through the same
|
|
236
|
+
* three, so what it says of a line is what the hook does with it.
|
|
237
|
+
*/
|
|
238
|
+
export type HookLine = {
|
|
239
|
+
readonly state: 'guards';
|
|
240
|
+
readonly root: string | undefined;
|
|
241
|
+
} | GuardOff;
|
|
242
|
+
export interface GuardOff {
|
|
243
|
+
readonly state: 'off';
|
|
244
|
+
readonly fault: LineFault;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* A line the parser refused: an option no command has, an option left
|
|
248
|
+
* without its value, a `--format` or an `--at` that is none. The parser's
|
|
249
|
+
* words are kept, on one line: what node says of an option that may have
|
|
250
|
+
* lost its value is three.
|
|
251
|
+
*/
|
|
252
|
+
export declare function unreadHookLine(said: string): GuardOff;
|
|
253
|
+
/**
|
|
254
|
+
* A line that parsed, by the root it gives. An empty root is the directory
|
|
255
|
+
* the hook was started in: git starts there when it is handed no directory,
|
|
256
|
+
* so the hook has guarded there for an empty root in every release. A root
|
|
257
|
+
* that is a file, or is not there, is one git starts in neither of, which
|
|
258
|
+
* read as a session outside a work tree, exit 0 and no word, and the guard
|
|
259
|
+
* someone had configured was off.
|
|
260
|
+
*/
|
|
261
|
+
export declare function readHookLine(root: string | undefined, cwd: string, isDirectory: (path: string) => boolean): HookLine;
|
|
262
|
+
/**
|
|
263
|
+
* What Claude Code's hook does with the words it is handed, or `null` for
|
|
264
|
+
* words that are not its line: read by the parser the command line reads
|
|
265
|
+
* every line with, and known by its command and the argument after it on a
|
|
266
|
+
* line that parsed and on one that did not, as the command line knows it
|
|
267
|
+
* (cli.ts). `parse` is that parser, which throws its refusal with the words
|
|
268
|
+
* it could still read.
|
|
269
|
+
*/
|
|
270
|
+
export declare function claudeHookLine(words: readonly string[], parse: (argv: readonly string[]) => CommandLine, cwd: string, isDirectory: (path: string) => boolean): HookLine | null;
|
|
225
271
|
/**
|
|
226
272
|
* Why the command line is refused, or `null` when the command can run:
|
|
227
273
|
* an option it does not read, alone or beside another, an argument it does
|
package/dist/usage.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* `null`. The one thing only the disk knows, whether `--root` is a
|
|
14
14
|
* directory, is asked of the caller.
|
|
15
15
|
*/
|
|
16
|
+
import { literal } from './literal.js';
|
|
16
17
|
/** Whether a value names nothing: empty, or only space. */
|
|
17
18
|
export function isBlank(value) {
|
|
18
19
|
return value.trim() === '';
|
|
@@ -26,7 +27,7 @@ const one = (value) => (value === undefined ? [] : [value]);
|
|
|
26
27
|
* parser refuses any other, the empty one with them. Nor is `--note`, which
|
|
27
28
|
* `rule` refuses by name itself.
|
|
28
29
|
*/
|
|
29
|
-
const VALUED = {
|
|
30
|
+
const VALUED = literal({
|
|
30
31
|
brief: { of: (line) => one(line.brief), says: "names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names" },
|
|
31
32
|
base: { of: (line) => one(line.base), says: 'names no commit; give it a branch or a commit, or leave it out for the configured base' },
|
|
32
33
|
root: { of: (line) => one(line.root), says: 'names no directory; give it one, or leave it out to run in the current directory' },
|
|
@@ -36,7 +37,7 @@ const VALUED = {
|
|
|
36
37
|
recommend: { of: (line) => one(line.recommend), says: 'recommends nothing; say which option and why, or leave it out' },
|
|
37
38
|
show: { of: (line) => one(line.show), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },
|
|
38
39
|
id: { of: (line) => one(line.id), says: "names no probe; give it a probe's id, or leave it out to run every probe" },
|
|
39
|
-
};
|
|
40
|
+
});
|
|
40
41
|
/**
|
|
41
42
|
* The line for a value that names nothing. `subject` is the input as its
|
|
42
43
|
* caller knows it: `--brief` on a command line, `"brief"` in a tool call. The
|
|
@@ -45,11 +46,11 @@ const VALUED = {
|
|
|
45
46
|
export function emptyValue(subject, option, value) {
|
|
46
47
|
return `${subject} is ${JSON.stringify(value)}, which ${VALUED[option].says}`;
|
|
47
48
|
}
|
|
48
|
-
const NO_ARGUMENT = { limit: { most: 0, takes: 'no argument' } };
|
|
49
|
-
const ONE_BRIEF = {
|
|
49
|
+
const NO_ARGUMENT = literal({ limit: { most: 0, takes: 'no argument' } });
|
|
50
|
+
const ONE_BRIEF = literal({
|
|
50
51
|
limit: { most: 1, takes: "one argument at most, a brief's id" },
|
|
51
52
|
argument: { role: 'the brief', instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names", option: 'brief' },
|
|
52
|
-
};
|
|
53
|
+
});
|
|
53
54
|
/**
|
|
54
55
|
* Every command, with what it reads of a command line. An option is listed
|
|
55
56
|
* for a command only where the command's answer depends on it: `init`
|
|
@@ -57,7 +58,7 @@ const ONE_BRIEF = {
|
|
|
57
58
|
* neither takes `--base` or `--brief`, and taking them would tell someone
|
|
58
59
|
* the base or the brief had been set.
|
|
59
60
|
*/
|
|
60
|
-
const SHAPE = {
|
|
61
|
+
const SHAPE = literal({
|
|
61
62
|
context: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },
|
|
62
63
|
guard: {
|
|
63
64
|
options: ['brief', 'base', 'root', 'format', 'strict'],
|
|
@@ -90,7 +91,7 @@ const SHAPE = {
|
|
|
90
91
|
// that acts on it stops: a brief or a base that names nothing is a line of
|
|
91
92
|
// doctor's report.
|
|
92
93
|
doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },
|
|
93
|
-
};
|
|
94
|
+
});
|
|
94
95
|
// A map, since a command is a word a person types and an object answers to
|
|
95
96
|
// more names than it was given: `constructor` has no shape.
|
|
96
97
|
const SHAPES = new Map(Object.entries(SHAPE));
|
|
@@ -117,6 +118,49 @@ export function isClaudeHook(command, argument) {
|
|
|
117
118
|
export function noDirectory(root) {
|
|
118
119
|
return `--root is "${root}", which is not a directory`;
|
|
119
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* A line the parser refused: an option no command has, an option left
|
|
123
|
+
* without its value, a `--format` or an `--at` that is none. The parser's
|
|
124
|
+
* words are kept, on one line: what node says of an option that may have
|
|
125
|
+
* lost its value is three.
|
|
126
|
+
*/
|
|
127
|
+
export function unreadHookLine(said) {
|
|
128
|
+
return { state: 'off', fault: { wrong: `the hook's line cannot be read (${said.split('\n').join(' ')})`, mend: 'mend it in Claude Code\'s settings, where init writes "hook claude" and nothing after it' } };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A line that parsed, by the root it gives. An empty root is the directory
|
|
132
|
+
* the hook was started in: git starts there when it is handed no directory,
|
|
133
|
+
* so the hook has guarded there for an empty root in every release. A root
|
|
134
|
+
* that is a file, or is not there, is one git starts in neither of, which
|
|
135
|
+
* read as a session outside a work tree, exit 0 and no word, and the guard
|
|
136
|
+
* someone had configured was off.
|
|
137
|
+
*/
|
|
138
|
+
export function readHookLine(root, cwd, isDirectory) {
|
|
139
|
+
const given = root === '' ? cwd : root;
|
|
140
|
+
if (given !== undefined && !isDirectory(given)) {
|
|
141
|
+
return { state: 'off', fault: { wrong: noDirectory(given), mend: "give the hook's line a directory that exists, or leave --root out for the project Claude Code names" } };
|
|
142
|
+
}
|
|
143
|
+
return { state: 'guards', root: given };
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* What Claude Code's hook does with the words it is handed, or `null` for
|
|
147
|
+
* words that are not its line: read by the parser the command line reads
|
|
148
|
+
* every line with, and known by its command and the argument after it on a
|
|
149
|
+
* line that parsed and on one that did not, as the command line knows it
|
|
150
|
+
* (cli.ts). `parse` is that parser, which throws its refusal with the words
|
|
151
|
+
* it could still read.
|
|
152
|
+
*/
|
|
153
|
+
export function claudeHookLine(words, parse, cwd, isDirectory) {
|
|
154
|
+
let line;
|
|
155
|
+
try {
|
|
156
|
+
line = parse(words);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
const refused = error;
|
|
160
|
+
return isClaudeHook(refused.words[0], refused.words[1]) ? unreadHookLine(refused.message) : null;
|
|
161
|
+
}
|
|
162
|
+
return isClaudeHook(line.command, line.positionals[0]) ? readHookLine(line.root, cwd, isDirectory) : null;
|
|
163
|
+
}
|
|
120
164
|
/**
|
|
121
165
|
* Why the command line is refused, or `null` when the command can run:
|
|
122
166
|
* an option it does not read, alone or beside another, an argument it does
|
package/dist/usage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmBH,2DAA2D;AAC3D,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAQD,8EAA8E;AAC9E,yEAAyE;A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AW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxD,OAAO,GAAG,OAAO,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,uBAAuB,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChI,CAAC;IACD,4EAA4E;IAC5E,uEAAuE;IACvE,yEAAyE;IACzE,oDAAoD;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,4EAA4E,CAAC;IAC/G,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * What a command line that parsed has still to be before it runs.\n *\n * The parser says what was typed. Whether it names anything was left to each\n * command, and most never asked: an option another command reads was taken\n * and did nothing, an argument no command asked for was dropped, and an\n * option given an empty value, as `--root \"$DIR\"` is where the variable is\n * not set, was read as the option left out. Each run then answered a\n * question nobody had put, exit 0, where a tool never falls back to its\n * defaults and reports clean (spec-core ADR-0005).\n *\n * Pure: the command line as it was read, and the line that refuses it, or\n * `null`. The one thing only the disk knows, whether `--root` is a\n * directory, is asked of the caller.\n */\n\n/** A command line as the parser read it; what `parseOptions` returns is one. */\nexport interface CommandLine {\n readonly command: string | undefined;\n readonly positionals: readonly string[];\n /** The long name of every option on it, in the order given. */\n readonly given: readonly string[];\n readonly brief: string | undefined;\n readonly base: string | undefined;\n readonly root: string | undefined;\n readonly paths: readonly string[];\n readonly reason: string | undefined;\n readonly options: readonly string[];\n readonly recommend: string | undefined;\n readonly show: string | undefined;\n readonly id: string | undefined;\n}\n\n/** Whether a value names nothing: empty, or only space. */\nexport function isBlank(value: string): boolean {\n return value.trim() === '';\n}\n\ninterface Valued {\n readonly of: (line: CommandLine) => readonly string[];\n /** What is said of a value that names nothing, and what to do instead. */\n readonly says: string;\n}\n\n// An option left out has no value to refuse, and a value that names something\n// is passed over as none is: the empty list is equivalent to its mutant.\nconst one = (value: string | undefined): readonly string[] => (value === undefined ? [] : [value]);\n\n/**\n * The options that take a value, and what an empty one fails to name.\n * `--format` and `--at` are not here: each takes one of a few words, and the\n * parser refuses any other, the empty one with them. Nor is `--note`, which\n * `rule` refuses by name itself.\n */\nconst VALUED = {\n brief: { of: (line) => one(line.brief), says: \"names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names\" },\n base: { of: (line) => one(line.base), says: 'names no commit; give it a branch or a commit, or leave it out for the configured base' },\n root: { of: (line) => one(line.root), says: 'names no directory; give it one, or leave it out to run in the current directory' },\n path: { of: (line) => line.paths, says: 'names no file; give it the path of a file' },\n reason: { of: (line) => one(line.reason), says: 'gives no reason; say why the round cannot be done without the file' },\n option: { of: (line) => line.options, says: 'names no choice; give it \"<label>: <cost>\", or leave it out' },\n recommend: { of: (line) => one(line.recommend), says: 'recommends nothing; say which option and why, or leave it out' },\n show: { of: (line) => one(line.show), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },\n id: { of: (line) => one(line.id), says: \"names no probe; give it a probe's id, or leave it out to run every probe\" },\n} as const satisfies Record<string, Valued>;\n\nexport type ValuedOption = keyof typeof VALUED;\n\n/**\n * The line for a value that names nothing. `subject` is the input as its\n * caller knows it: `--brief` on a command line, `\"brief\"` in a tool call. The\n * value is shown as JSON, where a tab or a line break in it can be seen.\n */\nexport function emptyValue(subject: string, option: ValuedOption, value: string): string {\n return `${subject} is ${JSON.stringify(value)}, which ${VALUED[option].says}`;\n}\n\ninterface Shape {\n /** The options the command reads, by their long names. */\n readonly options: readonly string[];\n /** The most arguments it takes, with that said for the refusal of one more; `null` where it takes any number. */\n readonly limit: { readonly most: number; readonly takes: string } | null;\n /**\n * What an argument of it is, and what to do about an empty one; absent\n * where it takes none, or says so itself. `option` is the option that\n * names the same thing, where there is one: the two together are refused.\n * Only a brief is named both ways.\n */\n readonly argument?: { readonly role: string; readonly instead: string; readonly option?: 'brief' };\n /** The options whose empty value the command says in its own report. */\n readonly reports?: readonly string[];\n /**\n * The options that make the command another one, each with the only\n * options it reads beside it. The first on the list that is given decides,\n * as the command itself decides.\n */\n readonly modes?: readonly { readonly option: string; readonly beside: readonly string[] }[];\n}\n\nconst NO_ARGUMENT = { limit: { most: 0, takes: 'no argument' } } as const;\nconst ONE_BRIEF = {\n limit: { most: 1, takes: \"one argument at most, a brief's id\" },\n argument: { role: 'the brief', instead: \"give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names\", option: 'brief' },\n} as const;\n\n/**\n * Every command, with what it reads of a command line. An option is listed\n * for a command only where the command's answer depends on it: `init`\n * chooses the base itself and the server is told the brief by each call, so\n * neither takes `--base` or `--brief`, and taking them would tell someone\n * the base or the brief had been set.\n */\nconst SHAPE = {\n context: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n guard: {\n options: ['brief', 'base', 'root', 'format', 'strict'],\n limit: null,\n argument: { role: 'a path', instead: 'give it the paths the round would write' },\n },\n hook: { options: ['brief', 'base', 'root'], limit: { most: 1, takes: 'one argument, \"claude\" or \"git\"' } },\n // `--list` and `--show` print what waits and raise nothing: neither reads\n // the parts of a request, nor a brief, since what waits is every round's.\n escalate: {\n options: ['brief', 'root', 'format', 'path', 'reason', 'option', 'recommend', 'list', 'show'],\n ...NO_ARGUMENT,\n modes: [\n { option: 'list', beside: ['root', 'format'] },\n { option: 'show', beside: ['root', 'format'] },\n ],\n },\n rule: {\n options: ['root', 'format', 'allow', 'deny', 'note'],\n limit: { most: 1, takes: \"one argument, the escalation's id\" },\n argument: { role: 'the escalation', instead: 'give it an id, as spec-harness escalate --list prints them' },\n },\n rulings: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n audit: { options: ['brief', 'base', 'root', 'format', 'strict'], ...ONE_BRIEF },\n probe: { options: ['brief', 'base', 'root', 'format', 'id', 'at'], ...ONE_BRIEF },\n premises: { options: ['brief', 'root', 'format', 'strict'], ...NO_ARGUMENT },\n init: { options: ['root', 'format', 'write', 'git-hook'], ...NO_ARGUMENT },\n mcp: { options: ['root'], ...NO_ARGUMENT },\n // A diagnosis says what is wrong with what it was given, where a command\n // that acts on it stops: a brief or a base that names nothing is a line of\n // doctor's report.\n doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },\n} as const satisfies Record<string, Shape>;\n\n/** Every command there is: the command line dispatches on these names and no other. */\nexport type Command = keyof typeof SHAPE;\n\n// A map, since a command is a word a person types and an object answers to\n// more names than it was given: `constructor` has no shape.\nconst SHAPES: ReadonlyMap<string, Shape> = new Map(Object.entries(SHAPE));\n\nfunction listed(options: readonly string[]): string {\n const names = options.map((option) => `--${option}`);\n // Every command reads at least `--root`, so a list is never empty.\n if (names.length === 1) return `its only option is ${names[0] as string}`;\n return `its options are ${names.slice(0, -1).join(', ')} and ${names.at(-1) as string}`;\n}\n\n/**\n * Whether a line is Claude Code's hook, by its command and the argument\n * after it. It is exempt from every refusal here, and read as each release\n * since 0.1.0 read it: the line lives in settings files and in the plugin of\n * every release, which this one cannot rewrite, and exit 2 from it holds\n * every write of a session, the write that would fix the line among them.\n * A line the parser cannot read is asked the same, and the hook says it\n * with exit 1 (cli.ts).\n */\nexport function isClaudeHook(command: string | undefined, argument: string | undefined): boolean {\n return command === 'hook' && argument === 'claude';\n}\n\n/** The words for a `--root` that is a file, or is not there, wherever it is said. */\nexport function noDirectory(root: string): string {\n return `--root is \"${root}\", which is not a directory`;\n}\n\n/**\n * Why the command line is refused, or `null` when the command can run:\n * an option it does not read, alone or beside another, an argument it does\n * not take, a brief named twice, a value or an argument that names nothing,\n * a `--root` that is no directory. Asked once a command is known and neither\n * `--help` nor `--version` answers instead; a command with no shape is none,\n * which its caller says.\n */\nexport function refusal(line: CommandLine, isDirectory: (path: string) => boolean): string | null {\n const { command, positionals } = line;\n // No shape is kept under `undefined`, so the first check is the compiler's,\n // and its mutant is equivalent.\n if (command === undefined) return null;\n const shape = SHAPES.get(command);\n if (shape === undefined || isClaudeHook(command, positionals[0])) return null;\n const stray = line.given.find((option) => !shape.options.includes(option));\n if (stray !== undefined) return `${command} does not take --${stray}; ${listed(shape.options)}`;\n // An option the command reads, beside one that leaves it unread:\n // `escalate --list --path src/a.ts` printed the list, exit 0, and the\n // request it also spelled out was never raised.\n const mode = shape.modes?.find((candidate) => line.given.includes(candidate.option));\n if (mode !== undefined) {\n const unread = line.given.find((option) => option !== mode.option && !mode.beside.includes(option));\n if (unread !== undefined) return `${command} --${mode.option} does not take --${unread}; beside --${mode.option} ${listed(mode.beside)}`;\n }\n if (shape.limit !== null && positionals.length > shape.limit.most) {\n return `${command} takes ${shape.limit.takes}, not ${positionals.map((argument) => JSON.stringify(argument)).join(', ')}`;\n }\n // One thing named two ways, whatever the two hold: the argument won with\n // no word, so `audit 012 --brief 013` audited 012 for someone who had\n // also typed 013.\n const { argument } = shape;\n if (argument?.option !== undefined && positionals.length > 0 && line.given.includes(argument.option)) {\n return `${command} was given ${argument.role} twice, as its argument ${JSON.stringify(positionals[0])} and as --${argument.option} ${JSON.stringify(line[argument.option])}; give one of them`;\n }\n for (const [option, valued] of Object.entries(VALUED) as [ValuedOption, Valued][]) {\n if (shape.reports?.includes(option)) continue;\n const empty = valued.of(line).find(isBlank);\n if (empty !== undefined) return emptyValue(`--${option}`, option, empty);\n }\n const empty = positionals.find(isBlank);\n if (shape.argument !== undefined && empty !== undefined) {\n return `${command} was given ${JSON.stringify(empty)} as ${shape.argument.role}, which names none; ${shape.argument.instead}`;\n }\n // An empty one was refused above, so this is a path that was meant: a file,\n // or a directory that is not there. git starts in neither, and the run\n // ended saying the path was outside a work tree, which named neither the\n // option nor what was wrong with what it was given.\n if (line.root !== undefined && !isDirectory(line.root)) {\n return `${noDirectory(line.root)}; give it one that exists, or leave it out to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BAA2B,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,aAAa,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,oBAAoB,CAAC;IACjM,CAAC;IACD,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAA6B,EAAE,CAAC;QAClF,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC;YAAE,SAAS;QAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,UAAU,CAAC,KAAK,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxD,OAAO,GAAG,OAAO,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,uBAAuB,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChI,CAAC;IACD,4EAA4E;IAC5E,uEAAuE;IACvE,yEAAyE;IACzE,oDAAoD;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,4EAA4E,CAAC;IAC/G,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * What a command line that parsed has still to be before it runs.\n *\n * The parser says what was typed. Whether it names anything was left to each\n * command, and most never asked: an option another command reads was taken\n * and did nothing, an argument no command asked for was dropped, and an\n * option given an empty value, as `--root \"$DIR\"` is where the variable is\n * not set, was read as the option left out. Each run then answered a\n * question nobody had put, exit 0, where a tool never falls back to its\n * defaults and reports clean (spec-core ADR-0005).\n *\n * Pure: the command line as it was read, and the line that refuses it, or\n * `null`. The one thing only the disk knows, whether `--root` is a\n * directory, is asked of the caller.\n */\n\nimport { literal } from './literal.js';\n\n/** A command line as the parser read it; what `parseOptions` returns is one. */\nexport interface CommandLine {\n readonly command: string | undefined;\n readonly positionals: readonly string[];\n /** The long name of every option on it, in the order given. */\n readonly given: readonly string[];\n readonly brief: string | undefined;\n readonly base: string | undefined;\n readonly root: string | undefined;\n readonly paths: readonly string[];\n readonly reason: string | undefined;\n readonly options: readonly string[];\n readonly recommend: string | undefined;\n readonly show: string | undefined;\n readonly id: string | undefined;\n}\n\n/** Whether a value names nothing: empty, or only space. */\nexport function isBlank(value: string): boolean {\n return value.trim() === '';\n}\n\ninterface Valued {\n readonly of: (line: CommandLine) => readonly string[];\n /** What is said of a value that names nothing, and what to do instead. */\n readonly says: string;\n}\n\n// An option left out has no value to refuse, and a value that names something\n// is passed over as none is: the empty list is equivalent to its mutant.\nconst one = (value: string | undefined): readonly string[] => (value === undefined ? [] : [value]);\n\n/**\n * The options that take a value, and what an empty one fails to name.\n * `--format` and `--at` are not here: each takes one of a few words, and the\n * parser refuses any other, the empty one with them. Nor is `--note`, which\n * `rule` refuses by name itself.\n */\nconst VALUED = literal({\n brief: { of: (line) => one(line.brief), says: \"names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names\" },\n base: { of: (line) => one(line.base), says: 'names no commit; give it a branch or a commit, or leave it out for the configured base' },\n root: { of: (line) => one(line.root), says: 'names no directory; give it one, or leave it out to run in the current directory' },\n path: { of: (line) => line.paths, says: 'names no file; give it the path of a file' },\n reason: { of: (line) => one(line.reason), says: 'gives no reason; say why the round cannot be done without the file' },\n option: { of: (line) => line.options, says: 'names no choice; give it \"<label>: <cost>\", or leave it out' },\n recommend: { of: (line) => one(line.recommend), says: 'recommends nothing; say which option and why, or leave it out' },\n show: { of: (line) => one(line.show), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },\n id: { of: (line) => one(line.id), says: \"names no probe; give it a probe's id, or leave it out to run every probe\" },\n}) satisfies Record<string, Valued>;\n\nexport type ValuedOption = keyof typeof VALUED;\n\n/**\n * The line for a value that names nothing. `subject` is the input as its\n * caller knows it: `--brief` on a command line, `\"brief\"` in a tool call. The\n * value is shown as JSON, where a tab or a line break in it can be seen.\n */\nexport function emptyValue(subject: string, option: ValuedOption, value: string): string {\n return `${subject} is ${JSON.stringify(value)}, which ${VALUED[option].says}`;\n}\n\ninterface Shape {\n /** The options the command reads, by their long names. */\n readonly options: readonly string[];\n /** The most arguments it takes, with that said for the refusal of one more; `null` where it takes any number. */\n readonly limit: { readonly most: number; readonly takes: string } | null;\n /**\n * What an argument of it is, and what to do about an empty one; absent\n * where it takes none, or says so itself. `option` is the option that\n * names the same thing, where there is one: the two together are refused.\n * Only a brief is named both ways.\n */\n readonly argument?: { readonly role: string; readonly instead: string; readonly option?: 'brief' };\n /** The options whose empty value the command says in its own report. */\n readonly reports?: readonly string[];\n /**\n * The options that make the command another one, each with the only\n * options it reads beside it. The first on the list that is given decides,\n * as the command itself decides.\n */\n readonly modes?: readonly { readonly option: string; readonly beside: readonly string[] }[];\n}\n\nconst NO_ARGUMENT = literal({ limit: { most: 0, takes: 'no argument' } });\nconst ONE_BRIEF = literal({\n limit: { most: 1, takes: \"one argument at most, a brief's id\" },\n argument: { role: 'the brief', instead: \"give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names\", option: 'brief' },\n});\n\n/**\n * Every command, with what it reads of a command line. An option is listed\n * for a command only where the command's answer depends on it: `init`\n * chooses the base itself and the server is told the brief by each call, so\n * neither takes `--base` or `--brief`, and taking them would tell someone\n * the base or the brief had been set.\n */\nconst SHAPE = literal({\n context: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n guard: {\n options: ['brief', 'base', 'root', 'format', 'strict'],\n limit: null,\n argument: { role: 'a path', instead: 'give it the paths the round would write' },\n },\n hook: { options: ['brief', 'base', 'root'], limit: { most: 1, takes: 'one argument, \"claude\" or \"git\"' } },\n // `--list` and `--show` print what waits and raise nothing: neither reads\n // the parts of a request, nor a brief, since what waits is every round's.\n escalate: {\n options: ['brief', 'root', 'format', 'path', 'reason', 'option', 'recommend', 'list', 'show'],\n ...NO_ARGUMENT,\n modes: [\n { option: 'list', beside: ['root', 'format'] },\n { option: 'show', beside: ['root', 'format'] },\n ],\n },\n rule: {\n options: ['root', 'format', 'allow', 'deny', 'note'],\n limit: { most: 1, takes: \"one argument, the escalation's id\" },\n argument: { role: 'the escalation', instead: 'give it an id, as spec-harness escalate --list prints them' },\n },\n rulings: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n audit: { options: ['brief', 'base', 'root', 'format', 'strict'], ...ONE_BRIEF },\n probe: { options: ['brief', 'base', 'root', 'format', 'id', 'at'], ...ONE_BRIEF },\n premises: { options: ['brief', 'root', 'format', 'strict'], ...NO_ARGUMENT },\n init: { options: ['root', 'format', 'write', 'git-hook'], ...NO_ARGUMENT },\n mcp: { options: ['root'], ...NO_ARGUMENT },\n // A diagnosis says what is wrong with what it was given, where a command\n // that acts on it stops: a brief or a base that names nothing is a line of\n // doctor's report.\n doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },\n}) satisfies Record<string, Shape>;\n\n/** Every command there is: the command line dispatches on these names and no other. */\nexport type Command = keyof typeof SHAPE;\n\n// A map, since a command is a word a person types and an object answers to\n// more names than it was given: `constructor` has no shape.\nconst SHAPES: ReadonlyMap<string, Shape> = new Map(Object.entries(SHAPE));\n\nfunction listed(options: readonly string[]): string {\n const names = options.map((option) => `--${option}`);\n // Every command reads at least `--root`, so a list is never empty.\n if (names.length === 1) return `its only option is ${names[0] as string}`;\n return `its options are ${names.slice(0, -1).join(', ')} and ${names.at(-1)!}`;\n}\n\n/**\n * Whether a line is Claude Code's hook, by its command and the argument\n * after it. It is exempt from every refusal here, and read as each release\n * since 0.1.0 read it: the line lives in settings files and in the plugin of\n * every release, which this one cannot rewrite, and exit 2 from it holds\n * every write of a session, the write that would fix the line among them.\n * A line the parser cannot read is asked the same, and the hook says it\n * with exit 1 (cli.ts).\n */\nexport function isClaudeHook(command: string | undefined, argument: string | undefined): boolean {\n return command === 'hook' && argument === 'claude';\n}\n\n/** The words for a `--root` that is a file, or is not there, wherever it is said. */\nexport function noDirectory(root: string): string {\n return `--root is \"${root}\", which is not a directory`;\n}\n\n/** What is wrong with the line of Claude Code's hook, and what mends it. */\nexport interface LineFault {\n readonly wrong: string;\n readonly mend: string;\n}\n\n/**\n * What Claude Code's hook does with its own line, as far as the line decides\n * it: it guards, in the root the line gives it where it gives one, or the\n * guard is off, for a fault the hook says with exit 1 and holds no write for\n * (ADR-0005). The hook reads its line through the three functions below, and\n * `doctor` reads a line it finds in Claude Code's settings through the same\n * three, so what it says of a line is what the hook does with it.\n */\nexport type HookLine = { readonly state: 'guards'; readonly root: string | undefined } | GuardOff;\n\nexport interface GuardOff {\n readonly state: 'off';\n readonly fault: LineFault;\n}\n\n/**\n * A line the parser refused: an option no command has, an option left\n * without its value, a `--format` or an `--at` that is none. The parser's\n * words are kept, on one line: what node says of an option that may have\n * lost its value is three.\n */\nexport function unreadHookLine(said: string): GuardOff {\n return { state: 'off', fault: { wrong: `the hook's line cannot be read (${said.split('\\n').join(' ')})`, mend: 'mend it in Claude Code\\'s settings, where init writes \"hook claude\" and nothing after it' } };\n}\n\n/**\n * A line that parsed, by the root it gives. An empty root is the directory\n * the hook was started in: git starts there when it is handed no directory,\n * so the hook has guarded there for an empty root in every release. A root\n * that is a file, or is not there, is one git starts in neither of, which\n * read as a session outside a work tree, exit 0 and no word, and the guard\n * someone had configured was off.\n */\nexport function readHookLine(root: string | undefined, cwd: string, isDirectory: (path: string) => boolean): HookLine {\n const given = root === '' ? cwd : root;\n if (given !== undefined && !isDirectory(given)) {\n return { state: 'off', fault: { wrong: noDirectory(given), mend: \"give the hook's line a directory that exists, or leave --root out for the project Claude Code names\" } };\n }\n return { state: 'guards', root: given };\n}\n\n/**\n * What Claude Code's hook does with the words it is handed, or `null` for\n * words that are not its line: read by the parser the command line reads\n * every line with, and known by its command and the argument after it on a\n * line that parsed and on one that did not, as the command line knows it\n * (cli.ts). `parse` is that parser, which throws its refusal with the words\n * it could still read.\n */\nexport function claudeHookLine(\n words: readonly string[],\n parse: (argv: readonly string[]) => CommandLine,\n cwd: string,\n isDirectory: (path: string) => boolean,\n): HookLine | null {\n let line: CommandLine;\n try {\n line = parse(words);\n } catch (error) {\n const refused = error as { readonly message: string; readonly words: readonly string[] };\n return isClaudeHook(refused.words[0], refused.words[1]) ? unreadHookLine(refused.message) : null;\n }\n return isClaudeHook(line.command, line.positionals[0]) ? readHookLine(line.root, cwd, isDirectory) : null;\n}\n\n/**\n * Why the command line is refused, or `null` when the command can run:\n * an option it does not read, alone or beside another, an argument it does\n * not take, a brief named twice, a value or an argument that names nothing,\n * a `--root` that is no directory. Asked once a command is known and neither\n * `--help` nor `--version` answers instead; a command with no shape is none,\n * which its caller says.\n */\nexport function refusal(line: CommandLine, isDirectory: (path: string) => boolean): string | null {\n const { command, positionals } = line;\n // No shape is kept under `undefined`, so the first check is the compiler's,\n // and its mutant is equivalent.\n if (command === undefined) return null;\n const shape = SHAPES.get(command);\n if (shape === undefined || isClaudeHook(command, positionals[0])) return null;\n const stray = line.given.find((option) => !shape.options.includes(option));\n if (stray !== undefined) return `${command} does not take --${stray}; ${listed(shape.options)}`;\n // An option the command reads, beside one that leaves it unread:\n // `escalate --list --path src/a.ts` printed the list, exit 0, and the\n // request it also spelled out was never raised.\n const mode = shape.modes?.find((candidate) => line.given.includes(candidate.option));\n if (mode !== undefined) {\n const unread = line.given.find((option) => option !== mode.option && !mode.beside.includes(option));\n if (unread !== undefined) return `${command} --${mode.option} does not take --${unread}; beside --${mode.option} ${listed(mode.beside)}`;\n }\n if (shape.limit !== null && positionals.length > shape.limit.most) {\n return `${command} takes ${shape.limit.takes}, not ${positionals.map((argument) => JSON.stringify(argument)).join(', ')}`;\n }\n // One thing named two ways, whatever the two hold: the argument won with\n // no word, so `audit 012 --brief 013` audited 012 for someone who had\n // also typed 013.\n const { argument } = shape;\n if (argument?.option !== undefined && positionals.length > 0 && line.given.includes(argument.option)) {\n return `${command} was given ${argument.role} twice, as its argument ${JSON.stringify(positionals[0])} and as --${argument.option} ${JSON.stringify(line[argument.option])}; give one of them`;\n }\n for (const [option, valued] of Object.entries(VALUED) as [ValuedOption, Valued][]) {\n if (shape.reports?.includes(option)) continue;\n const empty = valued.of(line).find(isBlank);\n if (empty !== undefined) return emptyValue(`--${option}`, option, empty);\n }\n const empty = positionals.find(isBlank);\n if (shape.argument !== undefined && empty !== undefined) {\n return `${command} was given ${JSON.stringify(empty)} as ${shape.argument.role}, which names none; ${shape.argument.instead}`;\n }\n // An empty one was refused above, so this is a path that was meant: a file,\n // or a directory that is not there. git starts in neither, and the run\n // ended saying the path was outside a work tree, which named neither the\n // option nor what was wrong with what it was given.\n if (line.root !== undefined && !isDirectory(line.root)) {\n return `${noDirectory(line.root)}; give it one that exists, or leave it out to run in the current directory`;\n }\n return null;\n}\n"]}
|
package/dist/versions.js
CHANGED
|
@@ -80,6 +80,9 @@ export function checkClaudeCode(answer) {
|
|
|
80
80
|
const said = answer.output.trim().split('\n')[0].trim();
|
|
81
81
|
if (said === '')
|
|
82
82
|
return { state: 'unknown', reason: 'claude --version printed nothing' };
|
|
83
|
+
// What was said is trimmed and not empty, so its first part ends at the
|
|
84
|
+
// first space, whether the pattern takes that one or the run of them: one
|
|
85
|
+
// is equivalent to its mutant.
|
|
83
86
|
const first = said.split(/\s+/)[0];
|
|
84
87
|
const parsed = parseVersion(first);
|
|
85
88
|
if (parsed === null)
|
package/dist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KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,6BAA6B,IAAI,2BAA2B,EAAE,CAAC;IACvH,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,mBAAmB,CAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACpH,CAAC","sourcesContent":["/**\n * The oldest release of each sibling this harness runs, and an installed\n * sibling measured against it.\n *\n * An older sibling is not run. It would answer, and the answer would lack what\n * this release relies on: spec-brief before 0.2.0 has no `waive` hook, so its\n * archive refuses a protected file a signed ruling allows. It is reported with\n * the minimum instead, as a missing sibling is reported (ADR-0002, ADR-0011).\n *\n * package.json says the same minimums to npm as `peerDependencies`; a test\n * holds the two together. So is the oldest Claude Code that runs the hooks,\n * which doctor measures the one on `PATH` against.\n */\n\nimport type { SiblingName } from './config.js';\n\nexport const MINIMUM_VERSIONS: Readonly<Record<SiblingName, string>> = {\n // The plugin `waive` hook, through which spec-brief's archive accepts a\n // protected file that a signed ruling allows.\n 'spec-brief': '0.2.0',\n // An archived brief read as a record, as init configures it, where an older\n // release reads it as retired and what depends on it as a stale premise.\n 'spec-graph': '0.9.0',\n // Scopes read with the spec-core globs the harness reads them with, and an\n // archived brief's assertions withheld rather than run.\n 'spec-guard': '0.12.0',\n};\n\nexport interface Version {\n readonly major: number;\n readonly minor: number;\n readonly patch: number;\n readonly prerelease: boolean;\n}\n\n/** A semver version, or `null`. Build metadata is accepted and ignored, as precedence ignores it. */\nexport function parseVersion(text: string): Version | null {\n const match = /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/.exec(text);\n if (match === null) return null;\n return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), prerelease: match[4] !== undefined };\n}\n\n/**\n * Whether `installed` is `minimum` or later by semver precedence. A minimum is\n * a release, never a prerelease, so a prerelease of the minimum comes before\n * it and a prerelease of anything later comes after it.\n */\nexport function meets(installed: Version, minimum: Version): boolean {\n const order = [installed.major - minimum.major, installed.minor - minimum.minor, installed.patch - minimum.patch].find((difference) => difference !== 0) ?? 0;\n return order > 0 || (order === 0 && !installed.prerelease);\n}\n\nexport type VersionCheck =\n | { readonly ok: true; readonly version: string }\n | { readonly ok: false; readonly version: string | null; readonly reason: string };\n\n/**\n * The `version` an installed sibling's package.json declares, against the\n * minimum. A version that cannot be read cannot be shown to meet it, and is\n * refused as an old one is.\n */\nexport function checkVersion(name: SiblingName, declared: unknown): VersionCheck {\n const minimum = MINIMUM_VERSIONS[name];\n const needs = `spec-harness needs ${minimum} or later: npm install --save-dev @descent-vtt/${name}@latest`;\n if (typeof declared !== 'string') return { ok: false, version: null, reason: `the ${name} installed here declares no version; ${needs}` };\n const parsed = parseVersion(declared);\n if (parsed === null) return { ok: false, version: declared, reason: `the ${name} installed here declares \"${declared}\", which is not a version; ${needs}` };\n if (meets(parsed, parseVersion(minimum) as Version)) return { ok: true, version: declared };\n return { ok: false, version: declared, reason: `${name} ${declared} is installed here; ${needs}` };\n}\n\n/**\n * The oldest Claude Code that runs the guard hooks (ADR-0012). Its changelog\n * adds hook `args` in 2.1.139. An older release runs the hook's bare\n * `command`, `node`, which reads the hook's input as a script and fails, and\n * a PreToolUse hook that fails with anything but exit 2 blocks nothing: every\n * write passes unguarded.\n */\nexport const CLAUDE_CODE_MINIMUM = '2.1.139';\n\n/**\n * What `claude --version` printed; the version the package.json of the\n * Claude Code a Windows shim runs declares, which is `file`; or why neither\n * could be had.\n */\nexport type ClaudeCodeAnswer = { readonly output: string } | { readonly declared: string; readonly file: string } | { readonly missing: string };\n\nexport type ClaudeCodeCheck =\n /** `file` is the package.json the version was read from, when a shim was read rather than claude run. */\n | { readonly state: 'ok' | 'outdated'; readonly version: string; readonly file?: string }\n /** Never read as fine: an older release lets every write through. */\n | { readonly state: 'unknown'; readonly reason: string };\n\n/**\n * The release `claude --version` names in its first word, `2.1.235 (Claude\n * Code)`, or the one a package.json declares, against the minimum.\n */\nexport function checkClaudeCode(answer: ClaudeCodeAnswer): ClaudeCodeCheck {\n if ('missing' in answer) return { state: 'unknown', reason: answer.missing };\n if ('declared' in answer) {\n const declared = parseVersion(answer.declared);\n if (declared === null) return { state: 'unknown', reason: `${answer.file} declares \"${answer.declared}\", which is not a version` };\n return { state: meets(declared, parseVersion(CLAUDE_CODE_MINIMUM) as Version) ? 'ok' : 'outdated', version: answer.declared, file: answer.file };\n }\n // split() gives at least one string, so the first line is always there.\n const said = answer.output.trim().split('\\n')[0]!.trim();\n if (said === '') return { state: 'unknown', reason: 'claude --version printed nothing' };\n // What was said is trimmed and not empty, so its first part ends at the\n // first space, whether the pattern takes that one or the run of them: one\n // is equivalent to its mutant.\n const first = said.split(/\\s+/)[0]!;\n const parsed = parseVersion(first);\n if (parsed === null) return { state: 'unknown', reason: `claude --version printed \"${said}\", which is not a version` };\n return { state: meets(parsed, parseVersion(CLAUDE_CODE_MINIMUM) as Version) ? 'ok' : 'outdated', version: first };\n}\n"]}
|
package/dist/workspace.js
CHANGED
|
@@ -33,6 +33,7 @@ export class UnreadableLine extends UsageError {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export function version() {
|
|
36
|
+
// A Buffer parses as its text, so the encoding is equivalent to its mutant.
|
|
36
37
|
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
37
38
|
return manifest.version;
|
|
38
39
|
}
|
|
@@ -73,7 +74,8 @@ export function parseOptions(argv) {
|
|
|
73
74
|
throw new UnreadableLine(error.message, parseArgs({ args: [...argv], strict: false, options }).positionals);
|
|
74
75
|
}
|
|
75
76
|
const { values, positionals } = parsed;
|
|
76
|
-
const
|
|
77
|
+
const asked = values.format ?? 'pretty';
|
|
78
|
+
const format = asked;
|
|
77
79
|
const formats = ['pretty', 'json', 'gitlab', 'sarif', 'github'];
|
|
78
80
|
if (!formats.includes(format))
|
|
79
81
|
throw new UnreadableLine(`--format must be pretty, json, gitlab, sarif or github, not "${format}"`, positionals);
|