opencode-wiki-historian 0.5.1 → 0.5.3
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/dist/anchor.d.ts +63 -0
- package/dist/anchor.js +186 -0
- package/dist/lint.d.ts +19 -2
- package/dist/lint.js +73 -10
- package/dist/maintain.d.ts +44 -1
- package/dist/maintain.js +235 -1
- package/dist/migrate.js +2 -2
- package/dist/surface.d.ts +1 -1
- package/dist/surface.js +15 -1
- package/dist/templates/genres.js +3 -3
- package/dist/templates/skeletons.js +28 -18
- package/dist/tools/anchor.d.ts +10 -0
- package/dist/tools/anchor.js +90 -0
- package/dist/tools/local.js +32 -5
- package/dist/tools/shared.d.ts +3 -2
- package/dist/tools/shared.js +4 -3
- package/dist/tools.js +2 -0
- package/dist/wiki/pages.write.d.ts +6 -0
- package/dist/wiki/pages.write.js +24 -1
- package/package.json +1 -1
- package/skills/historian/SKILL.md +2 -2
- package/skills/historian/references/adapting-your-own-wiki.md +1 -1
- package/skills/historian/references/genres.md +4 -4
- package/skills/historian/references/rules.md +5 -4
package/dist/anchor.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export declare const DCP_STRIP_CLOSED_LIST: readonly ["trailing <dcp-message-id…</dcp-message-id> block", "outer whitespace"];
|
|
2
|
+
export declare function sha256(text: string): string;
|
|
3
|
+
export declare function canonicalText(raw: string): string;
|
|
4
|
+
export type StoreRow = {
|
|
5
|
+
readonly messageId: string;
|
|
6
|
+
readonly ordinal: number;
|
|
7
|
+
readonly role: string;
|
|
8
|
+
readonly rawText: string;
|
|
9
|
+
};
|
|
10
|
+
export type SealReceipt = {
|
|
11
|
+
readonly kind: 'historian-anchor';
|
|
12
|
+
readonly action: 'seal';
|
|
13
|
+
readonly sessionId: string;
|
|
14
|
+
readonly messageId: string;
|
|
15
|
+
readonly ordinal: number;
|
|
16
|
+
readonly role: string;
|
|
17
|
+
readonly dbPath: string;
|
|
18
|
+
readonly raw_sha256: string;
|
|
19
|
+
readonly canon_sha256: string;
|
|
20
|
+
readonly canon_len: number;
|
|
21
|
+
readonly normalization: readonly string[];
|
|
22
|
+
readonly sealed_at: string;
|
|
23
|
+
};
|
|
24
|
+
export type AnchorError = {
|
|
25
|
+
readonly ok: false;
|
|
26
|
+
readonly error: string;
|
|
27
|
+
readonly detail?: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function defaultDbPath(homeDir: string): string;
|
|
30
|
+
/** Minimal seam so the test environment (vitest cannot resolve node:sqlite)
|
|
31
|
+
* injects a fake store while production keeps the real read-only DatabaseSync. */
|
|
32
|
+
export interface DbLike {
|
|
33
|
+
prepare(sql: string): {
|
|
34
|
+
all(...a: unknown[]): unknown[];
|
|
35
|
+
get(...a: unknown[]): unknown;
|
|
36
|
+
};
|
|
37
|
+
close(): void;
|
|
38
|
+
}
|
|
39
|
+
export type DbOpener = (dbPath: string) => DbLike | AnchorError;
|
|
40
|
+
export declare function resolveSessionId(db: DbLike, sessionId: string | undefined, titleLike: string | undefined): string | AnchorError;
|
|
41
|
+
/** Locate the anchor message: by ordinal (1-based; negative counts from end) or by UNIQUE exact canonical-body match. */
|
|
42
|
+
export declare function locateMessage(db: DbLike, sessionId: string, index: number | undefined, body: string | undefined): StoreRow | AnchorError;
|
|
43
|
+
export declare function sealAnchor(opts: {
|
|
44
|
+
dbPath: string;
|
|
45
|
+
sessionId?: string | undefined;
|
|
46
|
+
sessionTitle?: string | undefined;
|
|
47
|
+
index?: number | undefined;
|
|
48
|
+
body?: string | undefined;
|
|
49
|
+
now: string;
|
|
50
|
+
open?: DbOpener | undefined;
|
|
51
|
+
}): SealReceipt | AnchorError;
|
|
52
|
+
export type VerifyVerdict = {
|
|
53
|
+
readonly verdict: 'MATCH' | 'MISMATCH' | 'ABSENT';
|
|
54
|
+
readonly stored: SealReceipt;
|
|
55
|
+
readonly current?: SealReceipt;
|
|
56
|
+
readonly drift: readonly string[];
|
|
57
|
+
};
|
|
58
|
+
export declare function verifyAnchor(stored: SealReceipt, opts: {
|
|
59
|
+
dbPath: string;
|
|
60
|
+
now: string;
|
|
61
|
+
open?: DbOpener | undefined;
|
|
62
|
+
}): VerifyVerdict | AnchorError;
|
|
63
|
+
export declare function renderSealPage(r: SealReceipt, label?: string): string;
|
package/dist/anchor.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anchor sealing core (g12b-3 merged into the historian per owner order
|
|
3
|
+
* 2026-10-01T16:24): a human order/approval message living in the engine's own
|
|
4
|
+
* session store is located by (session, ordinal) or by unique exact body match,
|
|
5
|
+
* hashed two ways (raw + canonical), and the receipt is written as an
|
|
6
|
+
* _evidence/anchors page. `verify` re-reads the store and re-computes: MATCH /
|
|
7
|
+
* MISMATCH / ABSENT — never a silent repair.
|
|
8
|
+
*
|
|
9
|
+
* The canonical-text rule is a CLOSED list (mirrors L-ORACLE-INTEGRITY's
|
|
10
|
+
* normalization discipline): trailing <dcp-message-id ...>...</dcp-message-id>
|
|
11
|
+
* block and surrounding whitespace. Anything else — including the engine
|
|
12
|
+
* merging several user turns into one message while the agent is busy — is
|
|
13
|
+
* NOT normalized away: a seal is only as atomic as the store row it names, and
|
|
14
|
+
* the receipt says which row that was.
|
|
15
|
+
*/
|
|
16
|
+
import { createHash } from 'node:crypto';
|
|
17
|
+
import { createRequire } from 'node:module';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
export const DCP_STRIP_CLOSED_LIST = ['trailing <dcp-message-id…</dcp-message-id> block', 'outer whitespace'];
|
|
20
|
+
export function sha256(text) {
|
|
21
|
+
return createHash('sha256').update(text, 'utf8').digest('hex');
|
|
22
|
+
}
|
|
23
|
+
export function canonicalText(raw) {
|
|
24
|
+
return raw.replace(/\s*<dcp-message-id[^>]*>[\s\S]*?<\/dcp-message-id>\s*$/g, '').trim();
|
|
25
|
+
}
|
|
26
|
+
export function defaultDbPath(homeDir) {
|
|
27
|
+
return process.env['OPENCODE_DB'] ?? `${homeDir}/.local/share/opencode/opencode.db`;
|
|
28
|
+
}
|
|
29
|
+
function productionOpener(dbPath) {
|
|
30
|
+
try {
|
|
31
|
+
// createRequire('node:sqlite') keeps the module out of vite's static graph
|
|
32
|
+
// (its loader cannot resolve node:sqlite); tests inject `open` and never reach here.
|
|
33
|
+
const req = createRequire(fileURLToPath(import.meta.url));
|
|
34
|
+
const mod = req('node:sqlite');
|
|
35
|
+
return new mod.DatabaseSync(dbPath, { readOnly: true });
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
return { ok: false, error: 'store-unreadable', detail: String(e).slice(0, 200) };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
;
|
|
42
|
+
function openRo(dbPath, open = productionOpener) {
|
|
43
|
+
return open(dbPath);
|
|
44
|
+
}
|
|
45
|
+
function messagesOf(db, sessionId) {
|
|
46
|
+
const rows = db
|
|
47
|
+
.prepare('select id, data from message where session_id = ? order by id')
|
|
48
|
+
.all(sessionId);
|
|
49
|
+
const out = [];
|
|
50
|
+
rows.forEach((r, i) => {
|
|
51
|
+
let role = '';
|
|
52
|
+
try {
|
|
53
|
+
role = JSON.parse(r.data).role ?? '';
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
role = '';
|
|
57
|
+
}
|
|
58
|
+
const parts = db.prepare('select data from part where message_id = ? order by id').all(r.id);
|
|
59
|
+
const texts = [];
|
|
60
|
+
for (const p of parts) {
|
|
61
|
+
try {
|
|
62
|
+
const d = JSON.parse(p.data);
|
|
63
|
+
if (d.type === 'text' && typeof d.text === 'string')
|
|
64
|
+
texts.push(d.text);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* part shapes we do not read are skipped, not fatal */
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
out.push({ messageId: r.id, ordinal: i + 1, role, rawText: texts.join('\n') });
|
|
71
|
+
});
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
export function resolveSessionId(db, sessionId, titleLike) {
|
|
75
|
+
if (sessionId !== undefined) {
|
|
76
|
+
const hit = db.prepare('select id from session where id = ?').get(sessionId);
|
|
77
|
+
return hit === undefined ? { ok: false, error: 'session-absent', detail: sessionId } : hit.id;
|
|
78
|
+
}
|
|
79
|
+
if (titleLike === undefined)
|
|
80
|
+
return { ok: false, error: 'no-locator', detail: 'pass session_id or session_title' };
|
|
81
|
+
const hits = db.prepare('select id from session where title like ? order by time_updated desc').all(`%${titleLike}%`);
|
|
82
|
+
if (hits.length === 0)
|
|
83
|
+
return { ok: false, error: 'session-absent', detail: titleLike };
|
|
84
|
+
if (hits.length > 1)
|
|
85
|
+
return { ok: false, error: 'session-ambiguous', detail: `${hits.length} sessions match "${titleLike}"` };
|
|
86
|
+
return hits[0].id;
|
|
87
|
+
}
|
|
88
|
+
/** Locate the anchor message: by ordinal (1-based; negative counts from end) or by UNIQUE exact canonical-body match. */
|
|
89
|
+
export function locateMessage(db, sessionId, index, body) {
|
|
90
|
+
const rows = messagesOf(db, sessionId);
|
|
91
|
+
if (rows.length === 0)
|
|
92
|
+
return { ok: false, error: 'session-empty', detail: sessionId };
|
|
93
|
+
if (index !== undefined) {
|
|
94
|
+
// locator convention = the receipt's 1-based ordinal; negative counts from the end.
|
|
95
|
+
const i = index > 0 ? index - 1 : rows.length + index;
|
|
96
|
+
const row = i < 0 ? undefined : rows[i];
|
|
97
|
+
return row === undefined ? { ok: false, error: 'index-absent', detail: `index ${index} of ${rows.length}` } : row;
|
|
98
|
+
}
|
|
99
|
+
if (body !== undefined) {
|
|
100
|
+
const want = canonicalText(body);
|
|
101
|
+
const hits = rows.filter((r) => canonicalText(r.rawText) === want);
|
|
102
|
+
if (hits.length === 0)
|
|
103
|
+
return { ok: false, error: 'body-absent', detail: `no single message equals the claimed body (scanned ${rows.length})` };
|
|
104
|
+
if (hits.length > 1) {
|
|
105
|
+
// A repeated short order ("同意" x2) is deliberately NOT auto-picked: ambiguity names the ordinals.
|
|
106
|
+
return { ok: false, error: 'body-ambiguous', detail: `body found at ordinals ${hits.map((h) => h.ordinal).join(',')} — re-seal with explicit index` };
|
|
107
|
+
}
|
|
108
|
+
return hits[0];
|
|
109
|
+
}
|
|
110
|
+
return { ok: false, error: 'no-locator', detail: 'pass index or body' };
|
|
111
|
+
}
|
|
112
|
+
export function sealAnchor(opts) {
|
|
113
|
+
const db = openRo(opts.dbPath, opts.open);
|
|
114
|
+
if ('ok' in db)
|
|
115
|
+
return db;
|
|
116
|
+
try {
|
|
117
|
+
const sid = resolveSessionId(db, opts.sessionId, opts.sessionTitle);
|
|
118
|
+
if (typeof sid !== 'string')
|
|
119
|
+
return sid;
|
|
120
|
+
const row = locateMessage(db, sid, opts.index, opts.body);
|
|
121
|
+
if ('ok' in row)
|
|
122
|
+
return row;
|
|
123
|
+
return {
|
|
124
|
+
kind: 'historian-anchor',
|
|
125
|
+
action: 'seal',
|
|
126
|
+
sessionId: sid,
|
|
127
|
+
messageId: row.messageId,
|
|
128
|
+
ordinal: row.ordinal,
|
|
129
|
+
role: row.role,
|
|
130
|
+
dbPath: opts.dbPath,
|
|
131
|
+
raw_sha256: sha256(row.rawText),
|
|
132
|
+
canon_sha256: sha256(canonicalText(row.rawText)),
|
|
133
|
+
canon_len: canonicalText(row.rawText).length,
|
|
134
|
+
normalization: DCP_STRIP_CLOSED_LIST,
|
|
135
|
+
sealed_at: opts.now,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
db.close();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function verifyAnchor(stored, opts) {
|
|
143
|
+
const db = openRo(opts.dbPath, opts.open);
|
|
144
|
+
if ('ok' in db)
|
|
145
|
+
return db;
|
|
146
|
+
try {
|
|
147
|
+
const rows = messagesOf(db, stored.sessionId);
|
|
148
|
+
const row = rows.find((r) => r.messageId === stored.messageId);
|
|
149
|
+
if (row === undefined)
|
|
150
|
+
return { verdict: 'ABSENT', stored, drift: ['message row gone'] };
|
|
151
|
+
const current = {
|
|
152
|
+
...stored,
|
|
153
|
+
dbPath: opts.dbPath,
|
|
154
|
+
raw_sha256: sha256(row.rawText),
|
|
155
|
+
canon_sha256: sha256(canonicalText(row.rawText)),
|
|
156
|
+
canon_len: canonicalText(row.rawText).length,
|
|
157
|
+
sealed_at: opts.now,
|
|
158
|
+
};
|
|
159
|
+
const drift = ['raw_sha256', 'canon_sha256'].filter((k) => current[k] !== stored[k]);
|
|
160
|
+
return { verdict: drift.length === 0 ? 'MATCH' : 'MISMATCH', stored, current, drift };
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
db.close();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export function renderSealPage(r, label) {
|
|
167
|
+
return [
|
|
168
|
+
`# Anchor seal: ${label ?? r.messageId}`,
|
|
169
|
+
'',
|
|
170
|
+
'| field | value |',
|
|
171
|
+
'|---|---|',
|
|
172
|
+
`| session | \`${r.sessionId}\` |`,
|
|
173
|
+
`| message | \`${r.messageId}\` (ordinal ${r.ordinal}, role ${r.role}) |`,
|
|
174
|
+
`| raw sha256 | \`${r.raw_sha256}\` |`,
|
|
175
|
+
`| canonical sha256 | \`${r.canon_sha256}\` (len ${r.canon_len}) |`,
|
|
176
|
+
`| normalization | ${r.normalization.join('; ')} |`,
|
|
177
|
+
`| store | \`${r.dbPath}\` |`,
|
|
178
|
+
`| sealed at | ${r.sealed_at} |`,
|
|
179
|
+
'',
|
|
180
|
+
'```json historian-anchor',
|
|
181
|
+
JSON.stringify(r),
|
|
182
|
+
'```',
|
|
183
|
+
'',
|
|
184
|
+
'Verify via historian_anchor action:"verify" — stored JSON above is the claim; the engine store is the truth.',
|
|
185
|
+
].join('\n');
|
|
186
|
+
}
|
package/dist/lint.d.ts
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { Locale } from './wiki/pages.read.js';
|
|
11
11
|
/** Machine rule keys; the human report renders zh labels from these. */
|
|
12
|
-
export type GateViolation = 'redirect-stub-no-exit' | 'active-with-unfinished-skeleton';
|
|
12
|
+
export type GateViolation = 'redirect-stub-no-exit' | 'active-with-unfinished-skeleton' | 'status-token-conflict';
|
|
13
13
|
export interface LintFinding {
|
|
14
|
-
readonly key: 'todo-markers' | 'empty-sections' | 'intro-empty' | 'no-related-pages' | 'no-state-block' | 'h1-mismatch' | 'zh-english-dominant' | 'claims-without-stamp';
|
|
14
|
+
readonly key: 'todo-markers' | 'empty-sections' | 'intro-empty' | 'no-related-pages' | 'no-state-block' | 'h1-mismatch' | 'zh-english-dominant' | 'claims-without-stamp' | 'status-token-conflict';
|
|
15
15
|
readonly detail: string;
|
|
16
16
|
}
|
|
17
17
|
export interface PageLink {
|
|
@@ -32,6 +32,15 @@ export interface BodyLint {
|
|
|
32
32
|
readonly stubHasLink: boolean;
|
|
33
33
|
readonly hasStateBlock: boolean;
|
|
34
34
|
readonly state: 'active' | 'draft' | 'superseded' | 'deprecated' | null;
|
|
35
|
+
/** First state token parsed from a `| Status | X |` metadata table row
|
|
36
|
+
* (P1); null when the body carries no parseable table token. The colon
|
|
37
|
+
* header in `state` stays the AUTHORITY — this is the view, never a fix. */
|
|
38
|
+
readonly tableState: 'active' | 'draft' | 'superseded' | 'deprecated' | null;
|
|
39
|
+
/** Every state token found in table rows, document order, deduped. */
|
|
40
|
+
readonly tableStates: readonly NonNullable<BodyLint['state']>[];
|
|
41
|
+
/** True when the header token and at least one table token disagree (P1:
|
|
42
|
+
* the machine-induced contradiction of live ids 9/92). */
|
|
43
|
+
readonly statusTokenConflict: boolean;
|
|
35
44
|
readonly todoMarkers: number;
|
|
36
45
|
/** Heading text of sections whose body (before the next heading ≤ level) is empty. */
|
|
37
46
|
readonly emptySections: readonly string[];
|
|
@@ -47,6 +56,14 @@ export interface BodyLint {
|
|
|
47
56
|
/** CJK chars / non-whitespace chars, zh body only meaningful; 0..1. */
|
|
48
57
|
readonly cjkRatio: number;
|
|
49
58
|
}
|
|
59
|
+
/** The one finding kind {@link statusTokenFindings} emits. */
|
|
60
|
+
export type StatusTokenFinding = LintFinding & {
|
|
61
|
+
readonly key: 'status-token-conflict';
|
|
62
|
+
};
|
|
63
|
+
/** Finding-key emission for status-token integrity (P1): both tokens present
|
|
64
|
+
* and disagreeing. The colon header remains the authority — this reports the
|
|
65
|
+
* contradiction, it never resolves it. */
|
|
66
|
+
export declare function statusTokenFindings(lint: BodyLint): readonly StatusTokenFinding[];
|
|
50
67
|
export interface HeadingSpan {
|
|
51
68
|
readonly level: number;
|
|
52
69
|
readonly heading: string;
|
package/dist/lint.js
CHANGED
|
@@ -47,24 +47,78 @@ function hasClickableExit(visibleNoAnchors) {
|
|
|
47
47
|
}
|
|
48
48
|
// --- status block -----------------------------------------------------------------
|
|
49
49
|
const STATE_LINE_RE = /(?:^|\n)\s*\*{0,2}\s*(?:状态\s*\/\s*Status|状态|Status)\s*\*{0,2}\s*[::]\s*([A-Za-z\u4e00-\u9fff][^\n·|<]*)/i;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
/** `| Status | X |` metadata-table row (P1). Line-anchored so only the FIRST
|
|
51
|
+
* cell is the label — column headers like `| Action | … | Status |` and
|
|
52
|
+
* separator rows never match. CJK-tolerant label (状态 / Status / 状态/Status
|
|
53
|
+
* in either order), optional bold. Run on fence-masked, comment-stripped
|
|
54
|
+
* text, so an injected fake token inside a code fence or HTML comment is
|
|
55
|
+
* inert. The value is only a token when classifyState() recognizes it —
|
|
56
|
+
* `| Status | — |` and free-form cells carry no token. */
|
|
57
|
+
const TABLE_STATE_RE = /^\s*\|\s*(?:\*\*)?\s*(?:状态|Status)(?:\s*\/\s*(?:状态|Status))?\s*(?:\*\*)?\s*\|\s*([^|\n]+?)\s*\|/i;
|
|
58
|
+
function classifyState(raw) {
|
|
59
|
+
const v = raw.trim().toLowerCase();
|
|
55
60
|
if (v.startsWith('active'))
|
|
56
|
-
return
|
|
61
|
+
return 'active';
|
|
57
62
|
if (v.startsWith('draft'))
|
|
58
|
-
return
|
|
63
|
+
return 'draft';
|
|
59
64
|
if (v.startsWith('superseded'))
|
|
60
|
-
return
|
|
65
|
+
return 'superseded';
|
|
61
66
|
if (v.startsWith('deprecated'))
|
|
62
|
-
return
|
|
63
|
-
return
|
|
67
|
+
return 'deprecated';
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function parseState(maskedNoComments) {
|
|
71
|
+
const m = STATE_LINE_RE.exec(maskedNoComments);
|
|
72
|
+
if (m === null)
|
|
73
|
+
return { has: false, state: null };
|
|
74
|
+
return { has: true, state: classifyState(m[1]) };
|
|
75
|
+
}
|
|
76
|
+
/** Deduped state tokens of every `| Status | X |` row, in document order. */
|
|
77
|
+
function parseTableStates(visible) {
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const line of visible.split('\n')) {
|
|
80
|
+
const m = TABLE_STATE_RE.exec(line);
|
|
81
|
+
if (m === null)
|
|
82
|
+
continue;
|
|
83
|
+
const st = classifyState(m[1]);
|
|
84
|
+
if (st !== null && !out.includes(st))
|
|
85
|
+
out.push(st);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/** Finding-key emission for status-token integrity (P1): both tokens present
|
|
90
|
+
* and disagreeing. The colon header remains the authority — this reports the
|
|
91
|
+
* contradiction, it never resolves it. */
|
|
92
|
+
export function statusTokenFindings(lint) {
|
|
93
|
+
if (!lint.statusTokenConflict || lint.state === null)
|
|
94
|
+
return [];
|
|
95
|
+
const table = lint.tableStates.filter((s) => s !== lint.state).join(', ');
|
|
96
|
+
return [
|
|
97
|
+
{
|
|
98
|
+
key: 'status-token-conflict',
|
|
99
|
+
detail: `colon header '${lint.state}' vs table row '${table}' on '${lint.h1 ?? '?'}'`,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
64
102
|
}
|
|
65
103
|
// --- markers, headings, intro -------------------------------------------------------
|
|
66
104
|
const TODO_COMMENT_RE = /(TODO|TBD|PLACEHOLDER|占位)/i;
|
|
67
105
|
const LITERAL_TODO_RE = /\bTODO:/g;
|
|
106
|
+
/** SYN-13 enforcement: a table cell that is nothing but a placeholder token is
|
|
107
|
+
* debt (bare `TBD`/`未定` cells passed the old comment-only scan and shipped Active).
|
|
108
|
+
* `todo` is deliberately NOT in this set — it is the skeleton's legitimate status
|
|
109
|
+
* vocabulary (待办/todo), not placeholder debt. */
|
|
110
|
+
const PLACEHOLDER_CELL_RE = /^(?:TBD|TBA|未定|待定|待补充|待定日期)[::]?$/i;
|
|
111
|
+
function countPlaceholderCells(masked) {
|
|
112
|
+
let n = 0;
|
|
113
|
+
for (const line of masked.split('\n')) {
|
|
114
|
+
if (!line.trimStart().startsWith('|'))
|
|
115
|
+
continue;
|
|
116
|
+
for (const cell of line.split('|'))
|
|
117
|
+
if (PLACEHOLDER_CELL_RE.test(cell.trim()))
|
|
118
|
+
n++;
|
|
119
|
+
}
|
|
120
|
+
return n;
|
|
121
|
+
}
|
|
68
122
|
function countTodoMarkers(masked) {
|
|
69
123
|
let n = 0;
|
|
70
124
|
for (const m of masked.matchAll(COMMENT_RE)) {
|
|
@@ -74,6 +128,7 @@ function countTodoMarkers(masked) {
|
|
|
74
128
|
// literal TODO: outside comments (comments already masked to '' for this pass)
|
|
75
129
|
const noComments = masked.replace(COMMENT_RE, '');
|
|
76
130
|
n += (noComments.match(LITERAL_TODO_RE) ?? []).length;
|
|
131
|
+
n += countPlaceholderCells(masked);
|
|
77
132
|
return n;
|
|
78
133
|
}
|
|
79
134
|
const HEADING_RE = /^(#{1,6})\s+(.+?)\s*#*$/;
|
|
@@ -217,12 +272,17 @@ export function lintBody(body, opts) {
|
|
|
217
272
|
commands: distinct(visible, CMD_RE),
|
|
218
273
|
};
|
|
219
274
|
const stateInfo = parseState(visible);
|
|
275
|
+
const tableStates = parseTableStates(visible);
|
|
276
|
+
const statusTokenConflict = stateInfo.state !== null && tableStates.some((s) => s !== stateInfo.state);
|
|
220
277
|
return {
|
|
221
278
|
isRedirectStub,
|
|
222
279
|
redirectTarget: target,
|
|
223
280
|
stubHasLink: !isRedirectStub || hasClickableExit(links.length),
|
|
224
281
|
hasStateBlock: stateInfo.has,
|
|
225
282
|
state: stateInfo.state,
|
|
283
|
+
tableState: tableStates.length > 0 ? tableStates[0] : null,
|
|
284
|
+
tableStates,
|
|
285
|
+
statusTokenConflict,
|
|
226
286
|
todoMarkers: countTodoMarkers(masked),
|
|
227
287
|
emptySections: emptySectionsOf(headings),
|
|
228
288
|
introEmpty,
|
|
@@ -250,5 +310,8 @@ export function publishGateViolations(lint) {
|
|
|
250
310
|
if (lint.state === 'active' && (lint.todoMarkers > 0 || lint.emptySections.length > 0)) {
|
|
251
311
|
out.push('active-with-unfinished-skeleton');
|
|
252
312
|
}
|
|
313
|
+
if (lint.state === 'active' && lint.statusTokenConflict) {
|
|
314
|
+
out.push('status-token-conflict');
|
|
315
|
+
}
|
|
253
316
|
return out;
|
|
254
317
|
}
|
package/dist/maintain.d.ts
CHANGED
|
@@ -64,6 +64,33 @@ export interface FreshnessScan {
|
|
|
64
64
|
readonly missingLastVerified: readonly MissingStamp[];
|
|
65
65
|
readonly expiredReviewBy: readonly ExpiredReview[];
|
|
66
66
|
}
|
|
67
|
+
/** One cadence-due page (advisory queue — maintain NEVER auto-writes the stamp). */
|
|
68
|
+
export interface DueForReviewRow {
|
|
69
|
+
readonly path: string;
|
|
70
|
+
readonly locale: Locale;
|
|
71
|
+
/** Whole days from the newest honest stamp date to now (floored; confessional-only
|
|
72
|
+
* stamps stamp their own date but never reset the clock — see dueForReviewOf). */
|
|
73
|
+
readonly stampAge: number;
|
|
74
|
+
/** Days: metadata 复核周期/Review cadence row when parseable, else genre default. */
|
|
75
|
+
readonly cadence: number;
|
|
76
|
+
/** Re-check commands parsed from the ledger's command column (empty when none). */
|
|
77
|
+
readonly verifyCommands: readonly string[];
|
|
78
|
+
}
|
|
79
|
+
/** One open action item past its due date (G1 action tables rot silently —
|
|
80
|
+
* corpus law: "an action item that ages out without completion is a red
|
|
81
|
+
* flag"). Advisory queue like dueForReview; twins dedupe by path. */
|
|
82
|
+
export interface OverdueAction {
|
|
83
|
+
readonly path: string;
|
|
84
|
+
readonly locale: Locale;
|
|
85
|
+
/** First table cell (the 措施/action text), flattened to one line, ≤80 chars. */
|
|
86
|
+
readonly action: string;
|
|
87
|
+
/** The ISO date found in the 期限/due column, verbatim. */
|
|
88
|
+
readonly due: string;
|
|
89
|
+
/** Whole days from due date to now (floored). */
|
|
90
|
+
readonly daysOverdue: number;
|
|
91
|
+
/** Status cell text, verbatim (matched open). */
|
|
92
|
+
readonly status: string;
|
|
93
|
+
}
|
|
67
94
|
export interface MaintainReport {
|
|
68
95
|
readonly schema: typeof MAINTAIN_SCHEMA;
|
|
69
96
|
readonly generatedAt: string;
|
|
@@ -113,10 +140,26 @@ export interface MaintainReport {
|
|
|
113
140
|
rows: number;
|
|
114
141
|
}[];
|
|
115
142
|
readonly freshness: FreshnessScan | null;
|
|
143
|
+
/** Deep-only advisory queue (null in light, like freshness). */
|
|
144
|
+
readonly dueForReview: readonly DueForReviewRow[] | null;
|
|
145
|
+
/** Deep-only advisory queue of open action items past due (null in light). */
|
|
146
|
+
readonly overdueActions: readonly OverdueAction[] | null;
|
|
116
147
|
}
|
|
117
|
-
export declare const MAINTAIN_SCHEMA = "historian.maintain.
|
|
148
|
+
export declare const MAINTAIN_SCHEMA = "historian.maintain.v3";
|
|
118
149
|
/** Trigram-Jaccard bar for calling two (different-path) titles near-duplicates. */
|
|
119
150
|
export declare const DUP_TITLE_THRESHOLD = 0.75;
|
|
151
|
+
/** Stamp label incl. the 上次验证 variant (the set lint.ts STAMP_RE tests) — one
|
|
152
|
+
* line-level source of truth for the honesty rule shared by surface + freshness. */
|
|
153
|
+
export declare const STAMP_LINE_RE: RegExp;
|
|
154
|
+
/** A stamp that confesses the review never executed (swarm-A P2 "stamp honesty"):
|
|
155
|
+
* it must not exempt the claim ledger (surface) nor reset the cadence clock
|
|
156
|
+
* (dueForReview). Matched per stamp line, never page-wide — "baseline" is a
|
|
157
|
+
* common GPU-benchmark noun outside a stamp. */
|
|
158
|
+
export declare const CONFESSIONAL_STAMP_RE: RegExp;
|
|
159
|
+
/** Finds open action items past due in any G1-shaped action table (header must
|
|
160
|
+
* carry 措施/期限/状态 columns). Undated (TBD) rows are skipped here — they are
|
|
161
|
+
* a different defect owned by the authoring gate, not the ageing sweep. */
|
|
162
|
+
export declare function overdueActionsOf(body: string, now: Date): Omit<OverdueAction, 'path' | 'locale'>[];
|
|
120
163
|
export declare function buildMaintainReport(input: MaintainInput, opts?: MaintainOptions): Promise<MaintainReport>;
|
|
121
164
|
/** Human report + (always) a fenced machine-readable JSON block at the END —
|
|
122
165
|
* the same MaintainReport object the tool envelope carries. */
|