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.
Files changed (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +771 -2
  3. package/concepts/bc-brainstorming/body/SKILL.md +43 -0
  4. package/concepts/bc-code-review/body/SKILL.md +120 -0
  5. package/concepts/bc-codebase-design/body/SKILL.md +54 -0
  6. package/concepts/bc-codebase-docs/body/SKILL.md +150 -0
  7. package/concepts/bc-council-audit-security/body/SKILL.md +72 -0
  8. package/concepts/bc-council-chain/body/SKILL.md +71 -0
  9. package/concepts/bc-council-challenge-plan/body/SKILL.md +78 -0
  10. package/concepts/bc-council-find-bugs/body/SKILL.md +70 -0
  11. package/concepts/bc-council-improve-architecture/body/SKILL.md +52 -0
  12. package/concepts/bc-council-mode/body/SKILL.md +56 -0
  13. package/concepts/bc-council-mode/body/examples/agents/README.md +11 -0
  14. package/concepts/bc-council-mode/body/examples/agents/council-change.md +14 -0
  15. package/concepts/bc-council-mode/body/examples/agents/council-compat.md +14 -0
  16. package/concepts/bc-council-mode/body/examples/agents/council-risk.md +14 -0
  17. package/concepts/bc-council-mode/body/references/pass-contracts.md +133 -0
  18. package/concepts/bc-delegate-investigation/body/SKILL.md +119 -0
  19. package/concepts/bc-delegate-investigation/body/examples/pi-settings-snippet.json +8 -0
  20. package/concepts/bc-delegate-investigation/body/pi.md +168 -0
  21. package/concepts/bc-design/body/SKILL.md +49 -0
  22. package/concepts/bc-design/body/design-framework.md +39 -0
  23. package/concepts/bc-design/body/existing-app.md +9 -0
  24. package/concepts/bc-design/body/new-work.md +22 -0
  25. package/concepts/bc-design/body/principles.md +34 -0
  26. package/concepts/bc-design/body/surfaces.md +13 -0
  27. package/concepts/bc-diagnosing-bugs/body/SKILL.md +83 -0
  28. package/concepts/bc-dispatching-parallel-agents/body/SKILL.md +63 -0
  29. package/concepts/bc-domain-modeling/body/SKILL.md +40 -0
  30. package/concepts/bc-executing-plans/body/SKILL.md +50 -0
  31. package/concepts/bc-explain-visually/body/SKILL.md +167 -0
  32. package/concepts/bc-find-bugs/body/SKILL.md +90 -0
  33. package/concepts/bc-finishing-development-branch/body/SKILL.md +73 -0
  34. package/concepts/bc-grilling/body/SKILL.md +22 -0
  35. package/concepts/bc-handoff/body/SKILL.md +104 -0
  36. package/concepts/bc-handoff/body/pickup.md +107 -0
  37. package/concepts/bc-handoff/body/writing.md +217 -0
  38. package/concepts/bc-improve-codebase-architecture/body/SKILL.md +101 -0
  39. package/concepts/bc-json-canvas/body/SKILL.md +40 -0
  40. package/concepts/bc-json-canvas/body/references/EXAMPLES.md +71 -0
  41. package/concepts/bc-json-canvas/body/references/SPEC.md +55 -0
  42. package/concepts/bc-json-canvas/body/references/VALIDATION.md +26 -0
  43. package/concepts/bc-minimal-solution-ladder/body/SKILL.md +120 -0
  44. package/concepts/bc-obsidian-bases/body/SKILL.md +59 -0
  45. package/concepts/bc-obsidian-bases/body/references/EXAMPLES.md +80 -0
  46. package/concepts/bc-obsidian-bases/body/references/FUNCTIONS.md +49 -0
  47. package/concepts/bc-obsidian-bases/body/references/SYNTAX.md +82 -0
  48. package/concepts/bc-obsidian-bases/body/references/TROUBLESHOOTING.md +41 -0
  49. package/concepts/bc-obsidian-markdown/body/SKILL.md +47 -0
  50. package/concepts/bc-obsidian-markdown/body/references/CALLOUTS.md +40 -0
  51. package/concepts/bc-obsidian-markdown/body/references/EMBEDS.md +35 -0
  52. package/concepts/bc-obsidian-markdown/body/references/PROPERTIES.md +37 -0
  53. package/concepts/bc-optimize-code/body/SKILL.md +41 -0
  54. package/concepts/bc-performance-guardrails/body/SKILL.md +53 -0
  55. package/concepts/bc-performance-guardrails/body/measuring.md +29 -0
  56. package/concepts/bc-performance-guardrails/body/targets.md +20 -0
  57. package/concepts/bc-pipeline-to-done/body/SKILL.md +205 -0
  58. package/concepts/bc-pipeline-to-done/body/agents/bc-drain-auditor.md +19 -0
  59. package/concepts/bc-pipeline-to-done/body/agents/bc-drain-reviewer.md +19 -0
  60. package/concepts/bc-pipeline-to-done/body/agents/bc-drain-worker.md +19 -0
  61. package/concepts/bc-pipeline-to-done/body/execute-issue.md +71 -0
  62. package/concepts/bc-pipeline-to-done/body/recovery-bundle.md +79 -0
  63. package/concepts/bc-pipeline-to-done/body/review-contract.md +105 -0
  64. package/concepts/bc-pipeline-to-done/body/roles.md +13 -0
  65. package/concepts/bc-pipeline-to-done/body/scripts/publish-check.py +172 -0
  66. package/concepts/bc-pipeline-to-done/body/source-issues.md +86 -0
  67. package/concepts/bc-pipeline-to-done/body/source-work-items.md +76 -0
  68. package/concepts/bc-plain-language/body/SKILL.md +134 -0
  69. package/concepts/bc-plan-slicing/body/SKILL.md +56 -0
  70. package/concepts/bc-plan-to-pipeline/body/SKILL.md +89 -0
  71. package/concepts/bc-prd-drafting/body/SKILL.md +43 -0
  72. package/concepts/bc-prompting-agents/body/SKILL.md +278 -0
  73. package/concepts/bc-prototype/body/SKILL.md +40 -0
  74. package/concepts/bc-qmd/body/SKILL.md +64 -0
  75. package/concepts/bc-research/body/SKILL.md +26 -0
  76. package/concepts/bc-security-audit/body/AI-AND-LLM.md +25 -0
  77. package/concepts/bc-security-audit/body/ATTACK-CLASSES.md +35 -0
  78. package/concepts/bc-security-audit/body/DESKTOP-MOBILE-AND-LOCAL-IPC.md +28 -0
  79. package/concepts/bc-security-audit/body/RECONNAISSANCE.md +49 -0
  80. package/concepts/bc-security-audit/body/SKILL.md +117 -0
  81. package/concepts/bc-security-audit/body/SUPPLY-CHAIN-AND-RELEASE.md +28 -0
  82. package/concepts/bc-security-audit/body/VALIDATION-AND-REPORTING.md +124 -0
  83. package/concepts/bc-security-audit/body/WEB-PROTOCOL-AND-AUTH.md +27 -0
  84. package/concepts/bc-security-audit/body/validate_audit.py +151 -0
  85. package/concepts/bc-self-improve/body/SKILL.md +104 -0
  86. package/concepts/bc-seo/body/CITATIONS.md +23 -0
  87. package/concepts/bc-seo/body/IMAGE-SEO.md +350 -0
  88. package/concepts/bc-seo/body/SKILL.md +453 -0
  89. package/concepts/bc-setup-project/body/SKILL.md +252 -0
  90. package/concepts/bc-setup-project/body/scaffold.py +2751 -0
  91. package/concepts/bc-setup-project/body/starter-items.md +157 -0
  92. package/concepts/bc-setup-project/body/work-data.md +114 -0
  93. package/concepts/bc-setup-project/body/work_index.py +626 -0
  94. package/concepts/bc-setup-project/body/work_spent.py +220 -0
  95. package/concepts/bc-subagent-driven-development/body/SKILL.md +61 -0
  96. package/concepts/bc-tdd/body/SKILL.md +184 -0
  97. package/concepts/bc-tdd/body/formal.md +77 -0
  98. package/concepts/bc-tdd/body/mocking.md +49 -0
  99. package/concepts/bc-tdd/body/properties.md +59 -0
  100. package/concepts/bc-tdd/body/refactoring.md +12 -0
  101. package/concepts/bc-tdd/body/scripts/confirm-red.py +136 -0
  102. package/concepts/bc-tdd/body/tests.md +59 -0
  103. package/concepts/bc-teach/body/GLOSSARY-FORMAT.md +36 -0
  104. package/concepts/bc-teach/body/LEARNING-RECORD-FORMAT.md +60 -0
  105. package/concepts/bc-teach/body/MISSION-FORMAT.md +34 -0
  106. package/concepts/bc-teach/body/RESOURCES-FORMAT.md +53 -0
  107. package/concepts/bc-teach/body/REVIEW-FORMAT.md +48 -0
  108. package/concepts/bc-teach/body/SKILL.md +281 -0
  109. package/concepts/bc-teach/body/WIKI-FORMAT.md +58 -0
  110. package/concepts/bc-teach/body/scripts/due.py +65 -0
  111. package/concepts/bc-to-spec/body/SKILL.md +21 -0
  112. package/concepts/bc-to-tickets/body/SKILL.md +21 -0
  113. package/concepts/bc-triage/body/AGENT-BRIEF.md +38 -0
  114. package/concepts/bc-triage/body/OUT-OF-SCOPE.md +51 -0
  115. package/concepts/bc-triage/body/SKILL.md +81 -0
  116. package/concepts/bc-unslop/body/SKILL.md +269 -0
  117. package/concepts/bc-using-git-worktrees/body/SKILL.md +91 -0
  118. package/concepts/bc-wiki-maintain/body/SKILL.md +361 -0
  119. package/concepts/bc-wiki-maintain/body/runner/README.md +552 -0
  120. package/concepts/bc-wiki-maintain/body/runner/bc-wiki-lint.service +24 -0
  121. package/concepts/bc-wiki-maintain/body/runner/bc-wiki-lint.timer +15 -0
  122. package/concepts/bc-wiki-maintain/body/runner/bc-wiki-maintain-all.service +29 -0
  123. package/concepts/bc-wiki-maintain/body/runner/bc-wiki-maintain-all.timer +16 -0
  124. package/concepts/bc-wiki-maintain/body/runner/bc-wiki-maintain.service +28 -0
  125. package/concepts/bc-wiki-maintain/body/runner/bc-wiki-maintain.timer +12 -0
  126. package/concepts/bc-wiki-maintain/body/runner/bc-wiki-notify@.service +15 -0
  127. package/concepts/bc-wiki-maintain/body/runner/notify-failure.sh +92 -0
  128. package/concepts/bc-wiki-maintain/body/runner/run-lint.sh +69 -0
  129. package/concepts/bc-wiki-maintain/body/runner/run-promotion-all.sh +103 -0
  130. package/concepts/bc-wiki-maintain/body/runner/run-promotion.sh +270 -0
  131. package/concepts/bc-wiki-maintain/body/wiki_lint.py +958 -0
  132. package/concepts/bc-wiki-maintain/body/wiki_search.py +206 -0
  133. package/concepts/bc-work-sync/body/PLAN.md +46 -0
  134. package/concepts/bc-work-sync/body/SKILL.md +71 -0
  135. package/concepts/bc-writing-plans/body/SKILL.md +79 -0
  136. package/package.json +130 -4
  137. package/packages/agent-kernel-pi/AGENT-KERNEL.md +109 -0
  138. package/packages/agent-kernel-pi/index.js +8 -0
  139. package/packages/agent-kernel-pi/package.json +12 -0
@@ -0,0 +1,12 @@
1
+ [Unit]
2
+ Description=Scheduled project wiki maintenance
3
+
4
+ [Timer]
5
+ OnCalendar=*-*-* 03:30:00
6
+ RandomizedDelaySec=15min
7
+ Persistent=true
8
+ AccuracySec=1min
9
+ Unit=bc-wiki-maintain.service
10
+
11
+ [Install]
12
+ WantedBy=timers.target
@@ -0,0 +1,15 @@
1
+ # TEMPLATE — runs the notifier from the installed bc-wiki-maintain skill.
2
+ # Copy this into ~/.config/systemd/user/ rather than symlinking it, so your local
3
+ # paths are not overwritten when this repository updates.
4
+
5
+ [Unit]
6
+ Description=Notify about a failed wiki runner (%i)
7
+ Documentation=man:systemd.service(5)
8
+
9
+ [Service]
10
+ Type=oneshot
11
+ SyslogIdentifier=bc-wiki-notify
12
+ # Edit only if the skill is installed somewhere other than ~/.agents/skills.
13
+ ExecStart=%h/.agents/skills/bc-wiki-maintain/runner/notify-failure.sh %i
14
+ StandardOutput=journal
15
+ StandardError=journal
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env bash
2
+ # Display a concise desktop notification for a failed wiki runner unit.
3
+ #
4
+ # The failed unit name is passed by bc-wiki-notify@.service. Keep this helper
5
+ # independent of any machine-local notification library: a missing or failing
6
+ # notify-send must remain visible as a nonzero result.
7
+ set -Eeuo pipefail
8
+
9
+ usage() {
10
+ printf 'Usage: %s FAILED_UNIT\n' "$0" >&2
11
+ exit 2
12
+ }
13
+
14
+ [[ "$#" -eq 1 ]] || usage
15
+ failed_unit="$1"
16
+ [[ -n "$failed_unit" ]] || usage
17
+
18
+ if ! command -v notify-send >/dev/null 2>&1; then
19
+ printf 'bc-wiki-notify: ERROR: notify-send is unavailable; cannot display failure for %s\n' \
20
+ "$failed_unit" >&2
21
+ exit 1
22
+ fi
23
+
24
+ syslog_identifier=''
25
+ if identifier_output="$(systemctl --user show -p SyslogIdentifier "$failed_unit" 2>/dev/null)"; then
26
+ syslog_identifier="${identifier_output#SyslogIdentifier=}"
27
+ fi
28
+
29
+ vault_display='unavailable (could not read VAULT_ROOT from the failed unit)'
30
+ environment_output=''
31
+ if environment_output="$(systemctl --user show -p Environment "$failed_unit" 2>/dev/null)"; then
32
+ environment_value="${environment_output#Environment=}"
33
+ if [[ "$environment_value" =~ (^|[[:space:]])VAULT_ROOT=([^[:space:]]*) ]]; then
34
+ vault_root="${BASH_REMATCH[2]}"
35
+ if [[ -n "$vault_root" ]]; then
36
+ vault_display="$vault_root"
37
+ else
38
+ vault_display='unavailable (VAULT_ROOT is empty on the failed unit)'
39
+ fi
40
+ elif [[ "$environment_value" =~ (^|[[:space:]])VAULT_LIST=([^[:space:]]+) ]]; then
41
+ # A list-driven unit has no single vault by design. Without this the notification
42
+ # reads like a notifier fault; the runner names the failing vaults in the journal.
43
+ vault_display="batch over ${BASH_REMATCH[2]} (see reason for failing vaults)"
44
+ fi
45
+ else
46
+ vault_display='unavailable (could not inspect the failed unit environment)'
47
+ fi
48
+
49
+ # No priority filter: systemd logs unit stderr at notice, not err, so filtering on
50
+ # err..emerg silently matches nothing. Scope by SyslogIdentifier to drop systemd's own
51
+ # lifecycle lines, then fall back unscoped so a unit killed before printing still reports.
52
+ read_journal() {
53
+ if [[ -n "$syslog_identifier" ]]; then
54
+ journal_output="$(journalctl --user -u "$failed_unit" -t "$syslog_identifier" -n 5 --no-pager -o cat 2>/dev/null)" || return 1
55
+ [[ "$journal_output" =~ [^[:space:]] ]] && return 0
56
+ fi
57
+ journal_output="$(journalctl --user -u "$failed_unit" -n 5 --no-pager -o cat 2>/dev/null)" || return 1
58
+ return 0
59
+ }
60
+
61
+ reason='unavailable (could not read the user journal)'
62
+ journal_output=''
63
+ if command -v journalctl >/dev/null 2>&1; then
64
+ if read_journal; then
65
+ if [[ "$journal_output" =~ [^[:space:]] ]]; then
66
+ reason="${journal_output//$'\n'/; }"
67
+ reason="${reason//$'\r'/}"
68
+ reason="${reason//$'\t'/ }"
69
+ reason="${reason#"${reason%%[![:space:]]*}"}"
70
+ reason="${reason%"${reason##*[![:space:]]}"}"
71
+ if (( ${#reason} > 500 )); then
72
+ reason="${reason:0:497}..."
73
+ fi
74
+ else
75
+ reason='no error output found in the user journal'
76
+ fi
77
+ else
78
+ reason='unavailable (journalctl could not read the user journal)'
79
+ fi
80
+ else
81
+ reason='unavailable (journalctl is not installed)'
82
+ fi
83
+
84
+ title="bc-wiki runner failed: $failed_unit"
85
+ body=$'Vault: '"$vault_display"$'\nReason: '"$reason"
86
+ if ! notify-send --urgency=critical --app-name=bc-wiki-maintain "$title" "$body"; then
87
+ printf 'bc-wiki-notify: ERROR: notify-send could not display failure for %s\n' \
88
+ "$failed_unit" >&2
89
+ exit 1
90
+ fi
91
+
92
+ printf 'bc-wiki-notify: displayed failure for %s\n' "$failed_unit"
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env bash
2
+ # Run the read-only wiki detector for every vault in a configured list.
3
+ #
4
+ # This runner never invokes an agent, writes Git state, or commits. It continues
5
+ # after a vault-level failure so one broken vault cannot hide the remaining reports.
6
+ set -Eeuo pipefail
7
+
8
+ fail() {
9
+ printf 'bc-wiki-lint: ERROR: %s\n' "$*" >&2
10
+ exit 1
11
+ }
12
+
13
+ VAULT_LIST="${VAULT_LIST:-}"
14
+
15
+ [[ -n "$VAULT_LIST" ]] || fail 'VAULT_LIST is not set'
16
+ [[ -f "$VAULT_LIST" ]] || fail "vault list does not exist: $VAULT_LIST"
17
+ [[ -r "$VAULT_LIST" ]] || fail "vault list is not readable: $VAULT_LIST"
18
+ command -v python3 >/dev/null 2>&1 || fail 'python3 is not installed or not on PATH'
19
+
20
+ skill_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
21
+ DETECTION_SCRIPT="$skill_dir/wiki_lint.py"
22
+ [[ -f "$DETECTION_SCRIPT" ]] || fail "detection script does not exist: $DETECTION_SCRIPT"
23
+ [[ -r "$DETECTION_SCRIPT" ]] || fail "detection script is not readable: $DETECTION_SCRIPT"
24
+
25
+ declare -a vaults=()
26
+ while IFS= read -r line || [[ -n "$line" ]]; do
27
+ # Accept files created on Windows and ignore surrounding whitespace around entries.
28
+ line="${line%$'\r'}"
29
+ line="${line#"${line%%[![:space:]]*}"}"
30
+ line="${line%"${line##*[![:space:]]}"}"
31
+ [[ -z "$line" || "$line" == \#* ]] && continue
32
+
33
+ case "$line" in
34
+ "~") vaults+=("$HOME") ;;
35
+ "~/"*) vaults+=("$HOME/${line#\~/}") ;;
36
+ *) vaults+=("$line") ;;
37
+ esac
38
+ done < "$VAULT_LIST"
39
+
40
+ ((${#vaults[@]} > 0)) || fail "vault list contains no vault paths: $VAULT_LIST"
41
+
42
+ failures=0
43
+ ran=0
44
+ for vault in "${vaults[@]}"; do
45
+ printf '\n=== wiki lint: %s ===\n' "$vault"
46
+ if [[ ! -d "$vault" ]]; then
47
+ printf 'bc-wiki-lint: ERROR: vault is not a directory: %s\n' "$vault" >&2
48
+ failures=$((failures + 1))
49
+ continue
50
+ fi
51
+
52
+ ran=$((ran + 1))
53
+ # wiki_lint.py returns nonzero for broken/ambiguous links or a required invalid
54
+ # promotion range. Its advisory findings (orphans, missing index, stale references,
55
+ # and a valid log backlog) remain non-fatal.
56
+ if python3 "$DETECTION_SCRIPT" "$vault"; then
57
+ printf 'bc-wiki-lint: PASS: detector completed for %s\n' "$vault"
58
+ else
59
+ status=$?
60
+ printf 'bc-wiki-lint: ERROR: detector failed for %s (exit %s)\n' "$vault" "$status" >&2
61
+ failures=$((failures + 1))
62
+ fi
63
+ done
64
+
65
+ printf '\nbc-wiki-lint: checked %s vault(s), failures=%s\n' "$ran" "$failures"
66
+ if ((failures > 0)); then
67
+ exit 1
68
+ fi
69
+ exit 0
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env bash
2
+ # Run the additive wiki promotion pass for every vault in a configured list.
3
+ #
4
+ # Each vault is delegated to run-promotion.sh so its per-vault safety gates remain
5
+ # the single implementation of promotion policy.
6
+ set -Eeuo pipefail
7
+
8
+ fail() {
9
+ printf 'bc-wiki-maintain-all: ERROR: %s\n' "$*" >&2
10
+ exit 1
11
+ }
12
+
13
+ VAULT_LIST="${VAULT_LIST:-}"
14
+
15
+ [[ -n "$VAULT_LIST" ]] || fail 'VAULT_LIST is not set'
16
+ [[ -f "$VAULT_LIST" ]] || fail "vault list does not exist: $VAULT_LIST"
17
+ [[ -r "$VAULT_LIST" ]] || fail "vault list is not readable: $VAULT_LIST"
18
+
19
+ runner_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
20
+ PROMOTION_RUNNER="${PROMOTION_RUNNER:-$runner_dir/run-promotion.sh}"
21
+ [[ -f "$PROMOTION_RUNNER" ]] || fail "promotion runner does not exist: $PROMOTION_RUNNER"
22
+ [[ -r "$PROMOTION_RUNNER" ]] || fail "promotion runner is not readable: $PROMOTION_RUNNER"
23
+
24
+ # One unit covers every vault, so a hung agent run would consume the whole
25
+ # TimeoutStartSec budget and the vaults after it would never run. Per-vault units
26
+ # never had that exposure. Bounding each child keeps a hang to one vault.
27
+ #
28
+ # --kill-after is load-bearing, not defensive: plain `timeout` sends SIGTERM and then
29
+ # waits forever, so a child that traps or ignores it is not bounded at all. Measured
30
+ # against a SIGTERM-ignoring child, `timeout 1s` ran the full 60s.
31
+ PROMOTION_TIMEOUT="${PROMOTION_TIMEOUT:-30m}"
32
+ PROMOTION_KILL_AFTER="${PROMOTION_KILL_AFTER:-30s}"
33
+ # GNU timeout signals the child's whole process group; uutils timeout (Ubuntu 26.04's default
34
+ # `timeout`) signals only the direct child, so a timed-out agent's descendants keep running.
35
+ # Ubuntu ships GNU's as `gnutimeout`, so prefer that name when present.
36
+ timeout_bin=''
37
+ for candidate in gnutimeout timeout; do
38
+ if command -v "$candidate" >/dev/null 2>&1; then
39
+ timeout_bin="$candidate"
40
+ break
41
+ fi
42
+ done
43
+ [[ -n "$timeout_bin" ]] || fail 'timeout is not installed or not on PATH'
44
+ [[ "$("$timeout_bin" --version 2>/dev/null || true)" == *'GNU coreutils'* ]] \
45
+ || fail "GNU timeout is required: $timeout_bin is not GNU coreutils, and a non-GNU timeout leaves descendants of a timed-out vault running; install GNU coreutils (on Ubuntu: the gnu-coreutils package, which provides gnutimeout)"
46
+
47
+ declare -a vaults=()
48
+ while IFS= read -r line || [[ -n "$line" ]]; do
49
+ # Accept files created on Windows and ignore surrounding whitespace around entries.
50
+ line="${line%$'\r'}"
51
+ line="${line#"${line%%[![:space:]]*}"}"
52
+ line="${line%"${line##*[![:space:]]}"}"
53
+ [[ -z "$line" || "$line" == \#* ]] && continue
54
+
55
+ case "$line" in
56
+ "~") vaults+=("$HOME") ;;
57
+ \~/*) vaults+=("$HOME/${line#\~/}") ;;
58
+ *) vaults+=("$line") ;;
59
+ esac
60
+ done < "$VAULT_LIST"
61
+
62
+ ((${#vaults[@]} > 0)) || fail "vault list contains no vault paths: $VAULT_LIST"
63
+
64
+ failures=0
65
+ checked=0
66
+ declare -a failed_vaults=()
67
+ for vault in "${vaults[@]}"; do
68
+ checked=$((checked + 1))
69
+ printf '\n=== wiki promotion: %s ===\n' "$vault"
70
+ if [[ ! -d "$vault" ]]; then
71
+ printf 'bc-wiki-maintain-all: ERROR: vault is not a directory: %s\n' "$vault" >&2
72
+ failures=$((failures + 1))
73
+ failed_vaults+=("$vault")
74
+ continue
75
+ fi
76
+
77
+ # The assignment is exported only to this child; PI_BIN is inherited.
78
+ if VAULT_ROOT="$vault" "$timeout_bin" --kill-after="$PROMOTION_KILL_AFTER" "$PROMOTION_TIMEOUT" "$PROMOTION_RUNNER"; then
79
+ printf 'bc-wiki-maintain-all: PASS: promotion completed for %s\n' "$vault"
80
+ else
81
+ status=$?
82
+ # 124 is a child that honoured SIGTERM; 137 is one that had to be SIGKILLed.
83
+ if ((status == 124 || status == 137)); then
84
+ printf 'bc-wiki-maintain-all: ERROR: promotion timed out after %s for %s\n' "$PROMOTION_TIMEOUT" "$vault" >&2
85
+ # A timeout can land mid-write, and run-promotion.sh refuses a dirty tree, so this
86
+ # vault fails closed every night until a human clears it. Say so where it is seen.
87
+ printf 'bc-wiki-maintain-all: %s may now have uncommitted changes; review and clear it before the next run\n' "$vault" >&2
88
+ else
89
+ printf 'bc-wiki-maintain-all: ERROR: promotion failed for %s (exit %s)\n' "$vault" "$status" >&2
90
+ fi
91
+ failures=$((failures + 1))
92
+ failed_vaults+=("$vault")
93
+ fi
94
+ done
95
+
96
+ printf '\nbc-wiki-maintain-all: checked %s vault(s), failures=%s\n' "$checked" "$failures"
97
+ if ((failures > 0)); then
98
+ printf 'bc-wiki-maintain-all: failing vaults:\n'
99
+ printf '%s\n' "${failed_vaults[@]}"
100
+ exit 1
101
+ fi
102
+ printf 'bc-wiki-maintain-all: failing vaults: (none)\n'
103
+ exit 0
@@ -0,0 +1,270 @@
1
+ #!/usr/bin/env bash
2
+ # Run the additive wiki promotion pass for one configured vault.
3
+ #
4
+ # The systemd unit supplies VAULT_ROOT and PI_BIN. Keeping these
5
+ # as environment inputs makes the wrapper usable for a later pilot without baking
6
+ # a home directory into the executable.
7
+ set -Eeuo pipefail
8
+
9
+ log() {
10
+ printf 'bc-wiki-maintain: %s\n' "$*"
11
+ }
12
+
13
+ fail() {
14
+ printf 'bc-wiki-maintain: ERROR: %s\n' "$*" >&2
15
+ exit 1
16
+ }
17
+
18
+ VAULT_ROOT="${VAULT_ROOT:-}"
19
+ PI_BIN="${PI_BIN:-pi}"
20
+
21
+ [[ -n "$VAULT_ROOT" ]] || fail 'VAULT_ROOT is not set'
22
+ [[ -d "$VAULT_ROOT" ]] || fail "vault does not exist: $VAULT_ROOT"
23
+ command -v git >/dev/null 2>&1 || fail 'git is not installed or not on PATH'
24
+ command -v python3 >/dev/null 2>&1 || fail 'python3 is not installed or not on PATH'
25
+
26
+ skill_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
27
+ DETECTION_SCRIPT="${DETECTION_SCRIPT:-$skill_dir/wiki_lint.py}"
28
+ PROMOTION_SKILL="${PROMOTION_SKILL:-$skill_dir/SKILL.md}"
29
+ [[ -f "$DETECTION_SCRIPT" ]] || fail "detection script does not exist: $DETECTION_SCRIPT"
30
+
31
+ REPO_ROOT="$(git -C "$VAULT_ROOT" rev-parse --show-toplevel 2>/dev/null)" \
32
+ || fail "vault is not inside a git worktree: $VAULT_ROOT"
33
+ VAULT_PREFIX="$(git -C "$VAULT_ROOT" rev-parse --show-prefix 2>/dev/null)" \
34
+ || fail 'could not determine the vault path inside its git worktree'
35
+ [[ -n "$VAULT_PREFIX" ]] || fail 'refusing to use the repository root as the vault'
36
+
37
+ repo_status() {
38
+ git -C "$REPO_ROOT" status --porcelain=v1 --untracked-files=all
39
+ }
40
+
41
+ require_clean_tree() {
42
+ local status
43
+ status="$(repo_status)"
44
+ if [[ -n "$status" ]]; then
45
+ printf '%s\n' "$status" >&2
46
+ fail 'refusing to run: the git worktree is dirty; review or commit user changes first'
47
+ fi
48
+ }
49
+
50
+ log "running detection for $VAULT_ROOT"
51
+
52
+ # wiki_lint.py's machine-readable contract is one anchored line:
53
+ # PROMOTION_REQUIRED=0 (no promotion pass needed)
54
+ # PROMOTION_REQUIRED=1 (run the promotion pass)
55
+ # The script may print a human-readable report around that line. Missing or
56
+ # malformed status fails closed instead of guessing that a write is safe.
57
+ # Detection is read-only, so it runs before the clean-tree gate: a visible-layout
58
+ # project must reach the not-applicable exit below even when its tree is dirty.
59
+ detection_status=0
60
+ detection_output="$(python3 "$DETECTION_SCRIPT" "$VAULT_ROOT" 2>&1)" || detection_status=$?
61
+
62
+ # Promotion moved log entries into vault pages. In the visible layout agents write
63
+ # decisions and research straight to the table's role folders and log.md is a plain
64
+ # journal, so there is nothing to promote. Exit 0 so a scheduled run over many vaults
65
+ # is not marked failed; the lint report (and lint timer) still shows any findings.
66
+ if printf '%s\n' "$detection_output" | grep -Eq '^Layout:[[:space:]]*visible[[:space:]]*$'; then
67
+ log "promotion is not applicable to visible-layout projects; nothing to do for $VAULT_ROOT"
68
+ exit 0
69
+ fi
70
+
71
+ if [[ "$detection_status" -ne 0 ]]; then
72
+ printf '%s\n' "$detection_output" >&2
73
+ fail 'detection failed'
74
+ fi
75
+ require_clean_tree
76
+ if [[ -n "$detection_output" ]]; then
77
+ printf '%s\n' "$detection_output"
78
+ fi
79
+
80
+ required_lines="$(printf '%s\n' "$detection_output" | grep -Ec '^PROMOTION_REQUIRED=' || true)"
81
+ range_lines="$(printf '%s\n' "$detection_output" | grep -Ec '^PROMOTION_RANGE=' || true)"
82
+ [[ "$required_lines" == 1 && "$range_lines" == 1 ]] \
83
+ || fail 'detection must emit exactly one PROMOTION_REQUIRED and one PROMOTION_RANGE result'
84
+ promotion_required="$(printf '%s\n' "$detection_output" | sed -n 's/^PROMOTION_REQUIRED=//p')"
85
+ promotion_range="$(printf '%s\n' "$detection_output" | sed -n 's/^PROMOTION_RANGE=//p')"
86
+ heading_count="$(printf '%s\n' "$detection_output" | grep -c $'^PROMOTION_HEADING\t' || true)"
87
+ case "$promotion_required" in
88
+ 0)
89
+ [[ "$promotion_range" == "none" ]] || fail 'detector returned an invalid range for a no-op'
90
+ [[ "$heading_count" == 0 ]] || fail 'detector emitted PROMOTION_HEADING lines for a no-op'
91
+ require_clean_tree
92
+ log 'nothing to promote; exiting without invoking the agent'
93
+ exit 0
94
+ ;;
95
+ 1)
96
+ if [[ ! "$promotion_range" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\.\.[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
97
+ fail 'promotion required but detector did not emit a valid PROMOTION_RANGE=YYYY-MM-DD..YYYY-MM-DD result'
98
+ fi
99
+ [[ "$heading_count" -gt 0 ]] || fail 'promotion required but detector emitted no PROMOTION_HEADING lines'
100
+ ;;
101
+ *)
102
+ fail 'detection did not emit exactly one usable PROMOTION_REQUIRED=0|1 result'
103
+ ;;
104
+ esac
105
+
106
+ require_clean_tree
107
+ [[ -f "$PROMOTION_SKILL" ]] || fail "promotion skill does not exist: $PROMOTION_SKILL"
108
+ if [[ "$PI_BIN" == */* ]]; then
109
+ [[ -x "$PI_BIN" ]] || fail "PI_BIN is not executable: $PI_BIN"
110
+ else
111
+ command -v "$PI_BIN" >/dev/null 2>&1 || fail "PI_BIN is not installed or not on PATH: $PI_BIN"
112
+ fi
113
+
114
+ BASE_HEAD="$(git -C "$REPO_ROOT" rev-parse HEAD)"
115
+ CLASSIFY_PATH="$(mktemp)" || fail 'could not create classification temp file'
116
+ export CLASSIFY_PATH
117
+ # On success the verdicts are already in the commit body; on any failure the file is the
118
+ # only record of what the agent decided, so keep it for review.
119
+ cleanup_classify() {
120
+ local status=$?
121
+ if [[ "$status" -eq 0 ]]; then
122
+ rm -f -- "$CLASSIFY_PATH"
123
+ else
124
+ printf 'bc-wiki-maintain: kept classification file for review: %s\n' "$CLASSIFY_PATH" >&2
125
+ fi
126
+ }
127
+ trap cleanup_classify EXIT
128
+ PROMOTION_PROMPT=$(cat <<EOF
129
+ Run the scheduled bc-wiki-maintain promotion pass.
130
+
131
+ Repository: $REPO_ROOT
132
+ Vault: $VAULT_ROOT
133
+ Classification file: $CLASSIFY_PATH
134
+
135
+ Read the vault's AGENTS.md, the loaded bc-wiki-maintain skill, and the relevant log.md
136
+ entries needed to classify the detector's headings before changing anything. Use the skill's
137
+ search-first retrieval (wiki_search.py) to locate relevant pages and verify them. Use index.md
138
+ only for broad project orientation, never as the lookup mechanism. Classify every unpromoted log
139
+ heading the detector listed.
140
+ Write one JSON object per heading, covering that exact list, to $CLASSIFY_PATH and
141
+ nowhere else; a new non-Markdown file left in the vault fails the pass. Format:
142
+ {"heading":"<exact ## line>","verdict":"promote|skip|conflict","reason":"<one line>","page":"<vault-relative page if promote or conflict>"}
143
+
144
+ Promote only durable observations from the append-only log that are not already
145
+ represented in the vault. Prefer the smallest existing page or an appropriately
146
+ named new page. Keep existing pages self-contained. A conflict stops that item, not
147
+ the pass. Stale page vs newer dated log is a promote (append a dated section). Only
148
+ mutually exclusive claims are conflicts. Append index.md links for existing
149
+ findings/ and decisions/ pages missing from the index, except README.md and
150
+ templates/.
151
+
152
+ Safety rules are absolute:
153
+ - Additive-only: create pages or append sections; never delete, rewrite, reflow, or
154
+ silently replace existing prose.
155
+ - Do not pick a winner on a mutually exclusive claim.
156
+ - Do not touch files outside this vault.
157
+ - Do not stage files and do not run git commit. The wrapper will inspect and create the dedicated commit.
158
+ - If every heading is a skip, leave the tree unchanged.
159
+
160
+ When done, briefly report the files considered and the files changed. Do not claim a
161
+ promotion occurred unless the corresponding files are actually changed on disk.
162
+ EOF
163
+ )
164
+
165
+ log 'invoking verified Pi headless promotion agent (gpt-5.6-luna, max)'
166
+ set +e
167
+ (
168
+ cd "$VAULT_ROOT"
169
+ "$PI_BIN" \
170
+ --print \
171
+ --no-session \
172
+ --approve \
173
+ --model 'openai-codex/gpt-5.6-luna:max' \
174
+ --thinking max \
175
+ --skill "$PROMOTION_SKILL" \
176
+ "$PROMOTION_PROMPT"
177
+ )
178
+ agent_status=$?
179
+ set -e
180
+ if [[ "$agent_status" -ne 0 ]]; then
181
+ fail "promotion agent failed with exit status $agent_status; leaving any changes uncommitted for review"
182
+ fi
183
+
184
+ # A promotion agent must not advance HEAD; the wrapper owns the single commit.
185
+ if [[ "$(git -C "$REPO_ROOT" rev-parse HEAD)" != "$BASE_HEAD" ]]; then
186
+ fail 'promotion agent committed unexpectedly; inspect the new commit before enabling the timer'
187
+ fi
188
+
189
+ # The agent must never stage anything. Compare the complete index with the
190
+ # pre-agent tree before inspecting or staging its working-tree changes.
191
+ if ! git -C "$REPO_ROOT" diff --cached --quiet "$BASE_HEAD" --; then
192
+ git -C "$REPO_ROOT" diff --cached --name-status "$BASE_HEAD" >&2 || true
193
+ fail 'promotion agent left staged changes; refusing to inspect or create a commit'
194
+ fi
195
+
196
+ status="$(repo_status)"
197
+ if [[ -z "$status" ]]; then
198
+ log 'agent found nothing to promote; no commit created'
199
+ exit 0
200
+ fi
201
+
202
+ # Never commit work outside the configured vault, and never commit deletions.
203
+ while IFS= read -r -d '' changed_path; do
204
+ case "$changed_path" in
205
+ "$VAULT_PREFIX"*) ;;
206
+ *) fail "promotion touched a path outside the vault: $changed_path" ;;
207
+ esac
208
+ done < <(
209
+ git -C "$REPO_ROOT" diff --name-only -z
210
+ git -C "$REPO_ROOT" ls-files --others --exclude-standard -z
211
+ )
212
+
213
+ deletions="$(git -C "$REPO_ROOT" diff --name-only --diff-filter=D)"
214
+ [[ -z "$deletions" ]] || fail "promotion deleted existing files; refusing to commit:\n$deletions"
215
+
216
+ # The commit stages the whole vault prefix, so a scratch artifact left behind would be
217
+ # committed as if it were a page. A promotion pass only ever adds Markdown.
218
+ while IFS= read -r -d '' new_path; do
219
+ case "$new_path" in
220
+ *.md) ;;
221
+ *) fail "promotion left a new non-Markdown file in the vault; refusing to commit: $new_path" ;;
222
+ esac
223
+ done < <(git -C "$REPO_ROOT" ls-files --others --exclude-standard -z)
224
+
225
+ # A thin write must not close the current heading list. The classification file is a
226
+ # same-pass artifact: it is not a vault page and is not committed, so its verdicts go
227
+ # into the commit body where the next reader can audit each skip.
228
+ if ! classification_summary="$(python3 "$DETECTION_SCRIPT" "$VAULT_ROOT" --verify-classify "$CLASSIFY_PATH")"; then
229
+ fail 'classification does not cover every unpromoted heading; leaving changes uncommitted'
230
+ fi
231
+
232
+ # A no-newline append may show one deleted line; allow it only when the committed bytes
233
+ # are an exact prefix of the new file, which cannot hide an in-place rewrite.
234
+ numstat_output="$(git -C "$REPO_ROOT" diff --numstat -- "$VAULT_PREFIX")" \
235
+ || fail 'could not determine whether tracked vault changes are additive'
236
+ non_additive=''
237
+ while IFS=$'\t' read -r added deleted changed_path; do
238
+ [[ -z "$added" && -z "$deleted" && -z "$changed_path" ]] && continue
239
+ if [[ -z "$changed_path" || ! "$added" =~ ^[0-9]+$ && "$added" != '-' || ! "$deleted" =~ ^[0-9]+$ && "$deleted" != '-' ]]; then
240
+ fail "could not determine additivity for changed vault path: $added<TAB>$deleted<TAB>$changed_path"
241
+ fi
242
+ [[ "$deleted" == '0' ]] && continue
243
+ if [[ "$deleted" == '-' ]]; then
244
+ fail "could not determine additivity for tracked vault file: $changed_path (binary diff)"
245
+ fi
246
+
247
+ old_bytes="$(git -C "$REPO_ROOT" cat-file blob "$BASE_HEAD:$changed_path" | wc -c)" \
248
+ || fail "could not read committed contents for tracked vault file: $changed_path"
249
+ current_bytes="$(wc -c < "$REPO_ROOT/$changed_path")" \
250
+ || fail "could not read working-tree contents for tracked vault file: $changed_path"
251
+ if [[ ! "$old_bytes" =~ ^[0-9]+$ || ! "$current_bytes" =~ ^[0-9]+$ ]]; then
252
+ fail "could not determine byte lengths for tracked vault file: $changed_path"
253
+ fi
254
+ if (( current_bytes < old_bytes )) \
255
+ || ! git -C "$REPO_ROOT" show "$BASE_HEAD:$changed_path" \
256
+ | cmp -n "$old_bytes" - "$REPO_ROOT/$changed_path" >/dev/null 2>&1; then
257
+ non_additive+=" $changed_path (deleted lines: $deleted; committed content is not a byte prefix of the new file)"$'\n'
258
+ fi
259
+ done <<< "$numstat_output"
260
+ [[ -z "$non_additive" ]] \
261
+ || fail $'promotion rewrote existing tracked vault files; refusing to commit:\n'"$non_additive"
262
+
263
+ log 'creating dedicated promotion commit'
264
+ git -C "$REPO_ROOT" add -- "$VAULT_PREFIX"
265
+ git -C "$REPO_ROOT" commit -m "wiki: promote log entries $promotion_range" -m "$classification_summary"
266
+
267
+ if [[ -n "$(repo_status)" ]]; then
268
+ fail 'promotion commit completed but the repository is still dirty'
269
+ fi
270
+ log "promotion committed: $(git -C "$REPO_ROOT" log -1 --format='%h %s')"