universal-dev-standards 6.14.0-beta.6 → 6.14.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -3
- package/bin/uds.js +30 -6
- package/bundled/ai/options/code-review/pr-review.ai.yaml +20 -1
- package/bundled/ai/standards/code-review.ai.yaml +15 -2
- package/bundled/ai/standards/developer-memory.ai.yaml +12 -2
- package/bundled/ai/standards/full-coverage-testing.ai.yaml +44 -6
- package/bundled/ai/standards/open-work-tracking.ai.yaml +191 -11
- package/bundled/ai/standards/pipeline-security-gates.ai.yaml +48 -3
- package/bundled/ai/standards/project-context-memory.ai.yaml +12 -2
- package/bundled/core/code-review-checklist.md +20 -2
- package/bundled/core/developer-memory.md +12 -2
- package/bundled/core/full-coverage-testing.md +44 -4
- package/bundled/core/open-work-tracking.md +156 -16
- package/bundled/core/pipeline-security-gates.md +63 -0
- package/bundled/core/project-context-memory.md +10 -2
- package/bundled/locales/zh-CN/CHANGELOG.md +51 -3
- package/bundled/locales/zh-CN/README.md +1 -1
- package/bundled/locales/zh-CN/SECURITY.md +1 -1
- package/bundled/locales/zh-CN/adoption/ADOPTION-GUIDE.md +13 -4
- package/bundled/locales/zh-CN/adoption/STATIC-DYNAMIC-GUIDE.md +7 -1
- package/bundled/locales/zh-CN/adoption/checklists/enterprise.md +7 -1
- package/bundled/locales/zh-CN/adoption/checklists/minimal.md +13 -3
- package/bundled/locales/zh-CN/adoption/checklists/recommended.md +7 -1
- package/bundled/locales/zh-CN/core/code-review-checklist.md +17 -0
- package/bundled/locales/zh-CN/core/developer-memory.md +9 -0
- package/bundled/locales/zh-CN/core/full-coverage-testing.md +48 -8
- package/bundled/locales/zh-CN/core/pipeline-security-gates.md +64 -4
- package/bundled/locales/zh-CN/core/project-context-memory.md +5 -0
- package/bundled/locales/zh-CN/docs/AVAILABLE-STANDARDS.md +70 -0
- package/bundled/locales/zh-CN/docs/CHEATSHEET.md +4 -3
- package/bundled/locales/zh-CN/docs/CLI-INIT-OPTIONS.md +25 -23
- package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +13 -11
- package/bundled/locales/zh-CN/docs/USAGE-MODES-COMPARISON.md +6 -6
- package/bundled/locales/zh-CN/docs/WINDOWS-GUIDE.md +7 -1
- package/bundled/locales/zh-CN/docs/user/GETTING-STARTED.md +44 -0
- package/bundled/locales/zh-CN/options/code-review/pr-review.md +13 -2
- package/bundled/locales/zh-TW/CHANGELOG.md +51 -3
- package/bundled/locales/zh-TW/README.md +1 -1
- package/bundled/locales/zh-TW/SECURITY.md +1 -1
- package/bundled/locales/zh-TW/adoption/ADOPTION-GUIDE.md +13 -4
- package/bundled/locales/zh-TW/adoption/STATIC-DYNAMIC-GUIDE.md +7 -1
- package/bundled/locales/zh-TW/adoption/checklists/enterprise.md +7 -1
- package/bundled/locales/zh-TW/adoption/checklists/minimal.md +13 -3
- package/bundled/locales/zh-TW/adoption/checklists/recommended.md +7 -1
- package/bundled/locales/zh-TW/core/code-review-checklist.md +17 -0
- package/bundled/locales/zh-TW/core/developer-memory.md +9 -0
- package/bundled/locales/zh-TW/core/full-coverage-testing.md +48 -8
- package/bundled/locales/zh-TW/core/open-work-tracking.md +90 -14
- package/bundled/locales/zh-TW/core/pipeline-security-gates.md +64 -4
- package/bundled/locales/zh-TW/core/project-context-memory.md +5 -0
- package/bundled/locales/zh-TW/docs/AVAILABLE-STANDARDS.md +70 -0
- package/bundled/locales/zh-TW/docs/CHEATSHEET.md +4 -3
- package/bundled/locales/zh-TW/docs/CLI-INIT-OPTIONS.md +25 -23
- package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +13 -11
- package/bundled/locales/zh-TW/docs/USAGE-MODES-COMPARISON.md +6 -6
- package/bundled/locales/zh-TW/docs/WINDOWS-GUIDE.md +7 -1
- package/bundled/locales/zh-TW/docs/user/GETTING-STARTED.md +44 -0
- package/bundled/locales/zh-TW/options/code-review/pr-review.md +13 -2
- package/bundled/skills/SKILL_NAMING.md +9 -0
- package/bundled/templates/gates/check-anti-fake-tests.mjs +305 -5
- package/package.json +3 -1
- package/src/commands/audit.js +9 -2
- package/src/commands/check.js +17 -0
- package/src/commands/init.js +41 -21
- package/src/commands/open-work.js +65 -6
- package/src/commands/skills.js +19 -33
- package/src/commands/update.js +61 -61
- package/src/core/open-work-config.js +103 -0
- package/src/flows/init-flow.js +10 -0
- package/src/i18n/messages.js +237 -60
- package/src/installers/skills-installer.js +3 -1
- package/src/prompts/init.js +148 -13
- package/src/reconciler/index.js +42 -5
- package/src/utils/available-standards-report.js +144 -0
- package/src/utils/available-standards.js +216 -0
- package/src/utils/copier.js +5 -4
- package/src/utils/friction-detector.js +27 -0
- package/src/utils/open-work-tracking.mjs +919 -48
- package/src/utils/skill-frontmatter.js +102 -0
- package/src/utils/skill-name-collision.js +169 -0
- package/src/utils/skills-install-paths.js +114 -0
- package/src/utils/skills-installer.js +63 -105
- package/src/utils/transient-fs.js +113 -0
- package/standards-registry.json +9 -9
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Open-work-tracking reference checks for OWT-017
|
|
4
|
-
* open-work-tracking 1.
|
|
3
|
+
* Open-work-tracking reference checks for OWT-017 … OWT-028.
|
|
4
|
+
* open-work-tracking 1.4.0 參考判定程序(OWT-017~028)。
|
|
5
5
|
* // implements DEC-122-L1
|
|
6
|
+
* // implements XSPEC-459
|
|
7
|
+
* // implements XSPEC-460
|
|
8
|
+
* // implements XSPEC-461
|
|
9
|
+
* // implements XSPEC-464
|
|
6
10
|
*
|
|
7
11
|
* ── Where this lives, and why there is exactly one copy ─────────────────────
|
|
8
12
|
* This file is the ONE body of the rules. Two front doors call it and neither
|
|
9
13
|
* holds a copy:
|
|
10
|
-
* uds open-work <next-action|revision|separation|self-test> ...
|
|
14
|
+
* uds open-work <next-action|revision|separation|waiting|observations|self-test> ...
|
|
11
15
|
* cli/src/commands/open-work.js, shipped in the npm package (`cli/src`
|
|
12
16
|
* is in package.json `files`), so an adopter can run it without a clone.
|
|
13
17
|
* node scripts/check-open-work-tracking.mjs ...
|
|
@@ -33,10 +37,10 @@
|
|
|
33
37
|
* nothing relative. The `.mjs` extension is part of that: a copy in a bare temp
|
|
34
38
|
* directory has no package.json, and only `.mjs` is read as an ES module there.
|
|
35
39
|
*
|
|
36
|
-
* ──
|
|
40
|
+
* ── Five checks ─────────────────────────────────────────────────────────────
|
|
37
41
|
* next-action OWT-019 every "next action" field names a file path, test
|
|
38
42
|
* name, command or requirement identifier.
|
|
39
|
-
* Three outcomes, never one green:
|
|
43
|
+
* Three outcomes, never one green, and (464) a fourth:
|
|
40
44
|
* named-resolved an object was found (a path exists)
|
|
41
45
|
* named-unresolved an object is named but not found
|
|
42
46
|
* (legitimate when the next action
|
|
@@ -44,6 +48,13 @@
|
|
|
44
48
|
* could not apply (command, test
|
|
45
49
|
* name, identifier)
|
|
46
50
|
* unnamed VIOLATION — the only failure
|
|
51
|
+
* waiting-on-reply the row is `asked-awaiting` and `waiting` finds
|
|
52
|
+
* nothing wrong with it (OWT-020, OWT-022: asked-at,
|
|
53
|
+
* what it waits for, what releases it), so its next
|
|
54
|
+
* step IS the reply and OWT-019 is not applied. Not
|
|
55
|
+
* a violation, not "named", not complete; listed
|
|
56
|
+
* apart with its age. Decided by the same function
|
|
57
|
+
* `waiting` runs, never by a second copy.
|
|
47
58
|
* A field is read in three shapes, all through the one
|
|
48
59
|
* VOCAB.nextAction list: a heading section, an inline
|
|
49
60
|
* "Next action: ..." label, and EVERY ROW of a table column whose
|
|
@@ -66,6 +77,23 @@
|
|
|
66
77
|
* listing never changes the exit code (OWT-008).
|
|
67
78
|
* separation OWT-017 no single carrier holds both an intent section and
|
|
68
79
|
* a progress / next-action section.
|
|
80
|
+
* waiting OWT-020 a waiting item says which of two states it is in:
|
|
81
|
+
* not-yet-asked or asked-awaiting. A waiting item that is
|
|
82
|
+
* neither is named one by one, never folded into a total.
|
|
83
|
+
* OWT-021 not-yet-asked names the draft or action (a path, command,
|
|
84
|
+
* test name or identifier; the OWT-019 recognisers).
|
|
85
|
+
* OWT-022 asked-awaiting carries asked-at (a dated day), what it
|
|
86
|
+
* waits for and what event releases it (OWT-002).
|
|
87
|
+
* observations OWT-023 a hand-written row about an external fact the assistant
|
|
88
|
+
* cannot observe carries observed-by, observed-at (a dated
|
|
89
|
+
* day, not in the future) and a value of yes, no or unknown.
|
|
90
|
+
* OWT-024 unknown is counted apart and never complete; a row marked
|
|
91
|
+
* done while unknown is a violation.
|
|
92
|
+
* OWT-025 the age of every observation is shown; one older than the
|
|
93
|
+
* threshold is reported as stale, counted apart, never confirmed.
|
|
94
|
+
* OWT-026 the exception does not reach a subject that version control,
|
|
95
|
+
* a spec marker or a CI result determines (OWT-003 stands).
|
|
96
|
+
* Time is injected (`--now`, `--stale-after`), never read inside a rule.
|
|
69
97
|
*
|
|
70
98
|
* ── What none of them can decide (stated, not implied) ──────────────────────
|
|
71
99
|
* - Whether a revision record honestly describes the diff (OWT-014: that is
|
|
@@ -80,10 +108,16 @@
|
|
|
80
108
|
* - Prose revision notes ("2026-09-29 amended R1") are not structural records.
|
|
81
109
|
* Only table rows and list items inside a section whose heading is a
|
|
82
110
|
* revision heading are read.
|
|
111
|
+
* - Whether an observation is TRUE, or still true now (OWT-014). `observations`
|
|
112
|
+
* decides that the fields exist, are well formed and how old the stamp is. A
|
|
113
|
+
* stamp says who saw it and when, never that it still holds.
|
|
114
|
+
* - A waiting item written in words VOCAB_STATE does not hold is read as "other",
|
|
115
|
+
* not as waiting; a table with neither an observed-by nor an observed-at column
|
|
116
|
+
* is not an observation carrier. A clean pass covers only what was recognised.
|
|
83
117
|
*
|
|
84
118
|
* ── UNCALIBRATED (OWT-016) ──────────────────────────────────────────────────
|
|
85
|
-
* Everything in VOCAB, COMMANDS, EXTENSIONS,
|
|
86
|
-
* ID_PREFIX_DENYLIST is an initial judgment. None of it was measured against
|
|
119
|
+
* Everything in VOCAB, VOCAB_STATE, DEFAULT_STALE_AFTER_DAYS, COMMANDS, EXTENSIONS,
|
|
120
|
+
* DEFAULT_ID_PATTERN and ID_PREFIX_DENYLIST is an initial judgment. None of it was measured against
|
|
87
121
|
* real usage. Adopters should pass their own identifier pattern
|
|
88
122
|
* (--id-pattern) and read the heading vocabulary as a starting point.
|
|
89
123
|
*
|
|
@@ -92,34 +126,56 @@
|
|
|
92
126
|
* script's own self-test arms failed). 2 is NOT a pass.
|
|
93
127
|
*
|
|
94
128
|
* Usage (`uds` from the npm package, or the repo shim; same arguments):
|
|
95
|
-
* uds open-work next-action <file...> [--root DIR] [--id-pattern RE]
|
|
129
|
+
* uds open-work next-action <file...> [--root DIR] [--id-pattern RE] [--next-action-word WORD ...] [--command-word WORD ...] [--now YYYY-MM-DD] [--stale-after DAYS]
|
|
96
130
|
* uds open-work revision --file PATH --base GIT_REV
|
|
97
131
|
* uds open-work revision --before FILE --after FILE
|
|
98
|
-
* uds open-work separation <file...>
|
|
132
|
+
* uds open-work separation <file...> [--next-action-word WORD ...]
|
|
133
|
+
* uds open-work waiting <file...> [--root DIR] [--root NAME=DIR ...] [--id-pattern RE] [--now YYYY-MM-DD]
|
|
134
|
+
* uds open-work observations <file...> [--now YYYY-MM-DD] [--stale-after DAYS]
|
|
99
135
|
* uds open-work self-test
|
|
100
136
|
* node scripts/check-open-work-tracking.mjs next-action <file...> ... (repo clone)
|
|
101
137
|
* node scripts/check-open-work-tracking.mjs --self-test
|
|
102
138
|
*/
|
|
103
139
|
|
|
104
|
-
import { readFileSync, existsSync, realpathSync } from 'node:fs';
|
|
105
|
-
import { execFileSync } from 'node:child_process';
|
|
140
|
+
import { readFileSync, existsSync, realpathSync, statSync } from 'node:fs';
|
|
141
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
106
142
|
import { resolve, dirname, join, isAbsolute, basename } from 'node:path';
|
|
107
143
|
import { fileURLToPath } from 'node:url';
|
|
108
144
|
|
|
109
145
|
// ── Vocabulary (UNCALIBRATED, OWT-016) ───────────────────────────────────────
|
|
110
146
|
|
|
147
|
+
// ONE list of "next action" words (461 R1). It is read three ways and there is no second copy:
|
|
148
|
+
// a heading (classifyHeading), a table column header (extractNextActions) and an inline
|
|
149
|
+
// label ("Next action: ...", built from the same source). Each entry is [regex source, text shown to a
|
|
150
|
+
// reader who asks which words are recognised]. Keep the sources free of capture groups: the
|
|
151
|
+
// label regex embeds them and reads its own group 1.
|
|
152
|
+
//
|
|
153
|
+
// 回來要做什麼 ("what to do when you come back") is the header the dev-platform worklog's
|
|
154
|
+
// main table actually uses (DEC-122 H2 baseline carrier); that file describes the column as
|
|
155
|
+
// 下一動 in prose but the header text drifted. Added because a header outside this list is
|
|
156
|
+
// invisible to the check, which is the failure DEC-122 measured. 下一個動作, 下一個步驟 and
|
|
157
|
+
// 接下來要做什麼 (461 R1) mean "next action" and nothing wider.
|
|
158
|
+
//
|
|
159
|
+
// What is deliberately NOT here, and is pinned by a regression test: 待辦, 後續, Next, TODO,
|
|
160
|
+
// Action, and a bare 接下來. They also head columns that are not the next action (a backlog, a
|
|
161
|
+
// follow-up list, a "next release"), and reading those as next actions would let a violation hide
|
|
162
|
+
// behind a column that was never one. An adopter whose carrier uses one of them declares it
|
|
163
|
+
// (--next-action-word, or open_work.next_action_words in uds.project.yaml).
|
|
164
|
+
//
|
|
165
|
+
// Adopter-specific and UNCALIBRATED (OWT-016).
|
|
166
|
+
export const NEXT_ACTION_WORDS = [
|
|
167
|
+
['next[\\s-]?(?:action|step)s?', 'next action, next step (also "next-action", "next steps")'],
|
|
168
|
+
['下一步', '下一步'],
|
|
169
|
+
['下一動', '下一動'],
|
|
170
|
+
['回來要做什麼', '回來要做什麼'],
|
|
171
|
+
['下一個動作', '下一個動作'],
|
|
172
|
+
['下一個步驟', '下一個步驟'],
|
|
173
|
+
['接下來要做什麼', '接下來要做什麼'],
|
|
174
|
+
];
|
|
175
|
+
|
|
111
176
|
export const VOCAB = {
|
|
112
177
|
revision: /revision|change[\s-]?log|amendment|history|修訂|變更紀錄|變更記錄|修改紀錄|修改記錄|異動/i,
|
|
113
|
-
|
|
114
|
-
// a heading (classifyHeading), a table column header (extractNextActions) and an inline
|
|
115
|
-
// label ("Next action: ...", built from .source below). Keep it free of capture groups:
|
|
116
|
-
// the label regex embeds it and reads its own group 1.
|
|
117
|
-
// 回來要做什麼 ("what to do when you come back") is the header the dev-platform worklog's
|
|
118
|
-
// main table actually uses (DEC-122 H2 baseline carrier); that file describes the column as
|
|
119
|
-
// 下一動 in prose but the header text drifted. Added because a header outside this list is
|
|
120
|
-
// invisible to the check, which is the failure DEC-122 measured. Adopter-specific and
|
|
121
|
-
// UNCALIBRATED (OWT-016); an adopter whose header differs adds its own word here.
|
|
122
|
-
nextAction: /next[\s-]?(?:action|step)s?|下一步|下一動|回來要做什麼/i,
|
|
178
|
+
nextAction: new RegExp(NEXT_ACTION_WORDS.map(([source]) => source).join('|'), 'i'),
|
|
123
179
|
progress: /\bprogress\b|\bstate\b|\bblockers?\b|\bblocked\b|進度|現況|卡在/i,
|
|
124
180
|
intent: /acceptance|criteria|\brequirements?\b|\bgoals?\b|objectives?|constraints?|驗收|需求|目標|限制/i,
|
|
125
181
|
// revision-table columns / labelled list fields
|
|
@@ -128,6 +184,47 @@ export const VOCAB = {
|
|
|
128
184
|
colReason: /reason|why|理由|原因|為什麼/i,
|
|
129
185
|
};
|
|
130
186
|
|
|
187
|
+
const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\/-]/g, '\\$&');
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Words an adopter declares (461 R2), as plain text: not a regular expression (a `.` or `(` in a word is
|
|
191
|
+
* that character), case-insensitive, matched as a substring like the built-in ones. A blank word is
|
|
192
|
+
* REFUSED, never dropped: an empty alternative matches every header and would turn the check green.
|
|
193
|
+
* @returns {{words:string[], error:string|null}}
|
|
194
|
+
*/
|
|
195
|
+
export function normaliseDeclaredWords(raw = []) {
|
|
196
|
+
const words = [];
|
|
197
|
+
for (const w of raw) {
|
|
198
|
+
const word = typeof w === 'string' ? w.replace(/\s+/g, ' ').trim() : '';
|
|
199
|
+
if (!word) return { words: [], error: 'a declared next-action word is empty or blank; it would match every header, so it is refused (give the exact word, for example --next-action-word 待辦)' }; // [mutation-anchor:blank-word-refused]
|
|
200
|
+
if (!words.some((x) => x.toLowerCase() === word.toLowerCase())) words.push(word);
|
|
201
|
+
}
|
|
202
|
+
return { words, error: null };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Program names an adopter declares (461 R5), under the same rules as the next-action words: plain text, never a
|
|
207
|
+
* pattern, and a blank one is refused. A command is one program name, so a word with a space in it could never
|
|
208
|
+
* match the first word of a command and is refused as well, with the reason, instead of being accepted and inert.
|
|
209
|
+
* @returns {{words:string[], error:string|null}}
|
|
210
|
+
*/
|
|
211
|
+
export function normaliseDeclaredCommands(raw = []) {
|
|
212
|
+
const words = [];
|
|
213
|
+
for (const w of raw) {
|
|
214
|
+
const word = typeof w === 'string' ? w.trim() : '';
|
|
215
|
+
if (!word) return { words: [], error: 'a declared command word is empty or blank; it would read every sentence as a command, so it is refused (give the program name, for example --command-word kubectl)' }; // [mutation-anchor:blank-command-refused]
|
|
216
|
+
if (/\s/.test(word)) return { words: [], error: `a declared command word is one program name, and "${word}" has a space in it, so it could never match; give the program name alone (for example --command-word kubectl)` };
|
|
217
|
+
if (!words.includes(word) && !COMMANDS.includes(word)) words.push(word);
|
|
218
|
+
}
|
|
219
|
+
return { words, error: null };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** The one recognition pattern: the built-in list, plus the declared words when there are any. */
|
|
223
|
+
export function nextActionRegExp(words = []) {
|
|
224
|
+
if (!words.length) return VOCAB.nextAction;
|
|
225
|
+
return new RegExp(`${VOCAB.nextAction.source}|${words.map(escapeRegExp).join('|')}`, 'i'); // [mutation-anchor:declared-merged]
|
|
226
|
+
}
|
|
227
|
+
|
|
131
228
|
const LABELS = [
|
|
132
229
|
['change', /(?:what(?:\s+changed)?|changed?|改了什麼|修改|變更)\s*[::]/gi],
|
|
133
230
|
['approver', /(?:approved\s+by|approver|approval|核可者|核可|核准|批准)\s*[::]/gi],
|
|
@@ -139,9 +236,12 @@ const EMPTY_FIELD = /^(?:|-+|—|–|n\/?a|none|無|done|完成|已完成|✅)$/
|
|
|
139
236
|
|
|
140
237
|
// Words that make `word arg` read as a command in prose. Deliberately excludes
|
|
141
238
|
// common English words (go, make, sh): "go through the list" is not a command.
|
|
239
|
+
// glab and dotnet (461 R5) are here because a user's carriers named them (`glab mr merge 486`, a .NET
|
|
240
|
+
// project); every other tool is declared by the adopter (--command-word, or open_work.command_words).
|
|
241
|
+
// A command is matched as an exact program name, case-sensitively, as the built-in ones are.
|
|
142
242
|
export const COMMANDS = [
|
|
143
|
-
'npm', 'npx', 'pnpm', 'yarn', 'node', 'tsx', 'git', 'gh', 'bash', 'python', 'python3',
|
|
144
|
-
'pytest', 'vitest', 'docker', 'cargo', 'uds', 'egr',
|
|
243
|
+
'npm', 'npx', 'pnpm', 'yarn', 'node', 'tsx', 'git', 'gh', 'glab', 'bash', 'python', 'python3',
|
|
244
|
+
'pytest', 'vitest', 'docker', 'cargo', 'dotnet', 'uds', 'egr',
|
|
145
245
|
];
|
|
146
246
|
|
|
147
247
|
export const EXTENSIONS = [
|
|
@@ -156,9 +256,9 @@ export const ID_PREFIX_DENYLIST = ['UTF', 'SHA', 'ISO', 'GPT', 'RFC', 'CRC', 'AE
|
|
|
156
256
|
// ── Markdown structure walk ──────────────────────────────────────────────────
|
|
157
257
|
|
|
158
258
|
/** @returns {string|null} */
|
|
159
|
-
function classifyHeading(h) {
|
|
259
|
+
function classifyHeading(h, nextRe = VOCAB.nextAction) {
|
|
160
260
|
if (VOCAB.revision.test(h)) return 'revision';
|
|
161
|
-
if (
|
|
261
|
+
if (nextRe.test(h)) return 'nextAction';
|
|
162
262
|
if (VOCAB.progress.test(h)) return 'progress';
|
|
163
263
|
if (VOCAB.intent.test(h)) return 'intent';
|
|
164
264
|
return null;
|
|
@@ -168,7 +268,7 @@ function classifyHeading(h) {
|
|
|
168
268
|
* Annotate every line with the class of its innermost classified ancestor
|
|
169
269
|
* heading. Front matter and fenced blocks keep their text but are flagged.
|
|
170
270
|
*/
|
|
171
|
-
export function parseDoc(md) {
|
|
271
|
+
export function parseDoc(md, nextRe = VOCAB.nextAction) {
|
|
172
272
|
const raw = md.split(/\r?\n/);
|
|
173
273
|
const lines = [];
|
|
174
274
|
const stack = [];
|
|
@@ -200,7 +300,7 @@ export function parseDoc(md) {
|
|
|
200
300
|
if (h) {
|
|
201
301
|
const level = h[1].length;
|
|
202
302
|
while (stack.length && stack[stack.length - 1].level >= level) stack.pop();
|
|
203
|
-
const entry = { level, heading: h[2], cls: classifyHeading(h[2]) };
|
|
303
|
+
const entry = { level, heading: h[2], cls: classifyHeading(h[2], nextRe) };
|
|
204
304
|
stack.push(entry);
|
|
205
305
|
const own = innermost(stack);
|
|
206
306
|
lines.push({ text, cls: own ? own.cls : null, owner: own, heading: entry });
|
|
@@ -428,10 +528,11 @@ export function checkIntentRevision({ before, after, path = '(carrier)' }) {
|
|
|
428
528
|
|
|
429
529
|
// ── OWT-017: carrier separation ──────────────────────────────────────────────
|
|
430
530
|
|
|
431
|
-
export function checkSeparation(carriers) {
|
|
531
|
+
export function checkSeparation(carriers, opts = {}) {
|
|
432
532
|
const res = { walked: carriers.length, recognised: 0, violations: [] };
|
|
533
|
+
const nextRe = nextActionRegExp(opts.words);
|
|
433
534
|
for (const c of carriers) {
|
|
434
|
-
const lines = parseDoc(c.content);
|
|
535
|
+
const lines = parseDoc(c.content, nextRe);
|
|
435
536
|
const intent = new Set();
|
|
436
537
|
const progress = new Set();
|
|
437
538
|
for (const l of lines) {
|
|
@@ -471,7 +572,7 @@ function pathLike(tok, inCode) {
|
|
|
471
572
|
*/
|
|
472
573
|
export function classifyNextAction(text, opts = {}) {
|
|
473
574
|
const idRe = new RegExp(opts.idPattern || DEFAULT_ID_PATTERN, 'g');
|
|
474
|
-
const commands = [...COMMANDS, ...(opts.extraCommands || [])];
|
|
575
|
+
const commands = [...COMMANDS, ...(opts.extraCommands || [])]; // [mutation-anchor:extra-commands]
|
|
475
576
|
const kinds = [];
|
|
476
577
|
const push = (kind, value) => { if (!kinds.some((k) => k.kind === kind && k.value === value)) kinds.push({ kind, value }); };
|
|
477
578
|
const idOk = (v) => !ID_PREFIX_DENYLIST.includes(v.split('-')[0]);
|
|
@@ -496,7 +597,7 @@ export function classifyNextAction(text, opts = {}) {
|
|
|
496
597
|
const p = pathLike(tok, false);
|
|
497
598
|
if (p) push('path', p);
|
|
498
599
|
}
|
|
499
|
-
const cmdRe = new RegExp(`(?:^|[^\\w-])(${commands.join('|')})\\s+([-@\\w./:]+)`, 'g');
|
|
600
|
+
const cmdRe = new RegExp(`(?:^|[^\\w-])(${commands.map(escapeRegExp).join('|')})\\s+([-@\\w./:]+)`, 'g');
|
|
500
601
|
let m;
|
|
501
602
|
while ((m = cmdRe.exec(prose)) !== null) push('command', `${m[1]} ${m[2]}`);
|
|
502
603
|
const testRe = /(?:test|測試)\s*[「"“']([^」"”']{6,})[」"”']/gi;
|
|
@@ -515,10 +616,15 @@ export function classifyNextAction(text, opts = {}) {
|
|
|
515
616
|
if (existsSync(isAbsolute(rel) ? rel : join(root, rel))) resolved = true;
|
|
516
617
|
}
|
|
517
618
|
}
|
|
619
|
+
// Only a PATH is ever looked up. A command, a test name or a requirement identifier is checked for being NAMED and
|
|
620
|
+
// can never be resolved, so a named-unresolved row is one of two different things (461 R6): a path that was looked
|
|
621
|
+
// up and is not there, or something that is never looked up. The status stays named-unresolved for both.
|
|
622
|
+
const lookedUp = !!root && kinds.some((k) => k.kind === 'path');
|
|
518
623
|
return {
|
|
519
624
|
status: resolved ? 'named-resolved' : 'named-unresolved',
|
|
520
625
|
kinds,
|
|
521
626
|
resolution: root ? 'attempted (paths only)' : 'not attempted (no --root)',
|
|
627
|
+
unresolved: resolved ? null : (lookedUp ? 'path-missing' : 'not-resolvable'), // [mutation-anchor:unresolved-split]
|
|
522
628
|
};
|
|
523
629
|
}
|
|
524
630
|
|
|
@@ -533,10 +639,13 @@ const clip = (s, n) => (s.length > n ? `${s.slice(0, n)}…` : s);
|
|
|
533
639
|
* `items`: after a stray or missing `|` the next-action cell cannot be told from its
|
|
534
640
|
* neighbour, and reading an absent cell as "empty" would turn a broken row into a quiet
|
|
535
641
|
* "no next action written". It is neither judged nor dropped: the caller counts and lists it.
|
|
536
|
-
* @returns {{fields:number, items:{text:string,where:string}[], ragged:{where:string,cells:number,expected:number}[]}}
|
|
642
|
+
* @returns {{fields:number, items:{text:string,where:string,idx?:number}[], ragged:{where:string,cells:number,expected:number}[]}}
|
|
643
|
+
* `idx` is the 0-based line of a table row or an inline label; a heading section has none (464: that is how a next-action item
|
|
644
|
+
* is joined to the record `waiting` read on the same line).
|
|
537
645
|
*/
|
|
538
|
-
export function extractNextActions(md) {
|
|
539
|
-
const
|
|
646
|
+
export function extractNextActions(md, words = []) {
|
|
647
|
+
const nextRe = nextActionRegExp(words);
|
|
648
|
+
const lines = parseDoc(md, nextRe);
|
|
540
649
|
const items = [];
|
|
541
650
|
const ragged = [];
|
|
542
651
|
let fields = 0;
|
|
@@ -546,7 +655,7 @@ export function extractNextActions(md) {
|
|
|
546
655
|
|
|
547
656
|
for (const t of tables) {
|
|
548
657
|
// every header cell in the shared vocabulary is a next-action column (usually exactly one)
|
|
549
|
-
const cols = t.header.map((c, n) => (
|
|
658
|
+
const cols = t.header.map((c, n) => (nextRe.test(c) ? n : -1)).filter((n) => n >= 0); // [mutation-anchor:table-header]
|
|
550
659
|
const hasCol = cols.length > 0;
|
|
551
660
|
tableIdx.add(t.headerIdx); tableIdx.add(t.headerIdx + 1); headerIdx.add(t.headerIdx);
|
|
552
661
|
t.rows.forEach((r) => tableIdx.add(r.idx));
|
|
@@ -559,7 +668,7 @@ export function extractNextActions(md) {
|
|
|
559
668
|
}
|
|
560
669
|
for (const col of cols) {
|
|
561
670
|
fields++;
|
|
562
|
-
items.push({ text: r.cells[col], where: `table column "${t.header[col]}" (line ${r.idx + 1}, ${who})` });
|
|
671
|
+
items.push({ text: r.cells[col], idx: r.idx, where: `table column "${t.header[col]}" (line ${r.idx + 1}, ${who})` });
|
|
563
672
|
}
|
|
564
673
|
}
|
|
565
674
|
}
|
|
@@ -568,7 +677,7 @@ export function extractNextActions(md) {
|
|
|
568
677
|
}
|
|
569
678
|
|
|
570
679
|
// inline labelled "**Next action**: ..." (outside tables that have their own column)
|
|
571
|
-
const labelRe = new RegExp(`(?:\\*\\*|__)?(?:${
|
|
680
|
+
const labelRe = new RegExp(`(?:\\*\\*|__)?(?:${nextRe.source})(?:\\*\\*|__)?\\s*[::]\\s*(.+)$`, 'i');
|
|
572
681
|
const colTableRows = new Set();
|
|
573
682
|
// Only rows read through the column are exempt from the label scan. A ragged row was not
|
|
574
683
|
// read, so an inline "Next action: ..." inside it must still be seen (else it goes dark).
|
|
@@ -578,7 +687,7 @@ export function extractNextActions(md) {
|
|
|
578
687
|
if (l.front || l.fence || l.inFence || l.heading || l.cls === 'nextAction' || colTableRows.has(idx)) return;
|
|
579
688
|
// a label inside a table row reads to the end of the row, not into its closing pipe
|
|
580
689
|
const m = labelRe.exec(unquote(l.text).trim().startsWith('|') ? l.text.replace(/\s*\|\s*$/, '') : l.text);
|
|
581
|
-
if (m && !/^\s*$/.test(m[1])) { fields++; items.push({ text: m[1], where: `label (line ${idx + 1})` }); }
|
|
690
|
+
if (m && !/^\s*$/.test(m[1])) { fields++; items.push({ text: m[1], idx, where: `label (line ${idx + 1})` }); }
|
|
582
691
|
});
|
|
583
692
|
|
|
584
693
|
// heading sections classed nextAction
|
|
@@ -616,18 +725,38 @@ export function extractNextActions(md) {
|
|
|
616
725
|
return { fields, items, ragged };
|
|
617
726
|
}
|
|
618
727
|
|
|
728
|
+
/**
|
|
729
|
+
* OWT-019, and (464) its fourth outcome. Before a next action is judged, the row it belongs to is read by `checkWaiting`, the
|
|
730
|
+
* very function `uds open-work waiting` runs, with the same date. A row that is `asked-awaiting` and that OWT-020 and OWT-022
|
|
731
|
+
* raise nothing against is `waiting-on-reply`: its next step is the reply, which OWT-022 already described (when it was asked,
|
|
732
|
+
* what is waited for, what releases it), so OWT-019 is not applied. It is counted apart, never as named, never as complete, and
|
|
733
|
+
* listed with its age (`waitingOnReply`). A row `waiting` fails is judged exactly as before. A heading section has no row, so it
|
|
734
|
+
* is never waived; a carrier with no status field behaves exactly as it always did.
|
|
735
|
+
*/
|
|
619
736
|
export function checkNextActions(carriers, opts = {}) {
|
|
620
|
-
const
|
|
737
|
+
const now = opts.now ?? todayUtc();
|
|
738
|
+
const staleAfter = opts.staleAfterDays ?? DEFAULT_STALE_AFTER_DAYS;
|
|
739
|
+
const res = { walked: 0, empty: 0, counts: { 'named-resolved': 0, 'named-unresolved': 0, unnamed: 0, 'waiting-on-reply': 0 }, unresolvedSplit: { 'path-missing': 0, 'not-resolvable': 0 }, violations: [], detail: [], noFieldCarriers: [], undecidable: [], waitingOnReply: [], staleAfter };
|
|
740
|
+
// No project is declared, so no other project is looked up: this call reads the carriers' own rows and nothing else.
|
|
741
|
+
const rows = checkWaiting(carriers, { now, root: opts.root, idPattern: opts.idPattern, extraCommands: opts.extraCommands, projects: new Map() }).records;
|
|
621
742
|
for (const c of carriers) {
|
|
622
|
-
const { fields, items, ragged } = extractNextActions(c.content);
|
|
743
|
+
const { fields, items, ragged } = extractNextActions(c.content, opts.words);
|
|
623
744
|
for (const g of ragged) res.undecidable.push({ path: c.path, ...g });
|
|
624
745
|
if (fields === 0 && ragged.length === 0) { res.noFieldCarriers.push(c.path); continue; }
|
|
625
746
|
for (const it of items) {
|
|
626
747
|
const text = it.text.replace(/\*\*|__/g, '').trim();
|
|
627
748
|
if (EMPTY_FIELD.test(text)) { res.empty++; continue; }
|
|
628
749
|
res.walked++;
|
|
750
|
+
const reply = it.idx === undefined ? undefined : rows.find((w) => w.path === c.path && w.waitingOnReply && it.idx >= w.lineStart && it.idx <= w.lineEnd); // [mutation-anchor:next-action-join]
|
|
751
|
+
if (reply) { // [mutation-anchor:next-action-exempt]
|
|
752
|
+
res.counts['waiting-on-reply']++;
|
|
753
|
+
res.detail.push({ path: c.path, where: it.where, text, status: 'waiting-on-reply', kinds: [], resolution: 'n/a' });
|
|
754
|
+
res.waitingOnReply.push({ path: c.path, where: it.where, askedDay: reply.askedDay, age: reply.age, awaiting: reply.awaiting, release: reply.release, stale: reply.age !== null && reply.age > staleAfter }); // [mutation-anchor:stale-marked]
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
629
757
|
const r = classifyNextAction(text, opts);
|
|
630
758
|
res.counts[r.status]++;
|
|
759
|
+
if (r.unresolved) res.unresolvedSplit[r.unresolved]++;
|
|
631
760
|
res.detail.push({ path: c.path, where: it.where, text, ...r });
|
|
632
761
|
if (r.status === 'unnamed') res.violations.push({ rule: 'OWT-019', path: c.path, where: it.where, text });
|
|
633
762
|
}
|
|
@@ -635,11 +764,530 @@ export function checkNextActions(carriers, opts = {}) {
|
|
|
635
764
|
return res;
|
|
636
765
|
}
|
|
637
766
|
|
|
767
|
+
// ── 461 R6: say what "resolved" resolved ─────────────────────────────────────
|
|
768
|
+
// `named-resolved`, `named-unresolved` and `unnamed` do not say against WHAT a path was looked up, and
|
|
769
|
+
// `named-unresolved` reads as a failure although it also holds every command, test name and requirement
|
|
770
|
+
// identifier, which are never looked up at all. These lines are ADDED after the counts line; nothing 1.1.0
|
|
771
|
+
// printed is changed or moved (the frozen capture is compared with these lines taken out).
|
|
772
|
+
|
|
773
|
+
/** Is this file inside a git working tree? Asked of git, never worked out from the path. */
|
|
774
|
+
function insideGitRepo(file) {
|
|
775
|
+
try {
|
|
776
|
+
execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd: dirname(resolve(file)), stdio: ['ignore', 'pipe', 'ignore'] });
|
|
777
|
+
return true;
|
|
778
|
+
} catch { return false; }
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/** The one sentence that says where a lookup starts and where that came from, for a path (next-action) and for a project (waiting) alike. */
|
|
782
|
+
export function lookupSentence(what, dir, source) {
|
|
783
|
+
return `${what} is looked up under ${resolve(dir)} (${source})`;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* @param {{root:string, rootGiven:boolean, carriers:{path:string}[], split:{'path-missing':number,'not-resolvable':number}, unresolved:number, commands:string[]}} a
|
|
788
|
+
* @returns {string[]} lines, without the `[owt] ` prefix
|
|
789
|
+
*/
|
|
790
|
+
export function explainResolution({ root, rootGiven, carriers, split, unresolved, commands = [] }) {
|
|
791
|
+
const out = [];
|
|
792
|
+
out.push(` of the named-unresolved (${unresolved}): path-missing=${split['path-missing']} not-resolvable=${split['not-resolvable']}`);
|
|
793
|
+
out.push(`RESOLUTION: ${lookupSentence('a path', root, rootGiven ? 'from --root' : 'the current directory: no --root was given')}. Only a PATH is looked up. A command, a test name or a requirement identifier is checked for being named and is never looked up, so it counts as not-resolvable, not as a missing path. path-missing is a path that was looked up and is not there.`); // [mutation-anchor:resolution-line]
|
|
794
|
+
if (!rootGiven) {
|
|
795
|
+
for (const c of carriers) {
|
|
796
|
+
if (!insideGitRepo(c.path)) { out.push(`RESOLUTION: ${c.path} is outside any git repository, so its paths are resolved against ${resolve(root)}, not against where the file is; pass --root to say where its paths start`); break; } // [mutation-anchor:outside-repo]
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (commands.length) out.push(`RESOLUTION: read as commands in addition to the built-in list: ${commands.join(', ')}`);
|
|
800
|
+
return out;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// ── 461 R3: when no carrier has a next-action field, say what each one showed ─
|
|
804
|
+
// Exit 2 ("cannot decide") says nothing about WHY. A reader cannot tell "this carrier writes the
|
|
805
|
+
// column in words the list does not hold" from "this carrier has no next-action field at all", and
|
|
806
|
+
// those two call for opposite actions (declare a word; or nothing). This reads the same structure the
|
|
807
|
+
// check read (headings and table headers) and says what it saw.
|
|
808
|
+
|
|
809
|
+
/** How many headings and table headers are listed per carrier before "and N more". About 20, on purpose. */
|
|
810
|
+
export const DIAGNOSTIC_LIST_LIMIT = 20;
|
|
811
|
+
|
|
812
|
+
/** The headings and table headers a carrier shows, each distinct text once with how many times it occurs. */
|
|
813
|
+
export function describeCarrier(md) {
|
|
814
|
+
const lines = parseDoc(md);
|
|
815
|
+
const count = (list) => {
|
|
816
|
+
const seen = new Map();
|
|
817
|
+
for (const t of list) { const k = norm(t); if (k) seen.set(k, (seen.get(k) || 0) + 1); }
|
|
818
|
+
return [...seen].map(([text, n]) => ({ text, n }));
|
|
819
|
+
};
|
|
820
|
+
const tables = findTables(lines);
|
|
821
|
+
return {
|
|
822
|
+
tables: tables.length,
|
|
823
|
+
headers: count(tables.flatMap((t) => t.header)),
|
|
824
|
+
headings: count(lines.filter((l) => l.heading).map((l) => l.heading.heading)),
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* The lines printed after "no next-action field found". Pure: carriers and declared words in, text out.
|
|
830
|
+
* `rowsUnreadable` lists the paths whose next-action column was found but whose rows could not be read.
|
|
831
|
+
* @returns {string[]}
|
|
832
|
+
*/
|
|
833
|
+
export function explainNoNextActionField(carriers, words = [], rowsUnreadable = []) {
|
|
834
|
+
const out = [];
|
|
835
|
+
const quoted = (list) => list.map((x) => `"${x.text}"${x.n > 1 ? ` (x${x.n})` : ''}`).join(', ');
|
|
836
|
+
out.push('WHY: no carrier had a next-action field. What each one showed:');
|
|
837
|
+
for (const c of carriers) {
|
|
838
|
+
const d = describeCarrier(c.content);
|
|
839
|
+
const unreadable = rowsUnreadable.includes(c.path);
|
|
840
|
+
let verdict;
|
|
841
|
+
if (unreadable) verdict = 'has a next-action column, but its table rows could not be read (see UNDECIDABLE above)';
|
|
842
|
+
else if (d.tables > 0) verdict = `has ${d.tables} table(s), but no table header matches a recognised word; if one of them is your next-action column, declare its word`;
|
|
843
|
+
else if (d.headings.length > 0) verdict = 'has no table, and no heading matches a recognised word; if one of these headings is your next-action section, declare its word';
|
|
844
|
+
else verdict = 'has no table and no heading to read; this carrier may have no next-action field at all, and no word would change that';
|
|
845
|
+
out.push(` ${c.path}: ${verdict}`);
|
|
846
|
+
let budget = DIAGNOSTIC_LIST_LIMIT;
|
|
847
|
+
const show = (label, list) => {
|
|
848
|
+
if (!list.length) return;
|
|
849
|
+
const shown = list.slice(0, Math.max(budget, 0));
|
|
850
|
+
budget -= shown.length;
|
|
851
|
+
out.push(` ${label} (${list.length} distinct): ${quoted(shown)}${list.length > shown.length ? `, and ${list.length - shown.length} more` : ''}`); // [mutation-anchor:diagnostic-list]
|
|
852
|
+
};
|
|
853
|
+
show('table headers', d.headers);
|
|
854
|
+
show('headings', d.headings);
|
|
855
|
+
}
|
|
856
|
+
out.push(`WORDS RECOGNISED (a heading, a table header or an inline "word: ..." label that contains one of these, any case): built in: ${NEXT_ACTION_WORDS.map(([, shown]) => shown).join(' | ')}`);
|
|
857
|
+
out.push(words.length ? ` declared by you: ${words.join(' | ')}` : ' declared by you: none');
|
|
858
|
+
out.push('TO ADD A WORD: pass --next-action-word <word> (repeat it for several), or list it under open_work: next_action_words: in uds.project.yaml. It is plain text, not a pattern, and it is added to the same list for headings, table headers and labels.');
|
|
859
|
+
return out;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// ── OWT-020 … OWT-026: two states before a reply, and observed facts ─────────
|
|
863
|
+
// open-work-tracking 1.2.0 (dev-platform XSPEC-459). Everything here is UNCALIBRATED (OWT-016):
|
|
864
|
+
// the state words, the field names and the "derivable subject" list are initial judgments in
|
|
865
|
+
// English and Chinese. A carrier whose words differ is not read, which is reported (coverage
|
|
866
|
+
// unknown, OWT-011), never read as clean.
|
|
867
|
+
|
|
868
|
+
export const VOCAB_STATE = {
|
|
869
|
+
// header / label vocabulary: which structural field is which
|
|
870
|
+
roles: {
|
|
871
|
+
status: /\bstatus\b|\bstate\b|狀態/i,
|
|
872
|
+
askedAt: /asked[\s-]?(?:at|on|date)|(?:詢問|發問|送出|寄出|已問)(?:時間|日期)|問於/i,
|
|
873
|
+
awaiting: /\bwait(?:ing)?[\s-]?(?:for|on)\b|\bawaiting\b|\bblocked[\s-]?on\b|等什麼|等待(?:對象|什麼|內容)|等誰/i,
|
|
874
|
+
release: /\brelease\b|\bunblock|解除|放行/i,
|
|
875
|
+
draft: /\bdraft\b|\bto[\s-]?send\b|草稿|待送出|待問/i,
|
|
876
|
+
observedBy: /observed[\s-]?by|seen[\s-]?by|觀察者|誰看到|觀察人/i,
|
|
877
|
+
observedAt: /observed[\s-]?(?:at|on|date)|seen[\s-]?(?:at|on)|觀察(?:時間|日期)|何時看到/i,
|
|
878
|
+
value: /^(?:value|observed[\s-]?value|result|觀察值|觀察結果|值|結果)$/i,
|
|
879
|
+
subject: /^(?:fact|subject|observation|observed[\s-]?fact|事實|觀察項目|觀察對象|事項)$/i,
|
|
880
|
+
},
|
|
881
|
+
notYetAsked: /not[\s-]*(?:yet[\s-]*)?(?:asked|sent)|\bunasked\b|\bunsent\b|還沒問|尚未(?:詢問|送出|提問|發問|問)|未(?:詢問|送出|提問|問)|還沒送出|待問|待送出/i,
|
|
882
|
+
askedAwaiting: /\b(?:asked|sent)[\s,;&—–-]*(?:and[\s-]*)?(?:awaiting|waiting)\b|已(?:問|詢問|送出|寄出|發問)/i,
|
|
883
|
+
waiting: /\b(?:waiting|awaiting|blocked[\s-]*on|on[\s-]*hold|pending)\b|等待|等候|待回覆|待回應|卡在/i,
|
|
884
|
+
// The WHOLE cell must be a done word: "done except X" and "尚未完成" are not done.
|
|
885
|
+
done: /^[\s\p{P}\p{S}]*(?:done|completed?|closed|resolved|已完成|已結案|完成|結案|✅)[\s\p{P}\p{S}]*$/iu,
|
|
886
|
+
// The value domain of an observed fact. `unknown` is a real value, never a blank.
|
|
887
|
+
yes: /^(?:yes|y|true|是|有)$/i,
|
|
888
|
+
no: /^(?:no|n|false|否|沒有)$/i,
|
|
889
|
+
unknown: /^(?:unknown|\?|未知|不明|看不到|無法確認|unobserved)$/i,
|
|
890
|
+
// Subjects that version control, a spec marker or a CI result already determine (OWT-003 stands).
|
|
891
|
+
derivable: /\b(?:merged|pushed|committed|tagged)\b|\bci\b|\bcontinuous integration\b|\b(?:tests?|build)\s+(?:pass(?:ed|ing)?|green)\b|\bspec\s+(?:status|marker)\b|已合併|已推送|已提交|CI\s*(?:通過|綠|狀態)|測試通過|建置通過|規格(?:狀態|標記)/i,
|
|
892
|
+
};
|
|
893
|
+
|
|
894
|
+
/** Default age (days) past which an observation is reported as stale. An initial judgment, UNCALIBRATED (OWT-016). */
|
|
895
|
+
export const DEFAULT_STALE_AFTER_DAYS = 7;
|
|
896
|
+
|
|
897
|
+
const BLANK_FIELD = /^(?:|-+|—|–|n\/?a|none|tbd|\?+|無|待定|未知|unknown)$/i;
|
|
898
|
+
const stripMd = (s) => s.replace(/\*\*|__|`/g, '').trim();
|
|
899
|
+
|
|
900
|
+
const rolesOf = (header) => Object.entries(VOCAB_STATE.roles).filter(([, re]) => re.test(header)).map(([role]) => role);
|
|
901
|
+
|
|
902
|
+
// inline labels in a list item: "status: not-yet-asked; draft: drafts/q.md"
|
|
903
|
+
const LABEL_WORDS = [
|
|
904
|
+
['status', /(?:status|state|狀態)/],
|
|
905
|
+
['askedAt', /(?:asked[\s-]?(?:at|on)|(?:詢問|發問|送出|寄出)(?:時間|日期))/],
|
|
906
|
+
['awaiting', /(?:waiting[\s-]?(?:for|on)|awaiting|等什麼|等待對象|等誰)/],
|
|
907
|
+
['release', /(?:release|unblock(?:ed)?[\s-]?(?:by|when)|解除條件|解除)/],
|
|
908
|
+
['draft', /(?:draft|to[\s-]?send|草稿|待送出)/],
|
|
909
|
+
['observedBy', /(?:observed[\s-]?by|seen[\s-]?by|觀察者)/],
|
|
910
|
+
['observedAt', /(?:observed[\s-]?(?:at|on)|seen[\s-]?(?:at|on)|觀察時間|觀察日期)/],
|
|
911
|
+
['value', /(?:observed[\s-]?value|value|觀察值|觀察結果)/],
|
|
912
|
+
['subject', /(?:fact|subject|事實|觀察項目)/],
|
|
913
|
+
// 464: a boundary and nothing else. A "Next action: ..." label ends the value of the label before it (a blank `release:` must not read
|
|
914
|
+
// as filled by the next-action line below it) and is never itself a field of the record. Without it a row lacking its release was
|
|
915
|
+
// read as complete in a list, and OWT-022 passed a row it should have failed. It is the built-in list only: a word an adopter declares
|
|
916
|
+
// is not known to `waiting`, which reads these records for `next-action` too, so the two read a declared word's line the same way.
|
|
917
|
+
['nextAction', VOCAB.nextAction],
|
|
918
|
+
];
|
|
919
|
+
|
|
920
|
+
function parseRoleLabels(text) {
|
|
921
|
+
const hits = [];
|
|
922
|
+
for (const [role, word] of LABEL_WORDS) {
|
|
923
|
+
const re = new RegExp(`(?:^|[;;,,|((]\\s*|\\s)(${word.source})[\\w\\s-]{0,12}[::]`, 'gi');
|
|
924
|
+
let m;
|
|
925
|
+
while ((m = re.exec(text)) !== null) {
|
|
926
|
+
const start = m.index + m[0].indexOf(m[1]);
|
|
927
|
+
hits.push({ role, start, end: m.index + m[0].length });
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
hits.sort((a, b) => a.start - b.start);
|
|
931
|
+
const kept = [];
|
|
932
|
+
for (const h of hits) if (!kept.length || h.start >= kept[kept.length - 1].end) kept.push(h);
|
|
933
|
+
const f = {};
|
|
934
|
+
const fr = {}; // the same values with their Markdown kept: a `code span` is how a command or a test name is told from prose
|
|
935
|
+
kept.forEach((h, i) => {
|
|
936
|
+
if (h.role === 'nextAction') return; // a boundary, not a field (see LABEL_WORDS)
|
|
937
|
+
const next = kept[i + 1] ? kept[i + 1].start : text.length;
|
|
938
|
+
const val = stripMd(text.slice(h.end, next)).replace(/[;;,,|]+$/, '').trim();
|
|
939
|
+
if (f[h.role] === undefined) { f[h.role] = val; fr[h.role] = text.slice(h.end, next).replace(/[;;,,|]+$/, '').trim(); }
|
|
940
|
+
});
|
|
941
|
+
const firstField = kept.find((h) => h.role !== 'nextAction');
|
|
942
|
+
const title = stripMd(text.slice(0, firstField ? firstField.start : text.length)).replace(/[\s;;,,|—–::-]+$/, '').trim();
|
|
943
|
+
return { f, fr, title };
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* The structural records a carrier holds for these checks: every row of a table that has a
|
|
948
|
+
* recognised field column, and every top-level list item (with its indented lines) that carries
|
|
949
|
+
* recognised labels. A table row whose cell count differs from its header is returned in
|
|
950
|
+
* `ragged`, never read as empty (same rule as the next-action table).
|
|
951
|
+
* @returns {{records:object[], ragged:object[]}}
|
|
952
|
+
*/
|
|
953
|
+
export function extractRecords(md) {
|
|
954
|
+
const lines = parseDoc(md);
|
|
955
|
+
const records = [];
|
|
956
|
+
const ragged = [];
|
|
957
|
+
const inTable = new Set();
|
|
958
|
+
for (const t of findTables(lines)) {
|
|
959
|
+
inTable.add(t.headerIdx); inTable.add(t.headerIdx + 1);
|
|
960
|
+
t.rows.forEach((r) => inTable.add(r.idx));
|
|
961
|
+
const roles = t.header.map(rolesOf);
|
|
962
|
+
const columns = new Set(roles.flat());
|
|
963
|
+
if (!columns.size) continue;
|
|
964
|
+
for (const r of t.rows) {
|
|
965
|
+
const title = stripMd(r.cells[0] || '');
|
|
966
|
+
const where = `table row (line ${r.idx + 1}, row "${clip(title, 40)}")`;
|
|
967
|
+
if (r.cells.length !== t.header.length) { ragged.push({ idx: r.idx, where, cells: r.cells.length, expected: t.header.length, columns }); continue; }
|
|
968
|
+
const f = {};
|
|
969
|
+
const fr = {};
|
|
970
|
+
roles.forEach((rs, n) => rs.forEach((role) => { if (f[role] === undefined) { f[role] = stripMd(r.cells[n]); fr[role] = r.cells[n]; } }));
|
|
971
|
+
records.push({ where, title, f, fr, columns, lineStart: r.idx, lineEnd: r.idx });
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
let cur = null;
|
|
975
|
+
const flush = () => {
|
|
976
|
+
if (cur) {
|
|
977
|
+
const text = cur.parts.join(' ; ');
|
|
978
|
+
const { f, fr, title } = parseRoleLabels(text);
|
|
979
|
+
if (Object.keys(f).length) {
|
|
980
|
+
records.push({ where: `list item (line ${cur.idx + 1}, "${clip(title || stripMd(cur.parts[0]), 40)}")`, title: title || stripMd(cur.parts[0]), f, fr, columns: new Set(Object.keys(f)), lineStart: cur.idx, lineEnd: cur.end });
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
cur = null;
|
|
984
|
+
};
|
|
985
|
+
lines.forEach((l, idx) => {
|
|
986
|
+
if (l.front || l.fence || l.inFence || l.heading || inTable.has(idx)) { flush(); return; }
|
|
987
|
+
const li = /^(\s*)(?:[-*+]|\d+[.)])\s+(.*)$/.exec(l.text);
|
|
988
|
+
if (li && li[1].length === 0) { flush(); cur = { idx, end: idx, parts: [li[2]] }; } else if (cur && /^\s+\S/.test(l.text)) { cur.parts.push(l.text.trim().replace(/^(?:[-*+]|\d+[.)])\s+/, '')); cur.end = idx; } else flush();
|
|
989
|
+
});
|
|
990
|
+
flush();
|
|
991
|
+
return { records, ragged };
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
const DATE_IN_TEXT = /(\d{4})\s*[-/.年]\s*(\d{1,2})\s*[-/.月]\s*(\d{1,2})/;
|
|
995
|
+
|
|
996
|
+
/** A calendar day (UTC ms) from the first date in the text, or null. The year is required; the time of day is ignored. */
|
|
997
|
+
export function parseDay(text) {
|
|
998
|
+
const m = DATE_IN_TEXT.exec(text || '');
|
|
999
|
+
if (!m) return null;
|
|
1000
|
+
const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
1001
|
+
const t = Date.UTC(y, mo - 1, d);
|
|
1002
|
+
const back = new Date(t);
|
|
1003
|
+
if (back.getUTCFullYear() !== y || back.getUTCMonth() !== mo - 1 || back.getUTCDate() !== d) return null;
|
|
1004
|
+
return t;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
const DAY_MS = 86400000;
|
|
1008
|
+
const dayString = (t) => new Date(t).toISOString().slice(0, 10);
|
|
1009
|
+
export const todayUtc = () => { const n = new Date(); return Date.UTC(n.getUTCFullYear(), n.getUTCMonth(), n.getUTCDate()); };
|
|
1010
|
+
|
|
1011
|
+
/** The structural state of a record's status field. */
|
|
1012
|
+
export function classifyState(statusText) {
|
|
1013
|
+
const t = stripMd(statusText || '');
|
|
1014
|
+
if (VOCAB_STATE.done.test(t)) return 'done';
|
|
1015
|
+
if (VOCAB_STATE.notYetAsked.test(t)) return 'not-yet-asked';
|
|
1016
|
+
if (VOCAB_STATE.askedAwaiting.test(t)) return 'asked-awaiting';
|
|
1017
|
+
if (VOCAB_STATE.waiting.test(t)) return 'waiting-unspecified';
|
|
1018
|
+
return 'other';
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/** `{value:'yes'|'no'|'unknown'}` or `{value:null}` for anything outside the domain, including blank. */
|
|
1022
|
+
export function classifyValue(text) {
|
|
1023
|
+
const t = stripMd(text || '').replace(/[.。]+$/, '');
|
|
1024
|
+
if (VOCAB_STATE.yes.test(t)) return 'yes';
|
|
1025
|
+
if (VOCAB_STATE.no.test(t)) return 'no';
|
|
1026
|
+
if (VOCAB_STATE.unknown.test(t)) return 'unknown';
|
|
1027
|
+
return null;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
const ageDays = (now, day) => Math.floor((now - day) / DAY_MS);
|
|
1031
|
+
|
|
1032
|
+
// ── OWT-027 / OWT-028: a release condition that names an object in another project ──
|
|
1033
|
+
// open-work-tracking 1.3.0 (dev-platform XSPEC-460). Local only: it reads files and git tags on THIS
|
|
1034
|
+
// machine and opens no network connection. The names, the machine-specific path prefixes and the
|
|
1035
|
+
// kinds it can resolve are an initial judgment (OWT-016).
|
|
1036
|
+
//
|
|
1037
|
+
// A project is named by a LOGICAL name (`uds`, `vibeops`), never by a directory: a directory is
|
|
1038
|
+
// machine-specific (it leaks a user name and is wrong on the next machine), and two readers of one
|
|
1039
|
+
// carrier must mean the same project by one name. Where a name lives on this machine is supplied
|
|
1040
|
+
// outside the carrier (`--root NAME=DIR`, or `open_work.projects` in uds.project.yaml).
|
|
1041
|
+
|
|
1042
|
+
export const PROJECT_NAME = /^[a-z][a-z0-9_-]{1,31}$/;
|
|
1043
|
+
const URL_SCHEMES = new Set(['http', 'https', 'ftp', 'file', 'ssh', 'git', 'mailto', 'tel', 'data', 'javascript', 'ws', 'wss']);
|
|
1044
|
+
// <name>:<object>. The name is lower-case and at least two characters (so `C:\` is never a project); the
|
|
1045
|
+
// object is one token, or a `code span` for a command or a test name. Not inside a word, a path or a URL.
|
|
1046
|
+
const REF_RE = /(?<![\w./@:\\-])([a-z][a-z0-9_-]{1,31}):(?!\/\/)(`[^`\n]+`|[^\s`|;,,;、()()[\]{}<>"']+)/g;
|
|
1047
|
+
// A machine-specific absolute path: a home or volume prefix, a drive letter, `~/`, a UNC share, a file: URL.
|
|
1048
|
+
const MACHINE_PATH = /(?:^|[\s"'`(=:])(?:\/(?:Users|home|root|Volumes|mnt|private|var|opt|srv|tmp|etc)\/|[A-Za-z]:[\\/]|~[\\/]|\\\\[\w.$-]+\\)|file:\/\//i;
|
|
1049
|
+
const TAG_NAME = /^[A-Za-z0-9][\w.+-]*$/;
|
|
1050
|
+
|
|
1051
|
+
const isAbsoluteObject = (o) => /^(?:\/|~[\\/]|[A-Za-z]:[\\/]|\\\\)/.test(o);
|
|
1052
|
+
const leavesProject = (o) => /(?:^|[\\/])\.\.(?:[\\/]|$)/.test(o);
|
|
1053
|
+
|
|
1054
|
+
/** @returns {{kind:'path'|'tag'|'id'|'command'|'test'|'object'|'absolute'|'outside', value:string}} */
|
|
1055
|
+
export function classifyObject(raw, idPattern = DEFAULT_ID_PATTERN, extraCommands = []) {
|
|
1056
|
+
const code = raw.startsWith('`');
|
|
1057
|
+
let obj = code ? raw.slice(1, -1).trim() : raw.replace(/[.:!?]+$/, '');
|
|
1058
|
+
if (!obj) return { kind: 'object', value: raw };
|
|
1059
|
+
if (isAbsoluteObject(obj)) return { kind: 'absolute', value: obj };
|
|
1060
|
+
if (leavesProject(obj)) return { kind: 'outside', value: obj };
|
|
1061
|
+
const idFull = new RegExp(`^(?:${idPattern})$`);
|
|
1062
|
+
const idOk = (v) => idFull.test(v) && !ID_PREFIX_DENYLIST.includes(v.split('-')[0]);
|
|
1063
|
+
if (code) {
|
|
1064
|
+
const first = obj.split(/\s+/)[0].replace(/^\$\s*/, '');
|
|
1065
|
+
if (pathLike(obj, true)) return { kind: 'path', value: obj };
|
|
1066
|
+
if (COMMANDS.includes(first) || extraCommands.includes(first)) return { kind: 'command', value: obj };
|
|
1067
|
+
if (/\.(?:test|spec)\.[cm]?[jt]sx?|(?:^|[\s/])test_\w+|::/.test(obj)) return { kind: 'test', value: obj };
|
|
1068
|
+
if (idOk(obj)) return { kind: 'id', value: obj };
|
|
1069
|
+
return { kind: 'object', value: obj };
|
|
1070
|
+
}
|
|
1071
|
+
if (pathLike(obj, true)) return { kind: 'path', value: obj };
|
|
1072
|
+
if (idOk(obj)) return { kind: 'id', value: obj };
|
|
1073
|
+
if (TAG_NAME.test(obj)) return { kind: 'tag', value: obj };
|
|
1074
|
+
return { kind: 'object', value: obj };
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/** Every `<project>:<object>` in a piece of text. */
|
|
1078
|
+
export function findReferences(text, idPattern, extraCommands = []) {
|
|
1079
|
+
const refs = [];
|
|
1080
|
+
REF_RE.lastIndex = 0;
|
|
1081
|
+
let m;
|
|
1082
|
+
while ((m = REF_RE.exec(text || '')) !== null) {
|
|
1083
|
+
if (URL_SCHEMES.has(m[1])) continue;
|
|
1084
|
+
const obj = classifyObject(m[2], idPattern, extraCommands);
|
|
1085
|
+
if (!refs.some((r) => r.name === m[1] && r.value === obj.value)) refs.push({ name: m[1], ...obj });
|
|
1086
|
+
}
|
|
1087
|
+
return refs;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* `--root` values for `waiting`. A value that looks like NAME=DIR (a name, then `=`, with no path separator
|
|
1092
|
+
* before the `=`) says where project NAME lives; any other value is the single directory relative paths are
|
|
1093
|
+
* resolved against, exactly as before. Directories are resolved against the current directory.
|
|
1094
|
+
* @returns {{plain:string|undefined, named:Map<string,string>, error:string|null}}
|
|
1095
|
+
*/
|
|
1096
|
+
export function parseRootOptions(values) {
|
|
1097
|
+
const named = new Map();
|
|
1098
|
+
let plain;
|
|
1099
|
+
for (const v of values) {
|
|
1100
|
+
if (typeof v !== 'string' || v === '') return { plain: undefined, named, error: '--root needs a directory, or NAME=DIR' };
|
|
1101
|
+
const m = /^([^\s/\\=]+)=(.*)$/s.exec(v);
|
|
1102
|
+
if (!m) {
|
|
1103
|
+
if (plain !== undefined) return { plain: undefined, named, error: `--root DIR was given more than once ("${plain}" and "${v}"); give one directory, and NAME=DIR for each other project` };
|
|
1104
|
+
plain = v;
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
if (!PROJECT_NAME.test(m[1])) return { plain: undefined, named, error: `--root ${v}: the project name "${m[1]}" is not a logical name (lower-case letters, digits, "-" and "_", starting with a letter, 2 to 32 characters)` };
|
|
1108
|
+
if (m[2].trim() === '') return { plain: undefined, named, error: `--root ${m[1]}=: the directory is empty` };
|
|
1109
|
+
const dir = resolve(m[2]);
|
|
1110
|
+
if (named.has(m[1]) && named.get(m[1]) !== dir) return { plain: undefined, named, error: `--root names project "${m[1]}" twice with different directories` };
|
|
1111
|
+
named.set(m[1], dir);
|
|
1112
|
+
}
|
|
1113
|
+
return { plain, named, error: null };
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/** What can be observed on this machine. Injected in the self-test, so a rule never reads the disk by itself. */
|
|
1117
|
+
export const REAL_ENV = {
|
|
1118
|
+
dirExists: (d) => { try { return statSync(d).isDirectory(); } catch { return false; } },
|
|
1119
|
+
pathExists: (p) => existsSync(p),
|
|
1120
|
+
// 'present' | 'absent' | 'unreadable' (not a git repository, git missing, or git failed): never a guess
|
|
1121
|
+
tagState: (dir, tag) => {
|
|
1122
|
+
const env = { ...process.env };
|
|
1123
|
+
for (const k of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_PREFIX', 'GIT_COMMON_DIR', 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES']) delete env[k];
|
|
1124
|
+
const r = spawnSync('git', ['-C', dir, 'show-ref', '--verify', '--quiet', `refs/tags/${tag}`], { stdio: 'ignore', env });
|
|
1125
|
+
if (r.error || r.status === null) return 'unreadable';
|
|
1126
|
+
if (r.status === 0) return 'present';
|
|
1127
|
+
if (r.status === 1) return 'absent';
|
|
1128
|
+
return 'unreadable';
|
|
1129
|
+
},
|
|
1130
|
+
};
|
|
1131
|
+
|
|
1132
|
+
const OBSERVABLE = { path: 'machine-observable', tag: 'machine-observable' };
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* OWT-028: where does the other project stand? Four answers, never folded into one:
|
|
1136
|
+
* released the object exists there now (a path on disk, a version-control tag)
|
|
1137
|
+
* not-yet-released the project is visible and the object is not there
|
|
1138
|
+
* not-visible this machine cannot see the project, so nothing is known — NOT released, NOT zero
|
|
1139
|
+
* needs-a-person the project is visible but this kind of object (a test name, a command, a spec or
|
|
1140
|
+
* requirement identifier) has nothing here that can be read; a person confirms it
|
|
1141
|
+
* @param {Map<string,string>} projects logical name -> directory on this machine
|
|
1142
|
+
*/
|
|
1143
|
+
export function resolveReference(ref, projects, env = REAL_ENV) {
|
|
1144
|
+
const dir = projects.get(ref.name);
|
|
1145
|
+
if (dir === undefined) return { status: 'not-visible', why: `no directory on this machine is declared for project "${ref.name}" (--root ${ref.name}=DIR)` }; // [mutation-anchor:not-visible]
|
|
1146
|
+
if (!env.dirExists(dir)) return { status: 'not-visible', why: `the directory declared for project "${ref.name}" does not exist on this machine` };
|
|
1147
|
+
if (ref.kind === 'path') return env.pathExists(join(dir, ref.value.replace(/^\.\//, ''))) ? { status: 'released', why: 'the path exists there' } : { status: 'not-yet-released', why: 'the path does not exist there'}; // [mutation-anchor:path-exists]
|
|
1148
|
+
if (ref.kind === 'tag') {
|
|
1149
|
+
const t = env.tagState(dir, ref.value);
|
|
1150
|
+
if (t === 'unreadable') return { status: 'not-visible', why: `the tags of project "${ref.name}" cannot be read here (not a git repository, or git failed)` };
|
|
1151
|
+
return t === 'present' ? { status: 'released', why: 'the tag exists there' } : { status: 'not-yet-released', why: 'the tag does not exist there' }; // [mutation-anchor:tag-present]
|
|
1152
|
+
}
|
|
1153
|
+
return { status: 'needs-a-person', why: `a ${ref.kind === 'id' ? 'requirement or specification identifier' : ref.kind === 'object' ? 'free-form object' : ref.kind} in another project has nothing this check can read` }; // [mutation-anchor:needs-a-person]
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* OWT-020 / OWT-021 / OWT-022. Reads every record that has a status field (OWT-010: a structural
|
|
1158
|
+
* field, never prose). `now` is a UTC day (ms); inject it, never read the clock inside a rule.
|
|
1159
|
+
*/
|
|
1160
|
+
export function checkWaiting(carriers, opts = {}) {
|
|
1161
|
+
const now = opts.now ?? todayUtc();
|
|
1162
|
+
const projects = opts.projects ?? new Map();
|
|
1163
|
+
const env = opts.env ?? REAL_ENV;
|
|
1164
|
+
const res = {
|
|
1165
|
+
walked: 0, counts: { 'not-yet-asked': 0, 'asked-awaiting': 0, 'waiting-unspecified': 0, 'waiting-cross-project': 0, done: 0, other: 0 },
|
|
1166
|
+
cross: { found: 0, counts: { released: 0, 'not-yet-released': 0, 'not-visible': 0, 'needs-a-person': 0 }, items: [] },
|
|
1167
|
+
violations: [], detail: [], ragged: [], noStateCarriers: [],
|
|
1168
|
+
// 464: one entry per record read, with the lines it covers and whether it is `waiting-on-reply`. `next-action` reads THIS
|
|
1169
|
+
// list to decide which rows OWT-019 does not apply to, so the two commands cannot disagree about a row (R2 by construction).
|
|
1170
|
+
records: [],
|
|
1171
|
+
};
|
|
1172
|
+
for (const c of carriers) {
|
|
1173
|
+
const { records, ragged } = extractRecords(c.content);
|
|
1174
|
+
for (const g of ragged) if (g.columns.has('status')) res.ragged.push({ path: c.path, ...g });
|
|
1175
|
+
const withStatus = records.filter((r) => r.f.status !== undefined);
|
|
1176
|
+
if (!withStatus.length) { res.noStateCarriers.push(c.path); continue; }
|
|
1177
|
+
for (const r of withStatus) {
|
|
1178
|
+
res.walked++;
|
|
1179
|
+
let state = classifyState(r.f.status);
|
|
1180
|
+
const at = { path: c.path, where: r.where };
|
|
1181
|
+
const raised = [];
|
|
1182
|
+
const bad = (rule, why) => { raised.push(rule); res.violations.push({ rule, ...at, why }); };
|
|
1183
|
+
const note = [];
|
|
1184
|
+
let askedDay = null;
|
|
1185
|
+
// OWT-027 / OWT-028: a release condition (or what it waits for) that names an object in another project
|
|
1186
|
+
const waitingNow = state === 'not-yet-asked' || state === 'asked-awaiting' || state === 'waiting-unspecified';
|
|
1187
|
+
const conditionText = [r.fr.release, r.fr.awaiting].filter((x) => x !== undefined && x !== '').join(' ; ');
|
|
1188
|
+
const refs = waitingNow ? findReferences(conditionText, opts.idPattern, opts.extraCommands) : [];
|
|
1189
|
+
if (waitingNow && (MACHINE_PATH.test(conditionText) || refs.some((x) => x.kind === 'absolute'))) { // [mutation-anchor:machine-path]
|
|
1190
|
+
bad('OWT-027', `names a machine-specific absolute path in what it waits for or its release ("${clip(conditionText, 60)}"): name the other project by its logical name, <name>:<path inside it>, and keep the directory out of the carrier`);
|
|
1191
|
+
}
|
|
1192
|
+
for (const x of refs) {
|
|
1193
|
+
if (x.kind === 'outside') { bad('OWT-027', `names "${x.name}:${x.value}", a path that leaves project "${x.name}"; give a path inside it`); continue; }
|
|
1194
|
+
if (x.kind === 'absolute') continue; // already a violation above
|
|
1195
|
+
const got = resolveReference(x, projects, env);
|
|
1196
|
+
res.cross.found++;
|
|
1197
|
+
res.cross.counts[got.status]++;
|
|
1198
|
+
res.cross.items.push({ ...at, name: x.name, object: x.value, kind: x.kind, observable: OBSERVABLE[x.kind] ?? 'needs a person', ...got });
|
|
1199
|
+
}
|
|
1200
|
+
// An item that waits for an observable event in another project has no request to have "asked":
|
|
1201
|
+
// OWT-020's two states are about a reply, and this is not one. It is counted on its own line.
|
|
1202
|
+
if (state === 'waiting-unspecified' && refs.some((x) => x.kind !== 'absolute' && x.kind !== 'outside')) state = 'waiting-cross-project'; // [mutation-anchor:cross-project-exempt]
|
|
1203
|
+
res.counts[state]++;
|
|
1204
|
+
const unspecified = state === 'waiting-unspecified'; // [mutation-anchor:waiting-unspecified]
|
|
1205
|
+
if (unspecified) bad('OWT-020', 'is waiting but does not say whether it has been asked (neither not-yet-asked nor asked-awaiting)');
|
|
1206
|
+
if (state === 'not-yet-asked') {
|
|
1207
|
+
const named = classifyNextAction(`${r.f.draft ?? ''} ${r.f.status}`, { root: opts.root, idPattern: opts.idPattern, extraCommands: opts.extraCommands }).status !== 'unnamed'; // [mutation-anchor:not-yet-asked-names]
|
|
1208
|
+
if (!named) bad('OWT-021', 'is not-yet-asked but names no draft or action: no file path, command, test name or requirement identifier');
|
|
1209
|
+
}
|
|
1210
|
+
if (state === 'asked-awaiting') {
|
|
1211
|
+
const day = parseDay(r.f.askedAt);
|
|
1212
|
+
if (day === null) bad('OWT-022', r.f.askedAt === undefined || BLANK_FIELD.test(r.f.askedAt ?? '') ? 'is asked-awaiting but has no asked-at' : `has an asked-at that is not a date with a year: "${clip(r.f.askedAt, 40)}"`); // [mutation-anchor:asked-at-required]
|
|
1213
|
+
else if (day > now) bad('OWT-022', `has an asked-at (${dayString(day)}) later than today (${dayString(now)})`);
|
|
1214
|
+
else { note.push(`asked ${ageDays(now, day)}d ago`); askedDay = day; }
|
|
1215
|
+
const hasWhat = r.f.awaiting !== undefined && !BLANK_FIELD.test(r.f.awaiting);
|
|
1216
|
+
const hasRelease = r.f.release !== undefined && !BLANK_FIELD.test(r.f.release);
|
|
1217
|
+
if (!(hasWhat && hasRelease)) bad('OWT-022', `is asked-awaiting but does not state ${!hasWhat && !hasRelease ? 'what it waits for and what event releases it' : !hasWhat ? 'what it waits for' : 'what event releases it'} (OWT-002)`); // [mutation-anchor:asked-release-required]
|
|
1218
|
+
}
|
|
1219
|
+
res.detail.push({ ...at, state, text: r.title, note: note.join(', ') });
|
|
1220
|
+
// 464 R1: `asked-awaiting` and nothing OWT-020 or OWT-022 objects to. Both rules are read from what THIS function just raised
|
|
1221
|
+
// for this record, never recomputed, so a row `waiting` fails is never one `next-action` waives.
|
|
1222
|
+
const waitingOnReply = state === 'asked-awaiting' && !raised.some((rule) => rule === 'OWT-020' || rule === 'OWT-022'); // [mutation-anchor:waiting-on-reply]
|
|
1223
|
+
res.records.push({ ...at, state, waitingOnReply, lineStart: r.lineStart, lineEnd: r.lineEnd, askedDay, age: askedDay === null ? null : ageDays(now, askedDay), awaiting: r.f.awaiting ?? '', release: r.f.release ?? '' });
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
return res;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* OWT-023 / OWT-024 / OWT-025 / OWT-026. Reads every record of a table or list item that carries an
|
|
1231
|
+
* observed-by or observed-at field. It decides that the fields exist, are well formed, and how old
|
|
1232
|
+
* the stamp is. It cannot decide that the observation is true, or that it still is (OWT-014).
|
|
1233
|
+
*/
|
|
1234
|
+
export function checkObservations(carriers, opts = {}) {
|
|
1235
|
+
const now = opts.now ?? todayUtc();
|
|
1236
|
+
const staleAfter = opts.staleAfterDays ?? DEFAULT_STALE_AFTER_DAYS;
|
|
1237
|
+
const res = {
|
|
1238
|
+
walked: 0, now, staleAfter, counts: { yes: 0, no: 0, unknown: 0, invalid: 0 }, stale: [], unknown: [], confirmed: 0,
|
|
1239
|
+
violations: [], detail: [], ragged: [], noObservationCarriers: [],
|
|
1240
|
+
};
|
|
1241
|
+
for (const c of carriers) {
|
|
1242
|
+
const { records, ragged } = extractRecords(c.content);
|
|
1243
|
+
for (const g of ragged) if (g.columns.has('observedBy') || g.columns.has('observedAt')) res.ragged.push({ path: c.path, ...g });
|
|
1244
|
+
const obs = records.filter((r) => r.columns.has('observedBy') || r.columns.has('observedAt'));
|
|
1245
|
+
if (!obs.length) { res.noObservationCarriers.push(c.path); continue; }
|
|
1246
|
+
for (const r of obs) {
|
|
1247
|
+
res.walked++;
|
|
1248
|
+
const at = { path: c.path, where: r.where };
|
|
1249
|
+
const bad = (rule, why) => res.violations.push({ rule, ...at, why });
|
|
1250
|
+
let wellFormed = true;
|
|
1251
|
+
const fail = (rule, why) => { wellFormed = false; bad(rule, why); };
|
|
1252
|
+
const by = r.f.observedBy;
|
|
1253
|
+
if (by === undefined || BLANK_FIELD.test(by)) fail('OWT-023', 'has no observed-by: who or what saw this is not recorded'); // [mutation-anchor:observed-by-required]
|
|
1254
|
+
const day = parseDay(r.f.observedAt);
|
|
1255
|
+
let age = null;
|
|
1256
|
+
if (day === null) fail('OWT-023', r.f.observedAt === undefined || BLANK_FIELD.test(r.f.observedAt) ? 'has no observed-at: when it was seen is not recorded' : `has an observed-at that is not a date with a year: "${clip(r.f.observedAt, 40)}"`); // [mutation-anchor:observed-at-required]
|
|
1257
|
+
else if (day > now) fail('OWT-023', `has an observed-at (${dayString(day)}) later than today (${dayString(now)})`);
|
|
1258
|
+
else age = ageDays(now, day);
|
|
1259
|
+
const value = classifyValue(r.f.value);
|
|
1260
|
+
if (value === null) fail('OWT-023', `has no value of yes, no or unknown${r.f.value ? ` (found "${clip(r.f.value, 30)}")` : ''}`); // [mutation-anchor:value-domain]
|
|
1261
|
+
const subject = r.f.subject ?? r.title;
|
|
1262
|
+
if (VOCAB_STATE.derivable.test(subject)) fail('OWT-026', `is a hand-written observation of "${clip(subject, 50)}", which version control, a spec marker or a CI result determines (OWT-003 stands)`); // [mutation-anchor:derivable]
|
|
1263
|
+
if (value === null) res.counts.invalid++; else res.counts[value]++;
|
|
1264
|
+
const isStale = age !== null && age > staleAfter; // [mutation-anchor:stale]
|
|
1265
|
+
const claimsDone = r.f.status !== undefined && classifyState(r.f.status) === 'done';
|
|
1266
|
+
if (value === 'unknown') {
|
|
1267
|
+
res.unknown.push({ ...at, text: r.title });
|
|
1268
|
+
if (claimsDone) bad('OWT-024', 'is marked done while its observation is unknown: unknown never counts as complete'); // [mutation-anchor:unknown-not-done]
|
|
1269
|
+
}
|
|
1270
|
+
if (isStale) res.stale.push({ ...at, text: r.title, age, claimsDone });
|
|
1271
|
+
const confirmed = wellFormed && value === 'yes' && !isStale; // [mutation-anchor:confirmed]
|
|
1272
|
+
if (confirmed) res.confirmed++;
|
|
1273
|
+
res.detail.push({ ...at, text: r.title, value: value ?? '?', age, by: by ?? '', observedAt: r.f.observedAt ?? '' });
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return res;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
638
1279
|
// ── Self-test arms (the main path runs these first; a broken checker is exit 2) ─
|
|
639
1280
|
|
|
1281
|
+
/** The shape every caller has always had: `{ ok, failures }`. `selfTestArms` is the same run with the names of the arms that were evaluated. */
|
|
640
1282
|
export function runSelfTest() {
|
|
1283
|
+
const { ok, failures } = selfTestArms();
|
|
1284
|
+
return { ok, failures };
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
export function selfTestArms() {
|
|
641
1288
|
const failures = [];
|
|
642
|
-
const
|
|
1289
|
+
const ran = []; // every arm that was evaluated, passed or not, so a test can tell "passed" from "never ran"
|
|
1290
|
+
const expect = (name, cond) => { ran.push(name); if (!cond) failures.push(name); };
|
|
643
1291
|
|
|
644
1292
|
// OWT-019
|
|
645
1293
|
expect('D2 violating: verb-only is unnamed', classifyNextAction('Continue implementation', {}).status === 'unnamed');
|
|
@@ -675,13 +1323,141 @@ export function runSelfTest() {
|
|
|
675
1323
|
]);
|
|
676
1324
|
expect('D1 clean: carriers apart', apart.violations.length === 0 && apart.recognised === 2);
|
|
677
1325
|
|
|
678
|
-
|
|
1326
|
+
// OWT-020 … OWT-026 (1.2.0): every check has a sample built to violate it and one built to satisfy it.
|
|
1327
|
+
const NOW = Date.UTC(2026, 9, 7);
|
|
1328
|
+
const wtab = (rows) => `| item | status | draft | asked-at | waiting for | release |\n|---|---|---|---|---|---|\n${rows}`;
|
|
1329
|
+
const waiting = (rows) => checkWaiting([{ path: 'w.md', content: wtab(rows) }], { now: NOW });
|
|
1330
|
+
const ruleOf = (res, rule) => res.violations.filter((v) => v.rule === rule).length;
|
|
1331
|
+
const w0 = waiting('| ask legal | waiting | | | | |\n');
|
|
1332
|
+
expect('OWT-020 violating: a waiting item that does not say whether it was asked', ruleOf(w0, 'OWT-020') === 1 && w0.counts['waiting-unspecified'] === 1);
|
|
1333
|
+
const w1 = waiting('| ask legal | not-yet-asked | drafts/legal.md | | | |\n| ask vendor | 已問、等回覆 | | 2026-10-01 | the quote | the reply arrives |\n');
|
|
1334
|
+
expect('OWT-020 clean: both named states, in English and in Chinese', w1.violations.length === 0 && w1.counts['not-yet-asked'] === 1 && w1.counts['asked-awaiting'] === 1);
|
|
1335
|
+
expect('OWT-021 violating: not-yet-asked names no draft or action', ruleOf(waiting('| ask legal | not-yet-asked | an email | | | |\n'), 'OWT-021') === 1);
|
|
1336
|
+
expect('OWT-021 clean: not-yet-asked names a path', ruleOf(waiting('| ask legal | not-yet-asked | `drafts/legal.md` | | | |\n'), 'OWT-021') === 0);
|
|
1337
|
+
expect('OWT-022 violating: asked-awaiting has no asked-at', ruleOf(waiting('| q | asked-awaiting | | | the quote | the reply arrives |\n'), 'OWT-022') === 1);
|
|
1338
|
+
expect('OWT-022 violating: asked-awaiting does not say what releases it (OWT-002)', ruleOf(waiting('| q | asked-awaiting | | 2026-10-01 | the quote | |\n'), 'OWT-022') === 1);
|
|
1339
|
+
expect('OWT-022 clean: asked-awaiting with asked-at, what it waits for and its release', ruleOf(waiting('| q | asked-awaiting | | 2026-10-01 | the quote | the reply arrives |\n'), 'OWT-022') === 0);
|
|
1340
|
+
expect('OWT-020 clean: a done item is not waiting', waiting('| q | done | | | | |\n').violations.length === 0);
|
|
1341
|
+
|
|
1342
|
+
const otab = (rows) => `| fact | status | observed-by | observed-at | value |\n|---|---|---|---|---|\n${rows}`;
|
|
1343
|
+
const obs = (rows, o = {}) => checkObservations([{ path: 'o.md', content: otab(rows) }], { now: NOW, ...o });
|
|
1344
|
+
expect('OWT-023 violating: an observation with no observed-by', ruleOf(obs('| mail sent | open | | 2026-10-05 | yes |\n'), 'OWT-023') === 1);
|
|
1345
|
+
expect('OWT-023 violating: an observation with no observed-at', ruleOf(obs('| mail sent | open | albert | | yes |\n'), 'OWT-023') === 1);
|
|
1346
|
+
expect('OWT-023 violating: a value outside yes, no, unknown', ruleOf(obs('| mail sent | open | albert | 2026-10-05 | maybe |\n'), 'OWT-023') === 1);
|
|
1347
|
+
const o1 = obs('| mail sent | open | albert | 2026-10-05 | yes |\n');
|
|
1348
|
+
expect('OWT-023 clean: observed-by, observed-at and a value; its age is computed', o1.violations.length === 0 && o1.detail[0].age === 2 && o1.confirmed === 1);
|
|
1349
|
+
const o2 = obs('| approved | done | albert | 2026-10-05 | unknown |\n');
|
|
1350
|
+
expect('OWT-024 violating: unknown marked done', ruleOf(o2, 'OWT-024') === 1);
|
|
1351
|
+
expect('OWT-024 violating: unknown is counted apart and never confirmed', o2.counts.unknown === 1 && o2.unknown.length === 1 && o2.confirmed === 0);
|
|
1352
|
+
expect('OWT-024 clean: unknown not marked done is listed, not a violation', ruleOf(obs('| approved | open | albert | 2026-10-05 | unknown |\n'), 'OWT-024') === 0);
|
|
1353
|
+
const o3 = obs('| mail sent | open | albert | 2026-09-01 | yes |\n');
|
|
1354
|
+
expect('OWT-025 violating: an observation older than the threshold is stale and not confirmed', o3.stale.length === 1 && o3.confirmed === 0);
|
|
1355
|
+
expect('OWT-025 clean: a fresh observation is not stale', o1.stale.length === 0);
|
|
1356
|
+
expect('OWT-025 clean: the threshold is injectable', obs('| mail sent | open | albert | 2026-09-01 | yes |\n', { staleAfterDays: 60 }).stale.length === 0);
|
|
1357
|
+
expect('OWT-026 violating: a hand-written observation of something version control determines', ruleOf(obs('| PR merged | open | albert | 2026-10-05 | yes |\n'), 'OWT-026') === 1);
|
|
1358
|
+
expect('OWT-026 clean: an external fact the assistant cannot see', ruleOf(obs('| legal replied | open | albert | 2026-10-05 | yes |\n'), 'OWT-026') === 0);
|
|
1359
|
+
|
|
1360
|
+
// OWT-027 / OWT-028 (1.3.0): a release condition naming an object in another project. The disk and git are
|
|
1361
|
+
// replaced by a fake environment, so the arms never touch either (the checker runs them before every command).
|
|
1362
|
+
const FAKE_DIR = join('/fake', 'other');
|
|
1363
|
+
const fakeEnv = {
|
|
1364
|
+
dirExists: (d) => d === FAKE_DIR,
|
|
1365
|
+
pathExists: (p) => p === join(FAKE_DIR, 'docs', 'a.md'),
|
|
1366
|
+
tagState: (_d, tag) => (tag === 'v1.0.0' ? 'present' : 'absent'),
|
|
1367
|
+
};
|
|
1368
|
+
const known = new Map([['other', FAKE_DIR]]);
|
|
1369
|
+
const cross = (release, projects = known, extra = '') => checkWaiting([{ path: 'x.md', content: wtab(`| wait for other | waiting | | | ${extra} | ${release} |\n`) }], { now: NOW, projects, env: fakeEnv });
|
|
1370
|
+
expect('OWT-027 violating: a release condition holding a machine-specific absolute path', ruleOf(cross('/Users/someone/work/other/docs/a.md'), 'OWT-027') === 1);
|
|
1371
|
+
expect('OWT-027 violating: an object that leaves the other project', ruleOf(cross('other:../secret.md'), 'OWT-027') === 1);
|
|
1372
|
+
expect('OWT-027 clean: a logical project name and an object inside it', ruleOf(cross('other:v1.0.0'), 'OWT-027') === 0);
|
|
1373
|
+
expect('OWT-027 violating: a drive letter is an absolute path, not a project name', ruleOf(cross('C:\\work\\other\\a.md'), 'OWT-027') === 1 && cross('C:\\work\\other\\a.md').cross.found === 0);
|
|
1374
|
+
expect('OWT-027 clean: a URL is not a project reference', cross('see https://example.com/a').cross.found === 0 && ruleOf(cross('see https://example.com/a'), 'OWT-027') === 0);
|
|
1375
|
+
expect('OWT-028 clean: a tag that exists there is released, in a project this machine can see', cross('other:v1.0.0').cross.counts.released === 1);
|
|
1376
|
+
expect('OWT-028 clean: a path that exists there is released', cross('other:docs/a.md').cross.counts.released === 1);
|
|
1377
|
+
expect('OWT-028 violating: a tag that is not there is not released', cross('other:v2.0.0').cross.counts['not-yet-released'] === 1 && cross('other:v2.0.0').cross.counts.released === 0);
|
|
1378
|
+
expect('OWT-028 violating: a path that is not there is not released', cross('other:docs/b.md').cross.counts['not-yet-released'] === 1);
|
|
1379
|
+
const unseen = cross('stranger:v1.0.0');
|
|
1380
|
+
expect('OWT-028 violating: a project this machine cannot see is counted apart, never released and never zero', unseen.cross.counts['not-visible'] === 1 && unseen.cross.counts.released === 0 && unseen.cross.found === 1);
|
|
1381
|
+
const person = cross('other:XSPEC-123');
|
|
1382
|
+
expect('OWT-028 violating: an identifier in another project needs a person and is never released', person.cross.counts['needs-a-person'] === 1 && person.cross.counts.released === 0);
|
|
1383
|
+
expect('OWT-028 clean: an unseen project is still listed with its reason', unseen.cross.items[0].status === 'not-visible' && /stranger/.test(unseen.cross.items[0].why));
|
|
1384
|
+
expect('OWT-020 clean: a waiting item that waits for another project is not asked about a reply', cross('other:v1.0.0').violations.length === 0 && cross('other:v1.0.0').counts['waiting-cross-project'] === 1);
|
|
1385
|
+
expect('OWT-020 violating: a plain waiting item is still named', ruleOf(waiting('| ask board | waiting | | | | |\n'), 'OWT-020') === 1);
|
|
1386
|
+
expect('OWT-027 clean: --root NAME=DIR and a plain --root are told apart', (() => { const r = parseRootOptions(['other=/fake/other', '/somewhere']); return r.error === null && r.plain === '/somewhere' && r.named.get('other') === resolve('/fake/other'); })());
|
|
1387
|
+
expect('OWT-027 violating: a project name that is not a logical name is refused', parseRootOptions(['Other=/x']).error !== null && parseRootOptions(['a', 'b']).error !== null);
|
|
1388
|
+
|
|
1389
|
+
// 461 R5 (1.3.0): a command the adopter declares is read by next-action AND by waiting; glab and dotnet are built in.
|
|
1390
|
+
expect('461 R5 clean: glab and dotnet are built-in commands', classifyNextAction('run `glab mr merge 486`', {}).status !== 'unnamed' && classifyNextAction('run `dotnet test X.csproj`', {}).status !== 'unnamed');
|
|
1391
|
+
expect('461 R5 violating: a program that was not declared is not a command', classifyNextAction('run `kubectl apply -f x.yaml`', {}).status === 'unnamed' && classifyNextAction('then go build it, make test, sh run', {}).status === 'unnamed');
|
|
1392
|
+
expect('461 R5 clean: a declared command is read by next-action', classifyNextAction('run `kubectl apply -f x.yaml`', { extraCommands: ['kubectl'] }).status !== 'unnamed');
|
|
1393
|
+
const kubeRow = '| ask ops | not-yet-asked | kubectl rollout restart | | | |\n';
|
|
1394
|
+
expect('461 R5 violating: waiting does not know an undeclared command, so the draft names nothing', ruleOf(waiting(kubeRow), 'OWT-021') === 1);
|
|
1395
|
+
expect('461 R5 clean: the same row under waiting names a draft once the command is declared', ruleOf(checkWaiting([{ path: 'k.md', content: wtab(kubeRow) }], { now: NOW, extraCommands: ['kubectl'] }), 'OWT-021') === 0);
|
|
1396
|
+
expect('461 R5 violating: a blank or spaced command word is refused', normaliseDeclaredCommands(['']).error !== null && normaliseDeclaredCommands(['git lfs']).error !== null && normaliseDeclaredCommands(['kubectl']).error === null);
|
|
1397
|
+
expect('461 R5 clean: a declared command is plain text, not a pattern', classifyNextAction('run `a.b x`', { extraCommands: ['a.b'] }).status !== 'unnamed' && classifyNextAction('run aXb now', { extraCommands: ['a.b'] }).status === 'unnamed');
|
|
1398
|
+
|
|
1399
|
+
// 461 R6 (1.3.0): named-unresolved says whether a path was looked up and missing, or nothing was looked up
|
|
1400
|
+
const split = checkNextActions([{ path: 'n.md', content: '| item | Next action |\n|---|---|\n| a | `glab mr merge 486` |\n| b | edit src/none.js |\n| c | finish XSPEC-12 |\n' }], { root: '/fake/root' });
|
|
1401
|
+
expect('461 R6 clean: a command and an identifier are not-resolvable, a path that is not there is path-missing, and they sum to named-unresolved', split.unresolvedSplit['not-resolvable'] === 2 && split.unresolvedSplit['path-missing'] === 1 && split.counts['named-unresolved'] === 3);
|
|
1402
|
+
expect('461 R6 violating: without a root nothing is looked up, so a path is not-resolvable too', checkNextActions([{ path: 'n.md', content: '| item | Next action |\n|---|---|\n| b | edit src/none.js |\n' }], {}).unresolvedSplit['not-resolvable'] === 1);
|
|
1403
|
+
const explained = explainResolution({ root: '/fake/root', rootGiven: false, carriers: [], split: { 'path-missing': 1, 'not-resolvable': 2 }, unresolved: 3 }).join('\n');
|
|
1404
|
+
expect('461 R6 clean: the resolution lines say the root, where it came from, and that only a path is looked up', explained.includes(`looked up under ${resolve('/fake/root')} (the current directory: no --root was given)`) && /Only a PATH is looked up/.test(explained) && /path-missing=1 not-resolvable=2/.test(explained) && /from --root/.test(explainResolution({ root: '/r', rootGiven: true, carriers: [], split, unresolved: 3 }).join('\n')));
|
|
1405
|
+
|
|
1406
|
+
// 461 (1.3.0): the one next-action list, the words an adopter declares, and the exit-2 explanation.
|
|
1407
|
+
const table461 = (h) => `| item | state | ${h} |\n|---|---|---|\n| a | open | edit scripts/foo.mjs |\n`;
|
|
1408
|
+
expect('461 R1 clean: 下一個動作, 下一個步驟 and 接下來要做什麼 are read by default', ['下一個動作', '下一個步驟', '接下來要做什麼'].every((h) => extractNextActions(table461(h)).fields === 1));
|
|
1409
|
+
expect('461 R1 violating: 待辦 is not read unless declared (the list is not widened)', extractNextActions(table461('待辦')).fields === 0 && extractNextActions(table461('Next')).fields === 0 && extractNextActions(table461('接下來')).fields === 0);
|
|
1410
|
+
expect('461 R2 clean: a declared word is read as a table header, a heading and an inline label, from one list', extractNextActions(table461('待辦'), ['待辦']).fields === 1 && extractNextActions('## 待辦\n- edit scripts/foo.mjs\n', ['待辦']).fields === 1 && extractNextActions('待辦: edit scripts/foo.mjs\n', ['待辦']).fields === 1);
|
|
1411
|
+
expect('461 R2 violating: the same carrier without the declaration is not read', extractNextActions('## 待辦\n- edit scripts/foo.mjs\n').fields === 0);
|
|
1412
|
+
expect('461 R2 clean: a declared word is plain text, any case, never a pattern', extractNextActions(table461('To.Do'), ['to.do']).fields === 1 && extractNextActions(table461('ToXDo'), ['to.do']).fields === 0);
|
|
1413
|
+
expect('461 R2 violating: a blank declared word is refused, not dropped', normaliseDeclaredWords(['']).error !== null && normaliseDeclaredWords([' ']).error !== null && normaliseDeclaredWords(['待辦']).error === null);
|
|
1414
|
+
const why = explainNoNextActionField([{ path: 'w.md', content: table461('待辦') }], ['後續']).join('\n');
|
|
1415
|
+
expect('461 R3 clean: exit-2 text names the headers the carrier showed, the words recognised and how to add one', /"待辦"/.test(why) && /"state"/.test(why) && /built in:/.test(why) && /declared by you: 後續/.test(why) && /--next-action-word/.test(why));
|
|
1416
|
+
expect('461 R3 clean: a carrier with a table and one with nothing to read are told apart', /has 1 table\(s\), but no table header matches/.test(why) && /no table and no heading to read/.test(explainNoNextActionField([{ path: 'n.md', content: 'just words\n' }]).join('\n')));
|
|
1417
|
+
|
|
1418
|
+
// 464 (1.4.0): an `asked-awaiting` row that OWT-022 is satisfied by is `waiting-on-reply` for next-action, and every row
|
|
1419
|
+
// `waiting` fails is still judged by OWT-019. Every arm here builds its carrier from text and reads no path.
|
|
1420
|
+
const reply = (rows, o = {}) => checkNextActions([{ path: 'w.md', content: `| item | status | asked-at | waiting for | release | Next action |\n|---|---|---|---|---|---|\n${rows}` }], { now: NOW, ...o });
|
|
1421
|
+
const REPLY_ROW = (status, askedAt, awaiting, release) => `| vendor quote | ${status} | ${askedAt} | ${awaiting} | ${release} | wait for the vendor reply |\n`;
|
|
1422
|
+
const FULL = REPLY_ROW('asked-awaiting', '2026-10-05', 'the quote', 'the quote arrives');
|
|
1423
|
+
const onlyReply = (res) => res.counts['waiting-on-reply'] === 1 && res.counts.unnamed === 0 && res.violations.length === 0 && res.counts['named-resolved'] + res.counts['named-unresolved'] === 0;
|
|
1424
|
+
const stillUnnamed = (res) => res.counts.unnamed === 1 && res.counts['waiting-on-reply'] === 0 && res.violations.length === 1;
|
|
1425
|
+
expect('OWT-019 clean: an asked-awaiting row with asked-at, what it waits for and its release is waiting-on-reply, not a violation and not named (XSPEC-464 R1)', onlyReply(reply(FULL)));
|
|
1426
|
+
expect('OWT-019 clean: the Chinese state word and the Chinese field names are read the same way (XSPEC-464 R1)', onlyReply(checkNextActions([{ path: 'w.md', content: '| 事情 | 狀態 | 詢問日期 | 等什麼 | 解除條件 | 下一步 |\n|---|---|---|---|---|---|\n| 廠商報價 | 已問、等回覆 | 2026-10-05 | 廠商回信 | 收到報價單 | 等對方回信 |\n' }], { now: NOW })));
|
|
1427
|
+
expect('OWT-019 violating: an asked-awaiting row with no asked-at is still unnamed (XSPEC-464 R3)', stillUnnamed(reply(REPLY_ROW('asked-awaiting', '', 'the quote', 'the quote arrives'))));
|
|
1428
|
+
expect('OWT-019 violating: an asked-awaiting row whose asked-at is in the future is still unnamed (XSPEC-464 R3)', stillUnnamed(reply(REPLY_ROW('asked-awaiting', '2026-10-09', 'the quote', 'the quote arrives'))));
|
|
1429
|
+
expect('OWT-019 violating: an asked-awaiting row that says nothing about what it waits for is still unnamed (XSPEC-464 R3)', stillUnnamed(reply(REPLY_ROW('asked-awaiting', '2026-10-05', '', 'the quote arrives'))));
|
|
1430
|
+
expect('OWT-019 violating: an asked-awaiting row that says nothing about its release is still unnamed (XSPEC-464 R3)', stillUnnamed(reply(REPLY_ROW('asked-awaiting', '2026-10-05', 'the quote', ''))));
|
|
1431
|
+
expect('OWT-019 violating: a not-yet-asked row is still unnamed (XSPEC-464 R3)', stillUnnamed(reply(REPLY_ROW('not-yet-asked', '', '', ''))));
|
|
1432
|
+
expect('OWT-019 violating: a row in any other state is still unnamed (XSPEC-464 R3)', stillUnnamed(reply(REPLY_ROW('in progress', '2026-10-05', 'the quote', 'the quote arrives'))));
|
|
1433
|
+
expect('OWT-019 violating: a table with no status column is read exactly as before (XSPEC-464 R3)', stillUnnamed(checkNextActions([{ path: 'n.md', content: '| item | Next action |\n|---|---|\n| vendor quote | wait for the vendor reply |\n' }], { now: NOW })));
|
|
1434
|
+
const LISTED = (label) => '- vendor quote\n - status: asked-awaiting\n - asked-at: 2026-10-05\n - waiting for: the quote\n - release: the quote arrives\n - Next action: wait for the vendor reply\n'.replace(label[0], label[1]);
|
|
1435
|
+
const asList = (label) => checkNextActions([{ path: 'l.md', content: LISTED(label) }], { now: NOW });
|
|
1436
|
+
expect('OWT-019 clean: a list item with every field is waiting-on-reply too (XSPEC-464 R1)', onlyReply(asList([' - Next action', ' - Next action'])));
|
|
1437
|
+
expect('OWT-019 violating: a list item whose release is blank is not read as filled by the Next action line under it, so it is still unnamed (XSPEC-464 R3)', stillUnnamed(asList(['release: the quote arrives', 'release:'])));
|
|
1438
|
+
expect('OWT-019 violating: a list item whose what-it-waits-for is blank is not read as filled by the lines under it, so it is still unnamed (XSPEC-464 R3)', stillUnnamed(asList(['waiting for: the quote', 'waiting for:'])));
|
|
1439
|
+
expect('OWT-019 violating: a next action that is a heading section is never waived (XSPEC-464 R3)', checkNextActions([{ path: 'n.md', content: '## Next action\n\n- wait for the vendor reply\n' }], { now: NOW }).counts.unnamed === 1);
|
|
1440
|
+
const oldAsk = reply(REPLY_ROW('asked-awaiting', '2026-08-01', 'the quote', 'the quote arrives'));
|
|
1441
|
+
expect('OWT-025 clean: a waiting-on-reply row shows its age and is marked stale past the threshold, still not a violation (XSPEC-464 R1)', onlyReply(oldAsk) && oldAsk.waitingOnReply[0]?.age === 67 && oldAsk.waitingOnReply[0]?.stale === true && reply(FULL).waitingOnReply[0]?.age === 2 && reply(FULL).waitingOnReply[0]?.stale === false);
|
|
1442
|
+
expect('OWT-025 clean: the stale threshold of a waiting-on-reply row is injectable (XSPEC-464 R1)', reply(FULL, { staleAfterDays: 1 }).waitingOnReply[0]?.stale === true && oldAsk.waitingOnReply.length === 1 && reply(REPLY_ROW('asked-awaiting', '2026-08-01', 'the quote', 'the quote arrives'), { staleAfterDays: 100 }).waitingOnReply[0]?.stale === false);
|
|
1443
|
+
const MATRIX = [FULL, REPLY_ROW('asked-awaiting', '', 'the quote', 'the quote arrives'), REPLY_ROW('asked-awaiting', '2026-10-09', 'the quote', 'the quote arrives'), REPLY_ROW('asked-awaiting', '2026-10-05', '', 'the quote arrives'), REPLY_ROW('asked-awaiting', '2026-10-05', 'the quote', ''), REPLY_ROW('asked-awaiting', 'last week', 'the quote', 'the quote arrives'), REPLY_ROW('not-yet-asked', '', '', ''), REPLY_ROW('waiting', '', '', ''), REPLY_ROW('in progress', '2026-10-05', 'the quote', 'the quote arrives'), REPLY_ROW('done', '2026-10-05', 'the quote', 'the quote arrives')];
|
|
1444
|
+
const agree = (row) => {
|
|
1445
|
+
const text = `| item | status | asked-at | waiting for | release | Next action |\n|---|---|---|---|---|---|\n${row}`;
|
|
1446
|
+
const w = checkWaiting([{ path: 'w.md', content: text }], { now: NOW });
|
|
1447
|
+
const n = checkNextActions([{ path: 'w.md', content: text }], { now: NOW });
|
|
1448
|
+
const waitingPasses = w.counts['asked-awaiting'] === 1 && !w.violations.some((v) => v.rule === 'OWT-020' || v.rule === 'OWT-022');
|
|
1449
|
+
return waitingPasses === (n.counts['waiting-on-reply'] === 1) && !(waitingPasses && n.violations.length > 0) && !(w.violations.some((v) => v.rule === 'OWT-022') && n.counts['waiting-on-reply'] > 0);
|
|
1450
|
+
};
|
|
1451
|
+
expect('OWT-019 clean: waiting and next-action never give opposite answers about the same row (XSPEC-464 R2)', MATRIX.every(agree) && MATRIX.length === 10);
|
|
1452
|
+
|
|
1453
|
+
return { ok: failures.length === 0, failures, ran };
|
|
679
1454
|
}
|
|
680
1455
|
|
|
681
1456
|
// ── CLI ──────────────────────────────────────────────────────────────────────
|
|
682
1457
|
|
|
683
1458
|
const COVERAGE_NOTE = 'COVERAGE UNKNOWN (OWT-011): recognising a path/command/test name/identifier is pattern matching; an unrecognised format is reported as unnamed. A clean pass does not mean every next action is specific.';
|
|
684
1459
|
const UNCALIBRATED_NOTE = 'UNCALIBRATED (OWT-016): heading vocabulary, command list, extension list and identifier pattern are initial judgments.';
|
|
1460
|
+
const UNCALIBRATED_STATE_NOTE = 'UNCALIBRATED (OWT-016): the state words, field names (English and Chinese), the derivable-subject word list and the stale-after threshold are initial judgments, none measured against real usage.';
|
|
685
1461
|
|
|
686
1462
|
function readCarrier(p) {
|
|
687
1463
|
return { path: p, content: readFileSync(p, 'utf8') };
|
|
@@ -715,6 +1491,13 @@ export function main(argv, io = { log: console.log, err: console.error }) {
|
|
|
715
1491
|
args.splice(i, 2);
|
|
716
1492
|
return v;
|
|
717
1493
|
};
|
|
1494
|
+
// every occurrence of a repeatable option, in order; a missing value is kept as undefined so the caller can refuse it
|
|
1495
|
+
const flagAll = (name) => {
|
|
1496
|
+
const values = [];
|
|
1497
|
+
let i;
|
|
1498
|
+
while ((i = args.indexOf(name)) !== -1) { values.push(args[i + 1]); args.splice(i, 2); }
|
|
1499
|
+
return values;
|
|
1500
|
+
};
|
|
718
1501
|
const finish = (code) => { for (const l of out) (code === 2 ? io.err : io.log)(l); return code; };
|
|
719
1502
|
|
|
720
1503
|
const selfTest = runSelfTest();
|
|
@@ -730,19 +1513,45 @@ export function main(argv, io = { log: console.log, err: console.error }) {
|
|
|
730
1513
|
const cmd = args.shift();
|
|
731
1514
|
try {
|
|
732
1515
|
if (cmd === 'next-action') {
|
|
733
|
-
const
|
|
1516
|
+
const rootArg = flag('--root');
|
|
1517
|
+
const root = rootArg ?? process.cwd();
|
|
734
1518
|
const idPattern = flag('--id-pattern');
|
|
1519
|
+
const declared = normaliseDeclaredWords(flagAll('--next-action-word'));
|
|
1520
|
+
if (declared.error) { say(`[owt] next-action: ${declared.error}`); return finish(2); }
|
|
1521
|
+
const commandsDeclared = normaliseDeclaredCommands(flagAll('--command-word'));
|
|
1522
|
+
if (commandsDeclared.error) { say(`[owt] next-action: ${commandsDeclared.error}`); return finish(2); }
|
|
1523
|
+
// 464: today and the stale threshold are injected, as they are for `waiting` and `observations`, never read inside a rule.
|
|
1524
|
+
const nowArg = flag('--now');
|
|
1525
|
+
const now = nowArg === undefined ? todayUtc() : parseDay(nowArg);
|
|
1526
|
+
if (now === null) { say(`[owt] next-action: --now must be a date with a year (YYYY-MM-DD), got "${nowArg}"`); return finish(2); }
|
|
1527
|
+
const staleArg = flag('--stale-after');
|
|
1528
|
+
const staleAfterDays = staleArg === undefined ? undefined : Number(staleArg);
|
|
1529
|
+
if (staleAfterDays !== undefined && (!Number.isFinite(staleAfterDays) || staleAfterDays < 0)) { say(`[owt] next-action: --stale-after must be a number of days, got "${staleArg}"`); return finish(2); }
|
|
735
1530
|
const files = args;
|
|
736
1531
|
if (!files.length) { say('[owt] next-action: no files given'); return finish(2); }
|
|
737
|
-
const
|
|
1532
|
+
const carriers = files.map(readCarrier);
|
|
1533
|
+
const res = checkNextActions(carriers, { root, idPattern, words: declared.words, extraCommands: commandsDeclared.words, now, staleAfterDays });
|
|
738
1534
|
say(`[owt] OWT-019 walked ${res.walked} next-action field(s) in ${files.length} carrier(s); ${res.empty} empty/done field(s) not evaluated; ${res.noFieldCarriers.length} carrier(s) had no next-action field`);
|
|
739
|
-
|
|
1535
|
+
// `waiting-on-reply=N` is appended only when N is not 0, as `waiting-cross-project` is: a carrier with no such row prints what it always printed.
|
|
1536
|
+
say(`[owt] named-resolved=${res.counts['named-resolved']} named-unresolved=${res.counts['named-unresolved']} unnamed=${res.counts.unnamed} undecidable-table-rows=${res.undecidable.length}${res.counts['waiting-on-reply'] ? ` waiting-on-reply=${res.counts['waiting-on-reply']}` : ''}`);
|
|
1537
|
+
// 461 R6: the lines below are additions; every line above and below them is what 1.1.0 printed.
|
|
1538
|
+
for (const l of explainResolution({ root, rootGiven: rootArg !== undefined, carriers, split: res.unresolvedSplit, unresolved: res.counts['named-unresolved'], commands: commandsDeclared.words })) say(`[owt] ${l}`);
|
|
740
1539
|
for (const d of res.detail) say(`[owt] ${d.status.padEnd(16)} ${d.path} ${d.where}: ${d.text.slice(0, 80)}${d.kinds.length ? ' <- ' + d.kinds.map((k) => `${k.kind}:${k.value}`).join(', ') : ''}`);
|
|
1540
|
+
if (res.waitingOnReply.length) {
|
|
1541
|
+
const stale = res.waitingOnReply.filter((x) => x.stale).length;
|
|
1542
|
+
say(`[owt] WAITING-ON-REPLY ${res.waitingOnReply.length} row(s) are asked-awaiting and carry everything OWT-022 asks for, so OWT-019 is not applied to them (counted apart: not named, not resolved, not complete; ${stale} older than ${res.staleAfter} day(s), UNCALIBRATED):`);
|
|
1543
|
+
for (const x of res.waitingOnReply) say(`[owt] ${x.path} ${x.where}: asked ${x.age}d ago (${dayString(x.askedDay)})${x.stale ? ` STALE (older than ${res.staleAfter}d)` : ''}; waiting for: ${clip(x.awaiting, 60)}; released by: ${clip(x.release, 60)}`);
|
|
1544
|
+
say('[owt] WAITING-ON-REPLY LIMIT: the check decides that asked-at, what is waited for and the release event are present and well formed (OWT-022). It cannot decide that the request was really sent or that it is still unanswered (OWT-014, as for OWT-023). A row without all of them is judged by OWT-019 as before.');
|
|
1545
|
+
}
|
|
741
1546
|
for (const v of res.violations) say(`[owt] VIOLATION OWT-019: ${v.path} ${v.where} names no file path, test name, command or requirement identifier: "${v.text.slice(0, 80)}"`);
|
|
742
1547
|
for (const u of res.undecidable) say(`[owt] UNDECIDABLE: ${u.path} ${u.where} has ${u.cells} cell(s) but its header has ${u.expected}; the next-action cell cannot be located, so the row is neither judged nor counted as empty`);
|
|
743
1548
|
say(`[owt] ${COVERAGE_NOTE}`);
|
|
744
1549
|
say(`[owt] ${UNCALIBRATED_NOTE}`);
|
|
745
|
-
if (res.walked + res.empty === 0) {
|
|
1550
|
+
if (res.walked + res.empty === 0) {
|
|
1551
|
+
say('[owt] CANNOT DECIDE: no next-action field found in any carrier (walked 0). Exit 2 is not a pass.');
|
|
1552
|
+
for (const l of explainNoNextActionField(carriers, declared.words, res.undecidable.map((u) => u.path))) say(`[owt] ${l}`);
|
|
1553
|
+
return finish(2);
|
|
1554
|
+
}
|
|
746
1555
|
// A violation is a definite answer whatever else is unreadable. Absent one, a row we could
|
|
747
1556
|
// not read means "no violation found" is not "no violation": exit 2, never a green 0.
|
|
748
1557
|
if (!res.violations.length && res.undecidable.length) { say(`[owt] CANNOT DECIDE: ${res.undecidable.length} table row(s) could not be read (see UNDECIDABLE above), so a clean result would cover only part of the field. Exit 2 is not a pass.`); return finish(2); }
|
|
@@ -769,19 +1578,81 @@ export function main(argv, io = { log: console.log, err: console.error }) {
|
|
|
769
1578
|
return finish(r.violations.length ? 1 : 0);
|
|
770
1579
|
}
|
|
771
1580
|
if (cmd === 'separation') {
|
|
1581
|
+
const declared = normaliseDeclaredWords(flagAll('--next-action-word'));
|
|
1582
|
+
if (declared.error) { say(`[owt] separation: ${declared.error}`); return finish(2); }
|
|
772
1583
|
const files = args;
|
|
773
1584
|
if (!files.length) { say('[owt] separation: no files given'); return finish(2); }
|
|
774
|
-
const r = checkSeparation(files.map(readCarrier));
|
|
1585
|
+
const r = checkSeparation(files.map(readCarrier), { words: declared.words });
|
|
775
1586
|
say(`[owt] OWT-017 walked ${r.walked} carrier(s); ${r.recognised} had a recognised intent or progress section`);
|
|
776
1587
|
for (const v of r.violations) say(`[owt] VIOLATION OWT-017: ${v.path} holds intent (${v.intent.join(', ')}) and progress (${v.progress.join(', ')}) in one carrier`);
|
|
777
1588
|
say(`[owt] ${UNCALIBRATED_NOTE}`);
|
|
778
1589
|
if (r.recognised === 0) { say('[owt] CANNOT DECIDE: no carrier had a recognised intent or progress heading. Exit 2 is not a pass.'); return finish(2); }
|
|
779
1590
|
return finish(r.violations.length ? 1 : 0);
|
|
780
1591
|
}
|
|
1592
|
+
if (cmd === 'waiting' || cmd === 'observations') {
|
|
1593
|
+
const nowArg = flag('--now');
|
|
1594
|
+
const now = nowArg === undefined ? todayUtc() : parseDay(nowArg);
|
|
1595
|
+
if (now === null) { say(`[owt] ${cmd}: --now must be a date with a year (YYYY-MM-DD), got "${nowArg}"`); return finish(2); }
|
|
1596
|
+
const staleArg = cmd === 'observations' ? flag('--stale-after') : undefined;
|
|
1597
|
+
const staleAfterDays = staleArg === undefined ? undefined : Number(staleArg);
|
|
1598
|
+
if (staleAfterDays !== undefined && (!Number.isFinite(staleAfterDays) || staleAfterDays < 0)) { say(`[owt] observations: --stale-after must be a number of days, got "${staleArg}"`); return finish(2); }
|
|
1599
|
+
let root;
|
|
1600
|
+
const projects = new Map();
|
|
1601
|
+
if (cmd === 'waiting') {
|
|
1602
|
+
// `--root DIR` (one, as before) says what relative paths are resolved against; `--root NAME=DIR`
|
|
1603
|
+
// (repeatable) says where another project lives on this machine (OWT-027 / OWT-028).
|
|
1604
|
+
const given = parseRootOptions(flagAll('--root'));
|
|
1605
|
+
if (given.error) { say(`[owt] waiting: ${given.error}`); return finish(2); }
|
|
1606
|
+
root = given.plain ?? process.cwd();
|
|
1607
|
+
for (const [name, dir] of given.named) projects.set(name, dir);
|
|
1608
|
+
}
|
|
1609
|
+
const idPattern = cmd === 'waiting' ? flag('--id-pattern') : undefined;
|
|
1610
|
+
const commandsDeclared = cmd === 'waiting' ? normaliseDeclaredCommands(flagAll('--command-word')) : { words: [], error: null };
|
|
1611
|
+
if (commandsDeclared.error) { say(`[owt] waiting: ${commandsDeclared.error}`); return finish(2); }
|
|
1612
|
+
const files = args;
|
|
1613
|
+
if (!files.length) { say(`[owt] ${cmd}: no files given`); return finish(2); }
|
|
1614
|
+
const carriers = files.map(readCarrier);
|
|
1615
|
+
if (cmd === 'waiting') {
|
|
1616
|
+
const res = checkWaiting(carriers, { now, root, idPattern, projects, extraCommands: commandsDeclared.words });
|
|
1617
|
+
say(`[owt] OWT-020/021/022 walked ${res.walked} record(s) with a status field in ${carriers.length} carrier(s) (today ${dayString(now)}); ${res.noStateCarriers.length} carrier(s) had none`);
|
|
1618
|
+
say(`[owt] not-yet-asked=${res.counts['not-yet-asked']} asked-awaiting=${res.counts['asked-awaiting']} waiting-unspecified=${res.counts['waiting-unspecified']} done=${res.counts.done} other=${res.counts.other}${res.counts['waiting-cross-project'] ? ` waiting-cross-project=${res.counts['waiting-cross-project']}` : ''} undecidable-table-rows=${res.ragged.length}`);
|
|
1619
|
+
for (const d of res.detail) say(`[owt] ${d.state.padEnd(20)} ${d.path} ${d.where}: ${d.text.slice(0, 60)}${d.note ? ` (${d.note})` : ''}`);
|
|
1620
|
+
if (res.cross.found > 0) {
|
|
1621
|
+
const k = res.cross.counts;
|
|
1622
|
+
say(`[owt] OWT-027/028 ${res.cross.found} release condition(s) name an object in another project (looked up on this machine only; no network): released=${k.released} not-yet-released=${k['not-yet-released']} not-visible-from-here=${k['not-visible']} needs-a-person=${k['needs-a-person']}`);
|
|
1623
|
+
const label = { released: 'RELEASED', 'not-yet-released': 'NOT YET RELEASED', 'not-visible': 'NOT VISIBLE FROM HERE', 'needs-a-person': 'NEEDS A PERSON' };
|
|
1624
|
+
for (const x of res.cross.items) say(`[owt] ${label[x.status].padEnd(21)} ${x.name}:${x.object} (${x.kind}, ${x.observable}) ${x.path} ${x.where}: ${x.why}`);
|
|
1625
|
+
for (const name of [...new Set(res.cross.items.map((x) => x.name))]) if (projects.has(name)) say(`[owt] RESOLUTION: ${lookupSentence(`project "${name}"`, projects.get(name), 'from --root NAME=DIR or open_work.projects')}. Only a path or a version-control tag is looked up; nothing leaves this machine.`);
|
|
1626
|
+
say('[owt] NOT VISIBLE FROM HERE is counted apart: it is not released and it is not zero. NEEDS A PERSON is counted apart and is never released. RELEASED says the object exists there now, never that it is the right object (OWT-014).');
|
|
1627
|
+
}
|
|
1628
|
+
for (const v of res.violations) say(`[owt] VIOLATION ${v.rule}: ${v.path} ${v.where} ${v.why}`);
|
|
1629
|
+
for (const u of res.ragged) say(`[owt] UNDECIDABLE: ${u.path} ${u.where} has ${u.cells} cell(s) but its header has ${u.expected}; the status cell cannot be located, so the row is neither judged nor counted as empty`);
|
|
1630
|
+
say('[owt] A waiting item that is neither not-yet-asked nor asked-awaiting is named above, one by one; it is never folded into a total and never counted as done.');
|
|
1631
|
+
say('[owt] COVERAGE UNKNOWN (OWT-011): state words and field names are matched by vocabulary. A waiting item written in words the vocabulary does not hold is read as "other", not as waiting. A clean pass does not mean nothing is waiting unasked.');
|
|
1632
|
+
say(`[owt] ${UNCALIBRATED_STATE_NOTE}`);
|
|
1633
|
+
if (res.walked === 0) { say('[owt] CANNOT DECIDE: no record with a status field in any carrier (walked 0). Exit 2 is not a pass.'); return finish(2); }
|
|
1634
|
+
if (!res.violations.length && res.ragged.length) { say(`[owt] CANNOT DECIDE: ${res.ragged.length} table row(s) could not be read (see UNDECIDABLE above), so a clean result would cover only part of the field. Exit 2 is not a pass.`); return finish(2); }
|
|
1635
|
+
return finish(res.violations.length ? 1 : 0);
|
|
1636
|
+
}
|
|
1637
|
+
const res = checkObservations(carriers, { now, staleAfterDays });
|
|
1638
|
+
say(`[owt] OWT-023/024/025/026 walked ${res.walked} observation(s) in ${carriers.length} carrier(s) (today ${dayString(now)}); stale after ${res.staleAfter} day(s) (${staleArg === undefined ? 'default, ' : ''}UNCALIBRATED); ${res.noObservationCarriers.length} carrier(s) had none`);
|
|
1639
|
+
say(`[owt] yes=${res.counts.yes} no=${res.counts.no} unknown=${res.counts.unknown} invalid=${res.counts.invalid} | stale=${res.stale.length} | confirmed=${res.confirmed} (yes, well formed, not stale) | undecidable-table-rows=${res.ragged.length}`);
|
|
1640
|
+
for (const d of res.detail) say(`[owt] value=${d.value} age=${d.age === null ? '?' : `${d.age}d`} by=${d.by || '?'} at=${d.observedAt || '?'} ${d.path} ${d.where}: ${d.text.slice(0, 60)}`);
|
|
1641
|
+
for (const u of res.unknown) say(`[owt] UNKNOWN (counted apart, never complete): ${u.path} ${u.where}: ${u.text.slice(0, 60)}`);
|
|
1642
|
+
for (const s of res.stale) say(`[owt] STALE (observed ${s.age}d ago, older than ${res.staleAfter}d; counted apart, not confirmed${s.claimsDone ? '; the item claims done on this observation' : ''}): ${s.path} ${s.where}: ${s.text.slice(0, 60)}`);
|
|
1643
|
+
for (const v of res.violations) say(`[owt] VIOLATION ${v.rule}: ${v.path} ${v.where} ${v.why}`);
|
|
1644
|
+
for (const u of res.ragged) say(`[owt] UNDECIDABLE: ${u.path} ${u.where} has ${u.cells} cell(s) but its header has ${u.expected}; the row is neither judged nor counted as empty`);
|
|
1645
|
+
say('[owt] LIMIT: the check decides that the fields exist, are well formed, and how old the stamp is. It cannot decide that an observation is true, or that it is still true now (OWT-014): a stamp says who saw it and when, never that it still holds.');
|
|
1646
|
+
say('[owt] COVERAGE UNKNOWN (OWT-011): a table is read as an observation carrier only if it has an observed-by or observed-at column (or a list item such a label); the "derivable subject" test is a short word list. A clean pass does not mean no hand-written fact is unstamped or derivable.');
|
|
1647
|
+
say(`[owt] ${UNCALIBRATED_STATE_NOTE}`);
|
|
1648
|
+
if (res.walked === 0) { say('[owt] CANNOT DECIDE: no observation record (no observed-by / observed-at field) in any carrier (walked 0). Exit 2 is not a pass.'); return finish(2); }
|
|
1649
|
+
if (!res.violations.length && res.ragged.length) { say(`[owt] CANNOT DECIDE: ${res.ragged.length} table row(s) could not be read (see UNDECIDABLE above), so a clean result would cover only part of the field. Exit 2 is not a pass.`); return finish(2); }
|
|
1650
|
+
return finish(res.violations.length ? 1 : 0);
|
|
1651
|
+
}
|
|
781
1652
|
// The repo shim (its own `--self-test` flag) is named FIRST on purpose: cli/scripts/check-command-existence.mjs
|
|
782
1653
|
// reads a `uds <...>` string up to the closing quote, so a `--self-test` written AFTER `uds open-work`
|
|
783
1654
|
// is judged as a flag of the `uds open-work` command, which has none (it is the subcommand `self-test`).
|
|
784
|
-
say('[owt] usage: node scripts/check-open-work-tracking.mjs ... | --self-test (or from the npm package: uds open-work next-action|revision|separation|self-test ...)');
|
|
1655
|
+
say('[owt] usage: node scripts/check-open-work-tracking.mjs ... | --self-test (or from the npm package: uds open-work next-action|revision|separation|waiting|observations|self-test ...)');
|
|
785
1656
|
return finish(2);
|
|
786
1657
|
} catch (e) {
|
|
787
1658
|
say(`[owt] CANNOT DECIDE: ${e.message.split('\n')[0]}`);
|