@techgoblin/gobstack 0.6.0-alpha.4 → 0.6.0-beta.2
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/CHANGELOG.md +59 -0
- package/README.md +249 -116
- package/VERSION +1 -1
- package/bans/README.md +5 -5
- package/bans/grep-ban.sh +1 -1
- package/bin/goblin-bans +103 -27
- package/bin/goblin-init +345 -259
- package/bin/goblin-install +269 -213
- package/bin/goblin-lib.sh +63 -66
- package/bin/goblin-map +130 -579
- package/bin/goblin-mcp.js +9 -14
- package/bin/goblin-verify +411 -993
- package/bin/goblin.js +4 -9
- package/docs/CURATION-2026-11-07-gobigrams.md +223 -0
- package/docs/GUIDE.md +727 -179
- package/docs/LIMITS.md +297 -301
- package/docs/RECORD-NOTES.md +1 -2
- package/manifest/bans.tsv +9 -9
- package/manifest/categories.tsv +18 -0
- package/manifest/enforcement.tsv +14 -67
- package/manifest/glossary.tsv +6 -12
- package/manifest/library.tsv +33 -0
- package/package.json +1 -4
- package/skills/goblin-bootstrap/SKILL.md +20 -32
- package/skills/goblin-feature-map/SKILL.md +1 -1
- package/skills/goblin-handoff/SKILL.md +5 -0
- package/skills/goblin-verify-author/SKILL.md +14 -2
- package/skills/practice/SKILL.md +4 -4
- package/templates/AGENTS.md.tmpl +6 -6
- package/templates/HANDOFF.md.tmpl +8 -6
- package/templates/SPEC.md.tmpl +2 -2
- package/templates/agents-block.tmpl +1 -10
- package/adapters/_template/adapter.tsv +0 -16
- package/adapters/_template/detect.sh +0 -10
- package/adapters/_template/emit.sh +0 -5
- package/adapters/_template/verify.sh +0 -4
- package/adapters/claude/adapter.tsv +0 -8
- package/adapters/claude/detect.sh +0 -8
- package/adapters/claude/verify.sh +0 -47
- package/adapters/codex/adapter.tsv +0 -12
- package/adapters/codex/detect.sh +0 -9
- package/adapters/codex/verify.sh +0 -45
- package/adapters/copilot/adapter.tsv +0 -10
- package/adapters/copilot/detect.sh +0 -8
- package/adapters/copilot/verify.sh +0 -45
- package/adapters/cursor/adapter.tsv +0 -11
- package/adapters/cursor/detect.sh +0 -10
- package/adapters/cursor/verify.sh +0 -45
- package/adapters/gemini/adapter.tsv +0 -15
- package/adapters/gemini/detect.sh +0 -11
- package/adapters/gemini/verify.sh +0 -49
- package/adapters/hermes/adapter.tsv +0 -9
- package/adapters/hermes/detect.sh +0 -8
- package/adapters/hermes/verify.sh +0 -27
- package/adapters/opencode/adapter.tsv +0 -14
- package/adapters/opencode/detect.sh +0 -9
- package/adapters/opencode/verify.sh +0 -45
- package/automations/README.md +0 -53
- package/automations/bugreporter-intake.sh +0 -145
- package/automations/drift-audit.sh +0 -139
- package/automations/report.schema.tsv +0 -10
- package/bin/goblin +0 -144
- package/bin/goblin-audit +0 -143
- package/bin/goblin-doctor +0 -233
- package/bin/goblin-emit +0 -495
- package/bin/goblin-extras +0 -365
- package/bin/goblin-model +0 -105
- package/bin/goblin-upgrade +0 -580
- package/docs/ADOPTION.md +0 -173
- package/docs/CI.md +0 -190
- package/docs/CONTRACTS.md +0 -218
- package/docs/DESIGN.md +0 -92
- package/docs/ENFORCEMENT.md +0 -228
- package/docs/FLOWS.md +0 -164
- package/docs/GLOSSARY.md +0 -40
- package/docs/GUARDRAILS.md +0 -126
- package/docs/INTEGRATION.md +0 -92
- package/docs/LOOP.md +0 -165
- package/docs/RE-PLAYBOOK.md +0 -183
- package/docs/RISKS.md +0 -70
- package/docs/ROLES.md +0 -105
- package/extras-catalogue/catalogue.tsv +0 -42
- package/extras-catalogue/payload/README.md +0 -14
- package/extras-catalogue/payload/taste-skill/taste/REFERENCE.md +0 -3
- package/extras-catalogue/payload/taste-skill/taste/SKILL.md +0 -9
- package/manifest/classes.tsv +0 -51
- package/manifest/playbooks.tsv +0 -16
- package/presets/electron-overlay.yaml +0 -38
- package/presets/fleet.yaml +0 -43
- package/presets/game.yaml +0 -38
- package/presets/research.yaml +0 -41
- package/presets/service.yaml +0 -40
- package/presets/software.yaml +0 -48
- package/roles.yaml +0 -54
- package/skills/goblin-bugfix/SKILL.md +0 -26
- package/skills/goblin-bugreporter/SKILL.md +0 -52
- package/skills/goblin-drift-audit/SKILL.md +0 -43
- package/skills/goblin-eval/SKILL.md +0 -68
- package/skills/goblin-feature/SKILL.md +0 -26
- package/skills/goblin-investigation/SKILL.md +0 -26
- package/skills/goblin-judge/SKILL.md +0 -74
- package/skills/goblin-loop/SKILL.md +0 -88
- package/skills/goblin-mode/SKILL.md +0 -70
- package/skills/goblin-overnight/SKILL.md +0 -42
- package/skills/goblin-pr-gate/SKILL.md +0 -42
- package/skills/goblin-re-mobile/SKILL.md +0 -51
- package/skills/goblin-refactor/SKILL.md +0 -23
- package/skills/goblin-sweep/SKILL.md +0 -23
- package/skills/goblin-tdd-repro/SKILL.md +0 -27
- package/templates/audit-waiver.tsv.tmpl +0 -10
- package/templates/install-hooks.allowlist.tmpl +0 -9
- package/templates/report.yaml.tmpl +0 -16
package/bin/goblin-map
CHANGED
|
@@ -1,70 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# goblin-map —
|
|
2
|
+
# goblin-map — the feature-map VALIDATOR (INTERNAL helper).
|
|
3
3
|
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
4
|
+
# This file is NOT a verb: `gob map` no longer exists. The map is authored by the agent
|
|
5
|
+
# inside the `gob init` proposal and installed in the same pass. `gob init --write` extracts
|
|
6
|
+
# the embedded feature files and calls THIS validator on them before it writes anything, so
|
|
7
|
+
# the FM-01 shape and FM-02 resolvability are checked by one code path (here), never
|
|
8
|
+
# re-implemented in the init flow.
|
|
8
9
|
#
|
|
9
|
-
#
|
|
10
|
-
# 1. the AGENT BRIEF — a structured prompt telling whichever agent is already running in
|
|
11
|
-
# this repo exactly what to inventory (routes, entry points, user-visible features)
|
|
12
|
-
# and how to justify each entry;
|
|
13
|
-
# 2. the SCHEMA of the feature files it must write under a directory it chooses (for
|
|
14
|
-
# example features/) — the same frontmatter + four-H2 contract the heuristic starter
|
|
15
|
-
# renders and FM-01/FM-02 verify.
|
|
16
|
-
# The agent writes the files with its own tools, then (or a human does) runs
|
|
17
|
-
# `gob map --write <dir>` to validate: every file carries the frontmatter block, >=1
|
|
18
|
-
# entry_paths, the four H2s in order, and a `verified:` line that is either a date or the
|
|
19
|
-
# never-driven form. Exit 0 validated | 2 bad input (the named file + the fix).
|
|
10
|
+
# goblin-map --validate <mapdir> [--root <reporoot>]
|
|
20
11
|
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
# --write --force -> regenerate ONLY the README index (indexing every existing feature
|
|
25
|
-
# file too) and ADD files for new slugs; hand-written feature files are never touched.
|
|
12
|
+
# <mapdir> the directory holding README.md (the index) and the <slug>.md feature files.
|
|
13
|
+
# --root the repo root the declared entry paths resolve against and `git ls-files`
|
|
14
|
+
# runs in (default: $PWD). `gob init --write` passes the target repo.
|
|
26
15
|
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
16
|
+
# What it validates (fail closed, exit 2 the moment anything is wrong):
|
|
17
|
+
# FM-01 shape README.md exists and indexes every feature via `](./<slug>.md)`; every
|
|
18
|
+
# relative link in the index resolves; >=1 feature file; each feature file
|
|
19
|
+
# carries frontmatter, `feature:` equals its filename stem, >=1 entry_paths
|
|
20
|
+
# item each a single whitespace-free token, EXACTLY the four contract H2s in
|
|
21
|
+
# order, and a `verified:` that is a date or the never-driven form.
|
|
22
|
+
# FM-02 resolve every entry path EXISTS under <root> AND is tracked by git (`git ls-files`),
|
|
23
|
+
# so a map cannot claim a `verified:` date over uncommitted source.
|
|
29
24
|
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
# declaration in AGENTS.md frontmatter (empty = SKIP — unchanged). See docs/GUIDE.md, the
|
|
33
|
-
# feature-map section, and skills/goblin-feature-map/SKILL.md (the format contract).
|
|
34
|
-
#
|
|
35
|
-
# What it scans (best-effort, honest about being a STARTER):
|
|
36
|
-
# next-app app/**/page.tsx|page.jsx|route.ts -> one feature per top-level route segment
|
|
37
|
-
# pages-router pages/**/*.tsx|jsx -> same grouping
|
|
38
|
-
# nuxt pages/**/*.vue -> same grouping
|
|
39
|
-
# routes directories named routes/ or *route* files -> one feature per file
|
|
40
|
-
# modules no framework: top-level src/ or lib/ module dirs -> candidate slugs, TODOs
|
|
41
|
-
# The first detector that fires wins; hybrids keep only the first hit. Deliberately ignored:
|
|
42
|
-
# node_modules, .git, dist/build output, test and fixture directories, files whose names carry
|
|
43
|
-
# whitespace. A scan that finds nothing still writes the README index, with the Features
|
|
44
|
-
# section saying so — an honest hole, not an invented feature.
|
|
45
|
-
#
|
|
46
|
-
# Never-clobber contract:
|
|
47
|
-
# features/ absent (or empty of .md) -> generate README + one file per slug, exit 0
|
|
48
|
-
# features/ already a map, no --force -> validate only; the index is kept (never rewritten)
|
|
49
|
-
# --force -> regenerate ONLY README.md (indexing every existing
|
|
50
|
-
# feature file too) and add files for NEW slugs;
|
|
51
|
-
# existing feature files are never touched, exit 0
|
|
52
|
-
# --force, nothing would change -> write nothing, say so, exit 0 (nothing-to-do)
|
|
53
|
-
#
|
|
54
|
-
# Exit codes: 0 generated or nothing-to-do | 1 refusal (existing map without --force) |
|
|
55
|
-
# 2 bad input.
|
|
56
|
-
#
|
|
57
|
-
# Frontmatter: `verified:` is NOT a drive claim — the generation run drives the generator,
|
|
58
|
-
# not the features — so it reads `never-driven (generated <date>)` until a human pass replaces
|
|
59
|
-
# it with a date. FM-01 does not read the verified line at all; FM-02, once a map is declared,
|
|
60
|
-
# treats any non-date as never-stale (string compare), so a starter cannot fail freshness it
|
|
61
|
-
# never earned — the dishonesty guard is the wording, and the per-file body repeats it.
|
|
62
|
-
#
|
|
63
|
-
# Entry paths are repo-relative paths that EXIST under the target (checked at generation
|
|
64
|
-
# time). Caveat, stated in every generated file: FM-02 greps file CONTENTS for a token, so
|
|
65
|
-
# after the human pass prefer a token that occurs in source text.
|
|
66
|
-
#
|
|
67
|
-
# No npm, no jq, no network. bash/awk/sed/grep/find only (the repo constraint, mirrored).
|
|
25
|
+
# Exit codes: 0 the map validates | 2 bad input or a failed clause (a reason is printed).
|
|
26
|
+
# No npm, no jq, no yq, no network. bash/awk/sed/grep/find only (the repo constraint).
|
|
68
27
|
|
|
69
28
|
set -uo pipefail
|
|
70
29
|
|
|
@@ -72,544 +31,136 @@ g_err() { printf 'error: map: %s\n' "$*" >&2; }
|
|
|
72
31
|
|
|
73
32
|
usage() {
|
|
74
33
|
cat <<'USAGE'
|
|
75
|
-
|
|
34
|
+
goblin-map --validate <mapdir> [--root <reporoot>]
|
|
76
35
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
run the starter scanner (the fallback)
|
|
81
|
-
gob map [target] --force shorthand for the heuristic --force path
|
|
82
|
-
|
|
83
|
-
The brief tells the agent already running in this repo what to inventory (routes, entry
|
|
84
|
-
points, user-visible features) and the schema its feature files must follow (frontmatter,
|
|
85
|
-
>=1 entry_paths, the four H2 sections, verified: date-or-never-driven). The agent writes
|
|
86
|
-
the files with its own tools; `gob map --write <dir>` validates them.
|
|
87
|
-
|
|
88
|
-
NEVER-CLOBBER: --write (or the heuristic path) into a dir that is already a map without
|
|
89
|
-
--force is a refusal — the path and the remedy are named, nothing is written. --force
|
|
90
|
-
regenerates ONLY the README index and adds NEW files; existing feature files are never
|
|
91
|
-
touched.
|
|
92
|
-
|
|
93
|
-
Standalone: no .gob/ install needed, none created; FM-01/FM-02 stay opt-in through a
|
|
94
|
-
feature_map: declaration in the AGENTS.md gob block.
|
|
95
|
-
|
|
96
|
-
Exit codes: 0 generated/validated/nothing-to-do | 1 refusal (existing map, no --force) |
|
|
97
|
-
2 bad input.
|
|
36
|
+
The INTERNAL feature-map validator. `gob map` is not a verb — `gob init --write` runs this
|
|
37
|
+
against the map embedded in the proposal, before it installs. You do not call it by hand
|
|
38
|
+
unless you are debugging the map the proposal asked for.
|
|
98
39
|
USAGE
|
|
99
40
|
}
|
|
100
41
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
print_brief() {
|
|
104
|
-
cat <<'BRIEF'
|
|
105
|
-
|
|
106
|
-
== gob map — AGENT BRIEF =======================================================
|
|
107
|
-
|
|
108
|
-
You are the agent running inside this repository. gobstack is an AI-driven-development
|
|
109
|
-
harness: the CLI does not scan this repo — YOU do, with your own tools, and you write the
|
|
110
|
-
feature map directly. Do this now:
|
|
111
|
-
|
|
112
|
-
1. INVENTORY the repository:
|
|
113
|
-
- routes and entry points (app/ or pages/ trees, routes/ dirs, *route* files)
|
|
114
|
-
- the user-visible features behind them (what a user can DO, not what a file contains)
|
|
115
|
-
- the test/harness layout, so each feature names how it is driven
|
|
116
|
-
|
|
117
|
-
2. WRITE the map under a directory you choose (the convention is features/):
|
|
118
|
-
- features/README.md — the index: baseline preconditions (launch/seed/health-check
|
|
119
|
-
commands), driving conventions, proof and skip reporting, one line per feature
|
|
120
|
-
- one features/<slug>.md per feature (slug: lowercase [a-z0-9-]), exactly in the
|
|
121
|
-
SCHEMA below
|
|
122
|
-
|
|
123
|
-
3. VALIDATE what you wrote:
|
|
124
|
-
|
|
125
|
-
npx @techgoblin/gobstack map --write features/
|
|
126
|
-
|
|
127
|
-
Notes:
|
|
128
|
-
- `verified:` is NOT a drive claim: write `never-driven (generated <date>)` until a
|
|
129
|
-
human pass has actually driven the feature once.
|
|
130
|
-
- entry_paths tokens must be repo-relative paths that EXIST, and should occur in
|
|
131
|
-
source text (a route literal, an import) so FM-02 can grep for them.
|
|
132
|
-
- --write validates and never rewrites: your hand-written README index is KEPT
|
|
133
|
-
(pass --force only if you want the index REGENERATED from the feature files);
|
|
134
|
-
existing feature files are never touched either way.
|
|
135
|
-
|
|
136
|
-
== FEATURE-FILE SCHEMA =========================================================
|
|
137
|
-
|
|
138
|
-
---
|
|
139
|
-
feature: <slug — lowercase [a-z0-9-], equals the filename stem>
|
|
140
|
-
entry_paths:
|
|
141
|
-
- <repo-relative path that exists, one or more>
|
|
142
|
-
verified: never-driven (generated <today>)
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
# <slug>
|
|
146
|
-
|
|
147
|
-
<one paragraph of user-visible behaviour, no implementation detail>
|
|
148
|
-
|
|
149
|
-
## Sub-features
|
|
150
|
-
|
|
151
|
-
- <the sub-behaviours, one `<id>` per line>
|
|
152
|
-
|
|
153
|
-
## How to get to it (user POV)
|
|
154
|
-
|
|
155
|
-
- <how a user reaches this feature, and what they should see>
|
|
156
|
-
|
|
157
|
-
## Driving it with <harness>
|
|
158
|
-
|
|
159
|
-
Preconditions: <what must be true first>.
|
|
160
|
-
**<action>.** Run `<exact command>`. <the observable result.>
|
|
161
|
-
|
|
162
|
-
## Gotchas
|
|
163
|
-
|
|
164
|
-
- <what commonly breaks, or what the entry-path token does and does not prove>
|
|
165
|
-
============================================================================== =
|
|
166
|
-
BRIEF
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
# ----------------------------------------------------------------- input ----
|
|
170
|
-
TARGET="" FORCE=0 AGENT=0 HEURISTIC=0 WRITE_DIR=""
|
|
42
|
+
MAPDIR=""
|
|
43
|
+
ROOT=""
|
|
171
44
|
while [ $# -gt 0 ]; do
|
|
172
45
|
case "$1" in
|
|
173
|
-
--
|
|
174
|
-
|
|
175
|
-
--
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
TARGET="${2:-}"; shift 2 ;;
|
|
180
|
-
-h|--help) usage; exit 0 ;;
|
|
181
|
-
--) shift; break ;;
|
|
182
|
-
-*) g_err "unknown option: $1"; usage >&2; exit 2 ;;
|
|
183
|
-
*) if [ -z "$TARGET" ]; then TARGET="$1"; shift
|
|
184
|
-
else g_err "unexpected argument: $1"; exit 2; fi ;;
|
|
46
|
+
--validate) [ -n "$MAPDIR" ] && { g_err "validate dir given twice"; exit 2; }
|
|
47
|
+
MAPDIR="${2:-}"; shift 2 ;;
|
|
48
|
+
--root) [ -n "$ROOT" ] && { g_err "root given twice"; exit 2; }
|
|
49
|
+
ROOT="${2:-}"; shift 2 ;;
|
|
50
|
+
-h|--help) usage; exit 0 ;;
|
|
51
|
+
*) g_err "unknown argument: $1"; usage >&2; exit 2 ;;
|
|
185
52
|
esac
|
|
186
53
|
done
|
|
187
54
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
exit 0
|
|
195
|
-
fi
|
|
196
|
-
|
|
197
|
-
# --write <dir>: validate the agent-written map. Needs --force semantics from the
|
|
198
|
-
# never-clobber contract; --heuristic and --write are separate modes, never both.
|
|
199
|
-
if [ -n "$WRITE_DIR" ]; then
|
|
200
|
-
[ "$HEURISTIC" -eq 0 ] || { g_err "--write and --heuristic are separate modes"; exit 2; }
|
|
201
|
-
[ -d "$WRITE_DIR" ] || { g_err "--write dir does not exist (the agent creates it): $WRITE_DIR"; exit 2; }
|
|
202
|
-
WDIR=$(cd "$WRITE_DIR" && pwd) || { g_err "cannot enter: $WRITE_DIR"; exit 2; }
|
|
203
|
-
# A map, for --write purposes, is the README index: --write never writes feature
|
|
204
|
-
# files (they are its INPUT), so the only thing it could clobber is the index.
|
|
205
|
-
# QA fix (v2-qa issue 5): an existing index used to be a refusal ("pass --force") —
|
|
206
|
-
# but the AGENT BRIEF itself tells the agent to WRITE features/README.md before
|
|
207
|
-
# running --write, so the first --write of the brief's own prescribed flow demanded
|
|
208
|
-
# the scary flag. The coherent contract: --write VALIDATES and never rewrites the
|
|
209
|
-
# index without --force; an existing index is the author's own output and is kept,
|
|
210
|
-
# named in the done line. (The never-clobber promise is unchanged: --write still
|
|
211
|
-
# writes NOTHING without --force — the refusal was protecting an empty write.)
|
|
212
|
-
HAVE_WMAP=0
|
|
213
|
-
if [ -f "$WDIR/README.md" ]; then HAVE_WMAP=1; fi
|
|
214
|
-
# Validation: the frontmatter + H2 + verified contract, per file, fail closed.
|
|
215
|
-
BAD=0; N=0
|
|
216
|
-
for f in "$WDIR"/*.md; do
|
|
217
|
-
[ -f "$f" ] || continue
|
|
218
|
-
case "$(basename "$f")" in README.md) continue ;; esac
|
|
219
|
-
N=$((N + 1))
|
|
220
|
-
slug=$(basename "$f"); slug=${slug%.md}
|
|
221
|
-
# frontmatter block present
|
|
222
|
-
sed -n '1,2p' "$f" | grep -q '^---[[:space:]]*$' \
|
|
223
|
-
|| { g_err "$f: no frontmatter block (must start: ---)"; BAD=1; continue; }
|
|
224
|
-
fm=$(awk 'BEGIN{fm=0} /^---[[:space:]]*$/ {fm++; if (fm==1) next; else exit} fm==1 {print}' "$f")
|
|
225
|
-
printf '%s\n' "$fm" | grep -q "^feature:[[:space:]]*$slug[[:space:]]*$" \
|
|
226
|
-
|| { g_err "$f: feature: must equal the filename stem ($slug)"; BAD=1; }
|
|
227
|
-
printf '%s\n' "$fm" | awk '/^entry_paths:/{f=1;next} f&&/^ - /{found=1} END{exit !found}' \
|
|
228
|
-
|| { g_err "$f: entry_paths: carries no item (>=1 existing repo-relative path)"; BAD=1; }
|
|
229
|
-
# every entry path exists under the CWD (repo-relative) and is a single token
|
|
230
|
-
while IFS= read -r tok; do
|
|
231
|
-
[ -n "$tok" ] || continue
|
|
232
|
-
case "$tok" in *" "*) g_err "$f: entry path with whitespace: $tok"; BAD=1; continue ;; esac
|
|
233
|
-
[ -e "$tok" ] || { g_err "$f: entry path does not exist: $tok"; BAD=1; }
|
|
234
|
-
done < <(printf '%s\n' "$fm" | awk '/^entry_paths:/{f=1;next} f&&/^ - /{sub(/^ - /,"");print;next} f&&!/^[[:space:]]/{f=0}')
|
|
235
|
-
v=$(printf '%s\n' "$fm" | sed -n 's/^verified:[[:space:]]*//p')
|
|
236
|
-
case "$v" in
|
|
237
|
-
""|"")
|
|
238
|
-
g_err "$f: no verified: line"; BAD=1 ;;
|
|
239
|
-
"never-driven"*)
|
|
240
|
-
: ;;
|
|
241
|
-
*) # a date, or anything else is refused — the line is either a date or never-driven
|
|
242
|
-
case "$v" in [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]) : ;; *)
|
|
243
|
-
g_err "$f: verified: must be a date or the never-driven form (got: $v)"; BAD=1 ;;
|
|
244
|
-
esac ;;
|
|
245
|
-
esac
|
|
246
|
-
# the four H2s, in order
|
|
247
|
-
hn=0; hok=1
|
|
248
|
-
while IFS= read -r line; do
|
|
249
|
-
hn=$((hn + 1))
|
|
250
|
-
case "$hn" in
|
|
251
|
-
1) [ "$line" = "Sub-features" ] || hok=0 ;;
|
|
252
|
-
2) [ "$line" = "How to get to it (user POV)" ] || hok=0 ;;
|
|
253
|
-
3) case "$line" in "Driving it with "*) ;; *) hok=0 ;; esac ;;
|
|
254
|
-
4) [ "$line" = "Gotchas" ] || hok=0 ;;
|
|
255
|
-
*) hok=0 ;;
|
|
256
|
-
esac
|
|
257
|
-
done < <(grep -n '^## ' "$f" | sed 's/^[0-9]*:## //; s/[[:space:]]*$//')
|
|
258
|
-
[ "$hn" -eq 4 ] && [ "$hok" -eq 1 ] || { g_err "$f: the four H2 sections are missing or out of order (Sub-features / How to get to it (user POV) / Driving it with <harness> / Gotchas)"; BAD=1; }
|
|
259
|
-
done
|
|
260
|
-
[ "$N" -ge 1 ] || { g_err "$WDIR carries no feature file (only README.md) — the map is the features"; exit 2; }
|
|
261
|
-
[ "$BAD" -eq 0 ] || { g_err "validation failed — fix the named file(s) and re-run"; exit 2; }
|
|
262
|
-
# --write --force: regenerate ONLY the README index (every existing feature file is
|
|
263
|
-
# listed; the files themselves are never touched). Without --force, the index is
|
|
264
|
-
# untouched.
|
|
265
|
-
if [ "$FORCE" -eq 1 ]; then
|
|
266
|
-
SLUGS_TSV="$WDIR/.wmap.tsv"; : > "$SLUGS_TSV"
|
|
267
|
-
for f in "$WDIR"/*.md; do
|
|
268
|
-
[ -f "$f" ] || continue
|
|
269
|
-
slug=$(basename "$f"); slug=${slug%.md}
|
|
270
|
-
# QA fix (v2-qa issue 6): $slug is the STEM (README, not README.md) — the old
|
|
271
|
-
# pattern compared README against README.md, never matched, and the regenerated
|
|
272
|
-
# index listed the index itself as a feature.
|
|
273
|
-
case "$slug" in README) continue ;; esac
|
|
274
|
-
printf '%s\t%s\n' "$slug" "$(printf '%s' "${f#"$WDIR"/}" | sed 's#^#./#')" >> "$SLUGS_TSV"
|
|
275
|
-
done
|
|
276
|
-
TODAY=$(date +%F)
|
|
277
|
-
{
|
|
278
|
-
printf '%s\n' '# Features'
|
|
279
|
-
printf '%s\n' ''
|
|
280
|
-
printf '%s\n' "regenerated by gob map --write ${TODAY} — the index only; every feature file was written by hand (or by an agent) and is never touched by --write."
|
|
281
|
-
printf '%s\n' ''
|
|
282
|
-
printf '%s\n' '## Features'
|
|
283
|
-
printf '%s\n' ''
|
|
284
|
-
while IFS= read -r row; do
|
|
285
|
-
[ -n "$row" ] || continue
|
|
286
|
-
slug=${row%% *}
|
|
287
|
-
printf '%s\n' "- [${slug}](./${slug}.md) — entry listed in the file's frontmatter"
|
|
288
|
-
done < "$SLUGS_TSV"
|
|
289
|
-
} > "$WDIR/README.md"
|
|
290
|
-
rm -f "$SLUGS_TSV"
|
|
291
|
-
printf 'map --write: validated %d feature file(s) in %s and regenerated the README index (feature files untouched; declare feature_map: in AGENTS.md to opt FM-01/FM-02 in)\n' "$N" "$WDIR"
|
|
292
|
-
else
|
|
293
|
-
printf 'map --write: validated %d feature file(s) in %s (index untouched; declare feature_map: in AGENTS.md to opt FM-01/FM-02 in)\n' "$N" "$WDIR"
|
|
294
|
-
fi
|
|
295
|
-
exit 0
|
|
296
|
-
fi
|
|
297
|
-
|
|
298
|
-
[ -n "$TARGET" ] || TARGET="$PWD"
|
|
299
|
-
[ -d "$TARGET" ] || { g_err "not a directory: $TARGET"; exit 2; }
|
|
300
|
-
T=$(cd "$TARGET" && pwd) || { g_err "cannot enter: $TARGET"; exit 2; }
|
|
301
|
-
FEAT="$T/features"
|
|
302
|
-
README_F="$FEAT/README.md"
|
|
303
|
-
TODAY=$(date +%F)
|
|
55
|
+
[ -n "$MAPDIR" ] || { g_err "--validate <mapdir> is required"; usage >&2; exit 2; }
|
|
56
|
+
[ -d "$MAPDIR" ] || { g_err "map dir does not exist: $MAPDIR"; exit 2; }
|
|
57
|
+
MAPDIR=$(cd "$MAPDIR" && pwd) || { g_err "cannot enter: $MAPDIR"; exit 2; }
|
|
58
|
+
ROOT="${ROOT:-$PWD}"
|
|
59
|
+
[ -d "$ROOT" ] || { g_err "--root is not a directory: $ROOT"; exit 2; }
|
|
60
|
+
ROOT=$(cd "$ROOT" && pwd) || { g_err "cannot enter root: $ROOT"; exit 2; }
|
|
304
61
|
|
|
305
|
-
|
|
306
|
-
trap 'rm -rf "$WORK"' EXIT
|
|
307
|
-
SLUGS_TSV="$WORK/slugs.tsv"; : > "$SLUGS_TSV"
|
|
62
|
+
BAD=0
|
|
308
63
|
|
|
309
|
-
#
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
printf '%s' "$1" | tr '[:upper:]' '[:lower:]' \
|
|
313
|
-
| sed -e 's/[^a-z0-9]/-/g' -e 's/-\{2,\}/-/g' -e 's/^-*//' -e 's/-*$//'
|
|
64
|
+
# fm_frontmatter <file> - the body of the leading --- block.
|
|
65
|
+
fm_frontmatter() {
|
|
66
|
+
awk 'BEGIN{fm=0} /^---[[:space:]]*$/ {fm++; if (fm==1) next; else exit} fm==1 {print}' "$1"
|
|
314
67
|
}
|
|
315
68
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
69
|
+
# fm_entry_paths <file> - one declared entry path per line.
|
|
70
|
+
fm_entry_paths() {
|
|
71
|
+
fm_frontmatter "$1" | awk '
|
|
72
|
+
/^entry_paths:/ { inb = 1; next }
|
|
73
|
+
inb && /^ - / { v = $0; sub(/^ - /, "", v); sub(/[[:space:]]+$/, "", v); print v; next }
|
|
74
|
+
inb && !/^[[:space:]]/ { inb = 0 }
|
|
75
|
+
'
|
|
323
76
|
}
|
|
324
77
|
|
|
325
|
-
#
|
|
326
|
-
#
|
|
327
|
-
#
|
|
328
|
-
|
|
329
|
-
local
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
prune_find=(\( -name node_modules -o -name .git -o -name dist -o -name build -o -name .next -o -name .nuxt \) -prune -o)
|
|
339
|
-
|
|
340
|
-
# --------------------------------------------------------------- detectors ----
|
|
341
|
-
MODE=""
|
|
342
|
-
SLUG_CAP=40
|
|
343
|
-
|
|
344
|
-
if [ -d "$T/app" ]; then
|
|
345
|
-
while IFS= read -r f; do
|
|
346
|
-
[ -n "$f" ] || continue
|
|
347
|
-
rel=${f#"$T"/}
|
|
348
|
-
slug=$(group_slug_for "$rel" "app")
|
|
349
|
-
scan_add "$slug" "$rel"
|
|
350
|
-
done < <(find "$T/app" -type f \( -name 'page.tsx' -o -name 'page.jsx' -o -name 'route.ts' \) 2>/dev/null)
|
|
351
|
-
grep -q . "$SLUGS_TSV" && MODE=next-app
|
|
352
|
-
fi
|
|
353
|
-
|
|
354
|
-
if [ -z "$MODE" ] && [ -d "$T/pages" ]; then
|
|
355
|
-
# .vue under pages/ is Nuxt; .tsx/.jsx is the Next pages router. Same grouping either way.
|
|
356
|
-
while IFS= read -r f; do
|
|
357
|
-
[ -n "$f" ] || continue
|
|
358
|
-
rel=${f#"$T"/}
|
|
359
|
-
rest=${rel#pages/}
|
|
360
|
-
case "$rest" in
|
|
361
|
-
*/*) slug=$(sanitize_slug "${rest%%/*}") ;;
|
|
362
|
-
*) slug=$(sanitize_slug "${rest%.*}") ;;
|
|
78
|
+
# fm_h2_ok <file> - exactly the four contract H2s, in order. The third is a PREFIX match: the
|
|
79
|
+
# map names the project's own harness ("Driving it with <harness>"), so a literal would make the
|
|
80
|
+
# rule un-portable.
|
|
81
|
+
fm_h2_ok() {
|
|
82
|
+
local n=0 ok=1 line
|
|
83
|
+
while IFS= read -r line; do
|
|
84
|
+
n=$((n + 1))
|
|
85
|
+
case "$n" in
|
|
86
|
+
1) [ "$line" = "Sub-features" ] || ok=0 ;;
|
|
87
|
+
2) [ "$line" = "How to get to it (user POV)" ] || ok=0 ;;
|
|
88
|
+
3) case "$line" in "Driving it with "*) ;; *) ok=0 ;; esac ;;
|
|
89
|
+
4) [ "$line" = "Gotchas" ] || ok=0 ;;
|
|
90
|
+
*) ok=0 ;;
|
|
363
91
|
esac
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
grep -q . "$SLUGS_TSV" && MODE=pages-router
|
|
367
|
-
fi
|
|
368
|
-
|
|
369
|
-
if [ -z "$MODE" ]; then
|
|
370
|
-
# React Router and friends: any routes/ directory (or *route* file) within reach. Capped,
|
|
371
|
-
# because a repo with generated route tables would otherwise grow one slug per row.
|
|
372
|
-
while IFS= read -r d; do
|
|
373
|
-
[ -n "$d" ] || continue
|
|
374
|
-
while IFS= read -r f; do
|
|
375
|
-
[ -n "$f" ] || continue
|
|
376
|
-
rel=${f#"$T"/}
|
|
377
|
-
b=$(basename "$f"); stem=${b%.*}
|
|
378
|
-
stem=$(printf '%s' "$stem" | sed -e 's/[-.]route$//' -e 's/^route[-.]//')
|
|
379
|
-
case "$stem" in
|
|
380
|
-
index|routes) stem=$(basename "$d") ;;
|
|
381
|
-
esac
|
|
382
|
-
slug=$(sanitize_slug "$stem")
|
|
383
|
-
scan_add "$slug" "$rel"
|
|
384
|
-
done < <(find "$d" -maxdepth 2 -type f \( -name '*.js' -o -name '*.ts' -o -name '*.jsx' -o -name '*.tsx' -o -name '*.vue' \) 2>/dev/null)
|
|
385
|
-
done < <(find "$T" "${prune_find[@]}" -type d -name routes -print 2>/dev/null | head -n 8)
|
|
386
|
-
if [ -z "$MODE" ]; then
|
|
387
|
-
while IFS= read -r f; do
|
|
388
|
-
[ -n "$f" ] || continue
|
|
389
|
-
rel=${f#"$T"/}
|
|
390
|
-
b=$(basename "$f"); stem=${b%.*}
|
|
391
|
-
stem=$(printf '%s' "$stem" | sed -e 's/[-.]route$//' -e 's/^route[-.]//' -e 's/^routes$//')
|
|
392
|
-
slug=$(sanitize_slug "$stem")
|
|
393
|
-
scan_add "$slug" "$rel"
|
|
394
|
-
done < <(find "$T" "${prune_find[@]}" -type f -name '*route*' \
|
|
395
|
-
\( -name '*.js' -o -name '*.ts' -o -name '*.jsx' -o -name '*.tsx' \) -print 2>/dev/null | head -n 40)
|
|
396
|
-
fi
|
|
397
|
-
grep -q . "$SLUGS_TSV" && MODE=routes
|
|
398
|
-
fi
|
|
399
|
-
|
|
400
|
-
if [ -z "$MODE" ]; then
|
|
401
|
-
# Fallback: top-level src/ or lib/ module dirs become candidate slugs with TODO bodies.
|
|
402
|
-
for base in src lib; do
|
|
403
|
-
[ -d "$T/$base" ] || continue
|
|
404
|
-
for d in "$T/$base"/*/; do
|
|
405
|
-
[ -d "$d" ] || continue
|
|
406
|
-
b=$(basename "$d")
|
|
407
|
-
case "$b" in
|
|
408
|
-
test|tests|spec|specs|__tests__|fixtures|mocks|node_modules|dist|build|types|typings) continue ;;
|
|
409
|
-
esac
|
|
410
|
-
slug=$(sanitize_slug "$b")
|
|
411
|
-
scan_add "$slug" "$base/$b"
|
|
412
|
-
done
|
|
413
|
-
done
|
|
414
|
-
grep -q . "$SLUGS_TSV" && MODE=modules
|
|
415
|
-
fi
|
|
416
|
-
|
|
417
|
-
# Cap the map: a detector gone wild (generated routes) must not write 300 stub files.
|
|
418
|
-
if grep -q . "$SLUGS_TSV"; then
|
|
419
|
-
awk -F'\t' 'NR==FNR { if (!seen[$1]++ && n < 40) { n++; keep[$1]=1 } next } $1 in keep' \
|
|
420
|
-
"$SLUGS_TSV" "$SLUGS_TSV" > "$WORK/capped.tsv" && mv "$WORK/capped.tsv" "$SLUGS_TSV"
|
|
421
|
-
fi
|
|
422
|
-
|
|
423
|
-
SLUG_N=$(awk -F'\t' '!seen[$1]++ {n++} END {print n + 0}' "$SLUGS_TSV")
|
|
424
|
-
|
|
425
|
-
# ------------------------------------------------------------ existing map ----
|
|
426
|
-
HAVE_MAP=0
|
|
427
|
-
if [ -f "$README_F" ]; then
|
|
428
|
-
HAVE_MAP=1
|
|
429
|
-
elif [ -d "$FEAT" ] && ls "$FEAT"/*.md >/dev/null 2>&1; then
|
|
430
|
-
HAVE_MAP=1 # feature files without an index is still a map — the refusal must fire
|
|
431
|
-
fi
|
|
432
|
-
|
|
433
|
-
if [ "$HAVE_MAP" -eq 1 ] && [ "$FORCE" -ne 1 ]; then
|
|
434
|
-
g_err "refusing to overwrite an existing feature map: $FEAT"
|
|
435
|
-
printf 'error: map: pass --force to regenerate the README index and add NEW slugs only; existing feature files are never rewritten\n' >&2
|
|
436
|
-
exit 1
|
|
437
|
-
fi
|
|
438
|
-
|
|
439
|
-
# ------------------------------------------------------------ rendering ----
|
|
440
|
-
script_cmd() { # <script name> — the flat "name": "cmd" shape from package.json, no jq
|
|
441
|
-
local pk="$T/package.json" v
|
|
442
|
-
[ -f "$pk" ] || return 0
|
|
443
|
-
v=$(sed -n "s/.*\"$1\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" "$pk" | head -n 1)
|
|
444
|
-
printf '%s' "$v"
|
|
92
|
+
done < <(grep -n '^## ' "$1" | sed 's/^[0-9]*:## //; s/[[:space:]]*$//')
|
|
93
|
+
[ "$n" -eq 4 ] && [ "$ok" -eq 1 ]
|
|
445
94
|
}
|
|
446
95
|
|
|
447
|
-
#
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
first_token() { # <slug>
|
|
455
|
-
awk -F'\t' -v s="$1" '$1 == s { print $2; exit }' "$SLUGS_TSV"
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
render_readme() { # > $WORK/readme.md
|
|
459
|
-
local slug tok title f
|
|
460
|
-
{
|
|
461
|
-
printf '%s\n' '# Features'
|
|
462
|
-
printf '%s\n' ''
|
|
463
|
-
printf '%s\n' "generated by gob map ${TODAY} — a STARTER; each feature file needs a human pass before its verified: date means anything."
|
|
464
|
-
printf '%s\n' ''
|
|
465
|
-
printf '%s\n' '## Baseline preconditions'
|
|
466
|
-
printf '%s\n' ''
|
|
467
|
-
if [ -f "$T/package.json" ]; then
|
|
468
|
-
got=0
|
|
469
|
-
for s in dev build test lint; do
|
|
470
|
-
c=$(script_cmd "$s")
|
|
471
|
-
if [ -n "$c" ]; then
|
|
472
|
-
printf '%s\n' "- $s: \`npm run $s\`"
|
|
473
|
-
got=1
|
|
474
|
-
fi
|
|
475
|
-
done
|
|
476
|
-
if [ "$got" -eq 1 ]; then
|
|
477
|
-
printf '%s\n' ''
|
|
478
|
-
printf '%s\n' '(read from package.json by the generator; edit by hand)'
|
|
479
|
-
else
|
|
480
|
-
printf '%s\n' '- TODO: package.json found, but no dev/build/test/lint script — write the launch + health-check commands here.'
|
|
481
|
-
fi
|
|
482
|
-
else
|
|
483
|
-
printf '%s\n' '- TODO: how to launch, isolate, seed, health-check (no package.json found — write your own commands here).'
|
|
484
|
-
fi
|
|
485
|
-
cat <<'MID'
|
|
486
|
-
|
|
487
|
-
## Driving conventions
|
|
488
|
-
|
|
489
|
-
TODO: the stable-handle rule, the literal-command rule, the restore rule
|
|
490
|
-
(skills/goblin-feature-map/SKILL.md defines all three; write this repo's own forms here).
|
|
491
|
-
|
|
492
|
-
## Proof and skip reporting
|
|
493
|
-
|
|
494
|
-
TODO: what counts as proof that a feature was driven, and how a skip is reported.
|
|
96
|
+
# ---------------------------------------------------------------- FM-01 shape ---
|
|
97
|
+
READMEF="$MAPDIR/README.md"
|
|
98
|
+
if [ ! -f "$READMEF" ]; then
|
|
99
|
+
g_err "$MAPDIR carries no README.md index — the map is the index plus one <slug>.md per feature"
|
|
100
|
+
exit 2
|
|
101
|
+
fi
|
|
495
102
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
103
|
+
N=0
|
|
104
|
+
for f in "$MAPDIR"/*.md; do
|
|
105
|
+
[ -f "$f" ] || continue
|
|
106
|
+
case "$(basename "$f")" in README.md) continue ;; esac
|
|
107
|
+
N=$((N + 1))
|
|
108
|
+
b=$(basename "$f")
|
|
109
|
+
slug=${b%.md}
|
|
110
|
+
# index hygiene: this feature file is linked from README.md in the (./<slug>.md) form.
|
|
111
|
+
grep -qF "](./$b)" "$READMEF" \
|
|
112
|
+
|| { g_err "$b is not linked from README.md as (./$b)"; BAD=1; }
|
|
113
|
+
# frontmatter block present
|
|
114
|
+
sed -n '1,2p' "$f" | grep -q '^---[[:space:]]*$' \
|
|
115
|
+
|| { g_err "$b: no frontmatter block (must start: ---)"; BAD=1; continue; }
|
|
116
|
+
fm=$(fm_frontmatter "$f")
|
|
117
|
+
printf '%s\n' "$fm" | grep -q "^feature:[[:space:]]*$slug[[:space:]]*\$" \
|
|
118
|
+
|| { g_err "$b: feature: must equal the filename stem ($slug)"; BAD=1; }
|
|
119
|
+
eps=$(fm_entry_paths "$f" | grep -c . || true)
|
|
120
|
+
[ "${eps:-0}" -ge 1 ] \
|
|
121
|
+
|| { g_err "$b: entry_paths: carries no item (>=1 repo-relative path that exists)"; BAD=1; }
|
|
122
|
+
while IFS= read -r tok; do
|
|
123
|
+
[ -n "$tok" ] || continue
|
|
124
|
+
case "$tok" in *[[:space:]]*) g_err "$b: entry path is not a single token: $tok"; BAD=1; continue ;; esac
|
|
125
|
+
done < <(fm_entry_paths "$f")
|
|
126
|
+
v=$(printf '%s\n' "$fm" | sed -n 's/^verified:[[:space:]]*//p')
|
|
127
|
+
case "$v" in
|
|
128
|
+
"") g_err "$b: no verified: line"; BAD=1 ;;
|
|
129
|
+
never-driven*) : ;;
|
|
130
|
+
*) case "$v" in [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]) : ;; *)
|
|
131
|
+
g_err "$b: verified: must be a date or the never-driven form (got: $v)"; BAD=1 ;;
|
|
132
|
+
esac ;;
|
|
133
|
+
esac
|
|
134
|
+
fm_h2_ok "$f" \
|
|
135
|
+
|| { g_err "$b: the H2s are not the contract four, in order (Sub-features / How to get to it (user POV) / Driving it with <harness> / Gotchas)"; BAD=1; }
|
|
136
|
+
done
|
|
137
|
+
[ "$N" -ge 1 ] \
|
|
138
|
+
|| { g_err "$MAPDIR indexes no feature file — an empty map is a hole, not a pass"; BAD=1; }
|
|
139
|
+
|
|
140
|
+
# every relative link in the index must resolve inside the map dir
|
|
141
|
+
while IFS= read -r link; do
|
|
142
|
+
[ -e "$MAPDIR/$link" ] || { g_err "README.md links $link, which does not resolve"; BAD=1; }
|
|
143
|
+
done < <(sed -n 's/.*](\.\/\([^)]*\.md\)).*/\1/p' "$READMEF")
|
|
144
|
+
|
|
145
|
+
# ---------------------------------------------------------------- FM-02 resolve -
|
|
146
|
+
for f in "$MAPDIR"/*.md; do
|
|
147
|
+
[ -f "$f" ] || continue
|
|
148
|
+
case "$(basename "$f")" in README.md) continue ;; esac
|
|
149
|
+
b=$(basename "$f")
|
|
150
|
+
while IFS= read -r e; do
|
|
151
|
+
[ -n "$e" ] || continue
|
|
152
|
+
if [ ! -e "$ROOT/$e" ]; then
|
|
153
|
+
g_err "$b: entry path \"$e\" does not exist under $ROOT"
|
|
154
|
+
BAD=1
|
|
155
|
+
continue
|
|
501
156
|
fi
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
if [ -f "$FEAT/$slug.md" ]; then
|
|
506
|
-
title=$(file_title "$FEAT/$slug.md" "$slug")
|
|
507
|
-
printf '%s\n' "- [${title}](./${slug}.md) covers TODO — starter entry: \`${tok}\` (never driven)"
|
|
508
|
-
else
|
|
509
|
-
printf '%s\n' "- [${slug}](./${slug}.md) covers TODO — starter entry: \`${tok}\` (never driven)"
|
|
510
|
-
fi
|
|
511
|
-
done < <(awk -F'\t' '!seen[$1]++ {print $1}' "$SLUGS_TSV")
|
|
512
|
-
# --force keeps files the scanner no longer detects: they stay indexed (FM-01 would
|
|
513
|
-
# red an unlinked file), marked as existing rather than re-described.
|
|
514
|
-
if [ "$HAVE_MAP" -eq 1 ]; then
|
|
515
|
-
for f in "$FEAT"/*.md; do
|
|
516
|
-
[ -f "$f" ] || continue
|
|
517
|
-
slug=$(basename "$f"); slug=${slug%.md}
|
|
518
|
-
# QA fix (v2-qa issue 6): stem comparison, same bug as the --write index loop —
|
|
519
|
-
# the slug is README after .md is stripped, so the old README.md pattern never fired.
|
|
520
|
-
case "$slug" in README) continue ;; esac
|
|
521
|
-
awk -F'\t' -v s="$slug" '$1 == s { found=1 } END { exit !found }' "$SLUGS_TSV" && continue
|
|
522
|
-
title=$(file_title "$f" "$slug")
|
|
523
|
-
printf '%s\n' "- [${title}](./${slug}.md) covers TODO — existing feature file kept by --force (not re-described)"
|
|
524
|
-
done
|
|
157
|
+
if ! git -C "$ROOT" ls-files --error-unmatch -- "$e" >/dev/null 2>&1; then
|
|
158
|
+
g_err "$b: entry path \"$e\" is not tracked by git — commit it before the map claims it"
|
|
159
|
+
BAD=1
|
|
525
160
|
fi
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
render_feature() { # <slug> — writes $FEAT/<slug>.md, never called on an existing file.
|
|
530
|
-
# The body renders in ONE pass: the entry_paths list is looped in awk (a bash body cannot
|
|
531
|
-
# loop the tab data cleanly), every other placeholder is data this function already holds.
|
|
532
|
-
# The awk program is single-quoted with no apostrophe inside (the repo's own rule).
|
|
533
|
-
local slug="$1"
|
|
534
|
-
awk -F'\t' -v slug="$slug" -v today="$TODAY" '
|
|
535
|
-
BEGIN {
|
|
536
|
-
print "---"
|
|
537
|
-
print "feature: " slug
|
|
538
|
-
print "entry_paths:"
|
|
539
|
-
eps = 0
|
|
540
|
-
}
|
|
541
|
-
$1 == slug && !seen[$2]++ {
|
|
542
|
-
print " - " $2
|
|
543
|
-
eps++
|
|
544
|
-
}
|
|
545
|
-
END {
|
|
546
|
-
if (eps == 0) print " - TODO: name one entry-path token"
|
|
547
|
-
print "verified: never-driven (generated " today ")"
|
|
548
|
-
print "---"
|
|
549
|
-
print ""
|
|
550
|
-
print "# " slug
|
|
551
|
-
print ""
|
|
552
|
-
print "TODO (human pass): one paragraph of user-visible behaviour, no implementation"
|
|
553
|
-
print "detail. Generated by gob map; nothing in this file has been driven."
|
|
554
|
-
print ""
|
|
555
|
-
print "## Sub-features"
|
|
556
|
-
print ""
|
|
557
|
-
print "- TODO: list the sub-behaviours, one `<id>` per line"
|
|
558
|
-
print ""
|
|
559
|
-
print "## How to get to it (user POV)"
|
|
560
|
-
print ""
|
|
561
|
-
print "- TODO: how a user reaches this feature, and what they should see"
|
|
562
|
-
print ""
|
|
563
|
-
print "## Driving it with <harness>"
|
|
564
|
-
print ""
|
|
565
|
-
print "Preconditions: TODO - what must be true first (see the README Baseline section)."
|
|
566
|
-
print "**TODO action.** Run `<exact command>`. TODO: the observable result."
|
|
567
|
-
print ""
|
|
568
|
-
print "## Gotchas"
|
|
569
|
-
print ""
|
|
570
|
-
print "- This file is GENERATED: the verified line above is not a drive claim - replace"
|
|
571
|
-
print " it with a date only after a human or an agent has driven the feature once."
|
|
572
|
-
print "- The entry path is a PATH that existed at generation time. If you declare this map"
|
|
573
|
-
print " later, FM-02 greps file CONTENTS for the token - prefer one that occurs in source"
|
|
574
|
-
print " text (a route literal, an import) so the tripwire can actually fire."
|
|
575
|
-
}' "$SLUGS_TSV" > "$FEAT/${slug}.md"
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
# ------------------------------------------------------------------ write ----
|
|
579
|
-
mkdir -p "$FEAT"
|
|
580
|
-
|
|
581
|
-
NEW_N=0
|
|
582
|
-
render_readme
|
|
583
|
-
|
|
584
|
-
if [ "$FORCE" -eq 1 ] && [ -f "$README_F" ]; then
|
|
585
|
-
KEPT_EXISTING=1
|
|
586
|
-
else
|
|
587
|
-
KEPT_EXISTING=0
|
|
588
|
-
fi
|
|
589
|
-
|
|
590
|
-
# new feature files: detected slugs with no file yet (in --force, or fresh generation)
|
|
591
|
-
NEW_LIST="$WORK/new.list"; : > "$NEW_LIST"
|
|
592
|
-
while IFS= read -r slug; do
|
|
593
|
-
[ -n "$slug" ] || continue
|
|
594
|
-
[ -f "$FEAT/$slug.md" ] || printf '%s\n' "$slug" >> "$NEW_LIST"
|
|
595
|
-
done < <(awk -F'\t' '!seen[$1]++ {print $1}' "$SLUGS_TSV")
|
|
596
|
-
NEW_N=$(wc -l < "$NEW_LIST" | tr -d '[:space:]')
|
|
597
|
-
|
|
598
|
-
if [ "$FORCE" -eq 1 ] && [ -f "$README_F" ] && [ "$NEW_N" -eq 0 ] \
|
|
599
|
-
&& cmp -s "$WORK/readme.md" "$README_F"; then
|
|
600
|
-
printf '%s\n' "map: nothing to do — the index and every detected slug are already in place (${SLUG_N} slug(s), mode: ${MODE:-none})"
|
|
601
|
-
exit 0
|
|
602
|
-
fi
|
|
603
|
-
|
|
604
|
-
cp "$WORK/readme.md" "$README_F"
|
|
605
|
-
while IFS= read -r slug; do
|
|
606
|
-
[ -n "$slug" ] || continue
|
|
607
|
-
render_feature "$slug"
|
|
608
|
-
done < "$NEW_LIST"
|
|
161
|
+
done < <(fm_entry_paths "$f")
|
|
162
|
+
done
|
|
609
163
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
else
|
|
613
|
-
printf '%s\n' "map: generated ${README_F} + ${NEW_N} feature file(s) — a STARTER; hand-pass each file before trusting it (mode: ${MODE:-none})"
|
|
614
|
-
fi
|
|
164
|
+
[ "$BAD" -eq 0 ] || exit 2
|
|
165
|
+
printf 'map valid: %s — %d feature file(s), every entry path resolves and is tracked\n' "$MAPDIR" "$N"
|
|
615
166
|
exit 0
|