@descent-vtt/spec-brief 0.2.7 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +99 -1
  2. package/README.md +161 -28
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +61 -43
  5. package/dist/cli.js.map +1 -1
  6. package/dist/collisions.js +13 -8
  7. package/dist/collisions.js.map +1 -1
  8. package/dist/corpus.d.ts +5 -0
  9. package/dist/corpus.js +7 -0
  10. package/dist/corpus.js.map +1 -1
  11. package/dist/glob.d.ts +6 -5
  12. package/dist/glob.js +22 -103
  13. package/dist/glob.js.map +1 -1
  14. package/dist/lint.js +1 -0
  15. package/dist/lint.js.map +1 -1
  16. package/dist/report.d.ts +18 -4
  17. package/dist/report.js +99 -28
  18. package/dist/report.js.map +1 -1
  19. package/dist/rules.d.ts +2 -0
  20. package/dist/rules.js +31 -9
  21. package/dist/rules.js.map +1 -1
  22. package/dist/schedule.js +12 -10
  23. package/dist/schedule.js.map +1 -1
  24. package/dist/schema.d.ts +5 -1
  25. package/dist/schema.js +6 -2
  26. package/dist/schema.js.map +1 -1
  27. package/dist/scope.d.ts +26 -4
  28. package/dist/scope.js +64 -8
  29. package/dist/scope.js.map +1 -1
  30. package/dist/trigger.d.ts +2 -1
  31. package/dist/trigger.js +2 -1
  32. package/dist/trigger.js.map +1 -1
  33. package/dist/types.d.ts +9 -0
  34. package/dist/types.js.map +1 -1
  35. package/dist/vendor/spec-core/markdown/frontmatter.d.ts +11 -1
  36. package/dist/vendor/spec-core/markdown/frontmatter.js +20 -3
  37. package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -1
  38. package/dist/vendor/spec-core/pattern/glob.d.ts +85 -0
  39. package/dist/vendor/spec-core/pattern/glob.js +207 -17
  40. package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
  41. package/dist/vendor/spec-core/pattern/index.d.ts +2 -2
  42. package/dist/vendor/spec-core/pattern/index.js +1 -1
  43. package/dist/vendor/spec-core/pattern/index.js.map +1 -1
  44. package/dist/vendor/spec-core/text/index.d.ts +1 -0
  45. package/dist/vendor/spec-core/text/index.js +1 -0
  46. package/dist/vendor/spec-core/text/index.js.map +1 -1
  47. package/dist/vendor/spec-core/text/width.d.ts +30 -0
  48. package/dist/vendor/spec-core/text/width.js +113 -0
  49. package/dist/vendor/spec-core/text/width.js.map +1 -0
  50. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2BH,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACzC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,MAAc,EAAE,IAAU;IACzC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,QAAQ;YACX,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;QAC5E,KAAK,SAAS;YACZ,OAAO,IAAI,KAAK,SAAS,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,IAAI,KAAK,QAAQ,CAAC;QAC3B,KAAK,OAAO;YACV,OAAO,IAAI,KAAK,OAAO,CAAC;QAC1B,KAAK,QAAQ,CAAC;QACd,KAAK,KAAK;YACR,OAAO,IAAI,KAAK,QAAQ,CAAC;QAC3B,KAAK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K,OAAO;YACV,OAAO,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzE,KAAK,QAAQ,EAAE,CAAC;YACd,MAAM,UAAU,GAA4B,EAAE,CAAC;YAC/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;gBAAE,UAAU,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YACpG,MAAM,IAAI,GAA4B,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;YAClG,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YACzG,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1F,KAAK,OAAO;YACV,OAAO,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QAChE,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;AACH,CAAC","sourcesContent":["/**\n * A small schema language: one description that both validates a value and\n * renders as JSON Schema, so the published `schema.json` and the checks the\n * loader runs cannot disagree about what a configuration may say.\n */\n\ninterface Described {\n readonly description?: string;\n}\n\nexport type Schema =\n | (Described & {\n readonly type: 'string';\n readonly enum?: readonly string[];\n readonly nullable?: boolean;\n readonly minLength?: number;\n })\n | (Described & { readonly type: 'boolean' })\n | (Described & { readonly type: 'integer'; readonly minimum?: number; readonly maximum?: number })\n | (Described & { readonly type: 'array'; readonly items: Schema })\n | (Described & {\n readonly type: 'object';\n readonly properties: Readonly<Record<string, Schema>>;\n readonly required?: readonly string[];\n })\n | (Described & { readonly type: 'map'; readonly values: Schema })\n | (Described & { readonly type: 'anyOf'; readonly options: readonly Schema[] })\n | (Described & { readonly type: 'any' });\n\ntype Kind = 'null' | 'string' | 'boolean' | 'number' | 'array' | 'object';\n\nfunction kindOf(value: unknown): Kind {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n switch (typeof value) {\n case 'string':\n return 'string';\n case 'boolean':\n return 'boolean';\n case 'number':\n return 'number';\n default:\n return 'object';\n }\n}\n\nfunction accepts(schema: Schema, kind: Kind): boolean {\n switch (schema.type) {\n case 'string':\n return kind === 'string' || (kind === 'null' && schema.nullable === true);\n case 'boolean':\n return kind === 'boolean';\n case 'integer':\n return kind === 'number';\n case 'array':\n return kind === 'array';\n case 'object':\n case 'map':\n return kind === 'object';\n case 'anyOf':\n return schema.options.some((option) => accepts(option, kind));\n case 'any':\n return true;\n }\n}\n\nfunction noun(schema: Schema): string {\n switch (schema.type) {\n case 'string':\n return schema.nullable === true ? 'a string or null' : 'a string';\n case 'boolean':\n return 'true or false';\n case 'integer':\n return 'an integer';\n case 'array':\n return 'a list';\n case 'object':\n case 'map':\n return 'an object';\n case 'anyOf':\n return schema.options.map(noun).join(' or ');\n /* v8 ignore next 2 -- \"any\" accepts every value, so no message ever names it. */\n case 'any':\n return 'anything';\n }\n}\n\nfunction at(path: string, key: string): string {\n return path === '' ? key : `${path}.${key}`;\n}\n\n/** The problems with `value`, each naming the path to it. Empty when it conforms. */\nexport function validate(schema: Schema, value: unknown, path = ''): string[] {\n const where = path === '' ? 'the configuration' : `\"${path}\"`;\n if (!accepts(schema, kindOf(value))) return [`${where} must be ${noun(schema)}`];\n switch (schema.type) {\n case 'string': {\n if (typeof value !== 'string') return [];\n if (schema.enum !== undefined && !schema.enum.includes(value)) {\n return [`${where} must be one of ${schema.enum.map((e) => `\"${e}\"`).join(', ')}, not \"${value}\"`];\n }\n if (schema.minLength !== undefined && value.length < schema.minLength) return [`${where} must not be empty`];\n return [];\n }\n case 'integer': {\n const number = value as number;\n if (!Number.isInteger(number)) return [`${where} must be an integer`];\n if (schema.minimum !== undefined && number < schema.minimum) return [`${where} must be at least ${schema.minimum}`];\n if (schema.maximum !== undefined && number > schema.maximum) return [`${where} must be at most ${schema.maximum}`];\n return [];\n }\n case 'array':\n return (value as unknown[]).flatMap((item, i) => validate(schema.items, item, `${path}[${i}]`));\n case 'object': {\n const record = value as Record<string, unknown>;\n const known = Object.keys(schema.properties);\n const problems: string[] = [];\n for (const key of Object.keys(record)) {\n const property = schema.properties[key];\n if (property === undefined) {\n const guess = closest(key, known);\n problems.push(`\"${at(path, key)}\" is not a known key${guess === undefined ? '' : `; did you mean \"${guess}\"?`}`);\n continue;\n }\n problems.push(...validate(property, record[key], at(path, key)));\n }\n for (const key of schema.required ?? []) {\n if (!(key in record)) problems.push(`\"${at(path, key)}\" is required`);\n }\n return problems;\n }\n case 'map':\n return Object.entries(value as Record<string, unknown>).flatMap(([key, item]) =>\n validate(schema.values, item, at(path, key)),\n );\n case 'anyOf': {\n const candidates = schema.options.filter((option) => accepts(option, kindOf(value)));\n let first: string[] | undefined;\n for (const option of candidates) {\n const problems = validate(option, value, path);\n if (problems.length === 0) return [];\n first ??= problems;\n }\n return first ?? [];\n }\n case 'boolean':\n case 'any':\n return [];\n }\n}\n\n/** The known key nearest to a misspelling, when one is near enough to be what was meant. */\nexport function closest(word: string, options: readonly string[]): string | undefined {\n let best: string | undefined;\n let bestDistance = Math.max(2, Math.floor(word.length / 3)) + 1;\n for (const option of options) {\n const d = distance(word.toLowerCase(), option.toLowerCase());\n if (d < bestDistance) {\n best = option;\n bestDistance = d;\n }\n }\n return best;\n}\n\nfunction distance(a: string, b: string): number {\n let previous = Array.from({ length: b.length + 1 }, (_, j) => j);\n for (let i = 1; i <= a.length; i += 1) {\n const row = [i];\n for (let j = 1; j <= b.length; j += 1) {\n const cost = a.charAt(i - 1) === b.charAt(j - 1) ? 0 : 1;\n row.push(Math.min((previous[j] as number) + 1, (row[j - 1] as number) + 1, (previous[j - 1] as number) + cost));\n }\n previous = row;\n }\n return previous[b.length] as number;\n}\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json };\n\n/** Renders a schema as JSON Schema (draft 2020-12). */\nexport function toJsonSchema(schema: Schema): { [key: string]: Json } {\n const described = (body: { [key: string]: Json }): { [key: string]: Json } =>\n schema.description === undefined ? body : { description: schema.description, ...body };\n switch (schema.type) {\n case 'string': {\n const body: { [key: string]: Json } = { type: schema.nullable === true ? ['string', 'null'] : 'string' };\n if (schema.enum !== undefined) body['enum'] = [...schema.enum, ...(schema.nullable === true ? [null] : [])];\n if (schema.minLength !== undefined) body['minLength'] = schema.minLength;\n return described(body);\n }\n case 'boolean':\n return described({ type: 'boolean' });\n case 'integer': {\n const body: { [key: string]: Json } = { type: 'integer' };\n if (schema.minimum !== undefined) body['minimum'] = schema.minimum;\n if (schema.maximum !== undefined) body['maximum'] = schema.maximum;\n return described(body);\n }\n case 'array':\n return described({ type: 'array', items: toJsonSchema(schema.items) });\n case 'object': {\n const properties: { [key: string]: Json } = {};\n for (const [key, value] of Object.entries(schema.properties)) properties[key] = toJsonSchema(value);\n const body: { [key: string]: Json } = { type: 'object', properties, additionalProperties: false };\n if (schema.required !== undefined && schema.required.length > 0) body['required'] = [...schema.required];\n return described(body);\n }\n case 'map':\n return described({ type: 'object', additionalProperties: toJsonSchema(schema.values) });\n case 'anyOf':\n return described({ anyOf: schema.options.map(toJsonSchema) });\n case 'any':\n return described({});\n }\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2BH,SAAS,MAAM,CAAC,K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G,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YACpG,MAAM,IAAI,GAA4B,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;YAClG,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YACzG,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1F,KAAK,OAAO;YACV,OAAO,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QAChE,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;AACH,CAAC","sourcesContent":["/**\n * A small schema language: one description that both validates a value and\n * renders as JSON Schema, so the published `schema.json` and the checks the\n * loader runs cannot disagree about what a configuration may say.\n */\n\ninterface Described {\n readonly description?: string;\n}\n\nexport type Schema =\n | (Described & {\n readonly type: 'string';\n readonly enum?: readonly string[];\n readonly nullable?: boolean;\n readonly minLength?: number;\n })\n | (Described & { readonly type: 'boolean' })\n | (Described & { readonly type: 'integer'; readonly minimum?: number; readonly maximum?: number })\n | (Described & { readonly type: 'array'; readonly items: Schema })\n | (Described & {\n readonly type: 'object';\n readonly properties: Readonly<Record<string, Schema>>;\n readonly required?: readonly string[];\n })\n | (Described & { readonly type: 'map'; readonly values: Schema })\n | (Described & { readonly type: 'anyOf'; readonly options: readonly Schema[] })\n | (Described & { readonly type: 'any' });\n\ntype Kind = 'null' | 'string' | 'boolean' | 'number' | 'array' | 'object';\n\nfunction kindOf(value: unknown): Kind {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n switch (typeof value) {\n case 'string':\n return 'string';\n case 'boolean':\n return 'boolean';\n case 'number':\n return 'number';\n default:\n return 'object';\n }\n}\n\nfunction accepts(schema: Schema, kind: Kind): boolean {\n switch (schema.type) {\n case 'string':\n return kind === 'string' || (kind === 'null' && schema.nullable === true);\n case 'boolean':\n return kind === 'boolean';\n case 'integer':\n return kind === 'number';\n case 'array':\n return kind === 'array';\n case 'object':\n case 'map':\n return kind === 'object';\n case 'anyOf':\n return schema.options.some((option) => accepts(option, kind));\n case 'any':\n return true;\n }\n}\n\nfunction noun(schema: Schema): string {\n switch (schema.type) {\n case 'string':\n return schema.nullable === true ? 'a string or null' : 'a string';\n case 'boolean':\n return 'true or false';\n case 'integer':\n return 'an integer';\n case 'array':\n return 'a list';\n case 'object':\n case 'map':\n return 'an object';\n case 'anyOf':\n return schema.options.map(noun).join(' or ');\n /* v8 ignore next 2 -- \"any\" accepts every value, so no message ever names it. */\n case 'any':\n return 'anything';\n }\n}\n\nfunction at(path: string, key: string): string {\n return path === '' ? key : `${path}.${key}`;\n}\n\n/** The problems with `value`, each naming the path to it. Empty when it conforms. */\nexport function validate(schema: Schema, value: unknown, path = ''): string[] {\n const where = path === '' ? 'the configuration' : `\"${path}\"`;\n if (!accepts(schema, kindOf(value))) return [`${where} must be ${noun(schema)}`];\n switch (schema.type) {\n case 'string': {\n if (typeof value !== 'string') return [];\n if (schema.enum !== undefined && !schema.enum.includes(value)) {\n return [`${where} must be one of ${schema.enum.map((e) => `\"${e}\"`).join(', ')}, not \"${value}\"`];\n }\n if (schema.minLength !== undefined && value.length < schema.minLength) return [`${where} must not be empty`];\n return [];\n }\n case 'integer': {\n const number = value as number;\n if (!Number.isInteger(number)) return [`${where} must be an integer`];\n if (schema.minimum !== undefined && number < schema.minimum) return [`${where} must be at least ${schema.minimum}`];\n if (schema.maximum !== undefined && number > schema.maximum) return [`${where} must be at most ${schema.maximum}`];\n return [];\n }\n case 'array':\n return (value as unknown[]).flatMap((item, i) => validate(schema.items, item, `${path}[${i}]`));\n case 'object': {\n const record = value as Record<string, unknown>;\n const known = Object.keys(schema.properties);\n const problems: string[] = [];\n for (const key of Object.keys(record)) {\n const property = schema.properties[key];\n if (property === undefined) {\n const guess = closest(key, known);\n problems.push(`\"${at(path, key)}\" is not a known key${guess === undefined ? '' : `; did you mean \"${guess}\"?`}`);\n continue;\n }\n problems.push(...validate(property, record[key], at(path, key)));\n }\n for (const key of schema.required ?? []) {\n if (!(key in record)) problems.push(`\"${at(path, key)}\" is required`);\n }\n return problems;\n }\n case 'map':\n return Object.entries(value as Record<string, unknown>).flatMap(([key, item]) =>\n validate(schema.values, item, at(path, key)),\n );\n case 'anyOf': {\n const candidates = schema.options.filter((option) => accepts(option, kindOf(value)));\n let first: string[] | undefined;\n for (const option of candidates) {\n const problems = validate(option, value, path);\n if (problems.length === 0) return [];\n first ??= problems;\n }\n return first ?? [];\n }\n case 'boolean':\n case 'any':\n return [];\n }\n}\n\n/**\n * The known key nearest to a misspelling, when one is near enough to be what\n * was meant. One that keeps no character of the word is no misspelling of it,\n * however short both are: `狀態` is two edits from `id`.\n */\nexport function closest(word: string, options: readonly string[]): string | undefined {\n let best: string | undefined;\n let bestDistance = Math.max(2, Math.floor(word.length / 3)) + 1;\n for (const option of options) {\n const d = distance(word.toLowerCase(), option.toLowerCase());\n if (d < bestDistance && d < Math.max(word.length, option.length)) {\n best = option;\n bestDistance = d;\n }\n }\n return best;\n}\n\nfunction distance(a: string, b: string): number {\n let previous = Array.from({ length: b.length + 1 }, (_, j) => j);\n for (let i = 1; i <= a.length; i += 1) {\n const row = [i];\n for (let j = 1; j <= b.length; j += 1) {\n const cost = a.charAt(i - 1) === b.charAt(j - 1) ? 0 : 1;\n row.push(Math.min((previous[j] as number) + 1, (row[j - 1] as number) + 1, (previous[j - 1] as number) + cost));\n }\n previous = row;\n }\n return previous[b.length] as number;\n}\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json };\n\n/** Renders a schema as JSON Schema (draft 2020-12). */\nexport function toJsonSchema(schema: Schema): { [key: string]: Json } {\n const described = (body: { [key: string]: Json }): { [key: string]: Json } =>\n schema.description === undefined ? body : { description: schema.description, ...body };\n switch (schema.type) {\n case 'string': {\n const body: { [key: string]: Json } = { type: schema.nullable === true ? ['string', 'null'] : 'string' };\n if (schema.enum !== undefined) body['enum'] = [...schema.enum, ...(schema.nullable === true ? [null] : [])];\n if (schema.minLength !== undefined) body['minLength'] = schema.minLength;\n return described(body);\n }\n case 'boolean':\n return described({ type: 'boolean' });\n case 'integer': {\n const body: { [key: string]: Json } = { type: 'integer' };\n if (schema.minimum !== undefined) body['minimum'] = schema.minimum;\n if (schema.maximum !== undefined) body['maximum'] = schema.maximum;\n return described(body);\n }\n case 'array':\n return described({ type: 'array', items: toJsonSchema(schema.items) });\n case 'object': {\n const properties: { [key: string]: Json } = {};\n for (const [key, value] of Object.entries(schema.properties)) properties[key] = toJsonSchema(value);\n const body: { [key: string]: Json } = { type: 'object', properties, additionalProperties: false };\n if (schema.required !== undefined && schema.required.length > 0) body['required'] = [...schema.required];\n return described(body);\n }\n case 'map':\n return described({ type: 'object', additionalProperties: toJsonSchema(schema.values) });\n case 'anyOf':\n return described({ anyOf: schema.options.map(toJsonSchema) });\n case 'any':\n return described({});\n }\n}\n"]}
package/dist/scope.d.ts CHANGED
@@ -5,8 +5,9 @@
5
5
  * protection wins, so "all of `src/` but the schema" is written
6
6
  * `affectedFiles: [src/**]` with `protectedFiles: [src/db/schema.ts]`. Two
7
7
  * briefs meet when some file lies in both writable scopes - in a pattern of
8
- * each, and in neither brief's protections - and the witness search names
9
- * the shortest such file (ADR-0005).
8
+ * each, and in neither brief's protections - and the witness is such a file
9
+ * the tree holds, or else the shortest such path the search builds, as an
10
+ * example (ADR-0005).
10
11
  */
11
12
  import type { Brief } from './brief.js';
12
13
  import { type Glob, type LiteralReading } from './glob.js';
@@ -29,19 +30,40 @@ export declare function scopeOf(brief: Brief, reading: Reading): Scope;
29
30
  export interface Overlap {
30
31
  readonly patterns: readonly [string, string];
31
32
  readonly witness: string;
33
+ /**
34
+ * `true` when the witness is a file the tree holds; `false` when the tree
35
+ * holds none both patterns match outside the protections, and the witness
36
+ * is an example the search built; `null` when no tree was given.
37
+ */
38
+ readonly inTree: boolean | null;
32
39
  }
33
40
  export interface Meeting {
34
41
  /** Every pair of patterns that meets outside both protections, the first scope's pattern first. */
35
42
  readonly overlaps: readonly Overlap[];
36
- /** Pairs of patterns the search could not decide within its budget. */
43
+ /** Pairs of patterns the search could not decide within its budget, and no file of the tree decides. */
37
44
  readonly undecided: readonly (readonly [string, string])[];
38
45
  }
39
46
  /**
40
47
  * Where two writable scopes meet. Each pair of affected patterns is searched
41
48
  * for a file both cover that neither brief protects: a file one brief protects
42
49
  * is one that brief will not write, so it is no collision.
50
+ *
51
+ * The search names the shortest such path, which the tree need not hold:
52
+ * `src/Shop/OrderService.cs` where the tree has `src/Shop/Orders/OrderService.cs`.
53
+ * So where the search finds a meeting, or cannot decide one, the tree's files
54
+ * are read, and the first both patterns match outside the protections is the
55
+ * witness (ADR-0005, amended 2026-09-30). A file that exists and both briefs
56
+ * may write settles a pair the search could not: it is a collision, proved by
57
+ * the file, not a guess. Where the tree holds none, the search's path stands,
58
+ * as an example. A pair the search proves apart has no such file, and the tree
59
+ * is not read for it.
60
+ */
61
+ export declare function meet(a: Scope, b: Scope, budget?: number, files?: readonly string[] | null): Meeting;
62
+ /**
63
+ * A witness as a reader is told it: a file of the tree by its path, and a path
64
+ * the search built with a word that it is an example.
43
65
  */
44
- export declare function meet(a: Scope, b: Scope, budget?: number): Meeting;
66
+ export declare function witnessText(overlap: Overlap): string;
45
67
  export interface Contradiction {
46
68
  /** Affected patterns every file of which is protected: nothing of them is writable. */
47
69
  readonly covered: readonly string[];
package/dist/scope.js CHANGED
@@ -5,10 +5,11 @@
5
5
  * protection wins, so "all of `src/` but the schema" is written
6
6
  * `affectedFiles: [src/**]` with `protectedFiles: [src/db/schema.ts]`. Two
7
7
  * briefs meet when some file lies in both writable scopes - in a pattern of
8
- * each, and in neither brief's protections - and the witness search names
9
- * the shortest such file (ADR-0005).
8
+ * each, and in neither brief's protections - and the witness is such a file
9
+ * the tree holds, or else the shortest such path the search builds, as an
10
+ * example (ADR-0005).
10
11
  */
11
- import { globCovers, globWitness, parseGlob, WITNESS_BUDGET } from './glob.js';
12
+ import { globCovers, globWitness, matchGlob, parseGlob, WITNESS_BUDGET } from './glob.js';
12
13
  /** Patterns that parse, read with one reading. */
13
14
  export function patternsOf(patterns, reading) {
14
15
  return patterns.flatMap((pattern) => {
@@ -19,26 +20,81 @@ export function patternsOf(patterns, reading) {
19
20
  export function scopeOf(brief, reading) {
20
21
  return { brief, affected: patternsOf(brief.affectedFiles, reading), protected: patternsOf(brief.protectedFiles, reading) };
21
22
  }
23
+ const matched = new WeakMap();
24
+ /**
25
+ * The files of a tree a pattern matches, in the tree's order. Found once per
26
+ * pattern and tree, which every pair a brief is in shares; kept or not, the
27
+ * answer is the same, and only the time differs.
28
+ */
29
+ function matching(files, glob) {
30
+ let byGlob = matched.get(files);
31
+ if (byGlob === undefined) {
32
+ byGlob = new WeakMap();
33
+ matched.set(files, byGlob);
34
+ }
35
+ let found = byGlob.get(glob);
36
+ if (found === undefined) {
37
+ found = new Set(files.filter((file) => matchGlob(glob, file)));
38
+ byGlob.set(glob, found);
39
+ }
40
+ return found;
41
+ }
42
+ /**
43
+ * The first file of the tree, in its order, that both patterns match and no
44
+ * protection does. The engine's list is sorted, so the file named is the same
45
+ * on every run.
46
+ */
47
+ function heldInBoth(files, x, y, avoid) {
48
+ const other = matching(files, y);
49
+ for (const file of matching(files, x)) {
50
+ if (other.has(file) && !avoid.some((glob) => matchGlob(glob, file)))
51
+ return file;
52
+ }
53
+ return undefined;
54
+ }
22
55
  /**
23
56
  * Where two writable scopes meet. Each pair of affected patterns is searched
24
57
  * for a file both cover that neither brief protects: a file one brief protects
25
58
  * is one that brief will not write, so it is no collision.
59
+ *
60
+ * The search names the shortest such path, which the tree need not hold:
61
+ * `src/Shop/OrderService.cs` where the tree has `src/Shop/Orders/OrderService.cs`.
62
+ * So where the search finds a meeting, or cannot decide one, the tree's files
63
+ * are read, and the first both patterns match outside the protections is the
64
+ * witness (ADR-0005, amended 2026-09-30). A file that exists and both briefs
65
+ * may write settles a pair the search could not: it is a collision, proved by
66
+ * the file, not a guess. Where the tree holds none, the search's path stands,
67
+ * as an example. A pair the search proves apart has no such file, and the tree
68
+ * is not read for it.
26
69
  */
27
- export function meet(a, b, budget = WITNESS_BUDGET) {
70
+ export function meet(a, b, budget = WITNESS_BUDGET, files = null) {
28
71
  const avoid = [...a.protected, ...b.protected].map((p) => p.glob);
29
72
  const overlaps = [];
30
73
  const undecided = [];
31
74
  for (const x of a.affected) {
32
75
  for (const y of b.affected) {
33
76
  const witness = globWitness([x.glob, y.glob], avoid, budget);
34
- if (witness.kind === 'found')
35
- overlaps.push({ patterns: [x.pattern, y.pattern], witness: witness.path });
36
- else if (witness.kind === 'undecided')
37
- undecided.push([x.pattern, y.pattern]);
77
+ if (witness.kind === 'none')
78
+ continue;
79
+ const patterns = [x.pattern, y.pattern];
80
+ const held = files === null ? undefined : heldInBoth(files, x.glob, y.glob, avoid);
81
+ if (held !== undefined)
82
+ overlaps.push({ patterns, witness: held, inTree: true });
83
+ else if (witness.kind === 'found')
84
+ overlaps.push({ patterns, witness: witness.path, inTree: files === null ? null : false });
85
+ else
86
+ undecided.push(patterns);
38
87
  }
39
88
  }
40
89
  return { overlaps, undecided };
41
90
  }
91
+ /**
92
+ * A witness as a reader is told it: a file of the tree by its path, and a path
93
+ * the search built with a word that it is an example.
94
+ */
95
+ export function witnessText(overlap) {
96
+ return overlap.inTree === false ? `${overlap.witness}, an example not in the tree` : overlap.witness;
97
+ }
42
98
  /** The affected patterns a brief's own protections cover entirely. */
43
99
  export function contradictions(scope, budget =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AAC;IAC3D,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC","sourcesContent":["/**\n * A brief's scope, and whether two briefs can write the same file.\n *\n * What a brief may write is its `affectedFiles` less its `protectedFiles`:\n * protection wins, so \"all of `src/` but the schema\" is written\n * `affectedFiles: [src/**]` with `protectedFiles: [src/db/schema.ts]`. Two\n * briefs meet when some file lies in both writable scopes - in a pattern of\n * each, and in neither brief's protections - and the witness search names\n * the shortest such file (ADR-0005).\n */\n\nimport type { Brief } from './brief.js';\nimport { type Glob, globCovers, globWitness, type LiteralReading, parseGlob, WITNESS_BUDGET } from './glob.js';\n\n/** How a literal path is read, as {@link readingIn} answers for a tree. */\nexport type Reading = (path: string) => LiteralReading;\n\nexport interface ScopePattern {\n readonly pattern: string;\n readonly glob: Glob;\n}\n\nexport interface Scope {\n readonly brief: Brief;\n /** The `affectedFiles` that parse. One that does not is the `glob` rule's finding, and scopes nothing. */\n readonly affected: readonly ScopePattern[];\n readonly protected: readonly ScopePattern[];\n}\n\n/** Patterns that parse, read with one reading. */\nexport function patternsOf(patterns: readonly string[], reading: Reading): ScopePattern[] {\n return patterns.flatMap((pattern) => {\n const parsed = parseGlob(pattern, { literal: reading });\n return parsed.ok ? [{ pattern, glob: parsed.glob }] : [];\n });\n}\n\nexport function scopeOf(brief: Brief, reading: Reading): Scope {\n return { brief, affected: patternsOf(brief.affectedFiles, reading), protected: patternsOf(brief.protectedFiles, reading) };\n}\n\n/** A pattern from each scope, and a file both may write. */\nexport interface Overlap {\n readonly patterns: readonly [string, string];\n readonly witness: string;\n}\n\nexport interface Meeting {\n /** Every pair of patterns that meets outside both protections, the first scope's pattern first. */\n readonly overlaps: readonly Overlap[];\n /** Pairs of patterns the search could not decide within its budget. */\n readonly undecided: readonly (readonly [string, string])[];\n}\n\n/**\n * Where two writable scopes meet. Each pair of affected patterns is searched\n * for a file both cover that neither brief protects: a file one brief protects\n * is one that brief will not write, so it is no collision.\n */\nexport function meet(a: Scope, b: Scope, budget: number = WITNESS_BUDGET): Meeting {\n const avoid = [...a.protected, ...b.protected].map((p) => p.glob);\n const overlaps: Overlap[] = [];\n const undecided: (readonly [string, string])[] = [];\n for (const x of a.affected) {\n for (const y of b.affected) {\n const witness = globWitness([x.glob, y.glob], avoid, budget);\n if (witness.kind === 'found') overlaps.push({ patterns: [x.pattern, y.pattern], witness: witness.path });\n else if (witness.kind === 'undecided') undecided.push([x.pattern, y.pattern]);\n }\n }\n return { overlaps, undecided };\n}\n\nexport interface Contradiction {\n /** Affected patterns every file of which is protected: nothing of them is writable. */\n readonly covered: readonly string[];\n /** Affected patterns for which the search could not decide within its budget. */\n readonly undecided: readonly string[];\n}\n\n/** The affected patterns a brief's own protections cover entirely. */\nexport function contradictions(scope: Scope, budget: number = WITNESS_BUDGET): Contradiction {\n const covered: string[] = [];\n const undecided: string[] = [];\n const outer = scope.protected.map((p) => p.glob);\n for (const { pattern, glob } of scope.affected) {\n const answer = globCovers(outer, glob, budget);\n if (answer === true) covered.push(pattern);\n else if (answer === 'undecided') undecided.push(pattern);\n }\n return { covered, undecided };\n}\n"]}
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAa,UAAU,EAAE,WAAW,EAAuB,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAiB1H,kDAAkD;AAClD,MAAM,UAAU,UAAU,CAAC,QAA2B,EAAE,OAAgB;IACtE,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAA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AAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC","sourcesContent":["/**\n * A brief's scope, and whether two briefs can write the same file.\n *\n * What a brief may write is its `affectedFiles` less its `protectedFiles`:\n * protection wins, so \"all of `src/` but the schema\" is written\n * `affectedFiles: [src/**]` with `protectedFiles: [src/db/schema.ts]`. Two\n * briefs meet when some file lies in both writable scopes - in a pattern of\n * each, and in neither brief's protections - and the witness is such a file\n * the tree holds, or else the shortest such path the search builds, as an\n * example (ADR-0005).\n */\n\nimport type { Brief } from './brief.js';\nimport { type Glob, globCovers, globWitness, type LiteralReading, matchGlob, parseGlob, WITNESS_BUDGET } from './glob.js';\n\n/** How a literal path is read, as {@link readingIn} answers for a tree. */\nexport type Reading = (path: string) => LiteralReading;\n\nexport interface ScopePattern {\n readonly pattern: string;\n readonly glob: Glob;\n}\n\nexport interface Scope {\n readonly brief: Brief;\n /** The `affectedFiles` that parse. One that does not is the `glob` rule's finding, and scopes nothing. */\n readonly affected: readonly ScopePattern[];\n readonly protected: readonly ScopePattern[];\n}\n\n/** Patterns that parse, read with one reading. */\nexport function patternsOf(patterns: readonly string[], reading: Reading): ScopePattern[] {\n return patterns.flatMap((pattern) => {\n const parsed = parseGlob(pattern, { literal: reading });\n return parsed.ok ? [{ pattern, glob: parsed.glob }] : [];\n });\n}\n\nexport function scopeOf(brief: Brief, reading: Reading): Scope {\n return { brief, affected: patternsOf(brief.affectedFiles, reading), protected: patternsOf(brief.protectedFiles, reading) };\n}\n\n/** A pattern from each scope, and a file both may write. */\nexport interface Overlap {\n readonly patterns: readonly [string, string];\n readonly witness: string;\n /**\n * `true` when the witness is a file the tree holds; `false` when the tree\n * holds none both patterns match outside the protections, and the witness\n * is an example the search built; `null` when no tree was given.\n */\n readonly inTree: boolean | null;\n}\n\nexport interface Meeting {\n /** Every pair of patterns that meets outside both protections, the first scope's pattern first. */\n readonly overlaps: readonly Overlap[];\n /** Pairs of patterns the search could not decide within its budget, and no file of the tree decides. */\n readonly undecided: readonly (readonly [string, string])[];\n}\n\nconst matched = new WeakMap<readonly string[], WeakMap<Glob, ReadonlySet<string>>>();\n\n/**\n * The files of a tree a pattern matches, in the tree's order. Found once per\n * pattern and tree, which every pair a brief is in shares; kept or not, the\n * answer is the same, and only the time differs.\n */\nfunction matching(files: readonly string[], glob: Glob): ReadonlySet<string> {\n let byGlob = matched.get(files);\n if (byGlob === undefined) {\n byGlob = new WeakMap();\n matched.set(files, byGlob);\n }\n let found = byGlob.get(glob);\n if (found === undefined) {\n found = new Set(files.filter((file) => matchGlob(glob, file)));\n byGlob.set(glob, found);\n }\n return found;\n}\n\n/**\n * The first file of the tree, in its order, that both patterns match and no\n * protection does. The engine's list is sorted, so the file named is the same\n * on every run.\n */\nfunction heldInBoth(files: readonly string[], x: Glob, y: Glob, avoid: readonly Glob[]): string | undefined {\n const other = matching(files, y);\n for (const file of matching(files, x)) {\n if (other.has(file) && !avoid.some((glob) => matchGlob(glob, file))) return file;\n }\n return undefined;\n}\n\n/**\n * Where two writable scopes meet. Each pair of affected patterns is searched\n * for a file both cover that neither brief protects: a file one brief protects\n * is one that brief will not write, so it is no collision.\n *\n * The search names the shortest such path, which the tree need not hold:\n * `src/Shop/OrderService.cs` where the tree has `src/Shop/Orders/OrderService.cs`.\n * So where the search finds a meeting, or cannot decide one, the tree's files\n * are read, and the first both patterns match outside the protections is the\n * witness (ADR-0005, amended 2026-09-30). A file that exists and both briefs\n * may write settles a pair the search could not: it is a collision, proved by\n * the file, not a guess. Where the tree holds none, the search's path stands,\n * as an example. A pair the search proves apart has no such file, and the tree\n * is not read for it.\n */\nexport function meet(a: Scope, b: Scope, budget: number = WITNESS_BUDGET, files: readonly string[] | null = null): Meeting {\n const avoid = [...a.protected, ...b.protected].map((p) => p.glob);\n const overlaps: Overlap[] = [];\n const undecided: (readonly [string, string])[] = [];\n for (const x of a.affected) {\n for (const y of b.affected) {\n const witness = globWitness([x.glob, y.glob], avoid, budget);\n if (witness.kind === 'none') continue;\n const patterns = [x.pattern, y.pattern] as const;\n const held = files === null ? undefined : heldInBoth(files, x.glob, y.glob, avoid);\n if (held !== undefined) overlaps.push({ patterns, witness: held, inTree: true });\n else if (witness.kind === 'found') overlaps.push({ patterns, witness: witness.path, inTree: files === null ? null : false });\n else undecided.push(patterns);\n }\n }\n return { overlaps, undecided };\n}\n\n/**\n * A witness as a reader is told it: a file of the tree by its path, and a path\n * the search built with a word that it is an example.\n */\nexport function witnessText(overlap: Overlap): string {\n return overlap.inTree === false ? `${overlap.witness}, an example not in the tree` : overlap.witness;\n}\n\nexport interface Contradiction {\n /** Affected patterns every file of which is protected: nothing of them is writable. */\n readonly covered: readonly string[];\n /** Affected patterns for which the search could not decide within its budget. */\n readonly undecided: readonly string[];\n}\n\n/** The affected patterns a brief's own protections cover entirely. */\nexport function contradictions(scope: Scope, budget: number = WITNESS_BUDGET): Contradiction {\n const covered: string[] = [];\n const undecided: string[] = [];\n const outer = scope.protected.map((p) => p.glob);\n for (const { pattern, glob } of scope.affected) {\n const answer = globCovers(outer, glob, budget);\n if (answer === true) covered.push(pattern);\n else if (answer === 'undecided') undecided.push(pattern);\n }\n return { covered, undecided };\n}\n"]}
package/dist/trigger.d.ts CHANGED
@@ -11,7 +11,8 @@
11
11
  *
12
12
  * The lists are deliberately short. A trigger this reads as an event when it
13
13
  * is a time is a miss, and a miss costs less here than refusing a real event
14
- * for looking like a date.
14
+ * for looking like a date. They are English, as the status words are: a time
15
+ * written in another language is a word on no list, so it reads as an event.
15
16
  */
16
17
  /** Whether a trigger has a word that says what must happen, rather than only when. */
17
18
  export declare function namesAnEvent(trigger: string): boolean;
package/dist/trigger.js CHANGED
@@ -11,7 +11,8 @@
11
11
  *
12
12
  * The lists are deliberately short. A trigger this reads as an event when it
13
13
  * is a time is a miss, and a miss costs less here than refusing a real event
14
- * for looking like a date.
14
+ * for looking like a date. They are English, as the status words are: a time
15
+ * written in another language is a word on no list, so it reads as an event.
15
16
  */
16
17
  const MONTHS = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
17
18
  const WEEKDAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
@@ -1 +1 @@
1
- {"version":3,"file":"trigger.js","sourceRoot":"","sources":["../src/trigger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAC1I,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAEhG,4CAA4C;AAC5C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC;IACnB,GAAG,MAAM;IACT,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnC,MAAM;IACN,GAAG,QAAQ;IACX,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,qBAAqB;IACrB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC;IACzG,OAAO;IACP,UAAU;IACV,MAAM;IACN,OAAO;IACP,oBAAoB;IACpB,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC;IAC5H,4BAA4B;IAC5B,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC;CACrI,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,IAAI,GAAG,kCAAkC,CAAC;AAEhD,oGAAoG;AACpG,SAAS,KAAK,CAAC,IAAY;IACzB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;AAC3D,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * Whether a deferral's trigger names an event or only a time.\n *\n * Deferred work comes back when something happens: \"when the second tenant\n * signs\", \"when p95 exceeds 200 ms\". A date is not that. It passes whether or\n * not the reason for the work has arrived, and a deferral that fires on a date\n * is a reminder to look again, which the deferral itself already is. So a\n * trigger made only of words that say when - a date, a quarter, a month or a\n * weekday, a stretch of time and the small words that join them - is refused,\n * and one word that says what is enough to pass.\n *\n * The lists are deliberately short. A trigger this reads as an event when it\n * is a time is a miss, and a miss costs less here than refusing a real event\n * for looking like a date.\n */\n\nconst MONTHS = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];\nconst WEEKDAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];\n\n/** Words that say when and nothing else. */\nconst WHEN = new Set([\n ...MONTHS,\n ...MONTHS.map((m) => m.slice(0, 3)),\n 'sept',\n ...WEEKDAYS,\n ...WEEKDAYS.map((d) => d.slice(0, 3)),\n // A stretch of time.\n ...['day', 'week', 'weekend', 'month', 'quarter', 'year', 'sprint'].flatMap((unit) => [unit, `${unit}s`]),\n 'today',\n 'tomorrow',\n 'soon',\n 'later',\n // How many of them.\n ...['a', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'few', 'couple'],\n // The words that join them.\n ...['in', 'on', 'by', 'at', 'after', 'before', 'until', 'from', 'of', 'the', 'next', 'this', 'end', 'start', 'early', 'mid', 'late'],\n]);\n\n/**\n * A number or an ordinal - `2026`, `15`, `15th` - or a quarter, `Q3`. A date is\n * its numbers: `2026-10-01` and `10/01/2026` are read a number at a time.\n */\nconst DATE = /^(?:q[1-4]|\\d+(?:st|nd|rd|th)?)$/;\n\n/** The runs of letters and digits, in lower case: `mid-2027` is two words, and punctuation none. */\nfunction words(text: string): readonly string[] {\n return text.toLowerCase().match(/[\\p{L}\\p{N}]+/gu) ?? [];\n}\n\n/** Whether a trigger has a word that says what must happen, rather than only when. */\nexport function namesAnEvent(trigger: string): boolean {\n return words(trigger).some((word) => !WHEN.has(word) && !DATE.test(word));\n}\n"]}
1
+ {"version":3,"file":"trigger.js","sourceRoot":"","sources":["../src/trigger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAC1I,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,SAA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AS,KAAK,CAAC,IAAY;IACzB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;AAC3D,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * Whether a deferral's trigger names an event or only a time.\n *\n * Deferred work comes back when something happens: \"when the second tenant\n * signs\", \"when p95 exceeds 200 ms\". A date is not that. It passes whether or\n * not the reason for the work has arrived, and a deferral that fires on a date\n * is a reminder to look again, which the deferral itself already is. So a\n * trigger made only of words that say when - a date, a quarter, a month or a\n * weekday, a stretch of time and the small words that join them - is refused,\n * and one word that says what is enough to pass.\n *\n * The lists are deliberately short. A trigger this reads as an event when it\n * is a time is a miss, and a miss costs less here than refusing a real event\n * for looking like a date. They are English, as the status words are: a time\n * written in another language is a word on no list, so it reads as an event.\n */\n\nconst MONTHS = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];\nconst WEEKDAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];\n\n/** Words that say when and nothing else. */\nconst WHEN = new Set([\n ...MONTHS,\n ...MONTHS.map((m) => m.slice(0, 3)),\n 'sept',\n ...WEEKDAYS,\n ...WEEKDAYS.map((d) => d.slice(0, 3)),\n // A stretch of time.\n ...['day', 'week', 'weekend', 'month', 'quarter', 'year', 'sprint'].flatMap((unit) => [unit, `${unit}s`]),\n 'today',\n 'tomorrow',\n 'soon',\n 'later',\n // How many of them.\n ...['a', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'few', 'couple'],\n // The words that join them.\n ...['in', 'on', 'by', 'at', 'after', 'before', 'until', 'from', 'of', 'the', 'next', 'this', 'end', 'start', 'early', 'mid', 'late'],\n]);\n\n/**\n * A number or an ordinal - `2026`, `15`, `15th` - or a quarter, `Q3`. A date is\n * its numbers: `2026-10-01` and `10/01/2026` are read a number at a time.\n */\nconst DATE = /^(?:q[1-4]|\\d+(?:st|nd|rd|th)?)$/;\n\n/** The runs of letters and digits, in lower case: `mid-2027` is two words, and punctuation none. */\nfunction words(text: string): readonly string[] {\n return text.toLowerCase().match(/[\\p{L}\\p{N}]+/gu) ?? [];\n}\n\n/** Whether a trigger has a word that says what must happen, rather than only when. */\nexport function namesAnEvent(trigger: string): boolean {\n return words(trigger).some((word) => !WHEN.has(word) && !DATE.test(word));\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -36,4 +36,13 @@ export interface Finding {
36
36
  readonly path?: string | undefined;
37
37
  /** The paths of a finding about several, such as the files a round changed outside its scope. */
38
38
  readonly paths?: readonly string[] | undefined;
39
+ /**
40
+ * What the finding is about within its brief, where a rule can report more
41
+ * than one thing there: a section, a pattern, a dependency, the other brief
42
+ * of a pair. With the rule, the file and the brief it is the finding's
43
+ * identity, which the GitLab fingerprint is built from, so it holds no
44
+ * count, no witness and nothing else a message says that can change while
45
+ * the problem stays.
46
+ */
47
+ readonly subject?: string | undefined;
39
48
  }
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG","sourcesContent":["/**\n * Types shared across the pipeline. Type-only: this module compiles to nothing.\n */\n\nexport type Severity = 'error' | 'warning' | 'note';\n\n/** A severity as configuration spells it, where `off` silences a rule. */\nexport type SeveritySetting = Severity | 'off';\n\n/** Where a brief lives. Location is the authority on whether a brief is archived. */\nexport type Phase = 'live' | 'archived';\n\n/**\n * The lifecycle a brief moves through. `draft` and `deferred` are optional: a\n * repository that never writes one maps no word to it. A deferred brief waits\n * in the live directory for an event its `trigger` names, and runs in no wave\n * until then. There is no persisted \"archiving\" state; archival is a\n * transaction, and a transaction that stops half-way is rolled back rather\n * than recorded.\n */\nexport type Status = 'draft' | 'active' | 'deferred' | 'archived';\n\n/**\n * One problem, located. Lines are 1-based; a finding about a file as a whole\n * points at line 1.\n */\nexport interface Finding {\n readonly rule: string;\n readonly severity: Severity;\n readonly message: string;\n /** Repository-relative POSIX path. */\n readonly file: string;\n readonly line: number;\n readonly brief?: string | undefined;\n /** The concrete next action, where there is one. */\n readonly hint?: string | undefined;\n /**\n * The one repository path a finding is about, where it is about one: a\n * protected file the round changed is one finding per file, and names it.\n */\n readonly path?: string | undefined;\n /** The paths of a finding about several, such as the files a round changed outside its scope. */\n readonly paths?: readonly string[] | undefined;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG","sourcesContent":["/**\n * Types shared across the pipeline. Type-only: this module compiles to nothing.\n */\n\nexport type Severity = 'error' | 'warning' | 'note';\n\n/** A severity as configuration spells it, where `off` silences a rule. */\nexport type SeveritySetting = Severity | 'off';\n\n/** Where a brief lives. Location is the authority on whether a brief is archived. */\nexport type Phase = 'live' | 'archived';\n\n/**\n * The lifecycle a brief moves through. `draft` and `deferred` are optional: a\n * repository that never writes one maps no word to it. A deferred brief waits\n * in the live directory for an event its `trigger` names, and runs in no wave\n * until then. There is no persisted \"archiving\" state; archival is a\n * transaction, and a transaction that stops half-way is rolled back rather\n * than recorded.\n */\nexport type Status = 'draft' | 'active' | 'deferred' | 'archived';\n\n/**\n * One problem, located. Lines are 1-based; a finding about a file as a whole\n * points at line 1.\n */\nexport interface Finding {\n readonly rule: string;\n readonly severity: Severity;\n readonly message: string;\n /** Repository-relative POSIX path. */\n readonly file: string;\n readonly line: number;\n readonly brief?: string | undefined;\n /** The concrete next action, where there is one. */\n readonly hint?: string | undefined;\n /**\n * The one repository path a finding is about, where it is about one: a\n * protected file the round changed is one finding per file, and names it.\n */\n readonly path?: string | undefined;\n /** The paths of a finding about several, such as the files a round changed outside its scope. */\n readonly paths?: readonly string[] | undefined;\n /**\n * What the finding is about within its brief, where a rule can report more\n * than one thing there: a section, a pattern, a dependency, the other brief\n * of a pair. With the rule, the file and the brief it is the finding's\n * identity, which the GitLab fingerprint is built from, so it holds no\n * count, no witness and nothing else a message says that can change while\n * the problem stays.\n */\n readonly subject?: string | undefined;\n}\n"]}
@@ -87,7 +87,17 @@ export declare function readFrontMatter(source: string, options?: ReadOptions):
87
87
  export declare function parseInline(text: string): YamlValue;
88
88
  /** Null in the YAML 1.2 core schema: empty, `~` or `null` in any of its three spellings. */
89
89
  export declare function isNull(scalar: YamlScalar): boolean;
90
- /** Renders a string as a scalar that reads back as the same string. */
90
+ /**
91
+ * Renders a string as a scalar that reads back as the same string.
92
+ *
93
+ * Plain only as a YAML plain scalar that reads back as itself: a letter
94
+ * first, of any script, then letters, marks, digits, spaces and `._/+-` - so
95
+ * a status of `封存` or `已接受` is written as it is typed - with no space at
96
+ * the end, and none of `true`, `false`, `null`, `yes`, `no`, `on`, `off` or
97
+ * `~` in any case, which YAML 1.2 or 1.1 reads as a boolean or a null.
98
+ * Anything else is quoted: an indicator, `: ` or ` #`, a number, a space at
99
+ * either end, a full-width space or punctuation.
100
+ */
91
101
  export declare function renderScalar(value: string): string;
92
102
  export declare function findEntry(frontMatter: FrontMatter | null, key: string): FrontMatterEntry | undefined;
93
103
  /**
@@ -30,7 +30,14 @@ export function frontMatterKind(firstLine) {
30
30
  export function frontMatterCloses(line, kind) {
31
31
  return (kind === 'yaml' ? YAML_CLOSE : TOML_FENCE).test(line);
32
32
  }
33
- const KEY = /^([A-Za-z_][\w.-]*)[ \t]*:(?:[ \t]+(.*))?$/;
33
+ /**
34
+ * A key and what follows its colon. A key is a word of any script, as a YAML
35
+ * plain key may be: a letter or `_` first, then letters, marks, digits and
36
+ * `_.-`, so `狀態` and `状态` are keys as `status` is. Nothing else is one: a
37
+ * digit or a mark first, a space, punctuation, and a full-width colon, which
38
+ * YAML does not read as one.
39
+ */
40
+ const KEY = /^([\p{L}_][\p{L}\p{M}\p{N}_.-]*)[ \t]*:(?:[ \t]+(.*))?$/u;
34
41
  const SEQUENCE_ITEM = /^([ \t]*)-(?:[ \t]+(.*))?$/;
35
42
  const BLANK_OR_COMMENT = /^[ \t]*(?:#.*)?$/;
36
43
  export function keyName(key) {
@@ -415,10 +422,20 @@ function parseFlowSequence(text) {
415
422
  export function isNull(scalar) {
416
423
  return !scalar.quoted && ['', '~', 'null', 'Null', 'NULL'].includes(scalar.text);
417
424
  }
418
- /** Renders a string as a scalar that reads back as the same string. */
425
+ /**
426
+ * Renders a string as a scalar that reads back as the same string.
427
+ *
428
+ * Plain only as a YAML plain scalar that reads back as itself: a letter
429
+ * first, of any script, then letters, marks, digits, spaces and `._/+-` - so
430
+ * a status of `封存` or `已接受` is written as it is typed - with no space at
431
+ * the end, and none of `true`, `false`, `null`, `yes`, `no`, `on`, `off` or
432
+ * `~` in any case, which YAML 1.2 or 1.1 reads as a boolean or a null.
433
+ * Anything else is quoted: an indicator, `: ` or ` #`, a number, a space at
434
+ * either end, a full-width space or punctuation.
435
+ */
419
436
  export function renderScalar(value) {
420
437
  const reserved = /^(?:true|false|null|yes|no|on|off|~)$/i.test(value);
421
- const plain = /^[A-Za-z][A-Za-z0-9 ._/+-]*$/.test(value) && !value.endsWith(' ');
438
+ const plain = /^\p{L}[\p{L}\p{M}\p{N} ._/+-]*$/u.test(value) && !value.endsWith(' ');
422
439
  return plain && !reserved ? value : JSON.stringify(value);
423
440
  }
424
441
  export function findEntry(frontMatter, key) {