@rubytech/create-realagent-code 0.1.567 → 0.1.569

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 (120) hide show
  1. package/dist/__tests__/brand-agent-root.test.js +91 -0
  2. package/dist/brand-agent-root.js +58 -0
  3. package/dist/index.js +25 -28
  4. package/package.json +1 -1
  5. package/payload/platform/plugins/admin/PLUGIN.md +4 -2
  6. package/payload/platform/plugins/admin/hooks/__tests__/quote-path-write-gate.test.sh +152 -0
  7. package/payload/platform/plugins/admin/hooks/__tests__/quote-pdf-bash-gate.test.sh +95 -0
  8. package/payload/platform/plugins/admin/hooks/__tests__/quote-render-gate.test.sh +141 -45
  9. package/payload/platform/plugins/admin/hooks/__tests__/quote-render-pdf-conformance.test.sh +114 -0
  10. package/payload/platform/plugins/admin/hooks/quote-path-write-gate.sh +137 -0
  11. package/payload/platform/plugins/admin/hooks/quote-pdf-bash-gate.sh +70 -0
  12. package/payload/platform/plugins/admin/hooks/quote-render-gate.sh +105 -37
  13. package/payload/platform/plugins/admin/hooks/quote-render-pdf-conformance.sh +178 -0
  14. package/payload/platform/plugins/admin/mcp/dist/index.js +7 -1
  15. package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
  16. package/payload/platform/plugins/admin/mcp/dist/lib/roster-census.d.ts +10 -1
  17. package/payload/platform/plugins/admin/mcp/dist/lib/roster-census.d.ts.map +1 -1
  18. package/payload/platform/plugins/admin/mcp/dist/lib/roster-census.js +52 -1
  19. package/payload/platform/plugins/admin/mcp/dist/lib/roster-census.js.map +1 -1
  20. package/payload/platform/plugins/admin/mcp/dist/tools/capabilities-here.d.ts +9 -0
  21. package/payload/platform/plugins/admin/mcp/dist/tools/capabilities-here.d.ts.map +1 -1
  22. package/payload/platform/plugins/admin/mcp/dist/tools/capabilities-here.js +1 -1
  23. package/payload/platform/plugins/admin/mcp/dist/tools/capabilities-here.js.map +1 -1
  24. package/payload/platform/plugins/admin/skills/capabilities-here/SKILL.md +1 -1
  25. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +44 -1
  26. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +15 -0
  27. package/payload/platform/plugins/docs/references/channel-wake-and-prompt.md +43 -0
  28. package/payload/platform/scripts/__tests__/mailbox-inject-registered.test.sh +5 -5
  29. package/payload/platform/scripts/__tests__/preference-hooks-registered.test.sh +3 -1
  30. package/payload/platform/scripts/__tests__/public-surface-registered.test.sh +5 -5
  31. package/payload/platform/scripts/__tests__/quote-ownership-contract.test.sh +86 -0
  32. package/payload/platform/scripts/lib/__tests__/account-settings-reconcile.test.sh +73 -0
  33. package/payload/platform/scripts/lib/account-settings-reconcile.sh +88 -0
  34. package/payload/platform/scripts/lib/provision-account-dir.sh +11 -146
  35. package/payload/platform/scripts/setup-account.sh +13 -0
  36. package/payload/platform/services/claude-session-manager/dist/account-agent-registry.d.ts +39 -0
  37. package/payload/platform/services/claude-session-manager/dist/account-agent-registry.d.ts.map +1 -0
  38. package/payload/platform/services/claude-session-manager/dist/account-agent-registry.js +223 -0
  39. package/payload/platform/services/claude-session-manager/dist/account-agent-registry.js.map +1 -0
  40. package/payload/platform/services/claude-session-manager/dist/fs-watcher.d.ts +5 -0
  41. package/payload/platform/services/claude-session-manager/dist/fs-watcher.d.ts.map +1 -1
  42. package/payload/platform/services/claude-session-manager/dist/fs-watcher.js +5 -5
  43. package/payload/platform/services/claude-session-manager/dist/fs-watcher.js.map +1 -1
  44. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts +11 -1
  45. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  46. package/payload/platform/services/claude-session-manager/dist/http-server.js +58 -12
  47. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  48. package/payload/platform/services/claude-session-manager/dist/index.js +112 -13
  49. package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
  50. package/payload/platform/services/claude-session-manager/dist/pty-census.d.ts +6 -1
  51. package/payload/platform/services/claude-session-manager/dist/pty-census.d.ts.map +1 -1
  52. package/payload/platform/services/claude-session-manager/dist/pty-census.js +6 -3
  53. package/payload/platform/services/claude-session-manager/dist/pty-census.js.map +1 -1
  54. package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts +21 -8
  55. package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts.map +1 -1
  56. package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +38 -15
  57. package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
  58. package/payload/platform/services/claude-session-manager/dist/quote-delivery-reconcile.d.ts +42 -0
  59. package/payload/platform/services/claude-session-manager/dist/quote-delivery-reconcile.d.ts.map +1 -0
  60. package/payload/platform/services/claude-session-manager/dist/quote-delivery-reconcile.js +215 -0
  61. package/payload/platform/services/claude-session-manager/dist/quote-delivery-reconcile.js.map +1 -0
  62. package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts +2 -0
  63. package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
  64. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +4 -1
  65. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
  66. package/payload/platform/services/claude-session-manager/dist/reaper.d.ts +3 -0
  67. package/payload/platform/services/claude-session-manager/dist/reaper.d.ts.map +1 -1
  68. package/payload/platform/services/claude-session-manager/dist/reaper.js +2 -1
  69. package/payload/platform/services/claude-session-manager/dist/reaper.js.map +1 -1
  70. package/payload/platform/services/claude-session-manager/dist/session-cap-audit.d.ts +2 -0
  71. package/payload/platform/services/claude-session-manager/dist/session-cap-audit.d.ts.map +1 -1
  72. package/payload/platform/services/claude-session-manager/dist/session-cap-audit.js +5 -2
  73. package/payload/platform/services/claude-session-manager/dist/session-cap-audit.js.map +1 -1
  74. package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.d.ts +2 -0
  75. package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.d.ts.map +1 -1
  76. package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.js +5 -3
  77. package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.js.map +1 -1
  78. package/payload/platform/services/claude-session-manager/dist/specialist-preference-audit.d.ts +108 -0
  79. package/payload/platform/services/claude-session-manager/dist/specialist-preference-audit.d.ts.map +1 -0
  80. package/payload/platform/services/claude-session-manager/dist/specialist-preference-audit.js +299 -0
  81. package/payload/platform/services/claude-session-manager/dist/specialist-preference-audit.js.map +1 -0
  82. package/payload/platform/services/claude-session-manager/dist/systemd-scope.d.ts +26 -16
  83. package/payload/platform/services/claude-session-manager/dist/systemd-scope.d.ts.map +1 -1
  84. package/payload/platform/services/claude-session-manager/dist/systemd-scope.js +84 -31
  85. package/payload/platform/services/claude-session-manager/dist/systemd-scope.js.map +1 -1
  86. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.d.ts +7 -0
  87. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.d.ts.map +1 -1
  88. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.js +6 -0
  89. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.js.map +1 -1
  90. package/payload/platform/services/telegram-channel/dist/notification.d.ts +10 -2
  91. package/payload/platform/services/telegram-channel/dist/notification.d.ts.map +1 -1
  92. package/payload/platform/services/telegram-channel/dist/notification.js +15 -3
  93. package/payload/platform/services/telegram-channel/dist/notification.js.map +1 -1
  94. package/payload/platform/services/telegram-channel/dist/server.d.ts.map +1 -1
  95. package/payload/platform/services/telegram-channel/dist/server.js +35 -3
  96. package/payload/platform/services/telegram-channel/dist/server.js.map +1 -1
  97. package/payload/platform/services/telegram-channel/dist/turn-follow.d.ts +10 -0
  98. package/payload/platform/services/telegram-channel/dist/turn-follow.d.ts.map +1 -1
  99. package/payload/platform/services/telegram-channel/dist/turn-follow.js +38 -1
  100. package/payload/platform/services/telegram-channel/dist/turn-follow.js.map +1 -1
  101. package/payload/platform/services/webchat-channel/dist/server.d.ts.map +1 -1
  102. package/payload/platform/services/webchat-channel/dist/server.js +31 -2
  103. package/payload/platform/services/webchat-channel/dist/server.js.map +1 -1
  104. package/payload/platform/services/webchat-channel/dist/turn-follow.d.ts +10 -0
  105. package/payload/platform/services/webchat-channel/dist/turn-follow.d.ts.map +1 -1
  106. package/payload/platform/services/webchat-channel/dist/turn-follow.js +38 -1
  107. package/payload/platform/services/webchat-channel/dist/turn-follow.js.map +1 -1
  108. package/payload/platform/services/whatsapp-channel/dist/instructions.d.ts +9 -0
  109. package/payload/platform/services/whatsapp-channel/dist/instructions.d.ts.map +1 -0
  110. package/payload/platform/services/whatsapp-channel/dist/instructions.js +22 -0
  111. package/payload/platform/services/whatsapp-channel/dist/instructions.js.map +1 -0
  112. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +3 -1
  113. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  114. package/payload/platform/services/whatsapp-channel/dist/notification.js +10 -2
  115. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  116. package/payload/platform/services/whatsapp-channel/dist/server.d.ts.map +1 -1
  117. package/payload/platform/services/whatsapp-channel/dist/server.js +26 -2
  118. package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
  119. package/payload/platform/templates/account-settings.json +153 -0
  120. package/payload/server/server.js +254 -96
