agent-concepts 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +771 -2
- package/concepts/bc-brainstorming/body/SKILL.md +43 -0
- package/concepts/bc-code-review/body/SKILL.md +120 -0
- package/concepts/bc-codebase-design/body/SKILL.md +54 -0
- package/concepts/bc-codebase-docs/body/SKILL.md +150 -0
- package/concepts/bc-council-audit-security/body/SKILL.md +72 -0
- package/concepts/bc-council-chain/body/SKILL.md +71 -0
- package/concepts/bc-council-challenge-plan/body/SKILL.md +78 -0
- package/concepts/bc-council-find-bugs/body/SKILL.md +70 -0
- package/concepts/bc-council-improve-architecture/body/SKILL.md +52 -0
- package/concepts/bc-council-mode/body/SKILL.md +56 -0
- package/concepts/bc-council-mode/body/examples/agents/README.md +11 -0
- package/concepts/bc-council-mode/body/examples/agents/council-change.md +14 -0
- package/concepts/bc-council-mode/body/examples/agents/council-compat.md +14 -0
- package/concepts/bc-council-mode/body/examples/agents/council-risk.md +14 -0
- package/concepts/bc-council-mode/body/references/pass-contracts.md +133 -0
- package/concepts/bc-delegate-investigation/body/SKILL.md +119 -0
- package/concepts/bc-delegate-investigation/body/examples/pi-settings-snippet.json +8 -0
- package/concepts/bc-delegate-investigation/body/pi.md +168 -0
- package/concepts/bc-design/body/SKILL.md +49 -0
- package/concepts/bc-design/body/design-framework.md +39 -0
- package/concepts/bc-design/body/existing-app.md +9 -0
- package/concepts/bc-design/body/new-work.md +22 -0
- package/concepts/bc-design/body/principles.md +34 -0
- package/concepts/bc-design/body/surfaces.md +13 -0
- package/concepts/bc-diagnosing-bugs/body/SKILL.md +83 -0
- package/concepts/bc-dispatching-parallel-agents/body/SKILL.md +63 -0
- package/concepts/bc-domain-modeling/body/SKILL.md +40 -0
- package/concepts/bc-executing-plans/body/SKILL.md +50 -0
- package/concepts/bc-explain-visually/body/SKILL.md +167 -0
- package/concepts/bc-find-bugs/body/SKILL.md +90 -0
- package/concepts/bc-finishing-development-branch/body/SKILL.md +73 -0
- package/concepts/bc-grilling/body/SKILL.md +22 -0
- package/concepts/bc-handoff/body/SKILL.md +104 -0
- package/concepts/bc-handoff/body/pickup.md +107 -0
- package/concepts/bc-handoff/body/writing.md +217 -0
- package/concepts/bc-improve-codebase-architecture/body/SKILL.md +101 -0
- package/concepts/bc-json-canvas/body/SKILL.md +40 -0
- package/concepts/bc-json-canvas/body/references/EXAMPLES.md +71 -0
- package/concepts/bc-json-canvas/body/references/SPEC.md +55 -0
- package/concepts/bc-json-canvas/body/references/VALIDATION.md +26 -0
- package/concepts/bc-minimal-solution-ladder/body/SKILL.md +120 -0
- package/concepts/bc-obsidian-bases/body/SKILL.md +59 -0
- package/concepts/bc-obsidian-bases/body/references/EXAMPLES.md +80 -0
- package/concepts/bc-obsidian-bases/body/references/FUNCTIONS.md +49 -0
- package/concepts/bc-obsidian-bases/body/references/SYNTAX.md +82 -0
- package/concepts/bc-obsidian-bases/body/references/TROUBLESHOOTING.md +41 -0
- package/concepts/bc-obsidian-markdown/body/SKILL.md +47 -0
- package/concepts/bc-obsidian-markdown/body/references/CALLOUTS.md +40 -0
- package/concepts/bc-obsidian-markdown/body/references/EMBEDS.md +35 -0
- package/concepts/bc-obsidian-markdown/body/references/PROPERTIES.md +37 -0
- package/concepts/bc-optimize-code/body/SKILL.md +41 -0
- package/concepts/bc-performance-guardrails/body/SKILL.md +53 -0
- package/concepts/bc-performance-guardrails/body/measuring.md +29 -0
- package/concepts/bc-performance-guardrails/body/targets.md +20 -0
- package/concepts/bc-pipeline-to-done/body/SKILL.md +205 -0
- package/concepts/bc-pipeline-to-done/body/agents/bc-drain-auditor.md +19 -0
- package/concepts/bc-pipeline-to-done/body/agents/bc-drain-reviewer.md +19 -0
- package/concepts/bc-pipeline-to-done/body/agents/bc-drain-worker.md +19 -0
- package/concepts/bc-pipeline-to-done/body/execute-issue.md +71 -0
- package/concepts/bc-pipeline-to-done/body/recovery-bundle.md +79 -0
- package/concepts/bc-pipeline-to-done/body/review-contract.md +105 -0
- package/concepts/bc-pipeline-to-done/body/roles.md +13 -0
- package/concepts/bc-pipeline-to-done/body/scripts/publish-check.py +172 -0
- package/concepts/bc-pipeline-to-done/body/source-issues.md +86 -0
- package/concepts/bc-pipeline-to-done/body/source-work-items.md +76 -0
- package/concepts/bc-plain-language/body/SKILL.md +134 -0
- package/concepts/bc-plan-slicing/body/SKILL.md +56 -0
- package/concepts/bc-plan-to-pipeline/body/SKILL.md +89 -0
- package/concepts/bc-prd-drafting/body/SKILL.md +43 -0
- package/concepts/bc-prompting-agents/body/SKILL.md +278 -0
- package/concepts/bc-prototype/body/SKILL.md +40 -0
- package/concepts/bc-qmd/body/SKILL.md +64 -0
- package/concepts/bc-research/body/SKILL.md +26 -0
- package/concepts/bc-security-audit/body/AI-AND-LLM.md +25 -0
- package/concepts/bc-security-audit/body/ATTACK-CLASSES.md +35 -0
- package/concepts/bc-security-audit/body/DESKTOP-MOBILE-AND-LOCAL-IPC.md +28 -0
- package/concepts/bc-security-audit/body/RECONNAISSANCE.md +49 -0
- package/concepts/bc-security-audit/body/SKILL.md +117 -0
- package/concepts/bc-security-audit/body/SUPPLY-CHAIN-AND-RELEASE.md +28 -0
- package/concepts/bc-security-audit/body/VALIDATION-AND-REPORTING.md +124 -0
- package/concepts/bc-security-audit/body/WEB-PROTOCOL-AND-AUTH.md +27 -0
- package/concepts/bc-security-audit/body/validate_audit.py +151 -0
- package/concepts/bc-self-improve/body/SKILL.md +104 -0
- package/concepts/bc-seo/body/CITATIONS.md +23 -0
- package/concepts/bc-seo/body/IMAGE-SEO.md +350 -0
- package/concepts/bc-seo/body/SKILL.md +453 -0
- package/concepts/bc-setup-project/body/SKILL.md +252 -0
- package/concepts/bc-setup-project/body/scaffold.py +2751 -0
- package/concepts/bc-setup-project/body/starter-items.md +157 -0
- package/concepts/bc-setup-project/body/work-data.md +114 -0
- package/concepts/bc-setup-project/body/work_index.py +626 -0
- package/concepts/bc-setup-project/body/work_spent.py +220 -0
- package/concepts/bc-subagent-driven-development/body/SKILL.md +61 -0
- package/concepts/bc-tdd/body/SKILL.md +184 -0
- package/concepts/bc-tdd/body/formal.md +77 -0
- package/concepts/bc-tdd/body/mocking.md +49 -0
- package/concepts/bc-tdd/body/properties.md +59 -0
- package/concepts/bc-tdd/body/refactoring.md +12 -0
- package/concepts/bc-tdd/body/scripts/confirm-red.py +136 -0
- package/concepts/bc-tdd/body/tests.md +59 -0
- package/concepts/bc-teach/body/GLOSSARY-FORMAT.md +36 -0
- package/concepts/bc-teach/body/LEARNING-RECORD-FORMAT.md +60 -0
- package/concepts/bc-teach/body/MISSION-FORMAT.md +34 -0
- package/concepts/bc-teach/body/RESOURCES-FORMAT.md +53 -0
- package/concepts/bc-teach/body/REVIEW-FORMAT.md +48 -0
- package/concepts/bc-teach/body/SKILL.md +281 -0
- package/concepts/bc-teach/body/WIKI-FORMAT.md +58 -0
- package/concepts/bc-teach/body/scripts/due.py +65 -0
- package/concepts/bc-to-spec/body/SKILL.md +21 -0
- package/concepts/bc-to-tickets/body/SKILL.md +21 -0
- package/concepts/bc-triage/body/AGENT-BRIEF.md +38 -0
- package/concepts/bc-triage/body/OUT-OF-SCOPE.md +51 -0
- package/concepts/bc-triage/body/SKILL.md +81 -0
- package/concepts/bc-unslop/body/SKILL.md +269 -0
- package/concepts/bc-using-git-worktrees/body/SKILL.md +91 -0
- package/concepts/bc-wiki-maintain/body/SKILL.md +361 -0
- package/concepts/bc-wiki-maintain/body/runner/README.md +552 -0
- package/concepts/bc-wiki-maintain/body/runner/bc-wiki-lint.service +24 -0
- package/concepts/bc-wiki-maintain/body/runner/bc-wiki-lint.timer +15 -0
- package/concepts/bc-wiki-maintain/body/runner/bc-wiki-maintain-all.service +29 -0
- package/concepts/bc-wiki-maintain/body/runner/bc-wiki-maintain-all.timer +16 -0
- package/concepts/bc-wiki-maintain/body/runner/bc-wiki-maintain.service +28 -0
- package/concepts/bc-wiki-maintain/body/runner/bc-wiki-maintain.timer +12 -0
- package/concepts/bc-wiki-maintain/body/runner/bc-wiki-notify@.service +15 -0
- package/concepts/bc-wiki-maintain/body/runner/notify-failure.sh +92 -0
- package/concepts/bc-wiki-maintain/body/runner/run-lint.sh +69 -0
- package/concepts/bc-wiki-maintain/body/runner/run-promotion-all.sh +103 -0
- package/concepts/bc-wiki-maintain/body/runner/run-promotion.sh +270 -0
- package/concepts/bc-wiki-maintain/body/wiki_lint.py +958 -0
- package/concepts/bc-wiki-maintain/body/wiki_search.py +206 -0
- package/concepts/bc-work-sync/body/PLAN.md +46 -0
- package/concepts/bc-work-sync/body/SKILL.md +71 -0
- package/concepts/bc-writing-plans/body/SKILL.md +79 -0
- package/package.json +130 -4
- package/packages/agent-kernel-pi/AGENT-KERNEL.md +109 -0
- package/packages/agent-kernel-pi/index.js +8 -0
- package/packages/agent-kernel-pi/package.json +12 -0
|
@@ -0,0 +1,2751 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Scaffold a project's agent workspace + root AGENTS.md for the grill→issues→drain workflow.
|
|
3
|
+
|
|
4
|
+
Code, ops and hybrid (the visible layout) get work items in `work/`, decisions and
|
|
5
|
+
research in `docs/`, a root `glossary.md`, and agent mechanics only in `.bc-agent/`,
|
|
6
|
+
whose "Where things go" table names every path. Learning and knowledge keep the
|
|
7
|
+
`.bc-agent/` Markdown/Obsidian vault: the glossary lives in project/overview.md, ADRs
|
|
8
|
+
in decisions/, and conventions/planning-workflow.md redirects planning persistence
|
|
9
|
+
into the vault. TODO stubs (validation, file-layout) are filled by the first agents.
|
|
10
|
+
|
|
11
|
+
Idempotent and additive: creates only the files that are missing and leaves every
|
|
12
|
+
existing file untouched, so it is safe to re-run and safe to plug into a project
|
|
13
|
+
that already has files (including a hand-written root AGENTS.md). It NEVER deletes
|
|
14
|
+
anything. Existing files are overwritten only when explicitly forced: --force for
|
|
15
|
+
files under .bc-agent/, --force-root for the root AGENTS.md; nothing else is ever
|
|
16
|
+
overwritten. A visible-layout run on a project with earlier-layout paths under
|
|
17
|
+
.bc-agent/ writes nothing unless --allow-earlier-layout is given. --dry-run reports
|
|
18
|
+
without writing.
|
|
19
|
+
|
|
20
|
+
--migrate (code, ops, hybrid; needs an explicit --archetype) is the one exception to
|
|
21
|
+
"never deletes": it plans moving an earlier-layout vault in a clean git repository to
|
|
22
|
+
the visible layout and prints the plan; with --apply it performs only the mechanical
|
|
23
|
+
part (git mv, generated files, placeholder deletes, link rewrites), stages it and does
|
|
24
|
+
not commit. Everything else is listed for judgment and left untouched.
|
|
25
|
+
|
|
26
|
+
Usage:
|
|
27
|
+
scaffold.py --root <repo-root> --slug <project-name> [--date YYYY-MM-DD]
|
|
28
|
+
[--archetype code|ops|learning|knowledge|hybrid]
|
|
29
|
+
[--force] [--force-root] [--allow-earlier-layout] [--dry-run]
|
|
30
|
+
scaffold.py --root <repo-root> --slug <project-name> --archetype code|ops|hybrid
|
|
31
|
+
--migrate [--apply]
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import annotations
|
|
35
|
+
|
|
36
|
+
import argparse
|
|
37
|
+
import datetime as _dt
|
|
38
|
+
import os
|
|
39
|
+
import re
|
|
40
|
+
import subprocess
|
|
41
|
+
import urllib.parse
|
|
42
|
+
from pathlib import Path
|
|
43
|
+
|
|
44
|
+
SLUG = "__SLUG__"
|
|
45
|
+
DATE = "__DATE__"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# --- explicit teach host adapter (learning/hybrid overlays) -------------------
|
|
49
|
+
# This is a pointer and storage map, not a second copy of teach's pedagogy.
|
|
50
|
+
TEACH_ADAPTER_MARKER = "<!-- teach-host-adapter: v1 -->"
|
|
51
|
+
TEACH_ADAPTER = """<!-- teach-host-adapter: v1 -->
|
|
52
|
+
# Teach Skill Host Adapter
|
|
53
|
+
|
|
54
|
+
This file is the explicit opt-in marker for the standalone `bc-teach` skill to use this
|
|
55
|
+
existing `.bc-agent` vault. It is a thin adapter, not a copy of teach's instructions,
|
|
56
|
+
a generic configuration framework, or a migration command. `bc-setup-project` owns the
|
|
57
|
+
host schema and orientation; `bc-teach` owns the mapped pedagogy, evidence, and spaced
|
|
58
|
+
review state.
|
|
59
|
+
|
|
60
|
+
Read the canonical teach instructions and formats from
|
|
61
|
+
`<agent-concepts>/concepts/bc-teach/body/`. Resolve those paths against this vault root.
|
|
62
|
+
Do not invoke `bc-setup-project` from `bc-teach`, move standalone files, or create a second
|
|
63
|
+
learning/knowledge home. If a standalone teach workspace and this host both contain
|
|
64
|
+
state, stop and ask the user which home to use; preserve the standalone home by default.
|
|
65
|
+
A valid adapter has this exact first line and the complete hosted path table below; a
|
|
66
|
+
prefix-only or altered-map file is incomplete and is not a host contract.
|
|
67
|
+
|
|
68
|
+
## Hosted teach path map
|
|
69
|
+
|
|
70
|
+
When invoked from the project root, `<teach-root>` is `.bc-agent`; when invoked from inside
|
|
71
|
+
that vault, `<teach-root>` is the current `.bc-agent` directory. All paths below are relative
|
|
72
|
+
to `<teach-root>`:
|
|
73
|
+
|
|
74
|
+
| Teach surface | Hosted path | Owner |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| Mission | `learning/plan.md` (no hosted `MISSION.md`) | `bc-teach` |
|
|
77
|
+
| Review queue | `learning/review.md` | `bc-teach` |
|
|
78
|
+
| Learning records | `learning/records/` | `bc-teach` |
|
|
79
|
+
| Lessons and session artifacts | existing `sessions/` (never `learning/sessions/`) | `bc-teach` |
|
|
80
|
+
| Notes | `learning/notes.md` | `bc-teach` |
|
|
81
|
+
| Raw sources | existing `sources/` | `bc-teach` |
|
|
82
|
+
| Compiled knowledge / wiki concepts | existing `concepts/` | `bc-teach` |
|
|
83
|
+
| Resource catalog | `references/teach-resources.md` | `bc-teach` |
|
|
84
|
+
| Glossary | the existing Glossary section of `project/overview.md` | `bc-teach` |
|
|
85
|
+
| Catalog and history | shared `index.md` and `log.md` | `bc-setup-project` host schema; `bc-teach` updates teach entries |
|
|
86
|
+
|
|
87
|
+
With a valid marker, host search-first retrieval is for knowledge pages and learning records:
|
|
88
|
+
use the host's canonical search path, never the index as a lookup. `bc-teach` may directly read
|
|
89
|
+
mapped known state (mission, review queue, and notes) plus shared `index.md`/recent `log.md`
|
|
90
|
+
for session orientation and bookkeeping; those are not knowledge lookups. When this marker is
|
|
91
|
+
valid, `bc-teach` owns the Glossary section of `project/overview.md`; planning and maintenance
|
|
92
|
+
skills must leave that section alone, while non-glossary host sections remain available to
|
|
93
|
+
host maintenance.
|
|
94
|
+
|
|
95
|
+
## Explicit destructive migration — only on a user request
|
|
96
|
+
|
|
97
|
+
Choosing the host for reading or writing is not migration. Only perform this operation when
|
|
98
|
+
the user explicitly asks to **consolidate** or **migrate** the standalone teach workspace into
|
|
99
|
+
this host, never because a marker was discovered or as part of another action. This operation
|
|
100
|
+
is destructive: it copies/moves content into the host and then **deletes the standalone
|
|
101
|
+
originals**. Tell the user plainly that the originals will be deleted before doing it.
|
|
102
|
+
|
|
103
|
+
Use a copy-then-verify sequence. Inventory every existing standalone item, prepare its mapped
|
|
104
|
+
host destination, and preflight every destination for collisions and writability before any
|
|
105
|
+
write. Verify that every destination is complete before removing any original; for directories,
|
|
106
|
+
verify every content-bearing file, not merely the directory. Content-bearing records, sources,
|
|
107
|
+
knowledge pages, and session artifacts must arrive byte-identical (compare bytes or hashes).
|
|
108
|
+
The mission, notes, queue, catalog/history, glossary, and resource catalog may be reformatted
|
|
109
|
+
to their host formats, but verify every source item, row, entry, or glossary term is represented.
|
|
110
|
+
Do not overwrite unrelated host content or proceed through a destination conflict.
|
|
111
|
+
|
|
112
|
+
If any destination is missing, incomplete, conflicting, or unwritable, stop and report the
|
|
113
|
+
failure with **all standalone originals intact**; delete nothing. Only after every mapped
|
|
114
|
+
destination passes verification may the corresponding standalone files and directories be
|
|
115
|
+
removed. Choosing the host without an explicit migration request leaves every standalone file
|
|
116
|
+
untouched.
|
|
117
|
+
|
|
118
|
+
| Standalone source | Hosted destination (relative to `<teach-root>`) | Verification |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `MISSION.md` | `learning/plan.md` | mission content represented in the host mission format |
|
|
121
|
+
| `REVIEW.md` | `learning/review.md` | every review item and scheduling value represented |
|
|
122
|
+
| `learning-records/*` | `learning/records/` | each record arrives byte-identical |
|
|
123
|
+
| `lessons/*` | existing `sessions/` | each lesson/session artifact arrives byte-identical |
|
|
124
|
+
| `NOTES.md` | `learning/notes.md` | every note represented |
|
|
125
|
+
| `sources/*` | existing `sources/` | each source arrives byte-identical |
|
|
126
|
+
| `wiki/*` | existing `concepts/` | each knowledge page arrives byte-identical |
|
|
127
|
+
| `RESOURCES.md` | `references/teach-resources.md` | every catalog entry represented |
|
|
128
|
+
| `GLOSSARY.md` | Glossary section of `project/overview.md` | every term and definition represented |
|
|
129
|
+
| `index.md` | shared `index.md` | every teach catalog entry represented without replacing host orientation |
|
|
130
|
+
| `log.md` | shared `log.md` | every teach history entry represented without replacing host history |
|
|
131
|
+
|
|
132
|
+
The host's `AGENTS.md`, `index.md`, and `log.md` remain shared orientation/catalog
|
|
133
|
+
surfaces. `bc-wiki-maintain` may search host context and promote ordinary host evidence,
|
|
134
|
+
but it must not fabricate learning evidence, edit teach-owned records or Glossary terms, or
|
|
135
|
+
advance the review queue. Raw sources remain immutable. Existing host files are authoritative
|
|
136
|
+
in place; this marker alone implies no migration or copied pedagogy.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _hybrid_teach_adapter() -> str:
|
|
141
|
+
"""The adapter for a visible-layout hybrid host: only the glossary differs.
|
|
142
|
+
|
|
143
|
+
The glossary is the project's root `glossary.md`, shared with the project, so a
|
|
144
|
+
hybrid project keeps one vocabulary instead of a second teach-only glossary.
|
|
145
|
+
"""
|
|
146
|
+
text = TEACH_ADAPTER
|
|
147
|
+
for old, new in (
|
|
148
|
+
("| Glossary | the existing Glossary section of `project/overview.md` | `bc-teach` |",
|
|
149
|
+
"| Glossary | the project's root `glossary.md` (`../glossary.md`), shared with the project | the project; `bc-teach` adds and refines learner terms |"),
|
|
150
|
+
("""valid, `bc-teach` owns the Glossary section of `project/overview.md`; planning and maintenance
|
|
151
|
+
skills must leave that section alone, while non-glossary host sections remain available to
|
|
152
|
+
host maintenance.""",
|
|
153
|
+
"""valid, the Glossary is `glossary.md` at the project root, one level above `<teach-root>`,
|
|
154
|
+
shared with the project: `bc-teach` adds and refines the terms the learner needs there, in the
|
|
155
|
+
file's one-line format, and does not remove or redefine project terms without asking;
|
|
156
|
+
`bc-domain-modeling` and planning skills keep using the same file."""),
|
|
157
|
+
("| `GLOSSARY.md` | Glossary section of `project/overview.md` | every term and definition represented |",
|
|
158
|
+
"| `GLOSSARY.md` | the project's root `glossary.md` (`../glossary.md`) | every term represented in the one-line format; no project term removed or redefined without asking |"),
|
|
159
|
+
("may search host context and promote ordinary host evidence,",
|
|
160
|
+
"may search host context (it does not promote log entries in this layout),"),
|
|
161
|
+
("""but it must not fabricate learning evidence, edit teach-owned records or Glossary terms, or
|
|
162
|
+
advance the review queue.""",
|
|
163
|
+
"""but it must not fabricate learning evidence, edit teach-owned records, or advance the
|
|
164
|
+
review queue. The shared root `glossary.md` is a project file: keep the terms the learner
|
|
165
|
+
needs when maintaining it."""),
|
|
166
|
+
):
|
|
167
|
+
if old not in text:
|
|
168
|
+
raise RuntimeError(f"TEACH_ADAPTER text changed; update replacement {old!r}")
|
|
169
|
+
text = text.replace(old, new)
|
|
170
|
+
return text
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
TEACH_ADAPTER_HYBRID = _hybrid_teach_adapter()
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _teach_adapter_map_rows(text: str) -> tuple[tuple[str, str, str], ...] | None:
|
|
177
|
+
"""Return the hosted map rows from a marker, or None when its table is malformed."""
|
|
178
|
+
lines = text.splitlines()
|
|
179
|
+
try:
|
|
180
|
+
heading = lines.index("## Hosted teach path map")
|
|
181
|
+
except ValueError:
|
|
182
|
+
return None
|
|
183
|
+
|
|
184
|
+
rows: list[tuple[str, str, str]] = []
|
|
185
|
+
table_started = False
|
|
186
|
+
for line in lines[heading + 1:]:
|
|
187
|
+
if not table_started:
|
|
188
|
+
if line.startswith("| Teach surface | Hosted path | Owner |"):
|
|
189
|
+
table_started = True
|
|
190
|
+
continue
|
|
191
|
+
if not line.startswith("|"):
|
|
192
|
+
break
|
|
193
|
+
cells = [cell.strip() for cell in line.strip().strip("|").split("|")]
|
|
194
|
+
if cells == ["---", "---", "---"]:
|
|
195
|
+
continue
|
|
196
|
+
if len(cells) != 3:
|
|
197
|
+
return None
|
|
198
|
+
rows.append((cells[0], cells[1], cells[2]))
|
|
199
|
+
|
|
200
|
+
return tuple(rows) if table_started else None
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def is_valid_teach_adapter(text: str) -> bool:
|
|
204
|
+
"""Use one structural rule for scaffold upgrade notes and host selection."""
|
|
205
|
+
return (
|
|
206
|
+
text.startswith(TEACH_ADAPTER_MARKER + "\n")
|
|
207
|
+
and _teach_adapter_map_rows(text) in {
|
|
208
|
+
_teach_adapter_map_rows(TEACH_ADAPTER), _teach_adapter_map_rows(TEACH_ADAPTER_HYBRID)}
|
|
209
|
+
and bool(_teach_adapter_map_rows(text))
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
# --- root AGENTS.md (project root, points agents at the vault) ----------------
|
|
214
|
+
ROOT_AGENTS = """# Agent instructions for __SLUG__
|
|
215
|
+
|
|
216
|
+
This project has a local, project-scoped agent wiki at `.bc-agent/`.
|
|
217
|
+
|
|
218
|
+
Before making non-trivial changes, first read:
|
|
219
|
+
|
|
220
|
+
1. `.bc-agent/AGENTS.md` — this is a mandatory gate before opening any vault page for a fact. Do not use `index.md`, `map.md`, or `log.md` as a lookup shortcut, even if a user says the index is right there, lists everything, search can wait, or they already know this vault. Those are orientation hubs that can omit or preserve superseded facts; the vault instructions define the bounded retrieval and verification path.
|
|
221
|
+
2. Any page returned by that search that is relevant to the task
|
|
222
|
+
3. `.bc-agent/tasks/active.md` if work is already in flight
|
|
223
|
+
4. `.bc-agent/map.md` when choosing additional context
|
|
224
|
+
|
|
225
|
+
Keep the wiki live as you work: track in-flight work in
|
|
226
|
+
`.bc-agent/tasks/active.md`, check off plan steps, record forks as ADRs in
|
|
227
|
+
`.bc-agent/decisions/`, and append durable discoveries to `.bc-agent/log.md`
|
|
228
|
+
before finishing. See `.bc-agent/AGENTS.md` for the update triggers and protocol.
|
|
229
|
+
|
|
230
|
+
## Planning loop trigger
|
|
231
|
+
|
|
232
|
+
If the human's request sounds like planning future codebase work — feature ideas,
|
|
233
|
+
architecture direction, implementation strategy, slicing, or "what should we build/change" —
|
|
234
|
+
pause before implementing and ask whether they want to enter `/bc-plan-to-pipeline`.
|
|
235
|
+
If they are already asking for a concrete edit/fix, proceed normally. If the request is
|
|
236
|
+
about architectural runway, offer `/bc-improve-codebase-architecture` first. For code/hybrid
|
|
237
|
+
wikis, also check `.bc-agent/conventions/architecture-runway.md`: if enough PRD-sized
|
|
238
|
+
changes have landed since the last architecture review, give a brief optional nudge to run
|
|
239
|
+
`/bc-improve-codebase-architecture` before more planning.
|
|
240
|
+
|
|
241
|
+
See `.bc-agent/references/agent-skills.md` for the local skill map and
|
|
242
|
+
`.bc-agent/conventions/planning-workflow.md` for the loop.
|
|
243
|
+
|
|
244
|
+
## Scope rules
|
|
245
|
+
|
|
246
|
+
- Treat `.bc-agent/` as the source of durable agent context for THIS project only.
|
|
247
|
+
- Do not use or update `~/Wiki` for this project unless the human explicitly asks.
|
|
248
|
+
- Put all agent-created research, plans, scratch, and generated docs under `.bc-agent/`;
|
|
249
|
+
do not create `docs/`-style notes in source folders or the repo root unless asked.
|
|
250
|
+
- Source-tree README, existing `docs/`, and JSDoc follow `bc-codebase-docs` (one home,
|
|
251
|
+
current state, same-change). Do not apply that skill to this vault.
|
|
252
|
+
- Do not store personal, cross-project, or machine-global knowledge here.
|
|
253
|
+
|
|
254
|
+
## Update rules
|
|
255
|
+
|
|
256
|
+
- Stable project facts → `.bc-agent/project/`.
|
|
257
|
+
- Commands and paths → `.bc-agent/references/`.
|
|
258
|
+
- Coding, validation, and workflow norms → `.bc-agent/conventions/`.
|
|
259
|
+
- Temporary task context → `.bc-agent/tasks/active.md`.
|
|
260
|
+
- Longer research writeups → `.bc-agent/research/`, with durable conclusions summarized back.
|
|
261
|
+
- PRDs that were actually drafted/published → `.bc-agent/project/` and/or GitHub parent issues; do not label exploratory research as a PRD.
|
|
262
|
+
- Major irreversible / architectural choices → `.bc-agent/decisions/` (ADRs).
|
|
263
|
+
- Brief durable discoveries → `.bc-agent/log.md`.
|
|
264
|
+
|
|
265
|
+
## Planning & execution workflow
|
|
266
|
+
|
|
267
|
+
This project is wired for the grill→issues→drain loop. See
|
|
268
|
+
`.bc-agent/conventions/planning-workflow.md`:
|
|
269
|
+
|
|
270
|
+
- `/bc-plan-to-pipeline` — interactive planning (grill → domain capture → PRD → ready-for-agent issues).
|
|
271
|
+
- `/bc-pipeline-to-done` — autonomous (AFK) execution of the ready-for-agent queue.
|
|
272
|
+
|
|
273
|
+
## Publishing
|
|
274
|
+
|
|
275
|
+
- Agents may push their own commits and close directly-completed GitHub issues only
|
|
276
|
+
if a matching rule authorizes it in the user-owned publish policy
|
|
277
|
+
(`~/.config/agent-concepts/publish.yaml`). No matching rule ⇒ ask.
|
|
278
|
+
"""
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
# --- minimal Obsidian vault metadata ------------------------------------------
|
|
282
|
+
# Deliberately tiny/stable: no workspace.json, graph.json, or plugin state.
|
|
283
|
+
OBSIDIAN_APP = """{
|
|
284
|
+
"newFileLocation": "current",
|
|
285
|
+
"attachmentFolderPath": "attachments",
|
|
286
|
+
"promptDelete": false
|
|
287
|
+
}
|
|
288
|
+
"""
|
|
289
|
+
|
|
290
|
+
OBSIDIAN_CORE_PLUGINS = """[
|
|
291
|
+
"file-explorer",
|
|
292
|
+
"global-search",
|
|
293
|
+
"switcher",
|
|
294
|
+
"graph",
|
|
295
|
+
"backlink",
|
|
296
|
+
"canvas",
|
|
297
|
+
"outgoing-link",
|
|
298
|
+
"tag-pane",
|
|
299
|
+
"page-preview",
|
|
300
|
+
"daily-notes",
|
|
301
|
+
"templates",
|
|
302
|
+
"note-composer",
|
|
303
|
+
"command-palette",
|
|
304
|
+
"slash-command",
|
|
305
|
+
"editor-status",
|
|
306
|
+
"bookmarks",
|
|
307
|
+
"markdown-importer",
|
|
308
|
+
"properties",
|
|
309
|
+
"bases"
|
|
310
|
+
]
|
|
311
|
+
"""
|
|
312
|
+
|
|
313
|
+
OBSIDIAN_APPEARANCE = """{
|
|
314
|
+
"baseFontSize": 16,
|
|
315
|
+
"translucency": false
|
|
316
|
+
}
|
|
317
|
+
"""
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
# --- vault AGENTS.md (maintainer schema) --------------------------------------
|
|
321
|
+
# Keep this block byte-for-byte aligned with bc-wiki-maintain's pasteable vault
|
|
322
|
+
# instruction block. The scaffold runs it from the vault directory, where $PWD
|
|
323
|
+
# is the boundary that wiki_search.py must search.
|
|
324
|
+
CANONICAL_VAULT_READ_PATH = """<!-- BEGIN canonical vault read path -->
|
|
325
|
+
## First move: search the vault, do not read the index
|
|
326
|
+
|
|
327
|
+
For any task that needs a fact from this vault, run from the directory containing this
|
|
328
|
+
`AGENTS.md`. Find `wiki_search.py` next to the installed `bc-wiki-maintain` skill's
|
|
329
|
+
`SKILL.md`. Use that directory if your install differs from the default below;
|
|
330
|
+
`AGENT_CONCEPTS`, when set, overrides it with a contributor checkout.
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
VAULT_ROOT="$PWD"
|
|
334
|
+
wiki_skill_dir="$HOME/.agents/skills/bc-wiki-maintain"
|
|
335
|
+
if [ -n "${AGENT_CONCEPTS:-}" ]; then
|
|
336
|
+
wiki_skill_dir="$AGENT_CONCEPTS/concepts/bc-wiki-maintain/body"
|
|
337
|
+
fi
|
|
338
|
+
python3 "$wiki_skill_dir/wiki_search.py" \\
|
|
339
|
+
--limit 15 "$VAULT_ROOT" "term one" "term two"
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Use **2–4 meaningful content keywords**, not the user's full question. Open the relevant
|
|
343
|
+
returned path(s) and verify the answer in the page text. The corpus is tracked Markdown only:
|
|
344
|
+
a newly created page is invisible until `git add` registers it with Git. If the fact may be in
|
|
345
|
+
an untracked page, do not interpret an empty result as absence; add the page and rerun the
|
|
346
|
+
search. Otherwise, if output is empty, reformulate once with a different 2–4 keyword set;
|
|
347
|
+
empty output is not proof that this vault lacks the answer. If the top result is `index.md`,
|
|
348
|
+
`map.md`, or `log.md`, add a distinguishing term and search again — those are hub/orientation
|
|
349
|
+
pages, not answers. Do not grep `index.md` rows for lookup.
|
|
350
|
+
|
|
351
|
+
Use qmd only for a deliberate cross-vault lookup, with every collection named explicitly:
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
qmd search "term one term two" -c vault-a -c vault-b --format files -n 15
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Never run qmd unscoped, guess a collection from a `.agent`/`.bc-agent` basename, treat exit 0
|
|
358
|
+
or `[]` as proof of an answer's absence, or use `qmd query`. If `wiki_search.py` cannot run,
|
|
359
|
+
do not read the whole vault; use a bounded lexical candidate search and verify its pages.
|
|
360
|
+
|
|
361
|
+
Read `index.md` only for broad project orientation ("what is this project?"); never load it
|
|
362
|
+
whole or grep its rows to locate a page.
|
|
363
|
+
<!-- END canonical vault read path -->
|
|
364
|
+
"""
|
|
365
|
+
|
|
366
|
+
VAULT_AGENTS = """# __SLUG__ Agent Wiki — Maintainer Instructions
|
|
367
|
+
|
|
368
|
+
> **You are the primary user and maintainer of this wiki.** A human rarely reads it.
|
|
369
|
+
> It exists so you — and the next agent — can pick up work mid-flight with the verified
|
|
370
|
+
> facts, the decisions, and the live progress intact. **It is a living record, not a
|
|
371
|
+
> one-time writeup.** Do project work without updating it and you've left it stale.
|
|
372
|
+
|
|
373
|
+
This is the project-scoped wiki for `__SLUG__`, local to `.bc-agent/` and detached
|
|
374
|
+
from the user's personal `~/Wiki` (see [ADR-0001](decisions/adr-0001-local-project-agent-wiki.md)).
|
|
375
|
+
The repo-root `AGENTS.md` holds the scope/where-things-go rules; **this file is the
|
|
376
|
+
how-to-maintain schema.**
|
|
377
|
+
|
|
378
|
+
""" + CANONICAL_VAULT_READ_PATH + """
|
|
379
|
+
|
|
380
|
+
## The deal: keep it live or it's worthless
|
|
381
|
+
|
|
382
|
+
Update the wiki *in the same turn* as the work — not "later," not only when asked.
|
|
383
|
+
|
|
384
|
+
### Update triggers
|
|
385
|
+
|
|
386
|
+
| When you… | Do this |
|
|
387
|
+
|---|---|
|
|
388
|
+
| Start non-trivial work | Follow the canonical search-first read path above, then read the relevant returned pages and any in-flight plan. |
|
|
389
|
+
| Hear planning intent for codebase work | Before implementing, ask whether to enter `/bc-plan-to-pipeline`; offer `/bc-improve-codebase-architecture` first for architecture runway. For code/hybrid wikis, check `conventions/architecture-runway.md` and nudge if the PRD-count threshold has been reached. |
|
|
390
|
+
| Verify/learn a durable fact | Update the smallest relevant `project/` or `references/` page (dated); append a line to `log.md`. |
|
|
391
|
+
| Find a recurring command / path / gotcha | Put it in `references/commands.md` / `paths.md` / `gotchas.md`. |
|
|
392
|
+
| Learn something that contradicts a page | Fix the page; note it in `log.md`. Never leave a stale claim. |
|
|
393
|
+
| Make an architectural / irreversible choice | Add a numbered ADR in `decisions/` (`Proposed`→`Accepted`); link from `index.md`. |
|
|
394
|
+
| Sharpen domain vocabulary | Update the glossary in `project/overview.md` (canonical names; no implementation detail). |
|
|
395
|
+
| Begin a multi-step effort | Create a plan (`project/<name>-plan.md`, see `templates/plan.md`); point `tasks/active.md` at it. |
|
|
396
|
+
| Finish a step | Check its box in the plan; update `tasks/active.md`. |
|
|
397
|
+
| Get blocked | Set the plan `Status: Blocked`; record the blocker in `tasks/active.md`. |
|
|
398
|
+
| Finish / abandon a plan | Set `Status: Done`/`Abandoned`; log a line in `tasks/completed.md`; clear `tasks/active.md`. |
|
|
399
|
+
| A step fails or is skipped | Say so — in the plan and the log. The record reflects what happened. |
|
|
400
|
+
|
|
401
|
+
## Plans & the live layer
|
|
402
|
+
|
|
403
|
+
- A multi-step effort gets a **plan page** under `project/` from `templates/plan.md`.
|
|
404
|
+
- For `bc-grilling` + `bc-domain-modeling` or `bc-plan-to-pipeline` → `bc-pipeline-to-done` work, apply
|
|
405
|
+
`conventions/planning-workflow.md`: it maps generic `glossary.md`/`docs/adr/` persistence
|
|
406
|
+
into this vault's pages.
|
|
407
|
+
- Use `references/agent-skills.md` as the local map of required loop skills and where their
|
|
408
|
+
canonical bodies live in the shared agent-concepts workspace.
|
|
409
|
+
- **`tasks/active.md` is the live cursor.** Keep it true every session.
|
|
410
|
+
- `tasks/parking-lot.md` = deferred ideas. `tasks/completed.md` = dated done-log.
|
|
411
|
+
- Plan lifecycle: `Proposed → Approved → In progress → Blocked → Done / Abandoned`.
|
|
412
|
+
|
|
413
|
+
## Where things go
|
|
414
|
+
|
|
415
|
+
- `project/` — durable architecture, specs, plans, actual PRDs, and the **glossary** (`overview.md`).
|
|
416
|
+
- `research/` — exploratory notes/reports that may feed a PRD but are not themselves PRDs.
|
|
417
|
+
- `references/` — commands, paths, gotchas, external links.
|
|
418
|
+
- `conventions/` — validation, git, file-layout, planning-workflow, architecture-runway cadence.
|
|
419
|
+
- `decisions/` — ADRs (numbered, with `## Status`).
|
|
420
|
+
- `tasks/` — `active.md`, `parking-lot.md`, `completed.md`.
|
|
421
|
+
- `log.md` — append-only journal. `index.md` — catalog. `map.md` — context picker.
|
|
422
|
+
- When `references/teach-skill.md` exists, read it before using `bc-teach`: it is the
|
|
423
|
+
explicit adapter for the host's learning paths. `bc-teach` owns the mapped pedagogy,
|
|
424
|
+
evidence, review state, and the Glossary section of `project/overview.md`; this vault
|
|
425
|
+
owns host schema/orientation. Host search-first is for knowledge and learning-record
|
|
426
|
+
retrieval. Teach may directly read mapped known mission/review/notes state and the shared
|
|
427
|
+
catalog/recent history for session bookkeeping; those are not hub lookups. Do not create
|
|
428
|
+
a second `learning/sessions/` directory or migrate a standalone teach workspace. A host
|
|
429
|
+
choice alone never migrates it; destructive migration is teach's separate, explicit-request
|
|
430
|
+
operation and deletes originals only after destination verification.
|
|
431
|
+
- Long research → `.bc-agent/research/`; scratch → `.bc-agent/scratch/`.
|
|
432
|
+
|
|
433
|
+
## Maintenance discipline
|
|
434
|
+
|
|
435
|
+
- Don't invent facts. Unverified ⇒ say so or park it.
|
|
436
|
+
- Smallest relevant page; summarize, don't dump; no secrets / `.env` values.
|
|
437
|
+
- Keep everything project-local — never push project context into `~/Wiki`.
|
|
438
|
+
|
|
439
|
+
## Git discipline
|
|
440
|
+
|
|
441
|
+
- Inspect `git status` first; stage only your own changes. Commit before finishing.
|
|
442
|
+
- Push / close issues only per `conventions/git-and-commit-policy.md` and the user-owned
|
|
443
|
+
publish policy.
|
|
444
|
+
"""
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
INDEX = """# __SLUG__ Agent Wiki
|
|
448
|
+
|
|
449
|
+
The local, project-scoped agent wiki for `__SLUG__`. Detached from the user's personal
|
|
450
|
+
`~/Wiki`; use it only for context about this repository.
|
|
451
|
+
|
|
452
|
+
## Orientation
|
|
453
|
+
|
|
454
|
+
This catalog is for broad human-facing orientation. For a fact lookup, follow the
|
|
455
|
+
search-first read path in `AGENTS.md` rather than loading this page wholesale.
|
|
456
|
+
|
|
457
|
+
- [Agent maintainer instructions](AGENTS.md) — you maintain this wiki
|
|
458
|
+
- [Home](home.md)
|
|
459
|
+
- [Context map](map.md)
|
|
460
|
+
- [Project overview + glossary](project/overview.md)
|
|
461
|
+
- [Planning workflow: grill → issues → drain](conventions/planning-workflow.md)
|
|
462
|
+
- [Architecture runway cadence](conventions/architecture-runway.md)
|
|
463
|
+
- [Agent skill map](references/agent-skills.md)
|
|
464
|
+
- [Validation](conventions/validation.md)
|
|
465
|
+
- [Commands](references/commands.md)
|
|
466
|
+
- [ADR-0001: local project agent wiki](decisions/adr-0001-local-project-agent-wiki.md)
|
|
467
|
+
- [Active task context](tasks/active.md)
|
|
468
|
+
- [Agent log](log.md)
|
|
469
|
+
|
|
470
|
+
## Scope
|
|
471
|
+
|
|
472
|
+
This wiki may contain repo-specific architecture, workflow notes, build/validation
|
|
473
|
+
facts, project decisions, and recurring commands/gotchas. It must **not** contain
|
|
474
|
+
personal wiki content, cross-project preferences, secrets/credentials, or long raw logs.
|
|
475
|
+
|
|
476
|
+
This wiki is also a standalone Obsidian vault rooted at `.bc-agent/`.
|
|
477
|
+
"""
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
HOME = """# __SLUG__ Agent Wiki Home
|
|
481
|
+
|
|
482
|
+
Human-facing orientation for the local project agent wiki. For a fact lookup, follow the
|
|
483
|
+
search-first read path in `AGENTS.md` rather than treating this page as the source.
|
|
484
|
+
|
|
485
|
+
- [Agent instructions](AGENTS.md)
|
|
486
|
+
- [Index](index.md)
|
|
487
|
+
- [Context map](map.md)
|
|
488
|
+
- [Agent log](log.md)
|
|
489
|
+
- [Active tasks](tasks/active.md)
|
|
490
|
+
- [Project overview + glossary](project/overview.md)
|
|
491
|
+
- [Commands](references/commands.md)
|
|
492
|
+
- [Gotchas](references/gotchas.md)
|
|
493
|
+
|
|
494
|
+
## Scope reminder
|
|
495
|
+
|
|
496
|
+
This vault is local to `.bc-agent/` and detached from the user's personal `~/Wiki`.
|
|
497
|
+
"""
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
MAP = """# Context Map
|
|
501
|
+
|
|
502
|
+
This human-facing map helps choose the smallest context set after the canonical search path
|
|
503
|
+
in `AGENTS.md`; it is orientation, not the lookup mechanism. Extend the sections as the
|
|
504
|
+
project grows.
|
|
505
|
+
|
|
506
|
+
Link only targets that resolve inside this vault; leave external source-tree references as
|
|
507
|
+
inline code because they cannot participate in this graph.
|
|
508
|
+
|
|
509
|
+
## Always useful
|
|
510
|
+
|
|
511
|
+
- [project/overview.md](project/overview.md)
|
|
512
|
+
- [references/commands.md](references/commands.md)
|
|
513
|
+
- [conventions/validation.md](conventions/validation.md)
|
|
514
|
+
|
|
515
|
+
## Planning / workflow work
|
|
516
|
+
|
|
517
|
+
- [conventions/planning-workflow.md](conventions/planning-workflow.md)
|
|
518
|
+
- [conventions/architecture-runway.md](conventions/architecture-runway.md)
|
|
519
|
+
- [references/agent-skills.md](references/agent-skills.md)
|
|
520
|
+
- [conventions/git-and-commit-policy.md](conventions/git-and-commit-policy.md)
|
|
521
|
+
- [conventions/validation.md](conventions/validation.md)
|
|
522
|
+
- [log.md](log.md)
|
|
523
|
+
|
|
524
|
+
## Research or PRD work
|
|
525
|
+
|
|
526
|
+
- [conventions/planning-workflow.md](conventions/planning-workflow.md)
|
|
527
|
+
- [project/overview.md](project/overview.md)
|
|
528
|
+
- [research/README.md](research/README.md)
|
|
529
|
+
- [templates/plan.md](templates/plan.md)
|
|
530
|
+
|
|
531
|
+
## File / layout work
|
|
532
|
+
|
|
533
|
+
- [conventions/file-layout.md](conventions/file-layout.md)
|
|
534
|
+
- [references/paths.md](references/paths.md)
|
|
535
|
+
|
|
536
|
+
## Decisions
|
|
537
|
+
|
|
538
|
+
For architectural or durable workflow changes, check `decisions/` before adding a new ADR.
|
|
539
|
+
|
|
540
|
+
<!-- Add task-type sections (e.g. "Frontend work", "API work") as the project takes shape. -->
|
|
541
|
+
"""
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
LOG = """# Agent Log
|
|
545
|
+
|
|
546
|
+
Append-only journal of durable discoveries and session outcomes. Newest at the bottom.
|
|
547
|
+
One to three lines each; no transcripts or long command output.
|
|
548
|
+
|
|
549
|
+
## [__DATE__]
|
|
550
|
+
|
|
551
|
+
- Scaffolded the project agent workspace (root `AGENTS.md` + `.bc-agent/` vault) with
|
|
552
|
+
`bc-setup-project`. Ready for the grill → issues → drain workflow. Validation/file-layout
|
|
553
|
+
stubs still TODO.
|
|
554
|
+
"""
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
OVERVIEW = """# Project Overview
|
|
558
|
+
|
|
559
|
+
> One-paragraph description of `__SLUG__`: what it is, who it's for, the stack. **TODO:** fill
|
|
560
|
+
> this in as the project takes shape.
|
|
561
|
+
|
|
562
|
+
## Glossary
|
|
563
|
+
|
|
564
|
+
The project's shared vocabulary — canonical names for the domain concepts, no implementation
|
|
565
|
+
detail. When `references/teach-skill.md` is a valid adapter, `bc-teach` owns this Glossary section
|
|
566
|
+
and `bc-plan-to-pipeline` and maintenance leave it unchanged. Without that adapter,
|
|
567
|
+
`bc-domain-modeling` (paired with `bc-grilling` directly or used through `bc-plan-to-pipeline`) maintains
|
|
568
|
+
this as the project's `glossary.md`-equivalent. Keep it a pure glossary.
|
|
569
|
+
|
|
570
|
+
<!-- Term — one-line canonical definition. -->
|
|
571
|
+
|
|
572
|
+
_None captured yet._
|
|
573
|
+
|
|
574
|
+
## Agent context policy
|
|
575
|
+
|
|
576
|
+
All durable agent context for this repository belongs in `.bc-agent/`. This wiki is
|
|
577
|
+
detached from the user's personal `~/Wiki` and scoped to this repository only.
|
|
578
|
+
|
|
579
|
+
## Open questions
|
|
580
|
+
|
|
581
|
+
- What are the canonical validation commands? (fill `conventions/validation.md`)
|
|
582
|
+
- What is the source/build file layout? (fill `conventions/file-layout.md`)
|
|
583
|
+
- What is the primary deliverable / target?
|
|
584
|
+
"""
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
PLANNING_WORKFLOW = """# Planning Workflow: grill → issues → drain
|
|
588
|
+
|
|
589
|
+
Date: __DATE__
|
|
590
|
+
|
|
591
|
+
This project is wired for the full loop. Use the `bc-` orchestrators with this repo-local
|
|
592
|
+
adapter so planning persistence lands in `.bc-agent/` instead of generic
|
|
593
|
+
`glossary.md` / `docs/adr/` files. See `$AGENT_CONCEPTS/docs/guides/pipeline.md` for the loop.
|
|
594
|
+
|
|
595
|
+
## Planning intent trigger
|
|
596
|
+
|
|
597
|
+
When the human sounds like they are planning codebase work — feature ideas, refactor
|
|
598
|
+
direction, architecture strategy, implementation approach, or issue slicing — ask whether
|
|
599
|
+
they want to enter `/bc-plan-to-pipeline` before writing implementation code. If the request is
|
|
600
|
+
architectural runway rather than a settled feature, offer `/bc-improve-codebase-architecture`
|
|
601
|
+
first. If they clearly ask for a concrete edit/fix, proceed normally.
|
|
602
|
+
|
|
603
|
+
## Canonical repo-local planning surfaces
|
|
604
|
+
|
|
605
|
+
- **Glossary / domain facts:** the Glossary section of `project/overview.md` (or a dedicated
|
|
606
|
+
`project/glossary.md` if it grows). Without a valid teach adapter, this is this project's
|
|
607
|
+
`glossary.md`-equivalent and `bc-domain-modeling` / `bc-plan-to-pipeline` maintain it. With the adapter,
|
|
608
|
+
`bc-teach` owns the Glossary section; planning and maintenance skills leave that section alone.
|
|
609
|
+
- **ADRs:** numbered files under `decisions/` using `templates/adr.md`.
|
|
610
|
+
- **Plans / actual PRDs:** durable planning artifacts under `project/`, linked from `index.md`. Only call it a PRD when the PRD drafting/publishing step actually happened; exploratory notes stay under `research/` or as plans.
|
|
611
|
+
- **Research / evidence:** exploratory reports, architecture-review HTML summaries, and investigation writeups under `research/` (or temp storage if intentionally throwaway), with durable conclusions summarized back to `project/` / `decisions/`.
|
|
612
|
+
- **Skill map:** required loop skills and source paths in `references/agent-skills.md`.
|
|
613
|
+
- **Live cursor:** `tasks/active.md` while work is in flight.
|
|
614
|
+
- **Issue tracker:** GitHub issues via `gh`; intake uses `needs-triage` / `needs-info`;
|
|
615
|
+
ready agent work uses `ready-for-agent`; claimed work may show `in-progress-agent`;
|
|
616
|
+
parked work uses `needs-human`; durable rejections use `wontfix` plus `.bc-agent/out-of-scope/`.
|
|
617
|
+
- **Session log:** short durable notes appended to `log.md`.
|
|
618
|
+
|
|
619
|
+
## Intake and evidence — `/bc-triage`, `/bc-prototype`, `/bc-improve-codebase-architecture`
|
|
620
|
+
|
|
621
|
+
- Use `/bc-triage` for existing GitHub issues/PRs before they enter the loop: verify, ask for
|
|
622
|
+
missing info, write an Agent Brief, mark `ready-for-agent`, or record durable rejections in
|
|
623
|
+
`.bc-agent/out-of-scope/`.
|
|
624
|
+
- Use `/bc-prototype` when a state model or UI direction needs a throwaway artifact before the
|
|
625
|
+
PRD. Capture the verdict in `project/` or an ADR; don't send prototype code to the drain.
|
|
626
|
+
- Use `/bc-improve-codebase-architecture` when a feature or bug needs a deep-module runway before
|
|
627
|
+
slicing. Its report lives in temp storage; durable decisions go into `decisions/` or a plan.
|
|
628
|
+
- For code/hybrid wikis, also follow `conventions/architecture-runway.md`: nudge the human to
|
|
629
|
+
consider `/bc-improve-codebase-architecture` after enough PRD-sized implementation work has
|
|
630
|
+
landed since the last review.
|
|
631
|
+
|
|
632
|
+
## Planning — `/bc-plan-to-pipeline`
|
|
633
|
+
|
|
634
|
+
One command runs grill → domain capture → PRD → slices. When the underlying skills would
|
|
635
|
+
persist to generic `glossary.md` / `docs/adr/`, persist here instead:
|
|
636
|
+
|
|
637
|
+
- Canonical terminology → the glossary in `project/overview.md`.
|
|
638
|
+
- Costly + surprising + trade-off decision → `decisions/adr-NNNN-<slug>.md` (`templates/adr.md`).
|
|
639
|
+
- Multi-step feature direction → a `project/<feature>-plan.md` / `project/<feature>-prd.md`.
|
|
640
|
+
- Current progress/blockers → `tasks/active.md`.
|
|
641
|
+
|
|
642
|
+
The one-question-at-a-time grilling rule and the slicing quiz (the last human gate before
|
|
643
|
+
AFK) still apply. Don't write implementation code while major branches remain open.
|
|
644
|
+
|
|
645
|
+
## Execution — `/bc-pipeline-to-done`
|
|
646
|
+
|
|
647
|
+
Once planning leaves a `ready-for-agent` queue, `/bc-pipeline-to-done` executes it autonomously
|
|
648
|
+
(AFK): per unblocked issue it dispatches a fresh subagent that builds the slice test-first and
|
|
649
|
+
lands it **trunk-based**, then moves on.
|
|
650
|
+
|
|
651
|
+
- **Authorization.** Follow `/bc-pipeline-to-done` preflight for the target-branch push, including its
|
|
652
|
+
local-only fallback. Claim refs and issue mutations need separate authorization.
|
|
653
|
+
- **Validation gate.** The per-issue agent reads THIS repo's `conventions/validation.md` +
|
|
654
|
+
`references/commands.md` for what "validated" means — not a generic test command. Criteria
|
|
655
|
+
met **and** that validation clean = eligible to land.
|
|
656
|
+
- **Claim before work.** Follow `/bc-pipeline-to-done`' authorized claim protocol: no-force create-if-absent or lease-guarded reuse of a Released Claim Marker; skip a lost race before dispatch.
|
|
657
|
+
- **Trunk-based, not PRs.** Each slice commits → pushes to the target branch recorded by preflight → closes its issue with a
|
|
658
|
+
sha + validation comment. Dependent slices then see prior work immediately.
|
|
659
|
+
- **Parking.** A slice that can't complete cleanly is parked: comment on the issue, swap
|
|
660
|
+
`ready-for-agent` → `needs-human`, push nothing partial/RED. A run of consecutive parks
|
|
661
|
+
trips the circuit-breaker and stops the loop.
|
|
662
|
+
- **Bookkeeping.** Treat landed slices like any project work: update `tasks/active.md`/
|
|
663
|
+
`completed.md` and append a dated `log.md` line with issue numbers and commits.
|
|
664
|
+
|
|
665
|
+
## Clean handoff after planning
|
|
666
|
+
|
|
667
|
+
- Resolved scope in a `project/` plan/actual-PRD page or GitHub parent issue. Parent PRD issues are coordination artifacts; implementation slices get `ready-for-agent`.
|
|
668
|
+
- Durable trade-offs in `decisions/`.
|
|
669
|
+
- Independent `ready-for-agent` issues ordered by dependency, each with an Agent Brief / concrete acceptance criteria.
|
|
670
|
+
- `tasks/active.md` clear or pointing at the in-flight plan.
|
|
671
|
+
- A dated `log.md` line with issue numbers and changed pages.
|
|
672
|
+
"""
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
ARCHITECTURE_RUNWAY = """# Architecture Runway Cadence
|
|
676
|
+
|
|
677
|
+
Date: __DATE__
|
|
678
|
+
|
|
679
|
+
For code/hybrid wikis, this page gives a computed, optional signal for when to offer
|
|
680
|
+
`/bc-improve-codebase-architecture`. The signal comes from Git history; do not maintain a
|
|
681
|
+
counter in this file. The goal is to refresh architecture runway after enough durable project
|
|
682
|
+
work has accumulated, not after a calendar interval.
|
|
683
|
+
|
|
684
|
+
## Computed check
|
|
685
|
+
|
|
686
|
+
Run this before planning, refactor, or seam-adjacent work. It finds the newest commit whose
|
|
687
|
+
message names an architecture review, then counts commits touching the durable project and
|
|
688
|
+
live-task surfaces after that review:
|
|
689
|
+
|
|
690
|
+
```sh
|
|
691
|
+
review_tip="$(
|
|
692
|
+
git log --format='%H%x09%s' -- .bc-agent |
|
|
693
|
+
awk 'tolower($0) ~ /architecture.?review|arch.?review|improve-codebase-architecture/ { print $1; exit }'
|
|
694
|
+
)"
|
|
695
|
+
if [ -n "$review_tip" ]; then
|
|
696
|
+
review_range="$review_tip..HEAD"
|
|
697
|
+
else
|
|
698
|
+
review_range="HEAD"
|
|
699
|
+
fi
|
|
700
|
+
planning_commits="$(git log --format='%h %cs %s' "$review_range" -- .bc-agent/project .bc-agent/tasks)"
|
|
701
|
+
planning_count="$(printf '%s\\n' "$planning_commits" | sed '/^$/d' | wc -l)"
|
|
702
|
+
printf 'Planning-surface commits since the latest recognized architecture review: %s\\n' "$planning_count"
|
|
703
|
+
printf '%s\\n' "$planning_commits"
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
The `review_tip` lookup is deliberately fail-safe. If no review commit is recognizable, the
|
|
707
|
+
range includes all reachable history and the signal may over-count. Git can count commits and
|
|
708
|
+
paths; it cannot prove that a change was PRD-sized. Over-counting produces an optional nudge,
|
|
709
|
+
not an unsafe edit. If a review commit uses a different subject, the same fallback applies.
|
|
710
|
+
|
|
711
|
+
## Nudge heuristic
|
|
712
|
+
|
|
713
|
+
Give a brief, optional nudge when the current request is planning/refactor/seam-adjacent and
|
|
714
|
+
one of these is true:
|
|
715
|
+
|
|
716
|
+
- `planning_count` is 3 or higher. This is a conservative Git-derived proxy for the former
|
|
717
|
+
three-PRD / PRD-sized-slice threshold, not a claim that Git understands PRD semantics.
|
|
718
|
+
- The current work shows structural friction: unclear module boundaries, hard-to-test code,
|
|
719
|
+
repeated bugs around the same seam, or "where should this live?" uncertainty.
|
|
720
|
+
|
|
721
|
+
A request that is itself architecture-heavy can also qualify from its content. This page does
|
|
722
|
+
not pretend to compute that judgment from filenames or commit messages.
|
|
723
|
+
|
|
724
|
+
Do **not** block concrete fixes. The nudge is advisory:
|
|
725
|
+
|
|
726
|
+
> Optional architecture runway nudge: Git shows multiple planning-surface changes since the last recognized architecture review. Before planning more work, do you want to run `/bc-improve-codebase-architecture` to look for seams and testability improvements?
|
|
727
|
+
|
|
728
|
+
## Review record
|
|
729
|
+
|
|
730
|
+
A review has no hand-maintained entry here. Store the review artifact in the normal project
|
|
731
|
+
wiki location and include `architecture review` in the commit subject so the next computed check
|
|
732
|
+
can find its boundary. If the subject does not use that wording, the fail-safe fallback simply
|
|
733
|
+
counts more history and may nudge again.
|
|
734
|
+
|
|
735
|
+
## Agent update rules
|
|
736
|
+
|
|
737
|
+
- Run the computed check when the request is planning/refactor/seam-adjacent; do not edit this
|
|
738
|
+
page to record the result.
|
|
739
|
+
- When `/bc-improve-codebase-architecture` runs, commit its review artifact with an explicit
|
|
740
|
+
`architecture review` subject so future checks can establish a new boundary.
|
|
741
|
+
- If `references/agent-skills.md` no longer lists `/bc-improve-codebase-architecture`, remove the
|
|
742
|
+
nudge and explain why here.
|
|
743
|
+
"""
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
VALIDATION = """# Validation
|
|
747
|
+
|
|
748
|
+
> **TODO:** canonical validation commands are not established yet. Fill these in as you learn
|
|
749
|
+
> the project; `bc-pipeline-to-done` reads this page to know what "validated" means.
|
|
750
|
+
|
|
751
|
+
## Build / test validation
|
|
752
|
+
|
|
753
|
+
```sh
|
|
754
|
+
# TODO: the project's real build/test/lint commands, e.g.
|
|
755
|
+
# <test command>
|
|
756
|
+
# <lint / typecheck command>
|
|
757
|
+
# <build command>
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
## Baseline checks
|
|
761
|
+
|
|
762
|
+
```sh
|
|
763
|
+
git status --short
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
## Agent guidance
|
|
767
|
+
|
|
768
|
+
- After changing files, run the most relevant available validation.
|
|
769
|
+
- If no project-specific tests exist yet, verify syntax/structure and summarize what you checked.
|
|
770
|
+
- Do not claim build/test/runtime validation was run unless it actually ran.
|
|
771
|
+
- Add newly discovered canonical commands here and to `../references/commands.md`.
|
|
772
|
+
"""
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
# Visible-layout projects carry code; vault archetypes keep the base VALIDATION byte-identical.
|
|
776
|
+
VISIBLE_VALIDATION = """# Validation
|
|
777
|
+
|
|
778
|
+
Run from the repository root. `bc-pipeline-to-done` reads this page to know what "validated" means.
|
|
779
|
+
Each stage has one owner. **TODO:** replace each placeholder with the real command when the
|
|
780
|
+
first test or build step lands.
|
|
781
|
+
|
|
782
|
+
## While working
|
|
783
|
+
|
|
784
|
+
Owner: the worker, job or reviewer. Run targeted checks only: typecheck, lint, and the unit
|
|
785
|
+
tests affected by the change (name the test files or IDs). Budget: 60 s. Workers, jobs and
|
|
786
|
+
reviewers run no browser or e2e tests and not the full gate.
|
|
787
|
+
Why: each full run costs minutes and parallel workers multiply it; the full gate runs once on
|
|
788
|
+
the integrated tree.
|
|
789
|
+
|
|
790
|
+
```sh
|
|
791
|
+
# TODO: <typecheck command>
|
|
792
|
+
# TODO: <lint command>
|
|
793
|
+
# TODO: <run the named unit tests>
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
## Full gate
|
|
797
|
+
|
|
798
|
+
Owner: the session that integrates changes. `scripts/gate` holds every step (install,
|
|
799
|
+
typecheck, lint, all tests including every browser/e2e test, build) and runs them directly,
|
|
800
|
+
so CI runs the same file on a clean checkout. Start it in the background with a wake, through
|
|
801
|
+
the machine's offload wrapper if its agent instructions name one; otherwise run the script directly.
|
|
802
|
+
Budget 300 s, measured, not enforced:
|
|
803
|
+
pass it to the wrapper's budget option if available; otherwise time the run. Never wrap the gate in `timeout`:
|
|
804
|
+
an over-budget run must finish and count toward the two-in-a-row rule.
|
|
805
|
+
|
|
806
|
+
```sh
|
|
807
|
+
scripts/gate
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
- Run it once per integrated tree and record the tree SHA (`git rev-parse HEAD^{tree}`) and
|
|
811
|
+
the result in the work item's evidence. A parallel reviewer reports the gate as pending
|
|
812
|
+
instead of rerunning it; the parent combines the gate result with the review verdict before landing.
|
|
813
|
+
Why: the same tree gives the same result; a second run only adds minutes.
|
|
814
|
+
- Run one full gate at a time on a host; queue the others (an offload wrapper may do this).
|
|
815
|
+
Why: two gates on one host slow each other and the owner's machine.
|
|
816
|
+
- For a flaky failure, rerun only the failing tests, never the whole gate in a loop.
|
|
817
|
+
- Budget: 5 minutes on the host that runs it. After two over-budget runs in a row, open a work item
|
|
818
|
+
to make the gate fast again before more feature work.
|
|
819
|
+
Why: an unmeasured gate only grows, and every later change pays for it.
|
|
820
|
+
|
|
821
|
+
## Release
|
|
822
|
+
|
|
823
|
+
Owner: the session cutting a release. **TODO:** checks that run only before a release
|
|
824
|
+
(packaging, delivery or install checks), or "none yet".
|
|
825
|
+
|
|
826
|
+
## Baseline checks
|
|
827
|
+
|
|
828
|
+
```sh
|
|
829
|
+
git status --short
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
- Do not claim build/test/runtime validation was run unless it actually ran.
|
|
833
|
+
- Add newly discovered canonical commands here and to `../references/commands.md`.
|
|
834
|
+
|
|
835
|
+
## Test levels
|
|
836
|
+
|
|
837
|
+
The `bc-tdd` skill defines these levels.
|
|
838
|
+
|
|
839
|
+
- Level 1: unit (example-based) tests — on.
|
|
840
|
+
- Level 2: property-based tests — required for logic with a statable rule. They run inside the
|
|
841
|
+
project's test command, with no separate gate. **TODO:** when the first property test lands,
|
|
842
|
+
name the library here (Hypothesis, fast-check or proptest) and add it as a dev dependency.
|
|
843
|
+
Keep the local failure cache out of version control (Hypothesis already writes its own
|
|
844
|
+
`.gitignore` inside `.hypothesis/`; add any other library's cache to `.gitignore`). It is
|
|
845
|
+
machine-local state: add it to a sync tool's ignore list only when the project sits in a folder a sync tool
|
|
846
|
+
replicates.
|
|
847
|
+
- Level 3: off
|
|
848
|
+
|
|
849
|
+
<!-- Only the owner turns Level 3 (formal verification) on, one line per component: -->
|
|
850
|
+
<!-- Level 3: on — <component path> — <tool> <pinned version> — spec: <spec file> — command: <proof command> -->
|
|
851
|
+
<!-- A refused Level 3 suggestion is recorded so agents stop re-suggesting it: -->
|
|
852
|
+
<!-- Level 3 declined: <component>, <YYYY-MM-DD>, <reason> -->
|
|
853
|
+
"""
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
# `scripts/gate` exits non-zero until filled: a vacuous green gate would let CI report success
|
|
857
|
+
# for a project whose checks were never written, and red blocks landing until the first agent
|
|
858
|
+
# with a test command fills it in.
|
|
859
|
+
GATE_SCRIPT = """#!/usr/bin/env bash
|
|
860
|
+
# Full gate: every check the integrated tree must pass, run directly (no offload wrapper here) so
|
|
861
|
+
# CI runs this file unchanged. Agents run it through the machine's offload wrapper if its agent
|
|
862
|
+
# instructions name one; otherwise run the script directly.
|
|
863
|
+
# Stages and owners: .bc-agent/conventions/validation.md
|
|
864
|
+
set -euo pipefail
|
|
865
|
+
|
|
866
|
+
# TODO: replace the lines below with the real steps, in order, for example:
|
|
867
|
+
# <install command>
|
|
868
|
+
# <typecheck command>
|
|
869
|
+
# <lint command>
|
|
870
|
+
# <all tests, including every browser/e2e test>
|
|
871
|
+
# <build command>
|
|
872
|
+
echo "scripts/gate: no gate steps yet; fill in this file (see .bc-agent/conventions/validation.md)" >&2
|
|
873
|
+
exit 1
|
|
874
|
+
"""
|
|
875
|
+
|
|
876
|
+
CI_WORKFLOW = """# Runs the full gate on a clean checkout. Before landing, check the latest trunk run.
|
|
877
|
+
name: gate
|
|
878
|
+
on:
|
|
879
|
+
push:
|
|
880
|
+
pull_request:
|
|
881
|
+
jobs:
|
|
882
|
+
gate:
|
|
883
|
+
runs-on: ubuntu-latest
|
|
884
|
+
steps:
|
|
885
|
+
- uses: actions/checkout@v4
|
|
886
|
+
# TODO: add language setup and dependency installation before scripts/gate.
|
|
887
|
+
# Reuse existing CI; if none, use project lockfiles and language markers.
|
|
888
|
+
- run: scripts/gate
|
|
889
|
+
"""
|
|
890
|
+
|
|
891
|
+
EXECUTABLE_TARGETS = frozenset({"scripts/gate"})
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
FILE_LAYOUT = """# File Layout
|
|
895
|
+
|
|
896
|
+
> **TODO:** record the real top-level paths once known.
|
|
897
|
+
|
|
898
|
+
Known top-level paths at scaffold time:
|
|
899
|
+
|
|
900
|
+
- `AGENTS.md` — repo-root instructions pointing agents at this wiki
|
|
901
|
+
- `.bc-agent/` — this project-scoped agent wiki
|
|
902
|
+
|
|
903
|
+
## Agent guidance
|
|
904
|
+
|
|
905
|
+
- Confirm source/build relationships before editing generated-looking files.
|
|
906
|
+
- Keep local project wiki files under `.bc-agent/`.
|
|
907
|
+
- Do not add project context to the user's personal `~/Wiki`.
|
|
908
|
+
"""
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
GIT_POLICY = """# Git and Commit Policy
|
|
912
|
+
|
|
913
|
+
Normal git discipline applies.
|
|
914
|
+
|
|
915
|
+
## Agent guidance
|
|
916
|
+
|
|
917
|
+
- Inspect `git status` first; stage and commit only your own changes — never sweep up
|
|
918
|
+
unrelated edits the human has in progress.
|
|
919
|
+
- Commit agent-made changes before finishing the task.
|
|
920
|
+
- Push / close GitHub issues only when authorized by the user-owned publish policy
|
|
921
|
+
(`~/.config/agent-concepts/publish.yaml`). After pushing, agents may close issues
|
|
922
|
+
directly completed by the pushed work, leaving a comment with the commit SHA and a
|
|
923
|
+
validation summary; never close partially satisfied or adjacent issues.
|
|
924
|
+
- Keep commits scoped, with concise messages. Do not rewrite history or re-init Git unless asked.
|
|
925
|
+
"""
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
def ref_stub(title: str, body: str) -> str:
|
|
929
|
+
return f"# {title}\n\n{body}\n"
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
ADR_0001 = """# ADR 0001: Local Project Agent Wiki
|
|
933
|
+
|
|
934
|
+
Date: __DATE__
|
|
935
|
+
|
|
936
|
+
## Status
|
|
937
|
+
|
|
938
|
+
Accepted
|
|
939
|
+
|
|
940
|
+
## Context
|
|
941
|
+
|
|
942
|
+
Agents need durable project context while working in this repository, segregated from and
|
|
943
|
+
detached from the user's personal `~/Wiki`.
|
|
944
|
+
|
|
945
|
+
## Decision
|
|
946
|
+
|
|
947
|
+
Create a project-local wiki at `.bc-agent/` and a repo-root `AGENTS.md` that instructs
|
|
948
|
+
agents to use it as the project-scoped context source. The wiki must not depend on or update
|
|
949
|
+
`~/Wiki` unless the user explicitly asks.
|
|
950
|
+
|
|
951
|
+
## Consequences
|
|
952
|
+
|
|
953
|
+
- Project context travels with this repository.
|
|
954
|
+
- Agents begin with the vault's `AGENTS.md`; its first move is to search the vault using the canonical search path, and `index.md` remains for broad orientation only.
|
|
955
|
+
- Personal/global wiki context stays separate.
|
|
956
|
+
- Durable discoveries are committed with the project.
|
|
957
|
+
"""
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
ACTIVE = """# Active Tasks
|
|
961
|
+
|
|
962
|
+
The live cursor for in-flight work. Keep this true every session — the next agent's first
|
|
963
|
+
move is the search-first path in [AGENTS.md](../AGENTS.md), then it reads this page when work
|
|
964
|
+
is in flight.
|
|
965
|
+
|
|
966
|
+
## In flight
|
|
967
|
+
|
|
968
|
+
_None right now._
|
|
969
|
+
|
|
970
|
+
<!-- For a multi-step effort:
|
|
971
|
+
- **Plan:** [project/<name>-plan.md](../project/<name>-plan.md) — Status: In progress
|
|
972
|
+
- **On step:** 3 of 7 — <what you're doing now>
|
|
973
|
+
- **Blocker:** <none | description>
|
|
974
|
+
-->
|
|
975
|
+
|
|
976
|
+
## Temporary handoff notes
|
|
977
|
+
|
|
978
|
+
_None right now._
|
|
979
|
+
"""
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
PARKING = """# Parking Lot
|
|
983
|
+
|
|
984
|
+
Deferred / future ideas and wiki improvements.
|
|
985
|
+
|
|
986
|
+
- Fill `conventions/validation.md` with canonical commands once discovered.
|
|
987
|
+
- Fill `conventions/file-layout.md` once the source/build layout is known.
|
|
988
|
+
- Follow `/bc-pipeline-to-done` preflight before the first AFK drain.
|
|
989
|
+
"""
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
COMPLETED = """# Completed Tasks
|
|
993
|
+
|
|
994
|
+
## [__DATE__]
|
|
995
|
+
|
|
996
|
+
- Scaffolded the project agent workspace with `bc-setup-project`.
|
|
997
|
+
"""
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
TPL_ADR = """# ADR NNNN: <title>
|
|
1001
|
+
|
|
1002
|
+
Date: YYYY-MM-DD
|
|
1003
|
+
|
|
1004
|
+
## Status
|
|
1005
|
+
Proposed <!-- Proposed | Accepted | Superseded by ADR-XXXX | Rejected -->
|
|
1006
|
+
|
|
1007
|
+
## Context
|
|
1008
|
+
The situation and the question being decided. Link the findings/pages that motivate it.
|
|
1009
|
+
|
|
1010
|
+
## Decision
|
|
1011
|
+
What we chose.
|
|
1012
|
+
|
|
1013
|
+
## Alternatives considered
|
|
1014
|
+
What else we could have done, and why each lost.
|
|
1015
|
+
|
|
1016
|
+
## Consequences
|
|
1017
|
+
What this commits us to, follow-on work, and what it rules out.
|
|
1018
|
+
"""
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
TPL_PLAN = """# <Plan name>
|
|
1022
|
+
|
|
1023
|
+
Status: Proposed <!-- Proposed | Approved | In progress | Blocked | Done | Abandoned -->
|
|
1024
|
+
Updated: YYYY-MM-DD
|
|
1025
|
+
|
|
1026
|
+
## Goal
|
|
1027
|
+
The outcome in one or two sentences. Define what "done" means.
|
|
1028
|
+
|
|
1029
|
+
## Current state
|
|
1030
|
+
Verified reality today. Link relevant `project/`, `references/`, and `decisions/` pages.
|
|
1031
|
+
|
|
1032
|
+
## Approach
|
|
1033
|
+
The chosen strategy in a short paragraph. Link the ADR(s) that justify it.
|
|
1034
|
+
|
|
1035
|
+
## Steps
|
|
1036
|
+
Ordered and staged so each is independently checkable.
|
|
1037
|
+
- [ ] 1. …
|
|
1038
|
+
- [ ] 2. …
|
|
1039
|
+
|
|
1040
|
+
## Validation
|
|
1041
|
+
How each milestone is verified (link `conventions/validation.md` / the relevant commands).
|
|
1042
|
+
|
|
1043
|
+
## Risks & rollback
|
|
1044
|
+
What can go wrong and how to undo it.
|
|
1045
|
+
|
|
1046
|
+
## Open questions / blockers
|
|
1047
|
+
Unresolved items. If one blocks the plan, set `Status: Blocked` and note it in `tasks/active.md`.
|
|
1048
|
+
|
|
1049
|
+
## Links
|
|
1050
|
+
The ADRs, references, and project pages this plan rests on.
|
|
1051
|
+
"""
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
RESEARCH_README = """# Research
|
|
1055
|
+
|
|
1056
|
+
Long-form research writeups and investigation notes live here. Summarize durable conclusions
|
|
1057
|
+
back into the relevant `.bc-agent/` page and keep the long version here for the trail.
|
|
1058
|
+
"""
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
AGENT_SKILLS = """# Agent Skill Map
|
|
1062
|
+
|
|
1063
|
+
Date: __DATE__
|
|
1064
|
+
|
|
1065
|
+
The bc loop skills are canonical in `$AGENT_CONCEPTS/concepts/<skill>/body/SKILL.md`
|
|
1066
|
+
and are normally deployed into `~/.pi/agent/skills/<skill>` and `~/.agents/skills/<skill>`
|
|
1067
|
+
via symlink. Do not vendor/copy their bodies into this repo; use this page as the repo-local
|
|
1068
|
+
map so agents know what to invoke.
|
|
1069
|
+
|
|
1070
|
+
## Planning/execution loop
|
|
1071
|
+
|
|
1072
|
+
- `/bc-plan-to-pipeline` — interactive planning front: grill → domain capture → PRD → issue slices.
|
|
1073
|
+
- `/bc-pipeline-to-done` — AFK executor for `ready-for-agent` issue queues.
|
|
1074
|
+
- `/bc-improve-codebase-architecture` — optional architecture runway before planning/slicing.
|
|
1075
|
+
|
|
1076
|
+
## Supporting skills used by the loop
|
|
1077
|
+
|
|
1078
|
+
- Intake/evidence: `/bc-triage`, `/bc-prototype`.
|
|
1079
|
+
- Planning disciplines: `bc-grilling`, `bc-domain-modeling`, `bc-prd-drafting`, `bc-plan-slicing`, `bc-codebase-design`.
|
|
1080
|
+
- Source-tree docs: `bc-codebase-docs` — README / existing `docs/` / JSDoc only; not this vault.
|
|
1081
|
+
- Execution disciplines: `bc-tdd`, `bc-diagnosing-bugs`, `bc-optimize-code`.
|
|
1082
|
+
- Wiki maintenance: `/bc-wiki-maintain` — compute vault health, find index/search drift, and promote durable log entries without silently resolving contradictions.
|
|
1083
|
+
|
|
1084
|
+
## Agent behavior
|
|
1085
|
+
|
|
1086
|
+
If the user's request sounds like planning future codebase work, ask whether to enter
|
|
1087
|
+
`/bc-plan-to-pipeline` before implementing. Offer `/bc-improve-codebase-architecture` first when
|
|
1088
|
+
the main uncertainty is architecture/seams. In code/hybrid wikis, run the computed check in
|
|
1089
|
+
`conventions/architecture-runway.md` and give the optional architecture-runway nudge when its
|
|
1090
|
+
planning-surface signal reaches the threshold.
|
|
1091
|
+
"""
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
ARCHETYPE_READMES = {
|
|
1095
|
+
"ops": """# Operations / System Wiki
|
|
1096
|
+
|
|
1097
|
+
Use this archetype when the workspace tracks a real system, service, host, workflow, or local infrastructure rather than one codebase feature pipeline.
|
|
1098
|
+
|
|
1099
|
+
- `components/` — verified state of systems/tools/hosts.
|
|
1100
|
+
- `findings/` — recon and evidence with commands, dates, and conclusions.
|
|
1101
|
+
- `decisions/` — choices and supersessions.
|
|
1102
|
+
- `open-questions/` — assumptions that gate plans.
|
|
1103
|
+
- `plans/` — staged executable plans.
|
|
1104
|
+
""",
|
|
1105
|
+
"learning": """# Learning Wiki
|
|
1106
|
+
|
|
1107
|
+
Use this archetype when bc agents are helping the human learn a subject over time.
|
|
1108
|
+
|
|
1109
|
+
The generated `references/teach-skill.md` is an explicit, thin adapter for the
|
|
1110
|
+
standalone `bc-teach` skill. It maps teach's mission to `learning/plan.md`, its review
|
|
1111
|
+
queue to `learning/review.md`, records to `learning/records/`, notes to
|
|
1112
|
+
`learning/notes.md`, raw sources to `sources/`, compiled knowledge to `concepts/`,
|
|
1113
|
+
resources to `references/teach-resources.md`, the glossary to the existing Glossary
|
|
1114
|
+
section of `project/overview.md`, and catalog/history to the shared `index.md`/`log.md`.
|
|
1115
|
+
When the adapter is valid, teach owns that Glossary section; planning and maintenance
|
|
1116
|
+
skills leave it alone. Lessons and session artifacts use the existing `sessions/`
|
|
1117
|
+
directory; never create `learning/sessions/`. The adapter does not copy teach pedagogy
|
|
1118
|
+
or migrate standalone state. A host choice alone never migrates it; teach's separate
|
|
1119
|
+
explicit migration operation is destructive and verifies destinations before deleting
|
|
1120
|
+
standalone originals.
|
|
1121
|
+
|
|
1122
|
+
- `learning/` — host learning paths and the teach-owned mission/review/records/notes.
|
|
1123
|
+
- `sources/` — immutable raw source material.
|
|
1124
|
+
- `concepts/` — compiled knowledge pages.
|
|
1125
|
+
- `questions/` — open questions only; teach review prompts belong in `learning/review.md`.
|
|
1126
|
+
- `sessions/` — dated tutoring/session notes and lesson artifacts.
|
|
1127
|
+
""",
|
|
1128
|
+
"knowledge": """# Knowledge Graph Wiki
|
|
1129
|
+
|
|
1130
|
+
Use this archetype when the workspace is primarily for source ingest and compounding knowledge.
|
|
1131
|
+
|
|
1132
|
+
- `raw/` — immutable dropped source material.
|
|
1133
|
+
- `wiki/sources/` — one compiled page per source.
|
|
1134
|
+
- `wiki/entities/` — people, tools, projects, libraries, services.
|
|
1135
|
+
- `wiki/concepts/` — reusable ideas and patterns.
|
|
1136
|
+
- `wiki/syntheses/` — cross-source summaries and maps.
|
|
1137
|
+
|
|
1138
|
+
Raw sources stay immutable; agents maintain the compiled `wiki/` layer.
|
|
1139
|
+
""",
|
|
1140
|
+
"hybrid": """# Hybrid Wiki
|
|
1141
|
+
|
|
1142
|
+
Use this archetype when the repo needs both execution scaffolding and another durable knowledge mode.
|
|
1143
|
+
|
|
1144
|
+
Start with the normal `.bc-agent` project workflow, then promote material into the relevant folders:
|
|
1145
|
+
|
|
1146
|
+
- `components/` / `findings/` / `open-questions/` for operations-style system work.
|
|
1147
|
+
- `learning/` / `sources/` / `concepts/` / `sessions/` for teaching and study. When the
|
|
1148
|
+
teach adapter is present, use its exact mapping and keep `sessions/` shared; do not
|
|
1149
|
+
create `learning/sessions/` or a second review/knowledge home.
|
|
1150
|
+
- In hybrid learning/knowledge work, immutable raw material stays in the existing `sources/`
|
|
1151
|
+
and compiled source/entity/concept/synthesis pages stay under the existing `concepts/` tree;
|
|
1152
|
+
do not add a parallel `raw/` or `wiki/` tree.
|
|
1153
|
+
""",
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
def archetype_files(archetype: str) -> dict[str, str]:
|
|
1158
|
+
"""Optional archetype-specific seed files layered on top of the base project wiki."""
|
|
1159
|
+
common = {"archetype.md": ARCHETYPE_READMES[archetype]} if archetype in ARCHETYPE_READMES else {}
|
|
1160
|
+
if archetype == "ops":
|
|
1161
|
+
return common | {
|
|
1162
|
+
"components/README.md": "# Components\n\nVerified state of real systems, tools, hosts, and services.\n",
|
|
1163
|
+
"findings/README.md": "# Findings\n\nEvidence from recon, commands, research, or validation. Include method, date, observations, and conclusion.\n",
|
|
1164
|
+
"open-questions/README.md": "# Open Questions\n\nUnverified assumptions that gate or shape plans. Resolve by linking findings/decisions.\n",
|
|
1165
|
+
"plans/README.md": "# Plans\n\nExecutable operational plans with current status and checkable steps.\n",
|
|
1166
|
+
"templates/component.md": "# __TITLE__\n\n## Verified state\n\nTODO — include date and method.\n\n## Interfaces / dependencies\n\nTODO.\n\n## Gotchas\n\nTODO.\n",
|
|
1167
|
+
"templates/finding.md": "# __TITLE__\n\n## Method\n\nTODO — commands, sources, date.\n\n## Observations\n\nTODO.\n\n## Conclusion\n\nTODO.\n",
|
|
1168
|
+
"templates/open-question.md": "# __TITLE__\n\n## Question\n\nTODO.\n\n## Why it matters\n\nTODO.\n\n## Resolution\n\nOpen.\n",
|
|
1169
|
+
}
|
|
1170
|
+
if archetype == "learning":
|
|
1171
|
+
return common | {
|
|
1172
|
+
"learning/plan.md": "# Mission: TODO\n\nThis is the hosted mission surface for `bc-teach`; the skill owns its pedagogy and keeps the mission concrete. Use `<agent-concepts>/concepts/bc-teach/body/MISSION-FORMAT.md` for the format.\n\n## Why\n\nTODO.\n\n## Success looks like\n\n- TODO.\n\n## Constraints\n\n- TODO.\n\n## Out of scope\n\n- TODO.\n\nThe hosted review queue lives at `learning/review.md`; do not create a second `REVIEW.md`.\n",
|
|
1173
|
+
"learning/review.md": "# Review Queue\n\nThe `bc-teach` skill owns this spaced-repetition queue. Use `<agent-concepts>/concepts/bc-teach/body/REVIEW-FORMAT.md` and its `due.py` script; keep review state here rather than in `questions/` or a root `REVIEW.md`.\n",
|
|
1174
|
+
"learning/notes.md": "# Teach Notes\n\nThe `bc-teach` skill owns learner preferences and session notes here. This is the hosted counterpart of standalone `NOTES.md`; do not create a duplicate root notes file.\n",
|
|
1175
|
+
"learning/records/.gitkeep": "",
|
|
1176
|
+
"sources/README.md": "# Sources\n\nImmutable raw source material for the hosted `bc-teach` knowledge layer. The `bc-teach` skill owns ingestion and citations; preserve source files once saved.\n",
|
|
1177
|
+
"concepts/README.md": "# Concepts\n\nCompiled knowledge pages for the hosted `bc-teach` knowledge layer. Cite the existing `sources/` material; do not create a parallel `wiki/` for this learning workspace.\n",
|
|
1178
|
+
"questions/README.md": "# Questions\n\nOpen questions only. Teach review prompts and scheduling belong in `learning/review.md`; all learning evidence belongs in `learning/records/`.\n",
|
|
1179
|
+
"sessions/README.md": "# Sessions\n\nThe existing shared directory for dated tutoring/session notes and lesson artifacts from `bc-teach`. Do not create `learning/sessions/`.\n",
|
|
1180
|
+
"references/teach-skill.md": TEACH_ADAPTER,
|
|
1181
|
+
"references/teach-resources.md": "# Teach Resources\n\nThe hosted resource catalog for `bc-teach`. Use `<agent-concepts>/concepts/bc-teach/body/RESOURCES-FORMAT.md`; raw material belongs in the existing `sources/` directory.\n",
|
|
1182
|
+
"templates/learning-session.md": "# YYYY-MM-DD — Session\n\n## Goal\n\nTODO.\n\n## What changed\n\nTODO.\n\n## Misconceptions / review items\n\nTODO.\n\n## Next\n\nTODO.\n",
|
|
1183
|
+
}
|
|
1184
|
+
if archetype == "knowledge":
|
|
1185
|
+
return common | {
|
|
1186
|
+
"raw/README.md": "# Raw Sources\n\nDropped source material. Treat as immutable once ingested; corrections belong in compiled wiki pages.\n",
|
|
1187
|
+
"wiki/index.md": "# Compiled Wiki Index\n\nCatalog sources, entities, concepts, and syntheses here.\n",
|
|
1188
|
+
"wiki/log.md": "# Wiki Log\n\nAppend ingest, synthesis, and maintenance events here.\n",
|
|
1189
|
+
"wiki/sources/README.md": "# Sources\n\nOne compiled page per source with provenance and key claims.\n",
|
|
1190
|
+
"wiki/entities/README.md": "# Entities\n\nPeople, projects, tools, organizations, services, libraries.\n",
|
|
1191
|
+
"wiki/concepts/README.md": "# Concepts\n\nReusable ideas and patterns synthesized across sources.\n",
|
|
1192
|
+
"wiki/syntheses/README.md": "# Syntheses\n\nCross-source overviews, maps, contradictions, and evidence gaps.\n",
|
|
1193
|
+
}
|
|
1194
|
+
if archetype == "hybrid":
|
|
1195
|
+
files: dict[str, str] = dict(common)
|
|
1196
|
+
for name in ("ops", "learning"):
|
|
1197
|
+
files |= {path: text for path, text in archetype_files(name).items() if path != "archetype.md"}
|
|
1198
|
+
files |= {
|
|
1199
|
+
"concepts/entities/README.md": "# Entities\n\nPeople, projects, tools, organizations, services, and libraries compiled from the existing immutable `sources/` directory.\n",
|
|
1200
|
+
"concepts/syntheses/README.md": "# Syntheses\n\nCross-source summaries, maps, contradictions, and evidence gaps compiled under the existing `concepts/` knowledge home.\n",
|
|
1201
|
+
}
|
|
1202
|
+
return files
|
|
1203
|
+
return {}
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
def vault_files(archetype: str = "code") -> dict[str, str]:
|
|
1207
|
+
files = {
|
|
1208
|
+
"AGENTS.md": VAULT_AGENTS,
|
|
1209
|
+
"index.md": INDEX,
|
|
1210
|
+
"home.md": HOME,
|
|
1211
|
+
"map.md": MAP,
|
|
1212
|
+
"log.md": LOG,
|
|
1213
|
+
"project/overview.md": OVERVIEW,
|
|
1214
|
+
"references/commands.md": ref_stub(
|
|
1215
|
+
"Commands", "Recurring project commands. **TODO:** fill as discovered.\n\n_None yet._"),
|
|
1216
|
+
"references/paths.md": ref_stub(
|
|
1217
|
+
"Paths", "Important paths in this repo. **TODO:** fill as discovered.\n\n_None yet._"),
|
|
1218
|
+
"references/gotchas.md": ref_stub(
|
|
1219
|
+
"Gotchas", "Surprising behaviors and traps. **TODO:** fill as discovered.\n\n_None yet._"),
|
|
1220
|
+
"references/agent-skills.md": AGENT_SKILLS,
|
|
1221
|
+
"references/external-links.md": ref_stub(
|
|
1222
|
+
"External Links", "Useful external references for this project.\n\n_None yet._"),
|
|
1223
|
+
"conventions/planning-workflow.md": PLANNING_WORKFLOW,
|
|
1224
|
+
"conventions/architecture-runway.md": ARCHITECTURE_RUNWAY,
|
|
1225
|
+
"conventions/validation.md": VALIDATION,
|
|
1226
|
+
"conventions/file-layout.md": FILE_LAYOUT,
|
|
1227
|
+
"conventions/git-and-commit-policy.md": GIT_POLICY,
|
|
1228
|
+
"decisions/adr-0001-local-project-agent-wiki.md": ADR_0001,
|
|
1229
|
+
"tasks/active.md": ACTIVE,
|
|
1230
|
+
"tasks/parking-lot.md": PARKING,
|
|
1231
|
+
"tasks/completed.md": COMPLETED,
|
|
1232
|
+
"templates/adr.md": TPL_ADR,
|
|
1233
|
+
"templates/plan.md": TPL_PLAN,
|
|
1234
|
+
".obsidian/app.json": OBSIDIAN_APP,
|
|
1235
|
+
".obsidian/core-plugins.json": OBSIDIAN_CORE_PLUGINS,
|
|
1236
|
+
".obsidian/appearance.json": OBSIDIAN_APPEARANCE,
|
|
1237
|
+
}
|
|
1238
|
+
files.update(archetype_files(archetype))
|
|
1239
|
+
return files
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
def render(text: str, slug: str, date: str) -> str:
|
|
1243
|
+
return text.replace(SLUG, slug).replace(DATE, date)
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
# --- visible layout (code, ops, hybrid) ----------------------------------------
|
|
1247
|
+
# Project knowledge and the work lifecycle live in ordinary folders at the repo
|
|
1248
|
+
# root; `.bc-agent/` keeps agent mechanics only. Learning and knowledge
|
|
1249
|
+
# archetypes keep the vault above unchanged.
|
|
1250
|
+
|
|
1251
|
+
VISIBLE_ARCHETYPES = frozenset({"code", "ops", "hybrid"})
|
|
1252
|
+
WORK_STATUS_FOLDERS = ("1-planned", "2-active", "3-done", "4-dropped")
|
|
1253
|
+
WORK_INDEX_SCRIPT = Path(__file__).resolve().with_name("work_index.py")
|
|
1254
|
+
WORK_SPENT_SCRIPT = Path(__file__).resolve().with_name("work_spent.py")
|
|
1255
|
+
WHERE_THINGS_GO_HEADING = "## Where things go"
|
|
1256
|
+
# Stable role keys of the "Where things go" table. Other skills look a role up
|
|
1257
|
+
# with parse_where_things_go() instead of assuming a path.
|
|
1258
|
+
LAYOUT_ROLES = (
|
|
1259
|
+
"work-planned", "work-active", "work-done", "work-dropped", "ideas",
|
|
1260
|
+
"decisions", "research", "glossary", "requirements", "architecture",
|
|
1261
|
+
"project-skills", "project-agents",
|
|
1262
|
+
)
|
|
1263
|
+
# Role keys a project may add to its table; the scaffold does not write them.
|
|
1264
|
+
# agent-extras lists, comma-separated, extra `.bc-agent/` entries a tool reads by path,
|
|
1265
|
+
# so bc-wiki-maintain's lint accepts them as agent mechanics.
|
|
1266
|
+
OPTIONAL_LAYOUT_ROLES = ("agent-extras",)
|
|
1267
|
+
|
|
1268
|
+
_BASE_ROWS = (
|
|
1269
|
+
("work-planned", "work/1-planned/", "agreed work that has not started"),
|
|
1270
|
+
("work-active", "work/2-active/", "work in progress; several items may be active"),
|
|
1271
|
+
("work-done", "work/3-done/", "finished work, always inside a `<year>-<month>/` folder such as `2026-03/`"),
|
|
1272
|
+
("work-dropped", "work/4-dropped/", "abandoned work and rejected requests, with the reason"),
|
|
1273
|
+
("ideas", "work/0-ideas.md", "undecided ideas and observations, one line each"),
|
|
1274
|
+
("decisions", "docs/decisions/", "one numbered decision record per file"),
|
|
1275
|
+
("research", "docs/research/", "one `<date>-<slug>/` folder per investigation"),
|
|
1276
|
+
("glossary", "glossary.md", "canonical names for the project's domain concepts"),
|
|
1277
|
+
("requirements", "docs/PRD.md", "product-level spec, created on first need; a feature's requirements live in its work item"),
|
|
1278
|
+
("architecture", "ARCHITECTURE.md", "created on first need"),
|
|
1279
|
+
("project-skills", ".agents/skills/", "created on first need; one `local-<name>/` folder per skill, with a README naming shared copies and how to refresh them"),
|
|
1280
|
+
("project-agents", ".agents/agents/", "created on first need; one `local-<name>.md` file per agent, beside `.agents/skills/`"),
|
|
1281
|
+
)
|
|
1282
|
+
_OPS_ROWS = (
|
|
1283
|
+
("components", "docs/components/", "verified state of real systems, hosts, tools and services"),
|
|
1284
|
+
)
|
|
1285
|
+
_TEACH_ROWS = (
|
|
1286
|
+
("teach-workspace", ".bc-agent/references/teach-skill.md", "path map of the hosted `bc-teach` workspace; `bc-teach` owns `learning/`, `sources/`, `concepts/`, `sessions/`, `questions/` and `index.md` under `.bc-agent/`, and shares the project's `glossary.md`"),
|
|
1287
|
+
)
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
def layout_rows(archetype: str) -> tuple[tuple[str, str, str], ...]:
|
|
1291
|
+
rows = _BASE_ROWS
|
|
1292
|
+
if archetype in {"ops", "hybrid"}:
|
|
1293
|
+
rows += _OPS_ROWS
|
|
1294
|
+
if archetype == "hybrid":
|
|
1295
|
+
rows += _TEACH_ROWS
|
|
1296
|
+
return rows
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
def where_things_go_table(archetype: str) -> str:
|
|
1300
|
+
lines = ["| Role | Path | Notes |", "| --- | --- | --- |"]
|
|
1301
|
+
for role, path, note in layout_rows(archetype):
|
|
1302
|
+
lines.append(f"| {role} | {f'`{path}`' if path else '—'} | {note} |")
|
|
1303
|
+
return "\n".join(lines)
|
|
1304
|
+
|
|
1305
|
+
|
|
1306
|
+
_WHERE_THINGS_GO_LINE = re.compile(r"^" + re.escape(WHERE_THINGS_GO_HEADING) + r"[ \t]*\r?$", re.M)
|
|
1307
|
+
_UNDECIDED_PATH_CELLS = {"", "—", "-"}
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
def parse_where_things_go(text: str) -> dict[str, str]:
|
|
1311
|
+
"""Map each role key of a "Where things go" table to its path.
|
|
1312
|
+
|
|
1313
|
+
Paths are relative to the project root. A backticked path is unwrapped; a plain
|
|
1314
|
+
path is returned stripped; only `—`, `-` or an empty cell means "no decided path"
|
|
1315
|
+
and maps to an empty string. Raises ValueError when the heading line is missing,
|
|
1316
|
+
when the section has no table rows, or when a role appears twice.
|
|
1317
|
+
"""
|
|
1318
|
+
match = _WHERE_THINGS_GO_LINE.search(text)
|
|
1319
|
+
if not match:
|
|
1320
|
+
raise ValueError(f"no {WHERE_THINGS_GO_HEADING!r} section")
|
|
1321
|
+
section = re.split(r"^## ", text[match.end():], maxsplit=1, flags=re.M)[0]
|
|
1322
|
+
result: dict[str, str] = {}
|
|
1323
|
+
for line in section.splitlines():
|
|
1324
|
+
line = line.strip()
|
|
1325
|
+
if not line.startswith("|"):
|
|
1326
|
+
continue
|
|
1327
|
+
cells = [cell.strip() for cell in line.strip("|").split("|")]
|
|
1328
|
+
if len(cells) < 2 or cells[0] == "Role" or set(cells[0]) <= {"-", ":", " "}:
|
|
1329
|
+
continue
|
|
1330
|
+
role, path = cells[0], cells[1]
|
|
1331
|
+
if role in result:
|
|
1332
|
+
raise ValueError(f"role {role!r} appears twice in {WHERE_THINGS_GO_HEADING!r}")
|
|
1333
|
+
if path.count("`") >= 2:
|
|
1334
|
+
path = path.split("`")[1].strip()
|
|
1335
|
+
result[role] = "" if path in _UNDECIDED_PATH_CELLS else path
|
|
1336
|
+
if not result:
|
|
1337
|
+
raise ValueError(f"{WHERE_THINGS_GO_HEADING!r} section has no table rows")
|
|
1338
|
+
return result
|
|
1339
|
+
|
|
1340
|
+
|
|
1341
|
+
VISIBLE_ROOT = """# Agent instructions for __SLUG__
|
|
1342
|
+
|
|
1343
|
+
Before non-trivial work, read `.bc-agent/AGENTS.md`. It holds the "Where things go" table
|
|
1344
|
+
and the work-item rules; pick further context with `.bc-agent/map.md`.
|
|
1345
|
+
|
|
1346
|
+
## At a glance
|
|
1347
|
+
|
|
1348
|
+
- `work/` — what is planned, active, done and dropped. The folder an item sits in is its status.
|
|
1349
|
+
- `docs/decisions/`, `docs/research/` — decision records and investigations.
|
|
1350
|
+
- `glossary.md` — the project's vocabulary. Use its terms in code, issues and docs.
|
|
1351
|
+
- `.bc-agent/` — agent mechanics only: instructions, conventions, references, templates, scripts, log.
|
|
1352
|
+
|
|
1353
|
+
## Planning loop trigger
|
|
1354
|
+
|
|
1355
|
+
If the request sounds like planning future work (feature ideas, architecture direction,
|
|
1356
|
+
slicing, "what should we build"), pause and ask whether to enter `/bc-plan-to-pipeline`
|
|
1357
|
+
before implementing. A concrete edit or fix proceeds normally. When the question is
|
|
1358
|
+
architectural runway, check `.bc-agent/conventions/architecture-runway.md` and offer
|
|
1359
|
+
`/bc-improve-codebase-architecture` first. Skill map: `.bc-agent/references/agent-skills.md`.
|
|
1360
|
+
|
|
1361
|
+
## Scope rules
|
|
1362
|
+
|
|
1363
|
+
- Project knowledge goes where the table says, in the same commit as the work it describes.
|
|
1364
|
+
- Source-tree README files, other `docs/` pages and JSDoc follow `bc-codebase-docs`. It does
|
|
1365
|
+
not apply to the paths named in the "Where things go" table: those are records.
|
|
1366
|
+
- Keep personal, cross-project and machine-global knowledge out of this repository.
|
|
1367
|
+
- No secrets or `.env` values anywhere in tracked files.
|
|
1368
|
+
|
|
1369
|
+
## Publishing
|
|
1370
|
+
|
|
1371
|
+
Push commits or close issues only when a rule in the user-owned publish policy
|
|
1372
|
+
(`~/.config/agent-concepts/publish.yaml`) authorizes it. No matching rule: ask.
|
|
1373
|
+
Before landing, check the latest trunk CI run; red blocks landing anything except the change that makes it green.
|
|
1374
|
+
Why: a red trunk nobody looked at hides every later regression behind the first one.
|
|
1375
|
+
"""
|
|
1376
|
+
|
|
1377
|
+
VISIBLE_AGENTS = """# __SLUG__ — agent session protocol
|
|
1378
|
+
|
|
1379
|
+
Read this file before non-trivial work. Project knowledge lives in ordinary folders at the
|
|
1380
|
+
repository root so people can browse it; `.bc-agent/` holds agent mechanics only.
|
|
1381
|
+
|
|
1382
|
+
## Where things go
|
|
1383
|
+
|
|
1384
|
+
Paths are relative to the repository root. Skills look a role up in this table instead of
|
|
1385
|
+
assuming a path, so change a path here when the project keeps something elsewhere.
|
|
1386
|
+
|
|
1387
|
+
__TABLE__
|
|
1388
|
+
|
|
1389
|
+
__DEFAULT_PATH_RULE__
|
|
1390
|
+
|
|
1391
|
+
## Work items
|
|
1392
|
+
|
|
1393
|
+
- **Carry on with active work first.** When told to carry on without a named item, read every item
|
|
1394
|
+
in `work/2-active/` first. Unfinished active work comes before new items from `work/order.md`.
|
|
1395
|
+
Before taking an active item, check its `Held by:` line and recent commits for a live holder.
|
|
1396
|
+
If another agent is still working on it, ask that agent rather than take the item. Why: work
|
|
1397
|
+
already in flight comes first, but taking it from a live holder duplicates the work.
|
|
1398
|
+
|
|
1399
|
+
A work item is one feature or plan. Template: [templates/work-item.md](templates/work-item.md).
|
|
1400
|
+
|
|
1401
|
+
- **The folder is the status.** Move an item between status folders with `git mv`, in the
|
|
1402
|
+
same commit as the work that changes its state. Why: the tree then always shows what is
|
|
1403
|
+
planned, active, done and dropped, with nothing else to keep in step.
|
|
1404
|
+
- **No `Status:` line in an item.** Why: a written status can disagree with the folder.
|
|
1405
|
+
- **Finished items go into `work/3-done/<year>-<month>/`** (for example `work/3-done/2026-03/`);
|
|
1406
|
+
create the month folder when it is missing, and never put an item directly in `3-done/`.
|
|
1407
|
+
Why: one rule from the first item on means the folder never needs reorganizing.
|
|
1408
|
+
- **Dropped work and rejected requests go to `work/4-dropped/`**, with the reason under
|
|
1409
|
+
`## Outcome`. Why: a recorded "no, because" stops the same idea being re-argued.
|
|
1410
|
+
Asked to delete an item instead, move it anyway and write what you know, even if that is
|
|
1411
|
+
only "Dropped <date>; no reason given". Why: a deleted item frees its number for reuse, so
|
|
1412
|
+
older references to that number would point at a different item.
|
|
1413
|
+
- **Names are `<3-digit number>-<slug>`**, for example `012-search-ranking`. The next number
|
|
1414
|
+
is the highest number in any status folder, including the month folders under `3-done/`,
|
|
1415
|
+
plus one. Why: a short number is easy to cite and survives a rename of the slug.
|
|
1416
|
+
- **Only the main checkout creates numbered items.** Working in a git worktree, add a line
|
|
1417
|
+
to `work/0-ideas.md` instead. Why: two worktrees cannot see each other's numbers and
|
|
1418
|
+
would pick the same one.
|
|
1419
|
+
- **A small item is one file; a large one is a folder** `NNN-slug/` holding `plan.md` (its
|
|
1420
|
+
`## Steps` are the slices) and `requirements.md`, plus any evidence worth keeping. The folder
|
|
1421
|
+
moves as a whole. Why: everything about a feature stays in one place through its whole
|
|
1422
|
+
life, and the steps already are the slice map, so separate slice files would drift.
|
|
1423
|
+
- **Every open item has a `Stage:` line** directly under `Done when:`, naming one of the
|
|
1424
|
+
stages listed in order on the `Stages:` line below. Run `python3 .bc-agent/scripts/work_index.py`
|
|
1425
|
+
after adding, moving or changing an item or `work/order.md`; it rebuilds the table in
|
|
1426
|
+
[work/README.md](../work/README.md) in the order described below, and `--check` fails while
|
|
1427
|
+
it is stale.
|
|
1428
|
+
On a merge conflict inside the work-index markers, take either side and re-run the script.
|
|
1429
|
+
Why: the order of the pipeline is visible on one page without a second list to keep in step.
|
|
1430
|
+
- **Every open item has a `Blocked by:` line** under `Stage:`. It names the items that must
|
|
1431
|
+
finish first, by full name (`012-search-ranking`, comma-separated), or `nothing`.
|
|
1432
|
+
`work_index.py` rejects unknown names, dropped blockers, self-blocks and cycles, and never
|
|
1433
|
+
puts an item before what it waits for.
|
|
1434
|
+
Why: what each item waits for is written once, on the item, where it changes.
|
|
1435
|
+
- **The owner may rank open items in `work/order.md`**, a numbered list of item names, top
|
|
1436
|
+
first (`1. 012-search-ranking`). The table has three tiers: active items, then planned items
|
|
1437
|
+
an active item waits on, then other planned items. Within each tier listed items come first,
|
|
1438
|
+
in list order, unless an item waits on another; `work_index.py` rejects unknown and repeated
|
|
1439
|
+
names and skips done and dropped ones. Why: the owner's priority beats the computed tiebreaks, but
|
|
1440
|
+
never what an item waits for.
|
|
1441
|
+
- **An item may name its kind on a `Kind:` line** (security, bug, build, architecture,
|
|
1442
|
+
performance, tests, feature, docs, ...): what the item is, while `Source:` says who filed it.
|
|
1443
|
+
The owner's dashboard shows it. Why: placement in `work/order.md` follows the kind.
|
|
1444
|
+
- **`Needs owner: <what the owner must decide or do, and when>` flags owner work ahead.** Write
|
|
1445
|
+
it on any item that will need an owner decision or action before or during its build: a choice
|
|
1446
|
+
only the owner can make, an approval, an account or store action, a hands-on check. Remove it
|
|
1447
|
+
when that is settled, and record the decision as usual. Why: the owner's dashboard shows it, so
|
|
1448
|
+
the owner can plan time away.
|
|
1449
|
+
- **`Changes UI: <what the user will see change>` flags UI work.** Write it on any item whose build
|
|
1450
|
+
changes what users see or operate: screens, controls, labels, keys, layout, styling. Leave it off
|
|
1451
|
+
otherwise, and keep it current when the plan changes. Why: the owner's dashboard shows it, so the
|
|
1452
|
+
owner can plan when to review UI work.
|
|
1453
|
+
- **Never reorder `work/order.md`; place what you add.** When it exists, a new item whose kind is
|
|
1454
|
+
on the `Top kinds:` line below goes directly below the run of top-kind items at the top of the
|
|
1455
|
+
list (at the top when there is none; several new ones oldest first); any other new item goes
|
|
1456
|
+
directly above the first listed item that waits on it, or at the bottom. An item never goes above
|
|
1457
|
+
an item it waits on. No other line moves. Create the item file first, run `work_index.py --check`
|
|
1458
|
+
before touching `order.md`, and add the line exactly where it says. Why: once the line is listed,
|
|
1459
|
+
`--check` can no longer tell that a new item jumped ahead of one the owner placed.
|
|
1460
|
+
Before adding a `Blocked by:` line that names an item listed below this one, check with the owner.
|
|
1461
|
+
`work_index.py --check` fails while the file leaves out an open item or lists an item above
|
|
1462
|
+
one it waits on, and says where the item goes. Why: the owner sets this order on their
|
|
1463
|
+
dashboard, which lists every item and refuses a blocker below its dependant; an unplaced
|
|
1464
|
+
item or a new blocker silently pushed the owner's items to the bottom.
|
|
1465
|
+
- **A building block gets its own item.** When two items would wait on one step of a third,
|
|
1466
|
+
that step becomes its own item, and both name it. Why: an item can only wait on a whole item,
|
|
1467
|
+
and a shared building block buried in a large item hides what is ready.
|
|
1468
|
+
- **Before creating an item, look for overlap.** Search the open items and `work/0-ideas.md`.
|
|
1469
|
+
Fold the work into an existing item rather than starting a parallel one, and delete the idea
|
|
1470
|
+
lines the new item absorbs. Why: duplicated items drift apart and split one decision across two places.
|
|
1471
|
+
- **One item, one deliverable.** Split an item that holds several deliverables that could ship
|
|
1472
|
+
and be used separately. Why: a large item's later parts block nothing but still hide behind its first.
|
|
1473
|
+
- **Every planned item is planned before it starts.** `bc-plan-to-pipeline` writes a
|
|
1474
|
+
`Planned: bc-plan-to-pipeline <date>` line under `Source:` once the item has its requirements
|
|
1475
|
+
and sliced `## Steps`. Before an item without that line moves from `1-planned/` to
|
|
1476
|
+
`2-active/`, by hand, on "carry on" or by a drain, run `bc-plan-to-pipeline` on it from a
|
|
1477
|
+
settled source, in the same reply: it fills the item in place and asks only what is still open.
|
|
1478
|
+
When the owner said they are away (or the run is a drain) and a question stays open, file it
|
|
1479
|
+
where the owner sees questions (check the project's or machine's instructions), never in chat.
|
|
1480
|
+
If none is named, or the named place cannot be used, park the item: write
|
|
1481
|
+
`Waiting on owner: <question>` in its header, replacing any `Ready for agent:` line, and name it
|
|
1482
|
+
in the run report. Leave it in `1-planned/`, then move the next eligible planned item to `2-active/`
|
|
1483
|
+
and start it in the same run. Planning an item is part of carrying on, not a reason to stop:
|
|
1484
|
+
never end a reply that only says an item needs planning, a question needs filing or an item
|
|
1485
|
+
needs starting; do that work first. `work_index.py --check` warns about each planned item
|
|
1486
|
+
without the line.
|
|
1487
|
+
Why: an item filed without planning starts with unstated requirements and no slices, and the
|
|
1488
|
+
work drifts from what the owner decided.
|
|
1489
|
+
- **`Ready for agent: yes` lets an agent build an item unattended.** `bc-plan-to-pipeline`
|
|
1490
|
+
writes the line in the item header only when every step states its done-criteria and what is
|
|
1491
|
+
out of scope; `bc-pipeline-to-done` builds only items that carry it. Why: being planned is not
|
|
1492
|
+
consent to build without the owner; the line is.
|
|
1493
|
+
- **`Waiting on owner: <question>` parks an item.** It replaces the ready line: a parked item is
|
|
1494
|
+
not ready until the owner's answer is recorded in the item, the waiting line is removed and the
|
|
1495
|
+
ready line restored. `work_index.py` marks both lines in the table and rejects an item with both.
|
|
1496
|
+
Why: a question the owner has not answered must stop unattended work on it, visibly.
|
|
1497
|
+
- **A `Held by:` line says who is working on an item.** Its form is
|
|
1498
|
+
`Held by: <tool> <session> since <YYYY-MM-DD HH:MM> <UTC or +HH:MM>`: your agent tool
|
|
1499
|
+
(`pi`, `claude-code`, `codex`, ...), your session name or id without spaces, and when you
|
|
1500
|
+
started, for example `Held by: pi swift-otter since 2026-11-25 14:05 +01:00`. Add it under the
|
|
1501
|
+
other header lines in the commit that moves the item to `2-active/`, and when you resume an
|
|
1502
|
+
active item in your first commit on it (replacing a line another agent left only once you have
|
|
1503
|
+
checked that agent has stopped). Remove it in the commit with which you stop working on the item,
|
|
1504
|
+
even with steps left, and in the commit that moves it to done or dropped. A worker in a worktree
|
|
1505
|
+
leaves the line to the session that dispatched it. `work_index.py --check` warns about a
|
|
1506
|
+
malformed line and about one left in a done or dropped item.
|
|
1507
|
+
Why: the owner's dashboard shows who holds each active item and since when; a line left behind
|
|
1508
|
+
looks like live work, and a missing one looks abandoned.
|
|
1509
|
+
- **`Review:` and `Gate:` lines record a step's checks.** When a step is reviewed or the project's
|
|
1510
|
+
check (gate) command runs on it, add one line per result in the step's Notes, each on its own
|
|
1511
|
+
indented line under the step, oldest first, keeping earlier results:
|
|
1512
|
+
`Review: <approved | changes requested> by <reviewer> <YYYY-MM-DD>` (who reviewed: a reviewer
|
|
1513
|
+
agent or role, or `owner`) and `Gate: <pass | fail> <command> at <commit> <YYYY-MM-DD>` (the
|
|
1514
|
+
command as run and the short SHA the checked tree was built on), for example
|
|
1515
|
+
`Gate: pass make check at 3f2a9c1 2026-11-25`. Write them in the commit that ticks the step, or
|
|
1516
|
+
in the next commit on the item when the step stays open. `work_index.py --check` warns about a
|
|
1517
|
+
malformed line.
|
|
1518
|
+
Why: the owner's dashboard shows whether each step passed review and the gate; a result left in
|
|
1519
|
+
chat or a run log is lost.
|
|
1520
|
+
- **A `Spent:` line records what a finished item cost.** When you finish an item, run
|
|
1521
|
+
`python3 .bc-agent/scripts/work_spent.py <item-name>` and paste the line it prints, unchanged, as
|
|
1522
|
+
the last line of `## Outcome`, for example `Spent: 2h 10m active, 3.4M tokens, $5.20 (estimated;
|
|
1523
|
+
pi 3 sessions, claude-code no files, codex 0 sessions; other tools not counted)`. The script
|
|
1524
|
+
estimates it from the agent tools' own session files for the item's active period; never write
|
|
1525
|
+
or adjust the figures yourself, and paste a line that says `cost unknown` or `not measured` as it is.
|
|
1526
|
+
`--json` lists the sessions it counted. `work_index.py --check` warns about a malformed line.
|
|
1527
|
+
Why: the owner's dashboard shows what each item cost; a guessed figure is worse than none.
|
|
1528
|
+
- **Several items may be active at once.**
|
|
1529
|
+
- **GitHub issues are optional.** When one exists, record its number on the item's `Issue:`
|
|
1530
|
+
line. Why: the folders are the source of truth; an issue is a pointer to them.
|
|
1531
|
+
- **Undecided ideas and observations** are one line each in `work/0-ideas.md`. An idea
|
|
1532
|
+
becomes a numbered item in `work/1-planned/` once someone decides to do it.
|
|
1533
|
+
- **Open questions live in work items.** An unanswered question that blocks a piece of work
|
|
1534
|
+
is a step in that work item. A standalone question that someone must investigate is a
|
|
1535
|
+
planned work item whose answer lands in `docs/research/`. One not worth an item yet is a
|
|
1536
|
+
line in `work/0-ideas.md`. Why: `work/` stays the single place that shows what is pending.
|
|
1537
|
+
|
|
1538
|
+
Stages: now, next, later, unscheduled
|
|
1539
|
+
Top kinds: security, bug, build, architecture
|
|
1540
|
+
|
|
1541
|
+
## Keep it current
|
|
1542
|
+
|
|
1543
|
+
| When you… | Do this |
|
|
1544
|
+
| --- | --- |
|
|
1545
|
+
| Start non-trivial work | Read the items in `work/2-active/`, then pick context with [map.md](map.md). |
|
|
1546
|
+
| Begin agreed work | Create the item from the template, or `git mv` it from `1-planned/` to `2-active/`, add your `Held by:` line in the same commit (see Work items), then run `python3 .bc-agent/scripts/work_index.py`. A planned item without a `Planned:` line is planned first (see Work items). |
|
|
1547
|
+
| Resume an active item | Replace or add the `Held by:` line with your own in your first commit on it. |
|
|
1548
|
+
| Stop working on an item | Even with steps left: remove your `Held by:` line and commit. |
|
|
1549
|
+
| Finish a step | Check its box in the item, add its `Review:` and `Gate:` lines (see Work items), then run `python3 .bc-agent/scripts/work_index.py`. |
|
|
1550
|
+
| Finish or drop an item | Only once the work is on the main branch and its full checks passed (until then the remaining review fixes and checks stay unticked steps; a worker in a worktree never moves an item). Fill `## Outcome`, ending a finished item's with the `Spent:` line `python3 .bc-agent/scripts/work_spent.py <item-name>` prints (see Work items), remove the `Held by:` line, then `git mv` it to its done month folder or to `4-dropped/`, then run `python3 .bc-agent/scripts/work_index.py`. |
|
|
1551
|
+
| Make an architectural or hard-to-reverse choice | Add a numbered record under `docs/decisions/` from [templates/adr.md](templates/adr.md). |
|
|
1552
|
+
| Investigate something at length | Write it up in a dated folder under `docs/research/`. |
|
|
1553
|
+
__OPS_KEEP_CURRENT__| Sharpen domain vocabulary | Update `glossary.md`. |
|
|
1554
|
+
| Learn a recurring command | Add it to [references/commands.md](references/commands.md). |
|
|
1555
|
+
| Learn a durable fact with no better home | Append one to three lines to [log.md](log.md). |
|
|
1556
|
+
| Find a page that is wrong | Fix it in the same commit. Never leave a stale claim. |
|
|
1557
|
+
|
|
1558
|
+
## Discipline
|
|
1559
|
+
|
|
1560
|
+
- Do not invent facts. Mark anything unverified as unverified.
|
|
1561
|
+
- Inspect `git status` first, stage only your own changes, and commit before finishing.
|
|
1562
|
+
- Validation commands: [conventions/validation.md](conventions/validation.md). Git and
|
|
1563
|
+
publishing: [conventions/git-and-commit-policy.md](conventions/git-and-commit-policy.md).
|
|
1564
|
+
"""
|
|
1565
|
+
|
|
1566
|
+
HYBRID_TEACH_SECTION = """
|
|
1567
|
+
## Hosted teach workspace
|
|
1568
|
+
|
|
1569
|
+
This project also hosts a `bc-teach` learning workspace inside `.bc-agent/`. Read
|
|
1570
|
+
[references/teach-skill.md](references/teach-skill.md) before using `bc-teach`: it is the
|
|
1571
|
+
explicit adapter for the host's learning paths. `bc-teach` owns the mapped pedagogy,
|
|
1572
|
+
evidence and review state. There is one glossary: `glossary.md` at the repository root,
|
|
1573
|
+
shared with the project. `bc-teach` adds and refines the terms the learner needs there and
|
|
1574
|
+
does not remove or redefine project terms without asking.
|
|
1575
|
+
Host search-first is for knowledge and learning-record retrieval. Teach may directly read
|
|
1576
|
+
mapped known mission/review/notes state and the shared catalog/recent history for session
|
|
1577
|
+
bookkeeping. Do not create a second `learning/sessions/` directory or migrate a standalone
|
|
1578
|
+
teach workspace.
|
|
1579
|
+
|
|
1580
|
+
The read path below applies to teach knowledge pages and learning records under `.bc-agent/`.
|
|
1581
|
+
Project orientation is the "Where things go" table above, not `index.md`; `index.md`
|
|
1582
|
+
catalogs only the teach workspace.
|
|
1583
|
+
|
|
1584
|
+
"""
|
|
1585
|
+
|
|
1586
|
+
VISIBLE_MAP = """# Context Map
|
|
1587
|
+
|
|
1588
|
+
Choose the smallest set of pages for the task. Link only targets that resolve inside this vault
|
|
1589
|
+
(`.bc-agent/`); name files outside it in inline code, relative to the repository root.
|
|
1590
|
+
|
|
1591
|
+
## Always useful
|
|
1592
|
+
|
|
1593
|
+
- [AGENTS.md](AGENTS.md)
|
|
1594
|
+
- [references/commands.md](references/commands.md)
|
|
1595
|
+
- [conventions/validation.md](conventions/validation.md)
|
|
1596
|
+
|
|
1597
|
+
## Planning and workflow
|
|
1598
|
+
|
|
1599
|
+
- [templates/work-item.md](templates/work-item.md)
|
|
1600
|
+
- [conventions/architecture-runway.md](conventions/architecture-runway.md)
|
|
1601
|
+
- [references/agent-skills.md](references/agent-skills.md)
|
|
1602
|
+
- [conventions/git-and-commit-policy.md](conventions/git-and-commit-policy.md)
|
|
1603
|
+
- [log.md](log.md)
|
|
1604
|
+
|
|
1605
|
+
## Decisions and layout
|
|
1606
|
+
|
|
1607
|
+
- [templates/adr.md](templates/adr.md)
|
|
1608
|
+
- [conventions/file-layout.md](conventions/file-layout.md)
|
|
1609
|
+
__OPS_MAP__
|
|
1610
|
+
## Outside this folder
|
|
1611
|
+
|
|
1612
|
+
Work items are in `work/` (ideas in `work/0-ideas.md`), decision records in
|
|
1613
|
+
`docs/decisions/`, investigations in `docs/research/`, and vocabulary in `glossary.md`.
|
|
1614
|
+
The "Where things go" table in `AGENTS.md` is the full list.
|
|
1615
|
+
|
|
1616
|
+
Design, UI or CLI wording work (a control, a screen, a message, a design decision) starts at `docs/design/README.md`.
|
|
1617
|
+
|
|
1618
|
+
Work on a speed, size, memory or structure limit, or a check that protects one, starts at `docs/guardrails/README.md`.
|
|
1619
|
+
"""
|
|
1620
|
+
|
|
1621
|
+
VISIBLE_FILE_LAYOUT = """# File Layout
|
|
1622
|
+
|
|
1623
|
+
Where project knowledge and work items go: the "Where things go" table in
|
|
1624
|
+
[AGENTS.md](../AGENTS.md).
|
|
1625
|
+
|
|
1626
|
+
> **TODO:** record the real source and build paths once known.
|
|
1627
|
+
|
|
1628
|
+
## Agent guidance
|
|
1629
|
+
|
|
1630
|
+
- Confirm source/build relationships before editing generated-looking files.
|
|
1631
|
+
- The four `work/` status folders keep their `.gitkeep` file permanently. Why: git drops an
|
|
1632
|
+
empty folder, and every stage must stay visible even when it holds no items.
|
|
1633
|
+
"""
|
|
1634
|
+
|
|
1635
|
+
WORK_ITEM = """# <title>
|
|
1636
|
+
|
|
1637
|
+
Why: <the problem or goal, in one or two sentences>
|
|
1638
|
+
Done when: <the observable outcome that means this is finished>
|
|
1639
|
+
Stage: <one of the stages on the `Stages:` line in .bc-agent/AGENTS.md>
|
|
1640
|
+
Blocked by: <full names of the items this waits for, such as 012-search-ranking, or "nothing">
|
|
1641
|
+
Issue: <optional issue number; delete the line when there is none>
|
|
1642
|
+
Kind: <optional: security, bug, build, architecture, performance, tests, feature, docs, ...; delete the line when unclear>
|
|
1643
|
+
Needs owner: <optional: what the owner must decide or do, and when; delete the line when nothing, or once it is settled>
|
|
1644
|
+
Changes UI: <optional: what the user will see change, e.g. new launcher box in the side panel; delete the line when the build changes nothing users see or operate>
|
|
1645
|
+
Source: <optional: the skill or review that produced this item, e.g. bc-plan-to-pipeline; delete the line when unknown>
|
|
1646
|
+
Planned: <written by bc-plan-to-pipeline once it has planned this item, e.g. bc-plan-to-pipeline 2026-11-24; delete the line until then>
|
|
1647
|
+
Ready for agent: <optional: yes when every step states its done-criteria and out of scope, so bc-pipeline-to-done may build it unattended; delete the line otherwise>
|
|
1648
|
+
Waiting on owner: <optional: the question that parks this item; delete the line when there is none, and never keep it with Ready for agent>
|
|
1649
|
+
|
|
1650
|
+
## Steps
|
|
1651
|
+
|
|
1652
|
+
- [ ] <first step>
|
|
1653
|
+
|
|
1654
|
+
## Outcome
|
|
1655
|
+
|
|
1656
|
+
<Filled when the item is finished or dropped: what happened, or why it was dropped.>
|
|
1657
|
+
"""
|
|
1658
|
+
|
|
1659
|
+
IDEAS = """# Ideas
|
|
1660
|
+
|
|
1661
|
+
Undecided ideas and observations, one line each, newest at the bottom. An idea that
|
|
1662
|
+
someone decides to do becomes a numbered work item in `1-planned/`; delete its line here.
|
|
1663
|
+
"""
|
|
1664
|
+
|
|
1665
|
+
WORK_README = """# Work
|
|
1666
|
+
|
|
1667
|
+
The pipeline of work items. The folder an item sits in is its status:
|
|
1668
|
+
|
|
1669
|
+
- [`0-ideas.md`](0-ideas.md): undecided ideas, one line each.
|
|
1670
|
+
- [`1-planned/`](1-planned/): decided, not started.
|
|
1671
|
+
- [`2-active/`](2-active/): in progress.
|
|
1672
|
+
- [`3-done/`](3-done/): finished, filed by month.
|
|
1673
|
+
- [`4-dropped/`](4-dropped/): dropped, with the reason.
|
|
1674
|
+
|
|
1675
|
+
Each open item names its stage on a `Stage:` line and the items it waits for on a `Blocked by:`
|
|
1676
|
+
line. The table below never puts an item before what it waits for, and has three tiers: active
|
|
1677
|
+
items, then planned items an active item waits on, then other planned items; the owner's
|
|
1678
|
+
ranking in `order.md`, when present, orders each tier, before the `Stages:` line and the
|
|
1679
|
+
number (see [.bc-agent/AGENTS.md](../.bc-agent/AGENTS.md#work-items)).
|
|
1680
|
+
It is generated: run `python3 .bc-agent/scripts/work_index.py` after changing an item or
|
|
1681
|
+
`order.md`; `--check` fails while it is out of date.
|
|
1682
|
+
An item with a `Ready for agent: yes` line may be built unattended by `bc-pipeline-to-done`;
|
|
1683
|
+
one with a `Waiting on owner: <question>` line is parked until the owner answers. The Folder
|
|
1684
|
+
column marks both.
|
|
1685
|
+
Write project-specific notes outside the markers; the script keeps them.
|
|
1686
|
+
|
|
1687
|
+
<!-- work-index:start -->
|
|
1688
|
+
<!-- Generated by `python3 .bc-agent/scripts/work_index.py`; do not edit by hand. -->
|
|
1689
|
+
|
|
1690
|
+
| # | Item | Folder | Waits on | Unblocks | Why | Steps |
|
|
1691
|
+
| --- | --- | --- | --- | --- | --- | --- |
|
|
1692
|
+
|
|
1693
|
+
- [Ideas](0-ideas.md): 0
|
|
1694
|
+
- [Done](3-done/): 0
|
|
1695
|
+
- [Dropped](4-dropped/): 0
|
|
1696
|
+
<!-- work-index:end -->
|
|
1697
|
+
"""
|
|
1698
|
+
|
|
1699
|
+
GLOSSARY = """# Glossary
|
|
1700
|
+
|
|
1701
|
+
Canonical names for this project's domain concepts: one line each, no implementation
|
|
1702
|
+
detail. Use these terms in code, issues and docs.
|
|
1703
|
+
|
|
1704
|
+
_None captured yet._
|
|
1705
|
+
"""
|
|
1706
|
+
|
|
1707
|
+
HYBRID_INDEX = """# __SLUG__ — teach workspace catalog
|
|
1708
|
+
|
|
1709
|
+
Catalog of the hosted `bc-teach` workspace in this folder. `bc-teach` adds its entries here.
|
|
1710
|
+
Project work, decisions and research are not catalogued here; see the "Where things go"
|
|
1711
|
+
table in [AGENTS.md](AGENTS.md).
|
|
1712
|
+
|
|
1713
|
+
- [Teach host adapter](references/teach-skill.md)
|
|
1714
|
+
- [Teach resources](references/teach-resources.md)
|
|
1715
|
+
- [Mission](learning/plan.md)
|
|
1716
|
+
- [Review queue](learning/review.md)
|
|
1717
|
+
- [Notes](learning/notes.md)
|
|
1718
|
+
- [Sources](sources/README.md)
|
|
1719
|
+
- [Concepts](concepts/README.md)
|
|
1720
|
+
- [Questions](questions/README.md)
|
|
1721
|
+
- [Sessions](sessions/README.md)
|
|
1722
|
+
- [Log](log.md)
|
|
1723
|
+
"""
|
|
1724
|
+
|
|
1725
|
+
|
|
1726
|
+
DEFAULT_PATH_RULE = """When a skill names a default path for one of these roles (for example `docs/adr/`,
|
|
1727
|
+
`.bc-agent/project/overview.md` or `.bc-agent/out-of-scope/`), use this table's path for that
|
|
1728
|
+
role instead. Why: shared skills are written for several layouts, and this table is the
|
|
1729
|
+
project's own answer."""
|
|
1730
|
+
|
|
1731
|
+
VISIBLE_OPS_KEEP_CURRENT = """| Check the state of a real system | Update its page under `docs/components/` from [templates/component.md](templates/component.md). |
|
|
1732
|
+
| Record a finding | Write it under `docs/research/` from [templates/finding.md](templates/finding.md). |
|
|
1733
|
+
"""
|
|
1734
|
+
|
|
1735
|
+
# The project's design framework entry page: current truth only, no fixed page list.
|
|
1736
|
+
# Its generic method lives in the bc-design skill's design-framework.md.
|
|
1737
|
+
DESIGN_README = """# Design
|
|
1738
|
+
|
|
1739
|
+
This folder says how this product looks and behaves **now**. Agents and people
|
|
1740
|
+
read it before adding or changing anything a user sees or operates. The
|
|
1741
|
+
generic method behind it is `design-framework.md` in the `bc-design` skill.
|
|
1742
|
+
|
|
1743
|
+
<!-- Optional: if the project has a page for its screenshot and review conventions, link it here. -->
|
|
1744
|
+
|
|
1745
|
+
## Current truth vs decision log
|
|
1746
|
+
|
|
1747
|
+
- These pages state current behaviour only: one fact per line, no history.
|
|
1748
|
+
- Why something is so lives in the project's decision log. Link the decision
|
|
1749
|
+
number; do not copy its text.
|
|
1750
|
+
- A page line becomes true in the same commit as the code that makes it true.
|
|
1751
|
+
A decision may be logged earlier, when it is made.
|
|
1752
|
+
|
|
1753
|
+
## Where a rule lives
|
|
1754
|
+
|
|
1755
|
+
| If two people could... | It belongs in |
|
|
1756
|
+
|---|---|
|
|
1757
|
+
| disagree about it (taste, wording, trade-off) | a page here, stating the current choice, whoever made it |
|
|
1758
|
+
| only differ by mistake (a value, a look, a part) | shared code or a design token |
|
|
1759
|
+
| break it without noticing, and it can be found by text search | a check in the project's test suites, with a message naming the part and the page line |
|
|
1760
|
+
| only see it on screen (alignment, matching neighbours) | the screenshot review |
|
|
1761
|
+
|
|
1762
|
+
## Before adding or restyling a control
|
|
1763
|
+
|
|
1764
|
+
Name the existing part you are reusing for that kind of control. If the
|
|
1765
|
+
change needs something new (a colour, size, icon, wording or control kind),
|
|
1766
|
+
pick the closest fit to the existing look, define it once as a token or shared
|
|
1767
|
+
part, use it only from there, and record it on a page here in the same commit,
|
|
1768
|
+
marked as the agent's choice the owner may change. Ask the owner only to
|
|
1769
|
+
contradict a recorded decision, to remove something users rely on,
|
|
1770
|
+
or any case listed under **Stricter ask-cases**; never for taste calls.
|
|
1771
|
+
|
|
1772
|
+
## Stricter ask-cases
|
|
1773
|
+
|
|
1774
|
+
<!-- Optional: one line per extra case where this project wants the owner asked. -->
|
|
1775
|
+
|
|
1776
|
+
## Pages
|
|
1777
|
+
|
|
1778
|
+
<!-- Add one line per page as the project grows: `page.md`: the question it answers. -->
|
|
1779
|
+
|
|
1780
|
+
(none yet)
|
|
1781
|
+
|
|
1782
|
+
## Checks
|
|
1783
|
+
|
|
1784
|
+
<!-- List each design check: file, what it rejects, and how exceptions are marked. -->
|
|
1785
|
+
|
|
1786
|
+
(none yet)
|
|
1787
|
+
"""
|
|
1788
|
+
|
|
1789
|
+
# The project's guardrails page: its limits and checks, current values only.
|
|
1790
|
+
# Its generic method lives in the bc-performance-guardrails skill; no measuring script is scaffolded.
|
|
1791
|
+
GUARDRAILS_README = """# Guardrails
|
|
1792
|
+
|
|
1793
|
+
This page lists the limits this project must stay within: how fast, how small,
|
|
1794
|
+
how lean and how well-structured it is. Every limit has a check in
|
|
1795
|
+
`scripts/gate` that fails when a change breaks it. Agents read this page before
|
|
1796
|
+
changing anything that could make the project slower, bigger or more tangled.
|
|
1797
|
+
The generic method behind it is the `bc-performance-guardrails` skill.
|
|
1798
|
+
|
|
1799
|
+
Design-consistency checks live on the design page, `docs/design/README.md`,
|
|
1800
|
+
not here.
|
|
1801
|
+
|
|
1802
|
+
## Who chooses a limit
|
|
1803
|
+
|
|
1804
|
+
- Agents set limits themselves and mark each one as the agent's choice; the
|
|
1805
|
+
owner may change any of them.
|
|
1806
|
+
- A limit marked as the owner's choice is never loosened to make a check pass.
|
|
1807
|
+
Fix the change instead, or ask the owner.
|
|
1808
|
+
- A page line lands in the same commit as the check that enforces it.
|
|
1809
|
+
|
|
1810
|
+
## Where a rule lives
|
|
1811
|
+
|
|
1812
|
+
| Kind of check | What it does | Use it when |
|
|
1813
|
+
|---|---|---|
|
|
1814
|
+
| static | reads the source or settings without running anything | the problem shows in the code (a banned call, a forbidden import) |
|
|
1815
|
+
| artifact | measures a built output without running the program | the problem is size (download size, number of dependencies) |
|
|
1816
|
+
| dynamic | runs the program and measures | only running shows it (startup time, time per frame, memory) |
|
|
1817
|
+
|
|
1818
|
+
Use the cheapest kind that reliably catches the problem.
|
|
1819
|
+
|
|
1820
|
+
## How to measure
|
|
1821
|
+
|
|
1822
|
+
- With no limit yet, measure today's value with repeated runs, and set the
|
|
1823
|
+
limit at today's value plus an allowance for run-to-run noise. Anything worse
|
|
1824
|
+
fails; this is a ratchet.
|
|
1825
|
+
- After a verified improvement, tighten the limit in the same commit.
|
|
1826
|
+
- Write down the command and input used, so the next measurement matches.
|
|
1827
|
+
|
|
1828
|
+
## Targets
|
|
1829
|
+
|
|
1830
|
+
<!-- One line per user-facing target: measure, limit, published source, who chose it. -->
|
|
1831
|
+
|
|
1832
|
+
(none yet)
|
|
1833
|
+
|
|
1834
|
+
## Budgets
|
|
1835
|
+
|
|
1836
|
+
<!-- One line per measured limit: measure, limit, source (date, runs, median, allowance), who chose it. -->
|
|
1837
|
+
|
|
1838
|
+
(none yet)
|
|
1839
|
+
|
|
1840
|
+
## Checks
|
|
1841
|
+
|
|
1842
|
+
<!-- One line per check: file, what it rejects or measures, the target or budget it enforces. -->
|
|
1843
|
+
|
|
1844
|
+
(none yet)
|
|
1845
|
+
"""
|
|
1846
|
+
|
|
1847
|
+
VISIBLE_OPS_MAP = """
|
|
1848
|
+
## Operations
|
|
1849
|
+
|
|
1850
|
+
- [templates/component.md](templates/component.md)
|
|
1851
|
+
- [templates/finding.md](templates/finding.md)
|
|
1852
|
+
"""
|
|
1853
|
+
|
|
1854
|
+
VISIBLE_TEACH_MAP = """
|
|
1855
|
+
## Hosted teach workspace
|
|
1856
|
+
|
|
1857
|
+
- [references/teach-skill.md](references/teach-skill.md)
|
|
1858
|
+
- [index.md](index.md)
|
|
1859
|
+
"""
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
def _guarded(text: str, replacements: tuple[tuple[str, str], ...], name: str) -> str:
|
|
1863
|
+
for old, new in replacements:
|
|
1864
|
+
if old not in text:
|
|
1865
|
+
raise RuntimeError(f"{name} text changed; update replacement {old!r}")
|
|
1866
|
+
text = text.replace(old, new)
|
|
1867
|
+
return text
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
def _visible_log() -> str:
|
|
1871
|
+
return _guarded(LOG, (
|
|
1872
|
+
("""- Scaffolded the project agent workspace (root `AGENTS.md` + `.bc-agent/` vault) with
|
|
1873
|
+
`bc-setup-project`. Ready for the grill → issues → drain workflow. Validation/file-layout
|
|
1874
|
+
stubs still TODO.""", """- Scaffolded the project agent workspace with `bc-setup-project`: root `AGENTS.md`,
|
|
1875
|
+
`glossary.md`, `work/`, `docs/` and the `.bc-agent/` mechanics. Ready for the
|
|
1876
|
+
grill → issues → drain workflow. Validation/file-layout stubs still TODO."""),
|
|
1877
|
+
), "LOG")
|
|
1878
|
+
|
|
1879
|
+
|
|
1880
|
+
def _visible_agent_skills() -> str:
|
|
1881
|
+
return _guarded(AGENT_SKILLS, (
|
|
1882
|
+
("`bc-codebase-docs` — README / existing `docs/` / JSDoc only; not this vault.",
|
|
1883
|
+
"`bc-codebase-docs` — README files, other `docs/` pages and JSDoc; not `.bc-agent/` and not the paths named in the \"Where things go\" table in `.bc-agent/AGENTS.md`, which are records."),
|
|
1884
|
+
("- Wiki maintenance: `/bc-wiki-maintain` — compute vault health, find index/search drift, and promote durable log entries without silently resolving contradictions.\n",
|
|
1885
|
+
""),
|
|
1886
|
+
("In code/hybrid wikis, run", "Run"),
|
|
1887
|
+
), "AGENT_SKILLS")
|
|
1888
|
+
|
|
1889
|
+
|
|
1890
|
+
def _visible_runway() -> str:
|
|
1891
|
+
replacements = (
|
|
1892
|
+
("For code/hybrid wikis, this page", "This page"),
|
|
1893
|
+
("-- .bc-agent |", "-- docs/research |"),
|
|
1894
|
+
("-- .bc-agent/project .bc-agent/tasks", "-- docs work"),
|
|
1895
|
+
("normal project\nwiki location", "dated folder under\n`docs/research/`"),
|
|
1896
|
+
("\n\nThe `review_tip` lookup is deliberately",
|
|
1897
|
+
"\n\nThe snippet uses the default paths. If this project's \"Where things go\" table in\n"
|
|
1898
|
+
"`.bc-agent/AGENTS.md` names other paths, substitute the research and work paths from the\n"
|
|
1899
|
+
"\"Where things go\" table for `docs/research` and `docs work` before running it; otherwise\n"
|
|
1900
|
+
"the count misses the project's real planning surfaces.\n\nThe `review_tip` lookup is deliberately"),
|
|
1901
|
+
)
|
|
1902
|
+
return _guarded(ARCHITECTURE_RUNWAY, replacements, "architecture runway")
|
|
1903
|
+
|
|
1904
|
+
|
|
1905
|
+
def visible_targets(root: Path, slug: str, date: str, archetype: str) -> list[tuple[Path, str, bool]]:
|
|
1906
|
+
"""Scaffold targets for archetypes that use the visible layout."""
|
|
1907
|
+
has_ops = archetype in {"ops", "hybrid"}
|
|
1908
|
+
agents = (VISIBLE_AGENTS.replace("__TABLE__", where_things_go_table(archetype))
|
|
1909
|
+
.replace("__DEFAULT_PATH_RULE__", DEFAULT_PATH_RULE)
|
|
1910
|
+
.replace("__OPS_KEEP_CURRENT__", VISIBLE_OPS_KEEP_CURRENT if has_ops else ""))
|
|
1911
|
+
map_text = VISIBLE_MAP.replace("__OPS_MAP__", VISIBLE_OPS_MAP if has_ops else "")
|
|
1912
|
+
if archetype == "hybrid":
|
|
1913
|
+
map_text += VISIBLE_TEACH_MAP
|
|
1914
|
+
vault_files_: dict[str, str] = {
|
|
1915
|
+
"AGENTS.md": agents,
|
|
1916
|
+
"map.md": map_text,
|
|
1917
|
+
"log.md": _visible_log(),
|
|
1918
|
+
"conventions/validation.md": VISIBLE_VALIDATION,
|
|
1919
|
+
"conventions/file-layout.md": VISIBLE_FILE_LAYOUT,
|
|
1920
|
+
"conventions/architecture-runway.md": _visible_runway(),
|
|
1921
|
+
"conventions/git-and-commit-policy.md": GIT_POLICY,
|
|
1922
|
+
"references/commands.md": ref_stub(
|
|
1923
|
+
"Commands", "Recurring project commands. **TODO:** fill as discovered.\n\n_None yet._"),
|
|
1924
|
+
"references/agent-skills.md": _visible_agent_skills(),
|
|
1925
|
+
"templates/adr.md": TPL_ADR + "\n<!-- Save as `docs/decisions/NNNN-<slug>.md`. -->\n",
|
|
1926
|
+
"templates/work-item.md": WORK_ITEM,
|
|
1927
|
+
"scripts/work_index.py": WORK_INDEX_SCRIPT.read_text(),
|
|
1928
|
+
"scripts/work_spent.py": WORK_SPENT_SCRIPT.read_text(),
|
|
1929
|
+
}
|
|
1930
|
+
root_files: dict[str, str] = {
|
|
1931
|
+
"glossary.md": GLOSSARY,
|
|
1932
|
+
"work/0-ideas.md": IDEAS,
|
|
1933
|
+
"work/README.md": WORK_README,
|
|
1934
|
+
**{f"work/{stage}/.gitkeep": "" for stage in WORK_STATUS_FOLDERS},
|
|
1935
|
+
"docs/decisions/.gitkeep": "",
|
|
1936
|
+
"docs/research/.gitkeep": "",
|
|
1937
|
+
"docs/design/README.md": DESIGN_README,
|
|
1938
|
+
"docs/guardrails/README.md": GUARDRAILS_README,
|
|
1939
|
+
"scripts/gate": GATE_SCRIPT,
|
|
1940
|
+
".github/workflows/gate.yml": CI_WORKFLOW,
|
|
1941
|
+
}
|
|
1942
|
+
if has_ops:
|
|
1943
|
+
ops = archetype_files("ops")
|
|
1944
|
+
root_files["docs/components/README.md"] = ops["components/README.md"]
|
|
1945
|
+
for name in ("component", "finding"):
|
|
1946
|
+
vault_files_[f"templates/{name}.md"] = ops[f"templates/{name}.md"]
|
|
1947
|
+
if archetype == "hybrid":
|
|
1948
|
+
# Exactly the paths the hosted teach adapter maps; nothing else from the vault.
|
|
1949
|
+
vault_files_.update(
|
|
1950
|
+
{path: text for path, text in archetype_files("learning").items() if path != "archetype.md"})
|
|
1951
|
+
vault_files_.update(
|
|
1952
|
+
{path: text for path, text in archetype_files("hybrid").items() if path.startswith("concepts/")})
|
|
1953
|
+
vault_files_["references/teach-skill.md"] = TEACH_ADAPTER_HYBRID
|
|
1954
|
+
vault_files_["index.md"] = HYBRID_INDEX
|
|
1955
|
+
vault_files_["AGENTS.md"] = agents + HYBRID_TEACH_SECTION + CANONICAL_VAULT_READ_PATH
|
|
1956
|
+
vault = root / ".bc-agent"
|
|
1957
|
+
result = [(root / "AGENTS.md", render(VISIBLE_ROOT, slug, date), True)]
|
|
1958
|
+
result += [(vault / path, render(text, slug, date), False) for path, text in vault_files_.items()]
|
|
1959
|
+
result += [(root / path, render(text, slug, date), False) for path, text in root_files.items()]
|
|
1960
|
+
return result
|
|
1961
|
+
|
|
1962
|
+
|
|
1963
|
+
def targets(root: Path, slug: str, date: str, archetype: str = "code") -> list[tuple[Path, str, bool]]:
|
|
1964
|
+
"""Every file the scaffold owns: (destination, rendered content, is_root_AGENTS)."""
|
|
1965
|
+
if archetype in VISIBLE_ARCHETYPES:
|
|
1966
|
+
return visible_targets(root, slug, date, archetype)
|
|
1967
|
+
vault = root / ".bc-agent"
|
|
1968
|
+
out: list[tuple[Path, str, bool]] = [(root / "AGENTS.md", render(ROOT_AGENTS, slug, date), True)]
|
|
1969
|
+
for relpath, text in vault_files(archetype).items():
|
|
1970
|
+
out.append((vault / relpath, render(text, slug, date), False))
|
|
1971
|
+
out.append((vault / "research" / "README.md", render(RESEARCH_README, slug, date), False))
|
|
1972
|
+
out.append((vault / "out-of-scope" / ".gitkeep", "", False))
|
|
1973
|
+
out.append((vault / "scratch" / ".gitkeep", "", False))
|
|
1974
|
+
return out
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
def _contains(path: Path, needle: str) -> bool:
|
|
1978
|
+
try:
|
|
1979
|
+
return needle in path.read_text(errors="ignore")
|
|
1980
|
+
except OSError:
|
|
1981
|
+
return False
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
def _teach_notes(root: Path) -> list[str]:
|
|
1985
|
+
"""Hints about an existing teach adapter or standalone teach state."""
|
|
1986
|
+
vault = root / ".bc-agent"
|
|
1987
|
+
notes: list[str] = []
|
|
1988
|
+
adapter = vault / "references" / "teach-skill.md"
|
|
1989
|
+
if adapter.exists():
|
|
1990
|
+
try:
|
|
1991
|
+
adapter_text = adapter.read_text(encoding="utf-8")
|
|
1992
|
+
except OSError:
|
|
1993
|
+
adapter_text = ""
|
|
1994
|
+
if not is_valid_teach_adapter(adapter_text):
|
|
1995
|
+
notes.append(
|
|
1996
|
+
"existing references/teach-skill.md is not the explicit v1 teach adapter "
|
|
1997
|
+
"(exact first line plus the complete hosted path map); merge the generated "
|
|
1998
|
+
"path map by hand after checking existing state"
|
|
1999
|
+
)
|
|
2000
|
+
standalone_names = {
|
|
2001
|
+
"MISSION.md", "REVIEW.md", "GLOSSARY.md", "RESOURCES.md", "NOTES.md",
|
|
2002
|
+
"learning-records", "lessons",
|
|
2003
|
+
}
|
|
2004
|
+
# Compare exact directory entry names: on a case-insensitive filesystem a hybrid
|
|
2005
|
+
# project's shared root `glossary.md` would otherwise answer to `GLOSSARY.md`.
|
|
2006
|
+
try:
|
|
2007
|
+
root_names = {entry.name for entry in root.iterdir()}
|
|
2008
|
+
except OSError:
|
|
2009
|
+
root_names = set()
|
|
2010
|
+
if standalone_names & root_names:
|
|
2011
|
+
notes.append(
|
|
2012
|
+
"standalone teach state exists outside .bc-agent; do not migrate or copy it "
|
|
2013
|
+
"automatically — preserve it and ask the user before choosing between competing homes"
|
|
2014
|
+
)
|
|
2015
|
+
return notes
|
|
2016
|
+
|
|
2017
|
+
|
|
2018
|
+
EARLIER_LAYOUT_PATHS = (
|
|
2019
|
+
"tasks", "decisions", "research", "scratch", "out-of-scope", "home.md",
|
|
2020
|
+
"components", "findings", "open-questions", "plans",
|
|
2021
|
+
"conventions/planning-workflow.md", "templates/plan.md", "project", "index.md",
|
|
2022
|
+
)
|
|
2023
|
+
|
|
2024
|
+
|
|
2025
|
+
def earlier_layout_paths(root: Path, archetype: str) -> list[str]:
|
|
2026
|
+
"""Paths under .bc-agent/ that belong to the earlier vault layout.
|
|
2027
|
+
|
|
2028
|
+
Hybrid legitimately generates `index.md` as its teach catalog, so that is not
|
|
2029
|
+
counted for hybrid.
|
|
2030
|
+
"""
|
|
2031
|
+
own = {"index.md"} if archetype == "hybrid" else set()
|
|
2032
|
+
vault = root / ".bc-agent"
|
|
2033
|
+
return sorted(name for name in EARLIER_LAYOUT_PATHS
|
|
2034
|
+
if name not in own and (vault / name).exists())
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
def _inside_vault_map_bullet(root: Path, line: str) -> bool:
|
|
2038
|
+
"""True for an inline-code map bullet whose target is an existing file inside .bc-agent/.
|
|
2039
|
+
|
|
2040
|
+
A bullet naming a path outside the vault (relative to the repository root, as the
|
|
2041
|
+
map tells agents to write it) is not a missing link, even before that path exists:
|
|
2042
|
+
some project files are created on first need.
|
|
2043
|
+
"""
|
|
2044
|
+
if not line.startswith("- `"):
|
|
2045
|
+
return False
|
|
2046
|
+
target = line[3:].split("`", 1)[0]
|
|
2047
|
+
if not target or target.startswith("../"):
|
|
2048
|
+
return False
|
|
2049
|
+
return (root / ".bc-agent" / target).is_file()
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
def upgrade_notes(root: Path, archetype: str) -> list[str]:
|
|
2053
|
+
"""Manual merge hints for existing files that were intentionally left untouched."""
|
|
2054
|
+
vault = root / ".bc-agent"
|
|
2055
|
+
notes: list[str] = []
|
|
2056
|
+
if archetype in VISIBLE_ARCHETYPES:
|
|
2057
|
+
map_path = vault / "map.md"
|
|
2058
|
+
if map_path.exists() and any(
|
|
2059
|
+
_inside_vault_map_bullet(root, line)
|
|
2060
|
+
for line in map_path.read_text(errors="ignore").splitlines()):
|
|
2061
|
+
notes.append("`.bc-agent/map.md` should use real Markdown links for in-vault targets")
|
|
2062
|
+
if map_path.exists() and "`docs/design/README.md`" not in map_path.read_text(errors="ignore"):
|
|
2063
|
+
notes.append("`.bc-agent/map.md` has no line routing design, UI or CLI wording work to "
|
|
2064
|
+
"`docs/design/README.md` (see MIGRATIONS.md#design-readme)")
|
|
2065
|
+
if map_path.exists() and "`docs/guardrails/README.md`" not in map_path.read_text(errors="ignore"):
|
|
2066
|
+
notes.append("`.bc-agent/map.md` has no line routing speed, size, memory or structure limit "
|
|
2067
|
+
"work to `docs/guardrails/README.md` (see MIGRATIONS.md#guardrails-readme)")
|
|
2068
|
+
legacy = earlier_layout_paths(root, archetype)
|
|
2069
|
+
if legacy:
|
|
2070
|
+
notes.append(
|
|
2071
|
+
"earlier-layout paths exist under .bc-agent (" + ", ".join(legacy) + "); "
|
|
2072
|
+
"they were left in place and nothing was moved — migrating them to the visible "
|
|
2073
|
+
"layout is a separate, explicit step (see MIGRATIONS.md)")
|
|
2074
|
+
agents_path = vault / "AGENTS.md"
|
|
2075
|
+
if agents_path.exists() and not re.search(r"^Stages:", agents_path.read_text(errors="ignore"), re.M):
|
|
2076
|
+
notes.append("`.bc-agent/AGENTS.md` has no `Stages:` line; work_index.py falls back to now, next, later, unscheduled (see MIGRATIONS.md#work-index).")
|
|
2077
|
+
try:
|
|
2078
|
+
has_table = agents_path.exists() and bool(parse_where_things_go(agents_path.read_text(errors="ignore")))
|
|
2079
|
+
except ValueError:
|
|
2080
|
+
has_table = False
|
|
2081
|
+
if agents_path.exists() and not has_table:
|
|
2082
|
+
notes.append("`.bc-agent/AGENTS.md` has no \"Where things go\" table; skills cannot look paths up until it is added")
|
|
2083
|
+
work_readme = root / "work/README.md"
|
|
2084
|
+
if work_readme.exists() and "<!-- work-index:start -->" not in work_readme.read_text(errors="ignore"):
|
|
2085
|
+
notes.append("work/README.md has no work-index markers.")
|
|
2086
|
+
if archetype == "hybrid":
|
|
2087
|
+
notes.extend(_teach_notes(root))
|
|
2088
|
+
return notes
|
|
2089
|
+
|
|
2090
|
+
# This contract applies to every archetype. Keep it outside the code/hybrid
|
|
2091
|
+
# gate below so learning and knowledge vaults receive the same migration hint.
|
|
2092
|
+
read_path_checks = [
|
|
2093
|
+
(root / "AGENTS.md", "1. `.bc-agent/AGENTS.md`",
|
|
2094
|
+
"root AGENTS.md should make `.bc-agent/AGENTS.md` the first read and defer vault retrieval to its canonical search-first path"),
|
|
2095
|
+
(vault / "AGENTS.md", "<!-- BEGIN canonical vault read path -->",
|
|
2096
|
+
"`.bc-agent/AGENTS.md` should include the canonical search-first vault read path block from `bc-wiki-maintain`"),
|
|
2097
|
+
(vault / "map.md", "- [project/overview.md](project/overview.md)",
|
|
2098
|
+
"`.bc-agent/map.md` should use real Markdown links for in-vault targets so `bc-wiki-maintain` can validate its graph edges"),
|
|
2099
|
+
]
|
|
2100
|
+
for path, needle, message in read_path_checks:
|
|
2101
|
+
if path.exists() and not _contains(path, needle):
|
|
2102
|
+
notes.append(message)
|
|
2103
|
+
|
|
2104
|
+
if archetype in {"learning", "hybrid"}:
|
|
2105
|
+
notes.extend(_teach_notes(root))
|
|
2106
|
+
|
|
2107
|
+
# These existing upgrade hints depend on the code/hybrid architecture
|
|
2108
|
+
# overlay and remain scoped to those archetypes.
|
|
2109
|
+
if archetype not in {"code", "hybrid"}:
|
|
2110
|
+
return notes
|
|
2111
|
+
|
|
2112
|
+
checks = [
|
|
2113
|
+
(root / "AGENTS.md", "architecture-runway.md",
|
|
2114
|
+
"root AGENTS.md should point coding/planning requests at `.bc-agent/conventions/architecture-runway.md` for the optional `/bc-improve-codebase-architecture` nudge"),
|
|
2115
|
+
(vault / "AGENTS.md", "architecture-runway.md",
|
|
2116
|
+
"`.bc-agent/AGENTS.md` should mention the architecture-runway cadence in its planning-intent/update triggers"),
|
|
2117
|
+
(vault / "references" / "agent-skills.md", "architecture-runway.md",
|
|
2118
|
+
"`references/agent-skills.md` should tell agents to check the architecture-runway cadence when `/bc-improve-codebase-architecture` is relevant"),
|
|
2119
|
+
(vault / "index.md", "architecture-runway.md",
|
|
2120
|
+
"`index.md` should link to `conventions/architecture-runway.md`"),
|
|
2121
|
+
(root / "AGENTS.md", "bc-codebase-docs",
|
|
2122
|
+
"root AGENTS.md should point source-tree README/docs/JSDoc at `bc-codebase-docs` and keep that skill off `.bc-agent/`"),
|
|
2123
|
+
(vault / "references" / "agent-skills.md", "bc-codebase-docs",
|
|
2124
|
+
"`references/agent-skills.md` should list `bc-codebase-docs` for source-tree docs, not the vault"),
|
|
2125
|
+
(vault / "references" / "agent-skills.md", "bc-wiki-maintain",
|
|
2126
|
+
"`references/agent-skills.md` should list `/bc-wiki-maintain` as the canonical project-vault maintenance skill"),
|
|
2127
|
+
]
|
|
2128
|
+
for path, needle, message in checks:
|
|
2129
|
+
if path.exists() and not _contains(path, needle):
|
|
2130
|
+
notes.append(message)
|
|
2131
|
+
return notes
|
|
2132
|
+
|
|
2133
|
+
|
|
2134
|
+
def _preflight_targets(root: Path, planned: list[tuple[Path, str, bool]]) -> bool:
|
|
2135
|
+
"""Reject path-type collisions before the additive scaffold writes anything."""
|
|
2136
|
+
for destination, _content, _is_root in planned:
|
|
2137
|
+
try:
|
|
2138
|
+
relative = destination.relative_to(root)
|
|
2139
|
+
except ValueError:
|
|
2140
|
+
print(f"ERROR: scaffold target is outside root: {destination}")
|
|
2141
|
+
return False
|
|
2142
|
+
|
|
2143
|
+
parent = root
|
|
2144
|
+
for component in relative.parts[:-1]:
|
|
2145
|
+
parent /= component
|
|
2146
|
+
if parent.exists() and not parent.is_dir():
|
|
2147
|
+
print(f"ERROR: cannot create {destination}: parent is not a directory: {parent}")
|
|
2148
|
+
return False
|
|
2149
|
+
if destination.exists() and not destination.is_file():
|
|
2150
|
+
print(f"ERROR: scaffold target is not a regular file: {destination}")
|
|
2151
|
+
return False
|
|
2152
|
+
return True
|
|
2153
|
+
|
|
2154
|
+
# --- migrate mode: earlier `.bc-agent/` vault layout -> visible layout ----------------
|
|
2155
|
+
|
|
2156
|
+
RULE_WORK = ("only work still open becomes numbered work items in `work/` (main checkout, next free "
|
|
2157
|
+
"number); finished lists are kept unchanged as one dated record under the research role")
|
|
2158
|
+
RULE_IDEAS = "meaningful lines move to the ideas file `work/0-ideas.md`"
|
|
2159
|
+
RULE_DRAFTS = "drafts go inside their parent work item's folder as evidence"
|
|
2160
|
+
RULE_OVERVIEW = "glossary terms move to `glossary.md`; the rest is split by role"
|
|
2161
|
+
RULE_PRD = ("project-level -> `docs/PRD.md`; feature-level -> the work item's `requirements.md`")
|
|
2162
|
+
RULE_FINDINGS = "-> research role (`docs/research/`) as dated folders; take the date from git history"
|
|
2163
|
+
RULE_QUESTIONS = ("blocking -> a step in its work item; standalone -> a planned item with the answer in "
|
|
2164
|
+
"research; minor -> a line in the ideas file")
|
|
2165
|
+
RULE_DELETE_CHECKED = "delete after checking for unique content"
|
|
2166
|
+
RULE_UNRECOGNISED = "unrecognised; decide by hand"
|
|
2167
|
+
RULE_GENERATED_EDITED = ("differs from the generated version; carry unique local guidance into "
|
|
2168
|
+
"conventions or the work-item template, then delete")
|
|
2169
|
+
RULE_CLASH = "another file would land at {dest}; rename one by hand, then move both"
|
|
2170
|
+
RULE_ALREADY_THERE = "an identical copy already exists at {dest}; delete this one after checking links"
|
|
2171
|
+
RULE_OLD_AGENTS = ("replaced by the generated version; diff the old one (`git show HEAD:.bc-agent/AGENTS.md`, "
|
|
2172
|
+
"recoverable from git history) and carry project-specific rules into the new file")
|
|
2173
|
+
|
|
2174
|
+
# Earlier-layout vault folders whose files move unchanged; components only where the archetype has them.
|
|
2175
|
+
_MIGRATE_MOVERS = {"decisions": "docs/decisions", "research": "docs/research"}
|
|
2176
|
+
_MIGRATE_OPS_MOVERS = {"components": "docs/components"}
|
|
2177
|
+
_MIGRATE_GENERATED = {"conventions/planning-workflow.md": PLANNING_WORKFLOW, "templates/plan.md": TPL_PLAN}
|
|
2178
|
+
|
|
2179
|
+
|
|
2180
|
+
def _git(root: Path, *args: str) -> subprocess.CompletedProcess:
|
|
2181
|
+
return subprocess.run(["git", *args], cwd=root, capture_output=True, text=True)
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
def _matches_generated(text: str, template: str, slug: str) -> bool:
|
|
2185
|
+
"""True when text equals the template rendered for this slug with any ISO date."""
|
|
2186
|
+
pattern = re.escape(template.replace(SLUG, slug)).replace(re.escape(DATE), r"\d{4}-\d{2}-\d{2}")
|
|
2187
|
+
return re.fullmatch(pattern, text) is not None
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
def _measure(root: Path, path: str, files: list[str]) -> str:
|
|
2191
|
+
if len(files) == 1 and files[0] == path:
|
|
2192
|
+
try:
|
|
2193
|
+
return f"{len((root / path).read_text(errors='ignore').splitlines())} lines"
|
|
2194
|
+
except OSError:
|
|
2195
|
+
return "unreadable"
|
|
2196
|
+
return f"{len(files)} files"
|
|
2197
|
+
|
|
2198
|
+
|
|
2199
|
+
class MigrationPlan:
|
|
2200
|
+
def __init__(self) -> None:
|
|
2201
|
+
self.moves: list[tuple[str, str]] = []
|
|
2202
|
+
self.creates: list[tuple[str, str]] = []
|
|
2203
|
+
self.replaces: list[tuple[str, str]] = []
|
|
2204
|
+
self.deletes: list[str] = []
|
|
2205
|
+
self.kept: list[str] = []
|
|
2206
|
+
self.judgment: list[tuple[str, str, str]] = []
|
|
2207
|
+
self.refusals: list[str] = []
|
|
2208
|
+
self.link_edits: dict[str, str] = {} # new path -> rewritten text
|
|
2209
|
+
self.link_count = 0
|
|
2210
|
+
self.link_files: set[str] = set() # new paths of files with a rewritten Markdown link
|
|
2211
|
+
self.unresolved: list[str] = []
|
|
2212
|
+
self.wikilink_count = 0
|
|
2213
|
+
self.wikilink_files: set[str] = set() # new paths of files with a rewritten wikilink
|
|
2214
|
+
self.ambiguous_wikilinks: list[str] = [] # file:line of bare names matching several files
|
|
2215
|
+
self.stay_wikilinks: list[str] = [] # file:line in a moved file naming a file that stays
|
|
2216
|
+
self.other_refs: list[str] = []
|
|
2217
|
+
|
|
2218
|
+
|
|
2219
|
+
_INLINE_LINK = re.compile(r"(\]\()(<[^>\n]*>|[^)\s]+)")
|
|
2220
|
+
_REF_DEFINITION = re.compile(r"^( {0,3}\[[^\]\n]+\]:[ \t]+)(<[^>\n]*>|\S+)")
|
|
2221
|
+
_FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})")
|
|
2222
|
+
_INLINE_CODE = re.compile(r"(`+)[^`\n]*?\1")
|
|
2223
|
+
_WIKILINK = re.compile(r"(!?)\[\[([^\[\]\n]+)\]\]")
|
|
2224
|
+
_URL_SCHEME = re.compile(r"^[A-Za-z][A-Za-z0-9+.-]*:")
|
|
2225
|
+
|
|
2226
|
+
|
|
2227
|
+
def _map_moved(path: str, file_moves: dict[str, str], dir_moves: dict[str, str]) -> str:
|
|
2228
|
+
if path in file_moves:
|
|
2229
|
+
return file_moves[path]
|
|
2230
|
+
for old_dir, new_dir in dir_moves.items():
|
|
2231
|
+
if path == old_dir or path.startswith(old_dir + "/"):
|
|
2232
|
+
return new_dir + path[len(old_dir):]
|
|
2233
|
+
return path
|
|
2234
|
+
|
|
2235
|
+
|
|
2236
|
+
def _rewrite_target(root: Path, target: str, old_file: str, new_file: str,
|
|
2237
|
+
file_moves: dict[str, str], dir_moves: dict[str, str]) -> str | None:
|
|
2238
|
+
"""New link text for target, the same text when unchanged, or None when it does not resolve."""
|
|
2239
|
+
bracketed = target.startswith("<") and target.endswith(">")
|
|
2240
|
+
raw = target[1:-1] if bracketed else target
|
|
2241
|
+
if not raw or raw.startswith(("#", "/")) or _URL_SCHEME.match(raw):
|
|
2242
|
+
return target
|
|
2243
|
+
cut = min((i for i in (raw.find("#"), raw.find("?")) if i >= 0), default=len(raw))
|
|
2244
|
+
path_part, suffix = raw[:cut], raw[cut:]
|
|
2245
|
+
if not path_part:
|
|
2246
|
+
return target
|
|
2247
|
+
resolved = os.path.normpath(os.path.join(os.path.dirname(old_file), urllib.parse.unquote(path_part)))
|
|
2248
|
+
if resolved.startswith("..") or not (root / resolved).exists():
|
|
2249
|
+
return None
|
|
2250
|
+
new_target = _map_moved(resolved.replace(os.sep, "/"), file_moves, dir_moves)
|
|
2251
|
+
if new_target == resolved and new_file == old_file:
|
|
2252
|
+
return target
|
|
2253
|
+
new_rel = os.path.relpath(new_target, os.path.dirname(new_file) or ".").replace(os.sep, "/")
|
|
2254
|
+
if path_part.endswith("/") and not new_rel.endswith("/"):
|
|
2255
|
+
new_rel += "/"
|
|
2256
|
+
if os.path.normpath(new_rel) == os.path.normpath(urllib.parse.unquote(path_part)):
|
|
2257
|
+
return target
|
|
2258
|
+
if "%" in path_part:
|
|
2259
|
+
new_rel = urllib.parse.quote(new_rel, safe="/")
|
|
2260
|
+
new_raw = new_rel + suffix
|
|
2261
|
+
return f"<{new_raw}>" if bracketed else new_raw
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
def _heading_anchor(heading: str) -> str:
|
|
2265
|
+
"""GitHub-style anchor: lower-case, punctuation other than - and _ dropped, spaces to hyphens."""
|
|
2266
|
+
return re.sub(r"[^\w\- ]", "", heading.strip().lower()).replace(" ", "-")
|
|
2267
|
+
|
|
2268
|
+
|
|
2269
|
+
def _wikilink_matches(target: str, by_name: dict[str, list[str]]) -> list[str]:
|
|
2270
|
+
"""Tracked files an Obsidian wikilink target names: by basename, or by path suffix for a path form."""
|
|
2271
|
+
target = target.strip().lower()
|
|
2272
|
+
name = target.rsplit("/", 1)[-1]
|
|
2273
|
+
found = by_name.get(name, []) + by_name.get(name + ".md", [])
|
|
2274
|
+
if "/" in target:
|
|
2275
|
+
found = [p for p in found if ("/" + p.lower()).endswith("/" + target)
|
|
2276
|
+
or ("/" + p.lower()).endswith("/" + target + ".md")]
|
|
2277
|
+
return sorted(set(found))
|
|
2278
|
+
|
|
2279
|
+
|
|
2280
|
+
def _rewrite_wikilinks(line: str, location: str, new_file: str, moved_file: bool, by_name: dict[str, list[str]],
|
|
2281
|
+
file_moves: dict[str, str], plan: MigrationPlan) -> tuple[str, int]:
|
|
2282
|
+
"""Replace wikilinks naming a moved file with relative Markdown links; report the ones left."""
|
|
2283
|
+
code = [m.span() for m in _INLINE_CODE.finditer(line)]
|
|
2284
|
+
count = 0
|
|
2285
|
+
for match in reversed(list(_WIKILINK.finditer(line))):
|
|
2286
|
+
if any(a <= match.start() < b for a, b in code):
|
|
2287
|
+
continue
|
|
2288
|
+
embed, inner = match.group(1), match.group(2)
|
|
2289
|
+
target, _bar, label = inner.partition("|")
|
|
2290
|
+
target, _hash, heading = target.rstrip("\\").partition("#")
|
|
2291
|
+
if not target.strip():
|
|
2292
|
+
continue
|
|
2293
|
+
found = _wikilink_matches(target, by_name)
|
|
2294
|
+
if not any(p in file_moves for p in found):
|
|
2295
|
+
if moved_file and found:
|
|
2296
|
+
plan.stay_wikilinks.append(location)
|
|
2297
|
+
continue
|
|
2298
|
+
if len(found) > 1:
|
|
2299
|
+
plan.ambiguous_wikilinks.append(location)
|
|
2300
|
+
continue
|
|
2301
|
+
old = found[0]
|
|
2302
|
+
rel = os.path.relpath(file_moves[old], os.path.dirname(new_file) or ".").replace(os.sep, "/")
|
|
2303
|
+
if any(c in rel for c in " ()<>"):
|
|
2304
|
+
rel = f"<{rel}>"
|
|
2305
|
+
is_markdown = old.lower().endswith(".md")
|
|
2306
|
+
if heading and is_markdown:
|
|
2307
|
+
rel = rel[:-1] + f"#{_heading_anchor(heading)}>" if rel.startswith("<") \
|
|
2308
|
+
else rel + f"#{_heading_anchor(heading)}"
|
|
2309
|
+
if embed and not is_markdown:
|
|
2310
|
+
new = f""
|
|
2311
|
+
else:
|
|
2312
|
+
new = f"[{label.strip() or target.strip()}]({rel})"
|
|
2313
|
+
line = line[:match.start()] + new + line[match.end():]
|
|
2314
|
+
count += 1
|
|
2315
|
+
return line, count
|
|
2316
|
+
|
|
2317
|
+
|
|
2318
|
+
def _plan_links(root: Path, tracked: list[str], plan: MigrationPlan, dir_moves: dict[str, str]) -> None:
|
|
2319
|
+
file_moves = dict(plan.moves)
|
|
2320
|
+
# Obsidian resolves a wikilink by bare file name anywhere, or by path suffix.
|
|
2321
|
+
by_name: dict[str, list[str]] = {}
|
|
2322
|
+
for path in tracked:
|
|
2323
|
+
by_name.setdefault(path.rsplit("/", 1)[-1].lower(), []).append(path)
|
|
2324
|
+
for old_file in (p for p in tracked if p.endswith(".md")):
|
|
2325
|
+
new_file = file_moves.get(old_file, old_file)
|
|
2326
|
+
try:
|
|
2327
|
+
text = (root / old_file).read_text()
|
|
2328
|
+
except (OSError, UnicodeDecodeError):
|
|
2329
|
+
continue
|
|
2330
|
+
lines = text.split("\n")
|
|
2331
|
+
changed = False
|
|
2332
|
+
fence: str | None = None
|
|
2333
|
+
for number, line in enumerate(lines, 1):
|
|
2334
|
+
opener = _FENCE.match(line)
|
|
2335
|
+
if fence:
|
|
2336
|
+
if opener and opener.group(1)[0] == fence[0] and len(opener.group(1)) >= len(fence):
|
|
2337
|
+
fence = None
|
|
2338
|
+
continue
|
|
2339
|
+
if opener:
|
|
2340
|
+
fence = opener.group(1)
|
|
2341
|
+
continue
|
|
2342
|
+
code = [m.span() for m in _INLINE_CODE.finditer(line)]
|
|
2343
|
+
spans = [(m.start(2), m.end(2)) for m in _INLINE_LINK.finditer(line)]
|
|
2344
|
+
ref = _REF_DEFINITION.match(line)
|
|
2345
|
+
if ref:
|
|
2346
|
+
spans.append((ref.start(2), ref.end(2)))
|
|
2347
|
+
for start, end in sorted(spans, reverse=True):
|
|
2348
|
+
if any(a <= start < b for a, b in code):
|
|
2349
|
+
continue
|
|
2350
|
+
target = line[start:end]
|
|
2351
|
+
new = _rewrite_target(root, target, old_file, new_file, file_moves, dir_moves)
|
|
2352
|
+
if new is None:
|
|
2353
|
+
plan.unresolved.append(f"{old_file}:{number}")
|
|
2354
|
+
elif new != target:
|
|
2355
|
+
line = line[:start] + new + line[end:]
|
|
2356
|
+
plan.link_count += 1
|
|
2357
|
+
plan.link_files.add(new_file)
|
|
2358
|
+
changed = True
|
|
2359
|
+
# After the Markdown links, so a link this produces is not rewritten a second time.
|
|
2360
|
+
line, wiki = _rewrite_wikilinks(line, f"{old_file}:{number}", new_file, old_file in file_moves,
|
|
2361
|
+
by_name, file_moves, plan)
|
|
2362
|
+
if wiki:
|
|
2363
|
+
plan.wikilink_count += wiki
|
|
2364
|
+
plan.wikilink_files.add(new_file)
|
|
2365
|
+
changed = True
|
|
2366
|
+
lines[number - 1] = line
|
|
2367
|
+
if changed:
|
|
2368
|
+
plan.link_edits[new_file] = "\n".join(lines)
|
|
2369
|
+
|
|
2370
|
+
|
|
2371
|
+
def _plan_other_references(root: Path, plan: MigrationPlan, sources: list[str]) -> None:
|
|
2372
|
+
needles = sorted({old for old, _new in plan.moves} | {s + "/" for s in sources})
|
|
2373
|
+
if not needles:
|
|
2374
|
+
return
|
|
2375
|
+
args = ["grep", "-n", "-I", "-F"]
|
|
2376
|
+
for needle in needles:
|
|
2377
|
+
args += ["-e", needle]
|
|
2378
|
+
found = _git(root, *args, "--", ".", ":(exclude)*.md")
|
|
2379
|
+
for line in found.stdout.splitlines():
|
|
2380
|
+
location, _, text = line.partition(":")
|
|
2381
|
+
number, _, text = text.partition(":")
|
|
2382
|
+
plan.other_refs.append(f"{location}:{number}: {text.strip()[:100]}")
|
|
2383
|
+
|
|
2384
|
+
|
|
2385
|
+
def plan_migration(root: Path, slug: str, date: str, archetype: str) -> MigrationPlan:
|
|
2386
|
+
"""Plan the move of an earlier-layout vault to the visible layout. Writes nothing."""
|
|
2387
|
+
plan = MigrationPlan()
|
|
2388
|
+
tracked = _git(root, "ls-files", "-z").stdout.split("\0")
|
|
2389
|
+
tracked = [p for p in tracked if p]
|
|
2390
|
+
vault_prefix = ".bc-agent/"
|
|
2391
|
+
movers = dict(_MIGRATE_MOVERS)
|
|
2392
|
+
if archetype in {"ops", "hybrid"}:
|
|
2393
|
+
movers.update(_MIGRATE_OPS_MOVERS)
|
|
2394
|
+
generated = visible_targets(root, slug, date, archetype)
|
|
2395
|
+
keep_tops = {dest.relative_to(root / ".bc-agent").parts[0]
|
|
2396
|
+
for dest, _c, _r in generated if (root / ".bc-agent") in dest.parents}
|
|
2397
|
+
|
|
2398
|
+
candidates: list[tuple[str, str]] = [] # (old, new)
|
|
2399
|
+
source_dirs = {vault_prefix + name: dest for name, dest in movers.items()}
|
|
2400
|
+
groups: dict[str, tuple[list[str], str]] = {}
|
|
2401
|
+
|
|
2402
|
+
def judge(path: str, file: str, rule: str) -> None:
|
|
2403
|
+
groups.setdefault(path, ([], rule))[0].append(file)
|
|
2404
|
+
|
|
2405
|
+
if any(p.startswith("docs/adr/") for p in tracked):
|
|
2406
|
+
source_dirs["docs/adr"] = "docs/decisions"
|
|
2407
|
+
for path in tracked:
|
|
2408
|
+
if path.startswith(vault_prefix):
|
|
2409
|
+
rel = path[len(vault_prefix):]
|
|
2410
|
+
top = rel.split("/", 1)[0]
|
|
2411
|
+
if top in movers and "/" in rel:
|
|
2412
|
+
if rel.endswith("/.gitkeep") or rel == top + "/.gitkeep":
|
|
2413
|
+
plan.deletes.append(path)
|
|
2414
|
+
else:
|
|
2415
|
+
candidates.append((path, movers[top] + rel[len(top):]))
|
|
2416
|
+
elif top in {"scratch", "out-of-scope"}:
|
|
2417
|
+
judge(vault_prefix + top, path, RULE_UNRECOGNISED)
|
|
2418
|
+
elif rel in _MIGRATE_GENERATED:
|
|
2419
|
+
text = (root / path).read_text(errors="ignore")
|
|
2420
|
+
if _matches_generated(text, _MIGRATE_GENERATED[rel], slug):
|
|
2421
|
+
plan.deletes.append(path)
|
|
2422
|
+
else:
|
|
2423
|
+
judge(path, path, RULE_GENERATED_EDITED)
|
|
2424
|
+
elif top in keep_tops:
|
|
2425
|
+
continue
|
|
2426
|
+
elif top == "tasks":
|
|
2427
|
+
name = rel.split("/")
|
|
2428
|
+
if len(name) == 2 and name[1] in {"active.md", "completed.md"}:
|
|
2429
|
+
judge(path, path, RULE_WORK)
|
|
2430
|
+
elif len(name) == 2 and name[1] == "parking-lot.md":
|
|
2431
|
+
judge(path, path, RULE_IDEAS)
|
|
2432
|
+
elif len(name) > 2 and "draft" in name[1]:
|
|
2433
|
+
judge(vault_prefix + "tasks/" + name[1], path, RULE_DRAFTS)
|
|
2434
|
+
else:
|
|
2435
|
+
judge(path, path, RULE_UNRECOGNISED)
|
|
2436
|
+
elif top == "plans":
|
|
2437
|
+
judge(vault_prefix + "plans", path, RULE_WORK)
|
|
2438
|
+
elif top == "project":
|
|
2439
|
+
base = rel.split("/")[-1].lower()
|
|
2440
|
+
if rel == "project/overview.md":
|
|
2441
|
+
judge(path, path, RULE_OVERVIEW)
|
|
2442
|
+
elif "prd" in base:
|
|
2443
|
+
judge(path, path, RULE_PRD)
|
|
2444
|
+
elif "-plan" in base or "-tasks" in base:
|
|
2445
|
+
judge(path, path, RULE_WORK)
|
|
2446
|
+
else:
|
|
2447
|
+
judge(path, path, RULE_UNRECOGNISED)
|
|
2448
|
+
elif top == "findings":
|
|
2449
|
+
judge(vault_prefix + top, path, RULE_FINDINGS)
|
|
2450
|
+
elif top == "open-questions":
|
|
2451
|
+
judge(vault_prefix + top, path, RULE_QUESTIONS)
|
|
2452
|
+
elif top in {"home.md", "index.md", ".obsidian"}:
|
|
2453
|
+
judge(vault_prefix + top, path, RULE_DELETE_CHECKED)
|
|
2454
|
+
else:
|
|
2455
|
+
judge(vault_prefix + top, path, RULE_UNRECOGNISED)
|
|
2456
|
+
elif path.startswith("docs/adr/"):
|
|
2457
|
+
if path.endswith("/.gitkeep"):
|
|
2458
|
+
plan.deletes.append(path)
|
|
2459
|
+
else:
|
|
2460
|
+
candidates.append((path, "docs/decisions/" + path[len("docs/adr/"):]))
|
|
2461
|
+
elif path.startswith("docs/plans/"):
|
|
2462
|
+
judge("docs/plans", path, RULE_WORK)
|
|
2463
|
+
|
|
2464
|
+
# scratch/ and out-of-scope/ holding only placeholders are deleted, not judged.
|
|
2465
|
+
for top in ("scratch", "out-of-scope"):
|
|
2466
|
+
key = vault_prefix + top
|
|
2467
|
+
if key in groups and all(f.endswith("/.gitkeep") for f in groups[key][0]):
|
|
2468
|
+
plan.deletes.extend(groups.pop(key)[0])
|
|
2469
|
+
|
|
2470
|
+
by_dest: dict[str, list[str]] = {}
|
|
2471
|
+
for old, new in candidates:
|
|
2472
|
+
by_dest.setdefault(new, []).append(old)
|
|
2473
|
+
for old, new in candidates:
|
|
2474
|
+
if len(by_dest[new]) > 1:
|
|
2475
|
+
judge(old, old, RULE_CLASH.format(dest=new))
|
|
2476
|
+
elif (root / new).exists():
|
|
2477
|
+
if (root / new).is_file() and (root / new).read_bytes() == (root / old).read_bytes():
|
|
2478
|
+
judge(old, old, RULE_ALREADY_THERE.format(dest=new))
|
|
2479
|
+
else:
|
|
2480
|
+
plan.refusals.append(f"destination already exists as a different file: {new} (for {old})")
|
|
2481
|
+
else:
|
|
2482
|
+
plan.moves.append((old, new))
|
|
2483
|
+
|
|
2484
|
+
move_dests = {new for _old, new in plan.moves}
|
|
2485
|
+
move_dirs = {os.path.dirname(new) for new in move_dests}
|
|
2486
|
+
for dest, content, _is_root in generated:
|
|
2487
|
+
rel = dest.relative_to(root).as_posix()
|
|
2488
|
+
if rel in move_dests or (rel.endswith("/.gitkeep") and any(
|
|
2489
|
+
d == os.path.dirname(rel) or d.startswith(os.path.dirname(rel) + "/") for d in move_dirs)):
|
|
2490
|
+
continue
|
|
2491
|
+
if not dest.exists():
|
|
2492
|
+
plan.creates.append((rel, content))
|
|
2493
|
+
elif rel == ".bc-agent/AGENTS.md":
|
|
2494
|
+
if dest.read_text(errors="ignore") != content:
|
|
2495
|
+
plan.replaces.append((rel, content))
|
|
2496
|
+
judge(rel, rel, RULE_OLD_AGENTS)
|
|
2497
|
+
elif not rel.endswith("/.gitkeep") and dest.read_text(errors="ignore") != content:
|
|
2498
|
+
plan.kept.append(rel)
|
|
2499
|
+
|
|
2500
|
+
for path, (files, rule) in sorted(groups.items()):
|
|
2501
|
+
plan.judgment.append((path, _measure(root, path, files), rule))
|
|
2502
|
+
|
|
2503
|
+
# A folder link is rewritten only when everything in the folder moves.
|
|
2504
|
+
unmoved = {old for old, _new in candidates} - {old for old, _new in plan.moves}
|
|
2505
|
+
dir_moves = {src: dst for src, dst in source_dirs.items()
|
|
2506
|
+
if not any(path.startswith(src + "/") for path in unmoved)}
|
|
2507
|
+
_plan_links(root, tracked, plan, dir_moves)
|
|
2508
|
+
_plan_other_references(root, plan, [src for src in source_dirs
|
|
2509
|
+
if any(old.startswith(src + "/") for old, _new in plan.moves)])
|
|
2510
|
+
return plan
|
|
2511
|
+
|
|
2512
|
+
|
|
2513
|
+
def _has_layout_table(text: str) -> bool:
|
|
2514
|
+
"""True for a parseable role table; earlier vaults used the same heading for a bullet list."""
|
|
2515
|
+
try:
|
|
2516
|
+
parse_where_things_go(text)
|
|
2517
|
+
except ValueError:
|
|
2518
|
+
return False
|
|
2519
|
+
return True
|
|
2520
|
+
|
|
2521
|
+
|
|
2522
|
+
def _migrate_refusal(root: Path, archetype: str) -> str | None:
|
|
2523
|
+
if archetype not in VISIBLE_ARCHETYPES:
|
|
2524
|
+
return (f"migrate mode is for code, ops and hybrid; the {archetype} archetype keeps the "
|
|
2525
|
+
f".bc-agent/ vault")
|
|
2526
|
+
top = _git(root, "rev-parse", "--show-toplevel")
|
|
2527
|
+
if top.returncode != 0:
|
|
2528
|
+
return f"{root} is not a git repository"
|
|
2529
|
+
if Path(top.stdout.strip()).resolve() != root:
|
|
2530
|
+
return f"{root} is not the repository root ({top.stdout.strip()})"
|
|
2531
|
+
if not (root / ".bc-agent").is_dir():
|
|
2532
|
+
return "no .bc-agent/ vault to migrate; run the scaffold without --migrate for a fresh layout"
|
|
2533
|
+
dirty = _git(root, "status", "--porcelain", "--untracked-files=all").stdout.splitlines()
|
|
2534
|
+
if dirty:
|
|
2535
|
+
return "the working tree has uncommitted changes:\n" + "\n".join(f" {line}" for line in dirty)
|
|
2536
|
+
agents = root / ".bc-agent" / "AGENTS.md"
|
|
2537
|
+
if agents.is_file() and _has_layout_table(agents.read_text(errors="ignore")):
|
|
2538
|
+
return f"{agents} already has a {WHERE_THINGS_GO_HEADING!r} table; the project is already migrated"
|
|
2539
|
+
return None
|
|
2540
|
+
|
|
2541
|
+
|
|
2542
|
+
def _print_section(title: str, items: list[str]) -> None:
|
|
2543
|
+
print(title)
|
|
2544
|
+
for item in items or ["(none)"]:
|
|
2545
|
+
print(f" {item}")
|
|
2546
|
+
|
|
2547
|
+
|
|
2548
|
+
def run_migrate(root: Path, slug: str, date: str, archetype: str, apply: bool) -> int:
|
|
2549
|
+
refusal = _migrate_refusal(root, archetype)
|
|
2550
|
+
if refusal:
|
|
2551
|
+
print(f"ERROR: {refusal}")
|
|
2552
|
+
print("Nothing was written.")
|
|
2553
|
+
return 1
|
|
2554
|
+
plan = plan_migration(root, slug, date, archetype)
|
|
2555
|
+
if plan.refusals:
|
|
2556
|
+
for message in plan.refusals:
|
|
2557
|
+
print(f"ERROR: {message}")
|
|
2558
|
+
print("Nothing was written.")
|
|
2559
|
+
return 1
|
|
2560
|
+
planned = [(root / rel, content, False) for rel, content in plan.creates + plan.replaces]
|
|
2561
|
+
if not _preflight_targets(root, planned):
|
|
2562
|
+
print("Nothing was written.")
|
|
2563
|
+
return 1
|
|
2564
|
+
|
|
2565
|
+
print(f"Repo: {root}")
|
|
2566
|
+
print(f"Branch: {_git(root, 'branch', '--show-current').stdout.strip() or '(detached)'}")
|
|
2567
|
+
print(f"Archetype: {archetype} (from --archetype)")
|
|
2568
|
+
print()
|
|
2569
|
+
_print_section("MOVE", [f"{old} -> {new}" for old, new in plan.moves])
|
|
2570
|
+
_print_section("CREATE", [rel for rel, _c in plan.creates])
|
|
2571
|
+
_print_section("REPLACE", [rel for rel, _c in plan.replaces])
|
|
2572
|
+
_print_section("DELETE", plan.deletes)
|
|
2573
|
+
_print_section("KEPT (review by hand)", plan.kept)
|
|
2574
|
+
_print_section("NEEDS JUDGMENT", [f"{path} — {size} — {rule}" for path, size, rule in plan.judgment])
|
|
2575
|
+
verb = "rewrote" if apply else "would rewrite"
|
|
2576
|
+
_print_section("LINKS", [f"{verb} {plan.link_count} links in {len(plan.link_files)} files; "
|
|
2577
|
+
f"unresolved: {len(plan.unresolved)} (left as is)"]
|
|
2578
|
+
+ [f" {loc}" for loc in plan.unresolved[:10]]
|
|
2579
|
+
+ [f"{verb} {plan.wikilink_count} wikilinks in {len(plan.wikilink_files)} files",
|
|
2580
|
+
f"ambiguous wikilinks (left as is): {len(plan.ambiguous_wikilinks)}"]
|
|
2581
|
+
+ [f" {loc}" for loc in plan.ambiguous_wikilinks[:10]]
|
|
2582
|
+
+ ["wikilinks from moved files to files that stay (left as is; they resolve only inside "
|
|
2583
|
+
f"an Obsidian vault): {len(plan.stay_wikilinks)}"])
|
|
2584
|
+
shown = plan.other_refs[:50]
|
|
2585
|
+
if len(plan.other_refs) > 50:
|
|
2586
|
+
shown.append(f"... {len(plan.other_refs) - 50} more")
|
|
2587
|
+
_print_section("OTHER REFERENCES", shown)
|
|
2588
|
+
print()
|
|
2589
|
+
print(f"Totals: {len(plan.moves)} move, {len(plan.creates)} create, {len(plan.replaces)} replace, "
|
|
2590
|
+
f"{len(plan.deletes)} delete, {len(plan.kept)} kept, {len(plan.judgment)} need judgment, "
|
|
2591
|
+
f"{plan.link_count} link rewrites, {plan.wikilink_count} wikilink rewrites")
|
|
2592
|
+
if not apply:
|
|
2593
|
+
command = (f"python3 {Path(__file__).resolve()} --root {root} --slug {slug} --date {date} "
|
|
2594
|
+
f"--archetype {archetype} --migrate --apply")
|
|
2595
|
+
print(f"Dry run; nothing was written. Apply with: {command}")
|
|
2596
|
+
return 0
|
|
2597
|
+
|
|
2598
|
+
for old, new in plan.moves:
|
|
2599
|
+
(root / new).parent.mkdir(parents=True, exist_ok=True)
|
|
2600
|
+
moved = _git(root, "mv", old, new)
|
|
2601
|
+
if moved.returncode != 0:
|
|
2602
|
+
print(f"ERROR: git mv {old} {new} failed: {moved.stderr.strip()}")
|
|
2603
|
+
print("Stopped part-way; inspect `git status` and undo with `git reset --hard` if needed.")
|
|
2604
|
+
return 1
|
|
2605
|
+
if plan.deletes:
|
|
2606
|
+
_git(root, "rm", "-q", "--", *plan.deletes)
|
|
2607
|
+
for old in sorted({os.path.dirname(p) for p, _n in plan.moves} | {os.path.dirname(p) for p in plan.deletes},
|
|
2608
|
+
key=len, reverse=True):
|
|
2609
|
+
try: # git mv leaves emptied source folders behind; remove them, never a non-empty one
|
|
2610
|
+
os.removedirs(root / old)
|
|
2611
|
+
except OSError:
|
|
2612
|
+
pass
|
|
2613
|
+
for rel, text in plan.link_edits.items():
|
|
2614
|
+
(root / rel).write_text(text)
|
|
2615
|
+
for rel, content in plan.creates + plan.replaces:
|
|
2616
|
+
(root / rel).parent.mkdir(parents=True, exist_ok=True)
|
|
2617
|
+
(root / rel).write_text(content)
|
|
2618
|
+
_git(root, "add", "-A")
|
|
2619
|
+
print(f"Applied: moved {len(plan.moves)}, created {len(plan.creates)}, replaced {len(plan.replaces)}, "
|
|
2620
|
+
f"deleted {len(plan.deletes)}, rewrote {plan.link_count} links in {len(plan.link_files)} files, "
|
|
2621
|
+
f"{plan.wikilink_count} wikilinks in {len(plan.wikilink_files)} files.")
|
|
2622
|
+
print("Everything is staged and nothing was committed: work through NEEDS JUDGMENT, then commit "
|
|
2623
|
+
"the project in one commit.")
|
|
2624
|
+
return 0
|
|
2625
|
+
|
|
2626
|
+
|
|
2627
|
+
|
|
2628
|
+
def main() -> int:
|
|
2629
|
+
ap = argparse.ArgumentParser(
|
|
2630
|
+
description="Idempotent: creates only missing files; never deletes, and never "
|
|
2631
|
+
"overwrites existing files unless explicitly forced.")
|
|
2632
|
+
ap.add_argument("--root", required=True, help="project (repo) root")
|
|
2633
|
+
ap.add_argument("--slug", required=True, help="project display name, kebab-case")
|
|
2634
|
+
ap.add_argument("--date", default=_dt.date.today().isoformat())
|
|
2635
|
+
ap.add_argument("--archetype", choices=["code", "ops", "learning", "knowledge", "hybrid"], default=None,
|
|
2636
|
+
help="optional wiki archetype layered on top of the base project scaffold "
|
|
2637
|
+
"(default code; required with --migrate)")
|
|
2638
|
+
ap.add_argument("--force", action="store_true",
|
|
2639
|
+
help="overwrite existing files under .bc-agent/ (never files outside it, never "
|
|
2640
|
+
"deletes; root AGENTS.md needs --force-root)")
|
|
2641
|
+
ap.add_argument("--force-root", action="store_true",
|
|
2642
|
+
help="also overwrite an existing root AGENTS.md")
|
|
2643
|
+
ap.add_argument("--allow-earlier-layout", action="store_true",
|
|
2644
|
+
help="code/ops/hybrid: create missing visible-layout files even when earlier-layout "
|
|
2645
|
+
"paths exist under .bc-agent/ (they stay untouched)")
|
|
2646
|
+
ap.add_argument("--dry-run", action="store_true", help="report what would happen; write nothing")
|
|
2647
|
+
ap.add_argument("--migrate", action="store_true",
|
|
2648
|
+
help="code/ops/hybrid: plan moving an earlier-layout .bc-agent/ vault to the visible "
|
|
2649
|
+
"layout; prints the plan and writes nothing unless --apply is given")
|
|
2650
|
+
ap.add_argument("--apply", action="store_true",
|
|
2651
|
+
help="with --migrate: perform the plan and stage it (never commits)")
|
|
2652
|
+
args = ap.parse_args()
|
|
2653
|
+
|
|
2654
|
+
root = Path(args.root).expanduser().resolve()
|
|
2655
|
+
slug = args.slug.strip()
|
|
2656
|
+
if not root.is_dir():
|
|
2657
|
+
print(f"ERROR: root is not a directory: {root}")
|
|
2658
|
+
return 1
|
|
2659
|
+
if not slug or slug != slug.lower() or " " in slug:
|
|
2660
|
+
print(f"ERROR: slug must be lower-case kebab with no spaces: {slug!r}")
|
|
2661
|
+
return 1
|
|
2662
|
+
if args.migrate:
|
|
2663
|
+
if args.archetype is None:
|
|
2664
|
+
print("ERROR: --migrate needs an explicit --archetype (code, ops or hybrid); "
|
|
2665
|
+
"nothing in the earlier vault records it reliably.")
|
|
2666
|
+
return 1
|
|
2667
|
+
return run_migrate(root, slug, args.date, args.archetype, args.apply)
|
|
2668
|
+
if args.apply:
|
|
2669
|
+
print("ERROR: --apply only applies to --migrate.")
|
|
2670
|
+
return 1
|
|
2671
|
+
if args.archetype is None:
|
|
2672
|
+
args.archetype = "code"
|
|
2673
|
+
|
|
2674
|
+
if args.archetype in VISIBLE_ARCHETYPES and not args.allow_earlier_layout:
|
|
2675
|
+
legacy = earlier_layout_paths(root, args.archetype)
|
|
2676
|
+
if legacy:
|
|
2677
|
+
print("ERROR: earlier-layout paths exist under .bc-agent (" + ", ".join(legacy) + "); "
|
|
2678
|
+
"nothing was written.")
|
|
2679
|
+
print("Migrating them to the visible layout is a separate, explicit step (see MIGRATIONS.md). "
|
|
2680
|
+
"Re-run with --allow-earlier-layout to create the missing visible-layout files beside "
|
|
2681
|
+
"them, leaving every existing file untouched.")
|
|
2682
|
+
return 1
|
|
2683
|
+
|
|
2684
|
+
vault = root / ".bc-agent"
|
|
2685
|
+
created: list[Path] = []
|
|
2686
|
+
overwritten: list[Path] = []
|
|
2687
|
+
skipped: list[Path] = [] # existed, left untouched
|
|
2688
|
+
planned = targets(root, slug, args.date, args.archetype)
|
|
2689
|
+
if not _preflight_targets(root, planned):
|
|
2690
|
+
return 1
|
|
2691
|
+
|
|
2692
|
+
for dest, content, is_root in planned:
|
|
2693
|
+
exists = dest.exists()
|
|
2694
|
+
may_overwrite = args.force_root if is_root else (args.force and vault in dest.parents)
|
|
2695
|
+
if exists and not may_overwrite:
|
|
2696
|
+
skipped.append(dest)
|
|
2697
|
+
continue
|
|
2698
|
+
if not args.dry_run:
|
|
2699
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
2700
|
+
dest.write_text(content)
|
|
2701
|
+
if dest.relative_to(root).as_posix() in EXECUTABLE_TARGETS:
|
|
2702
|
+
dest.chmod(0o755)
|
|
2703
|
+
(overwritten if exists else created).append(dest)
|
|
2704
|
+
|
|
2705
|
+
verb = "Would create" if args.dry_run else "Created"
|
|
2706
|
+
if created:
|
|
2707
|
+
print(f"{verb} {len(created)} file(s):")
|
|
2708
|
+
for p in created:
|
|
2709
|
+
print(f" + {p}")
|
|
2710
|
+
if overwritten:
|
|
2711
|
+
word = "Would overwrite" if args.dry_run else "Overwrote"
|
|
2712
|
+
print(f"{word} {len(overwritten)} existing file(s) (forced):")
|
|
2713
|
+
for p in overwritten:
|
|
2714
|
+
print(f" ~ {p}")
|
|
2715
|
+
if skipped:
|
|
2716
|
+
print(f"Left {len(skipped)} existing file(s) untouched:")
|
|
2717
|
+
for p in skipped:
|
|
2718
|
+
print(f" = {p}")
|
|
2719
|
+
|
|
2720
|
+
notes = upgrade_notes(root, args.archetype)
|
|
2721
|
+
if notes:
|
|
2722
|
+
print("\nUpgrade notes for existing files left untouched:")
|
|
2723
|
+
for note in notes:
|
|
2724
|
+
print(f" ! {note}")
|
|
2725
|
+
print("These are manual merge hints for the agent running the skill; the scaffold stays additive and does not overwrite existing instructions.")
|
|
2726
|
+
|
|
2727
|
+
if not created and not overwritten:
|
|
2728
|
+
print("\nNothing to do — the workspace is already present; nothing was created, "
|
|
2729
|
+
"overwritten, or deleted.")
|
|
2730
|
+
return 0
|
|
2731
|
+
|
|
2732
|
+
if skipped:
|
|
2733
|
+
# Most relevant when plugging into an existing project: flag the un-pointed root AGENTS.
|
|
2734
|
+
root_agents = root / "AGENTS.md"
|
|
2735
|
+
if root_agents in skipped:
|
|
2736
|
+
if args.archetype in VISIBLE_ARCHETYPES:
|
|
2737
|
+
print(f"\nNOTE: existing {root_agents} was left as-is. Merge the 'read .bc-agent first' "
|
|
2738
|
+
f"pointer into it by hand (see `.bc-agent/AGENTS.md` and its \"Where things go\" table).")
|
|
2739
|
+
else:
|
|
2740
|
+
print(f"\nNOTE: existing {root_agents} was left as-is. Merge the 'read .bc-agent first' "
|
|
2741
|
+
f"pointer into it by hand (see `.bc-agent/AGENTS.md` and its canonical search-first block).")
|
|
2742
|
+
|
|
2743
|
+
print("\nNext: fill conventions/validation.md + file-layout.md as you learn the project; "
|
|
2744
|
+
"read .bc-agent/references/agent-skills.md for the loop skill map; "
|
|
2745
|
+
"follow /bc-pipeline-to-done preflight before an AFK drain; "
|
|
2746
|
+
"then /triage existing issues or /bc-plan-to-pipeline to plan the first feature.")
|
|
2747
|
+
return 0
|
|
2748
|
+
|
|
2749
|
+
|
|
2750
|
+
if __name__ == "__main__":
|
|
2751
|
+
raise SystemExit(main())
|