@forwardimpact/libwiki 0.2.25 → 0.2.27
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/LICENSE +21 -201
- package/README.md +5 -3
- package/bin/fit-wiki.js +1 -1
- package/package.json +1 -1
- package/src/audit/admission.js +53 -0
- package/src/audit/conflict-markers-rule.js +24 -0
- package/src/audit/grammar.js +97 -0
- package/src/audit/rules.js +96 -5
- package/src/audit/scopes.js +121 -5
- package/src/audit/status-row.js +91 -6
- package/src/block-renderer.js +19 -5
- package/src/boot.js +39 -1
- package/src/cli-definition.js +17 -16
- package/src/commands/audit.js +6 -1
- package/src/commands/boot.js +7 -2
- package/src/commands/claim.js +138 -32
- package/src/commands/fix.js +13 -5
- package/src/commands/inbox.js +7 -8
- package/src/commands/init.js +6 -0
- package/src/commands/log.js +47 -25
- package/src/commands/memo.js +10 -9
- package/src/commands/refresh.js +1 -0
- package/src/commands/rotate.js +40 -19
- package/src/commands/sync.js +54 -6
- package/src/conflict-markers.js +78 -0
- package/src/constants.js +31 -1
- package/src/gitattributes.js +40 -0
- package/src/index.js +2 -1
- package/src/integrity.js +288 -0
- package/src/lane-files.js +62 -0
- package/src/marker-scanner.js +2 -0
- package/src/secret-gate.js +177 -0
- package/src/status.js +39 -12
- package/src/util/agent-flag.js +31 -0
- package/src/weekly-log.js +146 -37
- package/src/wiki-sync.js +528 -11
package/LICENSE
CHANGED
|
@@ -1,201 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2026 Dick Olsson
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Zachary Rice
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -27,8 +27,10 @@ npx fit-wiki audit
|
|
|
27
27
|
## CLI
|
|
28
28
|
|
|
29
29
|
Every command accepts `--wiki-root` (default `wiki/`) and `--today` (default
|
|
30
|
-
today, ISO date). Agent commands
|
|
31
|
-
`
|
|
30
|
+
today, ISO date). Agent-scoped commands require an explicit `--agent <name>`
|
|
31
|
+
(`--from` for `memo`) and fail closed without it — there is no environment
|
|
32
|
+
fallback. The only exception is `release --expired`, a cross-agent cleanup
|
|
33
|
+
sweep that runs without `--agent`.
|
|
32
34
|
|
|
33
35
|
### `boot` — start a session
|
|
34
36
|
|
|
@@ -55,7 +57,7 @@ line budget would be exceeded.
|
|
|
55
57
|
```sh
|
|
56
58
|
npx fit-wiki claim --agent X --target spec-NNNN --branch claude/spec-NNNN
|
|
57
59
|
npx fit-wiki release --agent X --target spec-NNNN
|
|
58
|
-
npx fit-wiki release --
|
|
60
|
+
npx fit-wiki release --expired
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
Maintains the `## Active Claims` table in `MEMORY.md`. Duplicates refused;
|
package/bin/fit-wiki.js
CHANGED
|
@@ -21,7 +21,7 @@ const NEEDS_WIKI_SYNC = new Set(["claim", "release", "push", "pull", "init"]);
|
|
|
21
21
|
|
|
22
22
|
async function main() {
|
|
23
23
|
const runtime = createDefaultRuntime();
|
|
24
|
-
const definition = createDefinition(
|
|
24
|
+
const definition = createDefinition();
|
|
25
25
|
const cli = createCli(definition, {
|
|
26
26
|
runtime,
|
|
27
27
|
packageJsonUrl: new URL("../package.json", import.meta.url),
|
package/package.json
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
// Tracked-file enumerator for the admission scope. Yields the
|
|
4
|
+
// admission universe: the wiki-relative paths the filename grammar governs.
|
|
5
|
+
//
|
|
6
|
+
// The universe is the on-disk file tree under `wikiRoot`, intersected with the
|
|
7
|
+
// git index when git state is present. Where there is no git state — a fresh
|
|
8
|
+
// bootstrap or a test fixture — the universe is the whole walk. This keeps the
|
|
9
|
+
// rule's true positive (a *git-tracked* residue) in scope while excluding VCS
|
|
10
|
+
// internals and uncommitted scratch where a real repo exists.
|
|
11
|
+
|
|
12
|
+
/** Recursively collect file paths (wiki-relative, POSIX) under `dir`. */
|
|
13
|
+
function walk(absDir, wikiRoot, fs, out) {
|
|
14
|
+
for (const name of fs.readdirSync(absDir)) {
|
|
15
|
+
// The wiki's own VCS internals are never part of the grammar's universe.
|
|
16
|
+
if (absDir === wikiRoot && name === ".git") continue;
|
|
17
|
+
const abs = path.join(absDir, name);
|
|
18
|
+
if (fs.statSync(abs).isDirectory()) {
|
|
19
|
+
walk(abs, wikiRoot, fs, out);
|
|
20
|
+
} else {
|
|
21
|
+
out.push(path.relative(wikiRoot, abs).split(path.sep).join("/"));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Read the git index at `wikiRoot` as a set of wiki-relative paths, or `null`
|
|
28
|
+
* when there is no git state (no `.git`, or the path is not a work tree — both
|
|
29
|
+
* surface as a non-zero `git ls-files` exit). `-z` is used so paths with
|
|
30
|
+
* unusual characters round-trip; output is NUL-delimited and relative to the
|
|
31
|
+
* repository root, which is `wikiRoot`.
|
|
32
|
+
*/
|
|
33
|
+
function trackedSet(wikiRoot, subprocess) {
|
|
34
|
+
const res = subprocess.runSync("git", ["ls-files", "-z"], { cwd: wikiRoot });
|
|
35
|
+
if (res.exitCode !== 0) return null;
|
|
36
|
+
return new Set(res.stdout.split("\0").filter((p) => p !== ""));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Enumerate the admission universe under `wikiRoot`.
|
|
41
|
+
* @param {{wikiRoot: string, fs: object, subprocess: object}} options
|
|
42
|
+
* `fs` is the sync filesystem surface (`runtime.fsSync`); `subprocess` is
|
|
43
|
+
* `runtime.subprocess` (its `runSync` shells out to git).
|
|
44
|
+
* @returns {string[]} Wiki-relative POSIX paths, tracked-filtered when git state exists.
|
|
45
|
+
*/
|
|
46
|
+
export function listAdmissionPaths({ wikiRoot, fs, subprocess }) {
|
|
47
|
+
if (!fs.existsSync(wikiRoot)) return [];
|
|
48
|
+
const walked = [];
|
|
49
|
+
walk(wikiRoot, wikiRoot, fs, walked);
|
|
50
|
+
const tracked = trackedSet(wikiRoot, subprocess);
|
|
51
|
+
if (tracked === null) return walked;
|
|
52
|
+
return walked.filter((p) => tracked.has(p));
|
|
53
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { scanConflictMarkers } from "../conflict-markers.js";
|
|
2
|
+
|
|
3
|
+
// Fail-severity audit rule that flags unresolved git conflict markers in any
|
|
4
|
+
// audited wiki surface. Resolved by the `conflict-scan` scope (scopes.js),
|
|
5
|
+
// which yields one `{ path, text, fenceExempt }` subject per file. The rule is
|
|
6
|
+
// deliberately distinct from the budget rules: a marker block can fit inside
|
|
7
|
+
// the word/line budget, and when it does trip the budget the budget hint
|
|
8
|
+
// ("trim history") is actively wrong for this defect. A co-occurring size
|
|
9
|
+
// breach therefore reports BOTH findings, never misattributing structure as
|
|
10
|
+
// size. The hint directs the writer to adjudicate the merged form, never to
|
|
11
|
+
// trim.
|
|
12
|
+
export const CONFLICT_MARKER_RULE = {
|
|
13
|
+
id: "conflict.markers",
|
|
14
|
+
scope: "conflict-scan",
|
|
15
|
+
severity: "fail",
|
|
16
|
+
check: (s) => {
|
|
17
|
+
const hits = scanConflictMarkers(s.text, { fenceExempt: s.fenceExempt });
|
|
18
|
+
return hits.length === 0
|
|
19
|
+
? null
|
|
20
|
+
: hits.map((h) => ({ lineNo: h.lineNo, kind: h.kind }));
|
|
21
|
+
},
|
|
22
|
+
message: (_s, r) => `unresolved git conflict marker (${r.kind})`,
|
|
23
|
+
hint: "adjudicate the merged form: reconcile the two variants into the intended content, then delete the markers — this is corruption, not a size breach, so do not shorten history to clear it",
|
|
24
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { WEEKLY_LOG_NAME_RE, WEEKLY_LOG_PART_NAME_RE } from "../constants.js";
|
|
3
|
+
|
|
4
|
+
// The wiki filename admission grammar. A pure classifier: given a
|
|
5
|
+
// wiki-relative path, decide whether the filename grammar admits it. The
|
|
6
|
+
// normative prose lives in memory-protocol.md's "Wiki Filename Grammar"
|
|
7
|
+
// section; this module is its enforcement — one home per policy, so the two
|
|
8
|
+
// cannot drift. The audit's `admission` scope is the only consumer.
|
|
9
|
+
|
|
10
|
+
const NAMED_LEDGERS = new Set(["Home.md", "MEMORY.md", "STATUS.md"]);
|
|
11
|
+
const STORYBOARD_RE = /^storyboard-\d{4}-M\d{2}\.md$/;
|
|
12
|
+
const DATED_DELIVERABLE_RE = /^(.+)-\d{4}-\d{2}-\d{2}\.md$/;
|
|
13
|
+
|
|
14
|
+
// Calendar tokens, anchored at hyphen-segment boundaries so a token must occupy
|
|
15
|
+
// whole `-`-delimited segments: `8080` *inside* a longer segment
|
|
16
|
+
// (`release8080-notes`) is not a token, but a standalone `8080` segment is a
|
|
17
|
+
// bare year. Anchoring with `(?:^|-)…(?=-|$)` is load-bearing — a per-segment
|
|
18
|
+
// split would silently miss the multi-segment week/month/date tokens.
|
|
19
|
+
const CALENDAR_TOKEN_RES = [
|
|
20
|
+
/(?:^|-)\d{4}-W\d{2}(?=-|$)/, // week YYYY-Www
|
|
21
|
+
/(?:^|-)\d{4}-M\d{2}(?=-|$)/, // month YYYY-MNN
|
|
22
|
+
/(?:^|-)\d{4}-\d{2}-\d{2}(?=-|$)/, // date YYYY-MM-DD
|
|
23
|
+
/(?:^|-)\d{4}(?=-|$)/, // bare year YYYY
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* True when `stem` (a basename without its `.md` extension, or a captured
|
|
28
|
+
* `<topic>`) contains any calendar token on a hyphen-segment boundary.
|
|
29
|
+
* @param {string} stem
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
export function hasCalendarToken(stem) {
|
|
33
|
+
return CALENDAR_TOKEN_RES.some((re) => re.test(stem));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A root-level `.md` file whose stem carries no calendar token: the summary class. */
|
|
37
|
+
function isSummaryName(base) {
|
|
38
|
+
if (!base.endsWith(".md")) return false;
|
|
39
|
+
return !hasCalendarToken(base.slice(0, -".md".length));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The summary-class stem of a root-level basename, or `null`. Named ledgers
|
|
44
|
+
* (`MEMORY.md` etc.) are not summaries. Used to derive the `rootSummaryAgents`
|
|
45
|
+
* set that gates `<agent>/` sidecar directory admission.
|
|
46
|
+
* @param {string} base - A root-level basename.
|
|
47
|
+
* @returns {string|null}
|
|
48
|
+
*/
|
|
49
|
+
export function rootSummaryStem(base) {
|
|
50
|
+
if (NAMED_LEDGERS.has(base)) return null;
|
|
51
|
+
return isSummaryName(base) ? base.slice(0, -".md".length) : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Classify a root-level file (no `/` in its relative path) by basename. */
|
|
55
|
+
function classifyRootFile(base) {
|
|
56
|
+
if (NAMED_LEDGERS.has(base)) return "admitted";
|
|
57
|
+
if (WEEKLY_LOG_NAME_RE.test(base) || WEEKLY_LOG_PART_NAME_RE.test(base)) {
|
|
58
|
+
return "admitted";
|
|
59
|
+
}
|
|
60
|
+
if (STORYBOARD_RE.test(base)) return "admitted";
|
|
61
|
+
const dated = base.match(DATED_DELIVERABLE_RE);
|
|
62
|
+
// A dated deliverable's `<topic>` must itself be token-free, so a trailing
|
|
63
|
+
// date cannot smuggle a token-bearing stem (`…-history-YYYY-MM-DD.md`) in.
|
|
64
|
+
if (dated && !hasCalendarToken(dated[1])) return "admitted";
|
|
65
|
+
if (isSummaryName(base)) return "admitted";
|
|
66
|
+
// Anything else at the root — non-`.md`, or a token-bearing name matching no
|
|
67
|
+
// exact dated shape — is rejected.
|
|
68
|
+
return "rejected";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Classify one wiki-relative path against the filename admission grammar.
|
|
73
|
+
*
|
|
74
|
+
* Root files (no `/`) are classified by their basename. A nested path is
|
|
75
|
+
* admitted iff its first segment is an admitted root-level directory —
|
|
76
|
+
* `metrics` or an `<agent>` that has a root summary-class file — and then every
|
|
77
|
+
* file beneath it is admitted by membership (innards unpoliced). Directory
|
|
78
|
+
* evaluation is at the wiki root level only.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} relPath - Path relative to the wiki root (POSIX separators).
|
|
81
|
+
* @param {{rootSummaryAgents: Set<string>|string[]}} options
|
|
82
|
+
* @returns {"admitted"|"rejected"}
|
|
83
|
+
*/
|
|
84
|
+
export function classifyPath(relPath, { rootSummaryAgents } = {}) {
|
|
85
|
+
const normalized = relPath.split(path.sep).join("/");
|
|
86
|
+
const slash = normalized.indexOf("/");
|
|
87
|
+
if (slash === -1) return classifyRootFile(normalized);
|
|
88
|
+
const firstSegment = normalized.slice(0, slash);
|
|
89
|
+
const agents =
|
|
90
|
+
rootSummaryAgents instanceof Set
|
|
91
|
+
? rootSummaryAgents
|
|
92
|
+
: new Set(rootSummaryAgents ?? []);
|
|
93
|
+
if (firstSegment === "metrics" || agents.has(firstSegment)) {
|
|
94
|
+
return "admitted";
|
|
95
|
+
}
|
|
96
|
+
return "rejected";
|
|
97
|
+
}
|
package/src/audit/rules.js
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
SUMMARY_LINE_BUDGET,
|
|
14
14
|
SUMMARY_WORD_BUDGET,
|
|
15
15
|
WEEKLY_LOG_LINE_BUDGET,
|
|
16
|
+
WEEKLY_LOG_SEAM_RE,
|
|
16
17
|
WEEKLY_LOG_WORD_BUDGET,
|
|
17
18
|
XMR_CLOSE_RE,
|
|
18
19
|
XMR_OPEN_RE,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
SUMMARY_H1_RE,
|
|
23
24
|
WEEKLY_LOG_H1_RE,
|
|
24
25
|
} from "./scopes.js";
|
|
26
|
+
import { CONFLICT_MARKER_RULE } from "./conflict-markers-rule.js";
|
|
25
27
|
import { STATUS_ROW_RULES } from "./status-row.js";
|
|
26
28
|
|
|
27
29
|
const PRIORITY_INDEX_HEADING_RE = new RegExp(
|
|
@@ -105,6 +107,22 @@ const decisionWithin5 =
|
|
|
105
107
|
return offenders.length === 0 ? null : offenders;
|
|
106
108
|
};
|
|
107
109
|
|
|
110
|
+
// Flag entry-shaped `## ` headings that the rotation seam-finder would skip —
|
|
111
|
+
// the grammar-drift that degrades a whole file to one unsplittable prologue and
|
|
112
|
+
// is otherwise silent (the decision-block rule matches only dated headings).
|
|
113
|
+
// Uses the same WEEKLY_LOG_SEAM_RE the seam-finder uses, so the flagged set is
|
|
114
|
+
// exactly the complement of the rotatable set.
|
|
115
|
+
const headingGrammarDrift = (s) => {
|
|
116
|
+
const offenders = [];
|
|
117
|
+
for (let i = 0; i < s.fileLines.length; i++) {
|
|
118
|
+
const line = s.fileLines[i];
|
|
119
|
+
if (/^## /.test(line) && !WEEKLY_LOG_SEAM_RE.test(line)) {
|
|
120
|
+
offenders.push({ lineNo: i + 1, observed: line.trim() });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return offenders.length === 0 ? null : offenders;
|
|
124
|
+
};
|
|
125
|
+
|
|
108
126
|
function scanMarkers(fileLines, openRe, closeRe, label) {
|
|
109
127
|
const openings = [];
|
|
110
128
|
const findings = [];
|
|
@@ -170,6 +188,25 @@ const AGENT_H3_REQUIREMENTS = STORYBOARD_DOMAIN_AGENTS.map((agent) => ({
|
|
|
170
188
|
pattern: new RegExp(`^### ${agent}(\\s|$|—|-)`),
|
|
171
189
|
}));
|
|
172
190
|
|
|
191
|
+
// -- Metrics CSV duplicate rows --
|
|
192
|
+
|
|
193
|
+
// Report every data line byte-identical to an earlier data line in the same
|
|
194
|
+
// CSV. Line 1 is the header (positionally) and blank lines are skipped; the
|
|
195
|
+
// header is never a duplicate subject. Keying on exact line equality gives the
|
|
196
|
+
// spec's exit path for free: any column edit (run id or note) on one row makes
|
|
197
|
+
// the pair non-identical and stops the finding firing.
|
|
198
|
+
const duplicateCsvRows = (s) => {
|
|
199
|
+
const seen = new Set();
|
|
200
|
+
const findings = [];
|
|
201
|
+
s.rows.forEach((text, i) => {
|
|
202
|
+
const lineNo = i + 1;
|
|
203
|
+
if (lineNo === 1 || text.trim() === "") return;
|
|
204
|
+
if (seen.has(text)) findings.push({ lineNo });
|
|
205
|
+
else seen.add(text);
|
|
206
|
+
});
|
|
207
|
+
return findings.length === 0 ? null : findings;
|
|
208
|
+
};
|
|
209
|
+
|
|
173
210
|
const memoryExists = (s) => s.exists;
|
|
174
211
|
const memoryHasPriorityHeader = (s) =>
|
|
175
212
|
s.exists && PRIORITY_HEADER_RE.test(s.text);
|
|
@@ -257,7 +294,8 @@ export const RULES = [
|
|
|
257
294
|
remediation: "rotate",
|
|
258
295
|
check: lineBudget(WEEKLY_LOG_LINE_BUDGET),
|
|
259
296
|
message: (_s, r) => `${r.value} lines (limit ${WEEKLY_LOG_LINE_BUDGET})`,
|
|
260
|
-
hint:
|
|
297
|
+
hint: (s) =>
|
|
298
|
+
`run \`bunx fit-wiki rotate --agent ${s.agentPrefix}\` to seal this file as a sealed part and start a fresh weekly log`,
|
|
261
299
|
},
|
|
262
300
|
{
|
|
263
301
|
id: "weekly-log.word-budget",
|
|
@@ -266,7 +304,8 @@ export const RULES = [
|
|
|
266
304
|
remediation: "rotate",
|
|
267
305
|
check: wordBudget(WEEKLY_LOG_WORD_BUDGET),
|
|
268
306
|
message: (_s, r) => `${r.value} words (limit ${WEEKLY_LOG_WORD_BUDGET})`,
|
|
269
|
-
hint:
|
|
307
|
+
hint: (s) =>
|
|
308
|
+
`run \`bunx fit-wiki rotate --agent ${s.agentPrefix}\` to seal this file as a sealed part and start a fresh weekly log`,
|
|
270
309
|
},
|
|
271
310
|
{
|
|
272
311
|
id: "weekly-log.h1-agent-matches-filename",
|
|
@@ -277,6 +316,15 @@ export const RULES = [
|
|
|
277
316
|
`H1 title slug '${r.titleSlug}' does not match filename prefix '${s.agentPrefix}'`,
|
|
278
317
|
hint: "rename either the H1 or the file so they agree",
|
|
279
318
|
},
|
|
319
|
+
{
|
|
320
|
+
id: "weekly-log.heading-grammar",
|
|
321
|
+
scope: "weekly-log-main",
|
|
322
|
+
severity: "fail",
|
|
323
|
+
check: headingGrammarDrift,
|
|
324
|
+
message: (_s, r) =>
|
|
325
|
+
`Entry heading '${r.observed}' does not match the dated grammar`,
|
|
326
|
+
hint: "weekly-log entry headings must be '## YYYY-MM-DD'; open entries with `fit-wiki log decision/note`, which emit a conforming heading the rotation seam-finder can split",
|
|
327
|
+
},
|
|
280
328
|
{
|
|
281
329
|
id: "decision-block.heading-within-5",
|
|
282
330
|
scope: "weekly-log-main",
|
|
@@ -290,7 +338,7 @@ export const RULES = [
|
|
|
290
338
|
r.nearMiss
|
|
291
339
|
? `Entry opens with '${r.nearMiss}'; the heading must be exactly '${DECISION_HEADING}' — move the suffix into the body`
|
|
292
340
|
: `Entry lacks a line that is exactly '${DECISION_HEADING}'`,
|
|
293
|
-
hint: `open each '## YYYY-MM-DD' entry with a line containing exactly '${DECISION_HEADING}' (no suffix — the check is an exact match); put the one-line summary in the body below it, drawn from the entry's own narrative — do not invent rationale the entry does not support`,
|
|
341
|
+
hint: `open each '## YYYY-MM-DD' entry with \`fit-wiki log decision\`, which emits a line containing exactly '${DECISION_HEADING}' (no suffix — the check is an exact match); put the one-line summary in the body below it, drawn from the entry's own narrative — do not invent rationale the entry does not support`,
|
|
294
342
|
},
|
|
295
343
|
|
|
296
344
|
// -- Weekly logs (sealed parts) --
|
|
@@ -303,6 +351,15 @@ export const RULES = [
|
|
|
303
351
|
message: () => "Missing valid H1 heading",
|
|
304
352
|
hint: "set the H1 to '# <agent> — YYYY-Www (part N of M)'",
|
|
305
353
|
},
|
|
354
|
+
{
|
|
355
|
+
id: "weekly-log-part.heading-grammar",
|
|
356
|
+
scope: "weekly-log-part",
|
|
357
|
+
severity: "fail",
|
|
358
|
+
check: headingGrammarDrift,
|
|
359
|
+
message: (_s, r) =>
|
|
360
|
+
`Entry heading '${r.observed}' does not match the dated grammar`,
|
|
361
|
+
hint: "weekly-log entry headings must be '## YYYY-MM-DD'; open entries with `fit-wiki log decision/note`, which emit a conforming heading the rotation seam-finder can split",
|
|
362
|
+
},
|
|
306
363
|
{
|
|
307
364
|
id: "weekly-log-part.line-budget",
|
|
308
365
|
scope: "weekly-log-part",
|
|
@@ -310,7 +367,7 @@ export const RULES = [
|
|
|
310
367
|
remediation: "rotate",
|
|
311
368
|
check: lineBudget(WEEKLY_LOG_LINE_BUDGET),
|
|
312
369
|
message: (_s, r) => `${r.value} lines (limit ${WEEKLY_LOG_LINE_BUDGET})`,
|
|
313
|
-
hint: "`bunx fit-wiki fix` re-bisects an over-budget part
|
|
370
|
+
hint: "`bunx fit-wiki fix` re-bisects an over-budget part at its day-section seams and, for a lone over-cap day, at its '### ' block seams; only a single '### ' block that alone exceeds the budget remains for a human to shorten",
|
|
314
371
|
},
|
|
315
372
|
{
|
|
316
373
|
id: "weekly-log-part.word-budget",
|
|
@@ -319,7 +376,7 @@ export const RULES = [
|
|
|
319
376
|
remediation: "rotate",
|
|
320
377
|
check: wordBudget(WEEKLY_LOG_WORD_BUDGET),
|
|
321
378
|
message: (_s, r) => `${r.value} words (limit ${WEEKLY_LOG_WORD_BUDGET})`,
|
|
322
|
-
hint: "`bunx fit-wiki fix` re-bisects an over-budget part
|
|
379
|
+
hint: "`bunx fit-wiki fix` re-bisects an over-budget part at its day-section seams and, for a lone over-cap day, at its '### ' block seams; only a single '### ' block that alone exceeds the budget remains for a human to shorten",
|
|
323
380
|
},
|
|
324
381
|
{
|
|
325
382
|
id: "weekly-log-part.h1-agent-matches-filename",
|
|
@@ -488,7 +545,41 @@ export const RULES = [
|
|
|
488
545
|
hint: "every '<!-- obstacles:* -->' or '<!-- experiments:* -->' needs a matching close marker",
|
|
489
546
|
},
|
|
490
547
|
|
|
548
|
+
// -- Metrics CSVs (union merge keeps both sides on concurrent appends;
|
|
549
|
+
// exact-duplicate rows are surfaced here, never silently removed) --
|
|
550
|
+
|
|
551
|
+
{
|
|
552
|
+
id: "metrics-csv.duplicate-row",
|
|
553
|
+
scope: "metrics-csv",
|
|
554
|
+
severity: "fail",
|
|
555
|
+
check: duplicateCsvRows,
|
|
556
|
+
message: (_s, r) =>
|
|
557
|
+
`Duplicate metrics row at line ${r.lineNo} (exact match of an earlier row)`,
|
|
558
|
+
hint: "remove the surplus row, or differentiate a genuinely-distinct measurement by editing its run id or note so the rows are no longer identical",
|
|
559
|
+
},
|
|
560
|
+
|
|
491
561
|
// -- STATUS.md rows (per-migration-unit sub-row schema) --
|
|
492
562
|
|
|
493
563
|
...STATUS_ROW_RULES,
|
|
564
|
+
|
|
565
|
+
// -- Conflict markers (structural; all audited surfaces) --
|
|
566
|
+
|
|
567
|
+
CONFLICT_MARKER_RULE,
|
|
568
|
+
|
|
569
|
+
// -- Filename admission --
|
|
570
|
+
|
|
571
|
+
// The `admission` resolver yields one subject per git-tracked path the
|
|
572
|
+
// filename grammar rejects, so the check always fires. Flag-for-human: a
|
|
573
|
+
// wrong automated move or delete destroys memory, so `fix` routes this to the
|
|
574
|
+
// human report (any non-`agent` remediation class does) and never touches the
|
|
575
|
+
// file.
|
|
576
|
+
{
|
|
577
|
+
id: "admission.not-in-grammar",
|
|
578
|
+
scope: "admission",
|
|
579
|
+
severity: "fail",
|
|
580
|
+
remediation: "flag",
|
|
581
|
+
check: () => ({}),
|
|
582
|
+
message: (s) => `${s.relPath} matches no wiki filename grammar class`,
|
|
583
|
+
hint: "rename to an admitted class, or extend the Wiki Filename Grammar section in memory-protocol.md and audit/grammar.js together (the single admission path)",
|
|
584
|
+
},
|
|
494
585
|
];
|