@@ -0,0 +1,88 @@
1
+ # account-settings-reconcile.sh — converge every account's Claude Code project
2
+ # settings against the shipped template, and state the divergence count.
3
+ #
4
+ # provision_account_dir writes <accountDir>/.claude/settings.json from
5
+ # platform/templates/account-settings.json at provision time only. The upgrade
6
+ # path re-provisions the house account and no other, so an account created
7
+ # before a hook was added runs a stale hook set indefinitely, and nothing says
8
+ # so. A client-quote delivery gate was registered on one of four accounts on a
9
+ # live install for exactly that reason, and the account it was missing from was
10
+ # the one that quotes.
11
+ #
12
+ # Five one-hook backfill libs were written the same way, each after a different
13
+ # hook was found missing on a live account: owned-dirs, askgate,
14
+ # pdf-conformance, mailbox-inject, public-surface. This lib converges the whole
15
+ # set instead, so a hook added to the template reaches every existing account on
16
+ # the next install without a sixth bespoke backfill.
17
+ #
18
+ # Requires jq. Idempotent. Never echoes file contents. Fail-open: an unusable
19
+ # file logs a status and is left untouched, never rewritten from a guess.
20
+ #
21
+ # Sourced by setup-account.sh; also runnable standalone for a manual repair.
22
+
23
+ # ensure_account_settings <settings_file> <template_file>
24
+ # Returns 0 when the file already matched the template, 1 when it diverged
25
+ # (seeded, updated, unwritable, or unparseable). Logs exactly one
26
+ # [settings-reconcile] account=<id> status=<already-set|updated|absent-seeded|rewrite-failed|no-template>
27
+ ensure_account_settings() {
28
+ local f="$1" tpl="$2"
29
+ local acct
30
+ acct="$(basename "$(dirname "$(dirname "$f")")")"
31
+
32
+ if [ ! -f "$tpl" ]; then
33
+ echo "[settings-reconcile] account=$acct status=no-template"
34
+ return 1
35
+ fi
36
+
37
+ if [ ! -f "$f" ]; then
38
+ mkdir -p "$(dirname "$f")" 2>/dev/null || true
39
+ if cp "$tpl" "$f" 2>/dev/null; then
40
+ echo "[settings-reconcile] account=$acct status=absent-seeded"
41
+ else
42
+ echo "[settings-reconcile] account=$acct status=rewrite-failed"
43
+ fi
44
+ return 1
45
+ fi
46
+
47
+ # Compare canonical forms, so key order and whitespace never read as drift.
48
+ # An empty result means jq refused the file; that is reported, not repaired —
49
+ # an unparseable settings file may carry an operator edit worth keeping, and
50
+ # this pass never destroys what it cannot read.
51
+ local before after
52
+ before="$(jq -S . "$f" 2>/dev/null || true)"
53
+ after="$(jq -S . "$tpl" 2>/dev/null || true)"
54
+ if [ -z "$before" ] || [ -z "$after" ]; then
55
+ echo "[settings-reconcile] account=$acct status=rewrite-failed"
56
+ return 1
57
+ fi
58
+ if [ "$before" = "$after" ]; then
59
+ echo "[settings-reconcile] account=$acct status=already-set"
60
+ return 0
61
+ fi
62
+
63
+ if cp "$tpl" "$f" 2>/dev/null; then
64
+ echo "[settings-reconcile] account=$acct status=updated"
65
+ else
66
+ echo "[settings-reconcile] account=$acct status=rewrite-failed"
67
+ fi
68
+ return 1
69
+ }
70
+
71
+ # reconcile_all_accounts_settings <accounts_dir>
72
+ # Standing check + durable backfill across every account carrying an
73
+ # account.json. Emits one status line per account plus one summary line on every
74
+ # run, including a zero count — silence is not evidence of convergence.
75
+ reconcile_all_accounts_settings() {
76
+ local accts="$1"
77
+ local tpl="${MAXY_ACCOUNT_SETTINGS_TEMPLATE:-${TEMPLATES_DIR:-}/account-settings.json}"
78
+ local n=0 divergent=0 acct
79
+ if [ -d "$accts" ]; then
80
+ for acct in "$accts"/*/; do
81
+ [ -f "$acct/account.json" ] || continue
82
+ n=$((n + 1))
83
+ ensure_account_settings "$acct/.claude/settings.json" "$tpl" || divergent=$((divergent + 1))
84
+ done
85
+ fi
86
+ echo "[settings-reconcile] accounts=$n divergent=$divergent"
87
+ return 0
88
+ }
@@ -70,151 +70,18 @@ provision_account_dir() {
70
70
  [ -d "$ACCOUNT_DIR/.git" ] || git init -q "$ACCOUNT_DIR"
71
71
 
72
72
  # --- project-level .claude/settings.json (hooks; no allowlist) -------------
73
+ # The hook set is data, not a heredoc: platform/templates/account-settings.json
74
+ # is copied verbatim (every $PLATFORM_ROOT in it is a literal Claude Code
75
+ # resolves at hook-run time, so no substitution is needed). Keeping it as a
76
+ # file is what lets account-settings-reconcile.sh converge accounts that
77
+ # already exist, which this writer alone never could — it runs at provision
78
+ # time, and the upgrade path re-provisions the house account and no other.
73
79
  local ACCOUNT_SETTINGS="$ACCOUNT_DIR/.claude/settings.json"
74
- local HOOKS_PATH="\$PLATFORM_ROOT/plugins/admin/hooks"
75
- cat > "$ACCOUNT_SETTINGS" << SETTINGS_EOF
76
- {
77
- "permissions": {
78
- "defaultMode": "bypassPermissions",
79
- "allow": [],
80
- "deny": []
81
- },
82
- "hooks": {
83
- "PreToolUse": [
84
- {
85
- "matcher": "Write",
86
- "hooks": [
87
- { "type": "command", "command": "bash $HOOKS_PATH/archive-ingest-surface-gate.sh" },
88
- { "type": "command", "command": "bash $HOOKS_PATH/fs-schema-guard.sh" }
89
- ]
90
- },
91
- {
92
- "matcher": "Edit",
93
- "hooks": [
94
- { "type": "command", "command": "bash $HOOKS_PATH/archive-ingest-surface-gate.sh" },
95
- { "type": "command", "command": "bash $HOOKS_PATH/fs-schema-guard.sh" }
96
- ]
97
- },
98
- {
99
- "matcher": "NotebookEdit",
100
- "hooks": [
101
- { "type": "command", "command": "bash $HOOKS_PATH/archive-ingest-surface-gate.sh" },
102
- { "type": "command", "command": "bash $HOOKS_PATH/fs-schema-guard.sh" }
103
- ]
104
- },
105
- {
106
- "matcher": "Bash",
107
- "hooks": [
108
- { "type": "command", "command": "bash $HOOKS_PATH/archive-ingest-surface-gate.sh" },
109
- { "type": "command", "command": "bash $HOOKS_PATH/fs-schema-guard-bash-pre.sh" },
110
- { "type": "command", "command": "bash $HOOKS_PATH/quote-engine-gate.sh" }
111
- ]
112
- },
113
- {
114
- "hooks": [
115
- { "type": "command", "command": "bash $HOOKS_PATH/archive-ingest-surface-gate.sh" },
116
- { "type": "command", "command": "bash $HOOKS_PATH/public-tool-surface.sh" }
117
- ]
118
- },
119
- {
120
- "matcher": "WebFetch",
121
- "hooks": [
122
- { "type": "command", "command": "node $HOOKS_PATH/webfetch-preflight.mjs" }
123
- ]
124
- },
125
- {
126
- "matcher": "AskUserQuestion",
127
- "hooks": [
128
- { "type": "command", "command": "bash $HOOKS_PATH/askuserquestion-investigate-gate.sh" },
129
- { "type": "command", "command": "bash $HOOKS_PATH/askuserquestion-channel-carrier-gate.sh" }
130
- ]
131
- },
132
- {
133
- "matcher": "mcp__plugin_browser_browser__browser-pdf-save",
134
- "hooks": [
135
- { "type": "command", "command": "bash $HOOKS_PATH/quote-render-gate.sh" }
136
- ]
137
- },
138
- {
139
- "matcher": "mcp__plugin_browser_browser__browser-pdf-save",
140
- "hooks": [
141
- { "type": "command", "command": "bash $HOOKS_PATH/preference-consult-gate.sh" }
142
- ]
143
- },
144
- {
145
- "matcher": "mcp__plugin_email_email__email-send|mcp__plugin_email_email__email-reply|mcp__plugin_email_email__email-draft-send|mcp__plugin_outlook_outlook__outlook-mail-send|mcp__plugin_outlook_outlook__outlook-mail-reply|mcp__plugin_outlook_outlook__outlook-draft-send|SendUserFile",
146
- "hooks": [
147
- { "type": "command", "command": "bash $HOOKS_PATH/preference-consult-gate.sh" }
148
- ]
149
- }
150
- ],
151
- "PostToolUse": [
152
- {
153
- "matcher": "Bash",
154
- "hooks": [
155
- { "type": "command", "command": "bash $HOOKS_PATH/fs-schema-guard-bash-post.sh" }
156
- ]
157
- },
158
- {
159
- "matcher": "Agent",
160
- "hooks": [
161
- { "type": "command", "command": "bash $HOOKS_PATH/post-tool-use-agent.sh" }
162
- ]
163
- },
164
- {
165
- "matcher": "mcp__plugin_browser_browser__browser-pdf-save",
166
- "hooks": [
167
- { "type": "command", "command": "bash $HOOKS_PATH/quote-render-pdf-conformance.sh" }
168
- ]
169
- },
170
- {
171
- "matcher": "mcp__.*__.*-(export|import)-parse$",
172
- "hooks": [
173
- { "type": "command", "command": "bash $HOOKS_PATH/archive-ingest-surface-gate.sh" }
174
- ]
175
- },
176
- {
177
- "matcher": "mcp__.*",
178
- "hooks": [
179
- { "type": "command", "command": "bash $HOOKS_PATH/mcp-tool-missing.sh" }
180
- ]
181
- },
182
- {
183
- "matcher": "Write",
184
- "hooks": [
185
- { "type": "command", "command": "bash $HOOKS_PATH/admin-authoring-observer.sh" }
186
- ]
187
- },
188
- {
189
- "matcher": "Edit",
190
- "hooks": [
191
- { "type": "command", "command": "bash $HOOKS_PATH/admin-authoring-observer.sh" }
192
- ]
193
- }
194
- ],
195
- "UserPromptSubmit": [
196
- {
197
- "hooks": [
198
- { "type": "command", "command": "bash $HOOKS_PATH/archive-ingest-surface-gate.sh" },
199
- { "type": "command", "command": "bash $HOOKS_PATH/prompt-optimiser-directive.sh" },
200
- { "type": "command", "command": "bash $HOOKS_PATH/datetime-inject.sh" },
201
- { "type": "command", "command": "bash $HOOKS_PATH/mailbox-inject.sh" },
202
- { "type": "command", "command": "bash $HOOKS_PATH/preference-consult-directive.sh" },
203
- { "type": "command", "command": "bash $HOOKS_PATH/public-tool-surface.sh" }
204
- ]
205
- }
206
- ],
207
- "Stop": [
208
- {
209
- "hooks": [
210
- { "type": "command", "command": "bash $HOOKS_PATH/prompt-optimiser-compliance.sh" },
211
- { "type": "command", "command": "bash $HOOKS_PATH/public-tool-surface.sh" }
212
- ]
213
- }
214
- ]
215
- }
216
- }
217
- SETTINGS_EOF
80
+ if [ -f "$TEMPLATES_DIR/account-settings.json" ]; then
81
+ cp "$TEMPLATES_DIR/account-settings.json" "$ACCOUNT_SETTINGS"
82
+ else
83
+ echo " [acct-settings] WARNING: template missing at $TEMPLATES_DIR/account-settings.json — settings.json not written" >&2
84
+ fi
218
85
 
219
86
  # --- agent identities + specialist plugin templates ------------------------
220
87
  cp "$TEMPLATES_DIR/agents/admin/IDENTITY.md" "$ACCOUNT_DIR/agents/admin/IDENTITY.md"
@@ -420,8 +287,6 @@ for n in names:
420
287
  echo " op=specialist-orphan-reconcile orphaned=$_orphaned"
421
288
  fi
422
289
 
423
- rm -f "$ACCOUNT_DIR/.claude/agents/"*.md 2>/dev/null || true
424
-
425
290
  # SOUL.md — user-controlled. Only create if missing. Never overwrite.
426
291
  if [ -f "$ACCOUNT_DIR/agents/admin/SOUL.md" ]; then
427
292
  echo " agents/admin/SOUL.md preserved ($(wc -c < "$ACCOUNT_DIR/agents/admin/SOUL.md" | tr -d ' ') bytes)"
@@ -119,3 +119,16 @@ reconcile_all_accounts_mailbox_inject "$ACCOUNTS_DIR"
119
119
  # under a one-tool allowlist. Reconcile every account on every install.
120
120
  # Idempotent; logs one [backfill-2339] line per account.
121
121
  reconcile_all_accounts_public_surface "$ACCOUNTS_DIR"
122
+
123
+ # ------------------------------------------------------------------
124
+ # 8. Converge the whole hook set on every account
125
+ # ------------------------------------------------------------------
126
+ # Steps 3 to 7 each retrofit one hook, and each was written after that hook was
127
+ # found missing on a live account. provision_account_dir writes the full set,
128
+ # but only at provision time, and this script re-provisions the house account
129
+ # and no other — so every future hook repeats the same fault. This step
130
+ # converges each account's settings against the shipped template instead, and
131
+ # states the divergence count on every run including zero. A hook added to
132
+ # platform/templates/account-settings.json needs no backfill of its own.
133
+ . "$SCRIPT_DIR/lib/account-settings-reconcile.sh"
134
+ reconcile_all_accounts_settings "$ACCOUNTS_DIR"
@@ -0,0 +1,39 @@
1
+ /** Two spawns in the same account sync concurrently — an admin session and a
2
+ * channel session are routine — and they write identical content. Whoever
3
+ * loses a link gets EEXIST on create or ENOENT on remove for work the winner
4
+ * has already done. Swallowing exactly those two codes keeps the loser going
5
+ * instead of aborting its remaining files and logging a failure that never
6
+ * happened, into the one surface this task exists to make trustworthy.
7
+ *
8
+ * Only the named code is swallowed. Every other errno propagates to the
9
+ * caller's own catch, which is what still turns a genuine EACCES or ENOTDIR
10
+ * into `op=account-agent-registry error`. Exported for its own unit test: the
11
+ * propagation half cannot be provoked through the filesystem from outside. */
12
+ export declare function ignoringRaceWith(code: 'EEXIST' | 'ENOENT', act: () => void): void;
13
+ /** What the CLI will be able to dispatch from the registry we just wrote.
14
+ *
15
+ * Task 2469 — the mirror is keyed on filename and dispatch is keyed on the
16
+ * frontmatter `name`, so `synced=<N>` cannot answer "can this be reached?".
17
+ * A card with no name, and two cards claiming one name, both mirror cleanly
18
+ * and neither dispatches; a specialist that is never dispatched never fails,
19
+ * so no transition log anywhere carries it. Only a state reconcile sees it.
20
+ *
21
+ * Measured over the registry rather than the source directory, because the
22
+ * registry is the directory the CLI reads: where an operator's own regular
23
+ * file sits at a card's name, that file is what resolves, and it is that file
24
+ * this must report on.
25
+ *
26
+ * Exported for its own unit test and for callers that want the state without
27
+ * re-running a sync. */
28
+ export declare function resolveRegistryNames(registryDir: string): {
29
+ resolvable: number;
30
+ unnamed: string[];
31
+ dupeNames: string[];
32
+ };
33
+ /** Mirror `<accountDir>/specialists/agents/*.md` into
34
+ * `<accountDir>/.claude/agents/` as symlinks, and remove every registry
35
+ * symlink the source no longer has. Emits exactly one line:
36
+ * `op=account-agent-registry synced=<N> pruned=<N> collisions=<basenames>`,
37
+ * or one `op=account-agent-registry error reason=<msg>` if anything threw. */
38
+ export declare function syncAccountAgentRegistry(accountDir: string, log: (line: string) => void): void;
39
+ //# sourceMappingURL=account-agent-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-agent-registry.d.ts","sourceRoot":"","sources":["../src/account-agent-registry.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;+EAU+E;AAC/E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,EAAE,GAAG,EAAE,MAAM,IAAI,GAAG,IAAI,CAOjF;AA6BD;;;;;;;;;;;;;;yBAcyB;AACzB,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG;IACzD,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB,CAsBA;AAED;;;;+EAI+E;AAC/E,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAgG9F"}
@@ -0,0 +1,223 @@
1
+ // Task 2460 — the one agent registry per account.
2
+ //
3
+ // Claude Code resolves a subagent name from exactly two directories, both
4
+ // string constants in the shipped binary: `$CLAUDE_CONFIG_DIR/agents/` and
5
+ // `<cwd>/.claude/agents/`. Three directories held agent files and nothing
6
+ // reconciled them, which produced three measured symptoms: an authored
7
+ // specialist was never registered; a retired template stayed registered forever
8
+ // (clare-craig's dangling `archive-ingest-operator.md`); and a specialist
9
+ // disabled on one account stayed resolvable in every account on the install.
10
+ //
11
+ // This module makes `<accountDir>/.claude/agents/` a mirror of
12
+ // `<accountDir>/specialists/agents/` and nothing else. cwd at every spawn is
13
+ // the account dir, so that path is the second constant, and the brand-wide root
14
+ // is cleared by the installer, so it is the only one.
15
+ //
16
+ // Symlinks rather than copies: the source stays the single writable surface, so
17
+ // authoring, disabling and provisioning keep working on it unchanged.
18
+ //
19
+ // It is called at spawn rather than at authoring so an account already in a
20
+ // broken state is repaired by its next session, with no manual step and no
21
+ // second disk writer that can drift from provisioning.
22
+ //
23
+ // It never throws. A registry that cannot be written is a specialist that
24
+ // cannot be dispatched, which is the state before this module existed; a spawn
25
+ // that dies instead is strictly worse.
26
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, symlinkSync, unlinkSync } from 'node:fs';
27
+ import { dirname, join, resolve } from 'node:path';
28
+ /** Two spawns in the same account sync concurrently — an admin session and a
29
+ * channel session are routine — and they write identical content. Whoever
30
+ * loses a link gets EEXIST on create or ENOENT on remove for work the winner
31
+ * has already done. Swallowing exactly those two codes keeps the loser going
32
+ * instead of aborting its remaining files and logging a failure that never
33
+ * happened, into the one surface this task exists to make trustworthy.
34
+ *
35
+ * Only the named code is swallowed. Every other errno propagates to the
36
+ * caller's own catch, which is what still turns a genuine EACCES or ENOTDIR
37
+ * into `op=account-agent-registry error`. Exported for its own unit test: the
38
+ * propagation half cannot be provoked through the filesystem from outside. */
39
+ export function ignoringRaceWith(code, act) {
40
+ try {
41
+ act();
42
+ }
43
+ catch (err) {
44
+ if (err.code === code)
45
+ return;
46
+ throw err;
47
+ }
48
+ }
49
+ /** The `name:` value from a card's frontmatter, or null. CRLF-tolerant and
50
+ * quote-stripping, matching the reader in `specialist-roster.ts` and the one
51
+ * in the roster census, so every surface agrees on what a card is called. A
52
+ * card that cannot be read — a dangling link, a directory at a `.md` path,
53
+ * EACCES — yields null rather than throwing, because "we could not tell" and
54
+ * "it does not resolve" are the same answer to the dispatcher. */
55
+ function readFrontmatterName(file) {
56
+ let raw;
57
+ try {
58
+ raw = readFileSync(file, 'utf8');
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ const fm = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
64
+ if (!fm)
65
+ return null;
66
+ const m = fm[1].match(/^name:\s*(.*?)\r?$/m);
67
+ if (!m)
68
+ return null;
69
+ let value = m[1].trim();
70
+ if ((value.startsWith('"') && value.endsWith('"')) ||
71
+ (value.startsWith("'") && value.endsWith("'"))) {
72
+ value = value.slice(1, -1);
73
+ }
74
+ return value || null;
75
+ }
76
+ /** What the CLI will be able to dispatch from the registry we just wrote.
77
+ *
78
+ * Task 2469 — the mirror is keyed on filename and dispatch is keyed on the
79
+ * frontmatter `name`, so `synced=<N>` cannot answer "can this be reached?".
80
+ * A card with no name, and two cards claiming one name, both mirror cleanly
81
+ * and neither dispatches; a specialist that is never dispatched never fails,
82
+ * so no transition log anywhere carries it. Only a state reconcile sees it.
83
+ *
84
+ * Measured over the registry rather than the source directory, because the
85
+ * registry is the directory the CLI reads: where an operator's own regular
86
+ * file sits at a card's name, that file is what resolves, and it is that file
87
+ * this must report on.
88
+ *
89
+ * Exported for its own unit test and for callers that want the state without
90
+ * re-running a sync. */
91
+ export function resolveRegistryNames(registryDir) {
92
+ let entries;
93
+ try {
94
+ entries = readdirSync(registryDir).filter((n) => n.endsWith('.md')).sort();
95
+ }
96
+ catch {
97
+ return { resolvable: 0, unnamed: [], dupeNames: [] };
98
+ }
99
+ const claims = new Map();
100
+ const unnamed = [];
101
+ for (const file of entries) {
102
+ const name = readFrontmatterName(join(registryDir, file));
103
+ if (name === null) {
104
+ unnamed.push(file);
105
+ continue;
106
+ }
107
+ claims.set(name, (claims.get(name) ?? 0) + 1);
108
+ }
109
+ const dupeNames = Array.from(claims.entries())
110
+ .filter(([, n]) => n > 1)
111
+ .map(([name]) => name)
112
+ .sort();
113
+ return { resolvable: claims.size, unnamed, dupeNames };
114
+ }
115
+ /** Mirror `<accountDir>/specialists/agents/*.md` into
116
+ * `<accountDir>/.claude/agents/` as symlinks, and remove every registry
117
+ * symlink the source no longer has. Emits exactly one line:
118
+ * `op=account-agent-registry synced=<N> pruned=<N> collisions=<basenames>`,
119
+ * or one `op=account-agent-registry error reason=<msg>` if anything threw. */
120
+ export function syncAccountAgentRegistry(accountDir, log) {
121
+ const sourceDir = join(accountDir, 'specialists', 'agents');
122
+ const registryDir = join(accountDir, '.claude', 'agents');
123
+ let synced = 0;
124
+ let pruned = 0;
125
+ const collisions = [];
126
+ try {
127
+ mkdirSync(registryDir, { recursive: true });
128
+ // An absent source directory is an account with no specialists, not an
129
+ // error. The prune pass below still runs, so a registry left behind by a
130
+ // removed source directory is cleared rather than frozen.
131
+ const sources = existsSync(sourceDir)
132
+ ? readdirSync(sourceDir).filter((n) => n.endsWith('.md')).sort()
133
+ : [];
134
+ for (const file of sources) {
135
+ const targetAbs = join(sourceDir, file);
136
+ const linkPath = join(registryDir, file);
137
+ let stat = null;
138
+ try {
139
+ stat = lstatSync(linkPath);
140
+ }
141
+ catch (err) {
142
+ if (err.code !== 'ENOENT')
143
+ throw err;
144
+ }
145
+ if (stat === null) {
146
+ // A concurrent sync may have created it between the lstat and here. It
147
+ // writes the same target, so counting it synced is accurate either way.
148
+ ignoringRaceWith('EEXIST', () => symlinkSync(targetAbs, linkPath));
149
+ synced++;
150
+ continue;
151
+ }
152
+ // A regular file here is an operator's own placement. Never overwritten,
153
+ // never silently ignored: it is named so the operator can resolve it, and
154
+ // not counted as synced, because that name does not resolve to the
155
+ // account's specialist.
156
+ if (!stat.isSymbolicLink()) {
157
+ collisions.push(file);
158
+ continue;
159
+ }
160
+ let current;
161
+ try {
162
+ current = resolve(dirname(linkPath), readlinkSync(linkPath));
163
+ }
164
+ catch {
165
+ current = '';
166
+ }
167
+ if (current !== targetAbs) {
168
+ // Both steps tolerate a concurrent sync doing the same retarget: an
169
+ // ENOENT unlink means the stale link is already gone, which is exactly
170
+ // when the create below still has to run, and an EEXIST create means
171
+ // the other process already wrote this same target.
172
+ ignoringRaceWith('ENOENT', () => unlinkSync(linkPath));
173
+ ignoringRaceWith('EEXIST', () => symlinkSync(targetAbs, linkPath));
174
+ }
175
+ synced++;
176
+ }
177
+ // Set difference, not dangling-target. A link the source no longer has is
178
+ // removed whether or not its target survives: symptom 2 was exactly a link
179
+ // that outlived its source, and a dangling-only rule would leave that class
180
+ // of drift reachable in the new registry. This is the half of the mirror
181
+ // that makes the registry's basename set equal the source's in both
182
+ // directions.
183
+ const sourceSet = new Set(sources);
184
+ for (const entry of readdirSync(registryDir)) {
185
+ if (!entry.endsWith('.md'))
186
+ continue;
187
+ if (sourceSet.has(entry))
188
+ continue;
189
+ const linkPath = join(registryDir, entry);
190
+ let stat;
191
+ try {
192
+ stat = lstatSync(linkPath);
193
+ }
194
+ catch {
195
+ continue;
196
+ }
197
+ // A regular file is the operator's, at a name the source does not claim.
198
+ // Left alone for the same reason as a collision above.
199
+ if (!stat.isSymbolicLink())
200
+ continue;
201
+ // A concurrent sync may have pruned it already; that is the same outcome,
202
+ // so count it either way rather than aborting the rest of the pass.
203
+ ignoringRaceWith('ENOENT', () => unlinkSync(linkPath));
204
+ pruned++;
205
+ }
206
+ log(`op=account-agent-registry synced=${synced} pruned=${pruned} collisions=${collisions.join(',')}`);
207
+ // Task 2469 — a second line, not three more fields on the first. That one
208
+ // is a transition record: what this spawn changed. This is a state
209
+ // reconcile: what is reachable now. Emitted every spawn including zero, so
210
+ // an account with no specialists is distinguishable from a reconcile that
211
+ // did not run. On the error path below it is deliberately absent — after a
212
+ // failed sync the reachable set is unknown, and reporting zero would assert
213
+ // something this never measured.
214
+ const resolution = resolveRegistryNames(registryDir);
215
+ log(`op=agent-registry-resolution resolvable=${resolution.resolvable}` +
216
+ ` unnamed=${resolution.unnamed.join(',')}` +
217
+ ` dupeNames=${resolution.dupeNames.join(',')}`);
218
+ }
219
+ catch (err) {
220
+ log(`op=account-agent-registry error reason=${err instanceof Error ? err.message : String(err)}`);
221
+ }
222
+ }
223
+ //# sourceMappingURL=account-agent-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-agent-registry.js","sourceRoot":"","sources":["../src/account-agent-registry.ts"],"names":[],"mappings":"AAAA,kD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AAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAC1C,cAAc,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAC/C,CAAA;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,0CAA0C,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACnG,CAAC;AACH,CAAC"}
@@ -190,5 +190,10 @@ export declare function createFsWatcher(opts: {
190
190
  * orphan-stop escalation. Default 5_000 ms (matches the scope's
191
191
  * `TimeoutStopSec`). Tests pass small values to keep run time bounded. */
192
192
  killGraceMs?: number;
193
+ /** Task 2457 — the brand that owns this manager's scopes. REQUIRED, with no
194
+ * default: the boot-seed reconciler stops every scope it cannot reattach,
195
+ * and a guessed brand would make it stop a co-resident brand's live
196
+ * sessions — the exact fault this field exists to close. */
197
+ brandSlug: string;
193
198
  }): FsWatcher;
194
199
  //# sourceMappingURL=fs-watcher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fs-watcher.d.ts","sourceRoot":"","sources":["../src/fs-watcher.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAI5D,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,eAAe,EAErB,MAAM,oBAAoB,CAAA;AAsC3B,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAA;AACpD;;;;;;;;gCAQgC;AAChC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAA;AAE7D,MAAM,WAAW,UAAU;IACzB;;mDAE+C;IAC/C,SAAS,EAAE,MAAM,CAAA;IACjB,0EAA0E;IAC1E,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;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AAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd;;;;sFAIkF;IAClF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;6EAIyE;IACzE,YAAY,CAAC,EAAE,eAAe,CAAA;IAC9B;;8EAE0E;IAC1E,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B;;+EAE2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;iEAG6D;IAC7D,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,SAAS,CA63BZ"}
@@ -125,7 +125,7 @@ function parsePidFile(path) {
125
125
  return { sessionId, pid, bridgeSessionId, bridgeSuffix, agent, cwd, status, updatedAt, processStartedAt, pidFilePath: path };
126
126
  }
127
127
  export function createFsWatcher(opts) {
128
- const { sessionsDir, projectsDir, logger } = opts;
128
+ const { sessionsDir, projectsDir, logger, brandSlug } = opts;
129
129
  // Task 1433 — resolveFromDisk scans `<claudeConfigDir>/projects/**`. The boot
130
130
  // layout is `<cfg>/projects/<slug>`, so the config root is two levels up from
131
131
  // projectsDir when not passed explicitly.
@@ -743,7 +743,7 @@ export function createFsWatcher(opts) {
743
743
  * orphaned-stopped=N` even when every count is zero so the operator
744
744
  * can confirm the reconciliation ran. */
745
745
  function reconcileSurvivingScopes(scopeRecords) {
746
- const { scopes, result } = listSurvivingScopes(runSystemctl);
746
+ const { scopes, result } = listSurvivingScopes(runSystemctl, brandSlug);
747
747
  if (result.exitCode !== 0) {
748
748
  logger(`[boot-seed] systemctl-list-units-failed exit-code=${result.exitCode} stderr=${JSON.stringify(result.stderr.slice(-200))} survived-scopes=0 reattached=0 orphaned=0 orphaned-stopped=0`);
749
749
  return;
@@ -769,9 +769,9 @@ export function createFsWatcher(opts) {
769
769
  // ms when escalation runs and we don't want to serialise boot on it).
770
770
  const pidForStop = decision.match === 'orphan-pid-dead'
771
771
  ? null
772
- : getScopeMainPid(runSystemctl, scope.unitToken);
772
+ : getScopeMainPid(runSystemctl, brandSlug, scope.unitToken);
773
773
  orphanedStopped += 1;
774
- void stopScopeUnit(runSystemctl, scope.unitToken, {
774
+ void stopScopeUnit(runSystemctl, brandSlug, scope.unitToken, {
775
775
  pid: pidForStop,
776
776
  killGraceMs,
777
777
  signals: processSignals,
@@ -829,7 +829,7 @@ export function createFsWatcher(opts) {
829
829
  // rc-spawn survivor's row has pid=null. Fall back to the scope's MainPID,
830
830
  // and adopt that pid onto the row so the operator's End and the standing
831
831
  // reconciler have a real process to act on.
832
- const effectivePid = row.pid ?? getScopeMainPid(runSystemctl, scope.unitToken);
832
+ const effectivePid = row.pid ?? getScopeMainPid(runSystemctl, brandSlug, scope.unitToken);
833
833
  if (effectivePid === null || !processSignals.isAlive(effectivePid)) {
834
834
  logger(`[boot-seed] scope-classify unit=${scope.unitName} sessionId=${sessionId.slice(0, 8)} match=orphan-pid-dead reason=pid-already-dead`);
835
835
  return { match: 'orphan-pid-dead', reason: 'pid-already-dead' };