create-egregore 0.19.32 → 0.20.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 (173) hide show
  1. package/assets/egregore-launcher.js +118 -13
  2. package/bin/cli.js +48 -3
  3. package/lib/connect-runtime.js +4 -2
  4. package/lib/local.js +15 -1
  5. package/lib/prime-runtime.js +208 -0
  6. package/lib/setup.js +45 -3
  7. package/package.json +5 -4
  8. package/runtime/codex/.codex/skills/ingest-notion/SKILL.md +29 -0
  9. package/runtime/codex/.codex/skills/notion-connect/SKILL.md +29 -0
  10. package/runtime/codex/.codex/skills/teams-connect/SKILL.md +29 -0
  11. package/runtime/codex/.codex/spec-manifest.json +3 -3
  12. package/runtime/codex/AGENTS.md +11 -4
  13. package/runtime/codex/bin/activity-data.sh +4 -8
  14. package/runtime/codex/bin/attendant.sh +13 -0
  15. package/runtime/codex/bin/autosave.sh +27 -1
  16. package/runtime/codex/bin/codex-render-spec.mjs +6 -0
  17. package/runtime/codex/bin/codex-session-start.sh +8 -1
  18. package/runtime/codex/bin/connect-refresh.sh +33 -0
  19. package/runtime/codex/bin/graph-batch.sh +25 -6
  20. package/runtime/codex/bin/graph-op.sh +5 -4
  21. package/runtime/codex/bin/graph.sh +31 -5
  22. package/runtime/codex/bin/ingest.py +81 -5
  23. package/runtime/codex/bin/lib/context.sh +26 -1
  24. package/runtime/codex/bin/lib/greeting.sh +4 -1
  25. package/runtime/codex/bin/lib/worktree-links.sh +25 -0
  26. package/runtime/codex/manifest.json +8 -1
  27. package/runtime/pi/.codex/skills/ingest-notion/SKILL.md +29 -0
  28. package/runtime/pi/.codex/skills/notion-connect/SKILL.md +29 -0
  29. package/runtime/pi/.codex/skills/teams-connect/SKILL.md +29 -0
  30. package/runtime/pi/.codex/spec-manifest.json +3 -3
  31. package/runtime/pi/.pi/APPEND_SYSTEM.md +3 -2
  32. package/runtime/pi/.pi/extensions/egregore.ts +17 -6
  33. package/runtime/pi/.pi/spec-manifest.json +2 -2
  34. package/runtime/pi/AGENTS.md +11 -4
  35. package/runtime/pi/bin/activity-data.sh +4 -8
  36. package/runtime/pi/bin/attendant.sh +13 -0
  37. package/runtime/pi/bin/autosave.sh +27 -1
  38. package/runtime/pi/bin/codex-render-spec.mjs +6 -0
  39. package/runtime/pi/bin/codex-session-start.sh +8 -1
  40. package/runtime/pi/bin/connect-refresh.sh +33 -0
  41. package/runtime/pi/bin/graph-batch.sh +25 -6
  42. package/runtime/pi/bin/graph-op.sh +5 -4
  43. package/runtime/pi/bin/graph.sh +31 -5
  44. package/runtime/pi/bin/ingest.py +81 -5
  45. package/runtime/pi/bin/lib/context.sh +26 -1
  46. package/runtime/pi/bin/lib/greeting.sh +4 -1
  47. package/runtime/pi/bin/lib/worktree-links.sh +25 -0
  48. package/runtime/pi/bin/pi-branch-policy.mjs +138 -1
  49. package/runtime/pi/bin/pi-product-workflows.mjs +35 -7
  50. package/runtime/pi/manifest.json +8 -1
  51. package/runtime/prime/.claude/context/notification-consent.md +66 -0
  52. package/runtime/prime/.codex/config.toml +17 -0
  53. package/runtime/prime/.codex/hooks/branch-guard.js +461 -0
  54. package/runtime/prime/.codex/hooks/search-hint.js +67 -0
  55. package/runtime/prime/.codex/hooks.json +30 -0
  56. package/runtime/prime/.codex/skills/activity/SKILL.md +82 -0
  57. package/runtime/prime/.codex/skills/announce/SKILL.md +67 -0
  58. package/runtime/prime/.codex/skills/archive/SKILL.md +45 -0
  59. package/runtime/prime/.codex/skills/branch/SKILL.md +29 -0
  60. package/runtime/prime/.codex/skills/checkup/SKILL.md +45 -0
  61. package/runtime/prime/.codex/skills/commit/SKILL.md +29 -0
  62. package/runtime/prime/.codex/skills/contribute/SKILL.md +29 -0
  63. package/runtime/prime/.codex/skills/create-skill/SKILL.md +29 -0
  64. package/runtime/prime/.codex/skills/dark-mode/SKILL.md +29 -0
  65. package/runtime/prime/.codex/skills/dashboard/SKILL.md +59 -0
  66. package/runtime/prime/.codex/skills/deep-reflect/SKILL.md +109 -0
  67. package/runtime/prime/.codex/skills/delete-user/SKILL.md +29 -0
  68. package/runtime/prime/.codex/skills/emissary/SKILL.md +45 -0
  69. package/runtime/prime/.codex/skills/handoff/SKILL.md +166 -0
  70. package/runtime/prime/.codex/skills/harvest/QUESTION_PALETTE.md +76 -0
  71. package/runtime/prime/.codex/skills/harvest/SKILL.md +131 -0
  72. package/runtime/prime/.codex/skills/ingest/SKILL.md +29 -0
  73. package/runtime/prime/.codex/skills/ingest-notion/SKILL.md +29 -0
  74. package/runtime/prime/.codex/skills/ingest-user-interview/SKILL.md +45 -0
  75. package/runtime/prime/.codex/skills/invite/SKILL.md +44 -0
  76. package/runtime/prime/.codex/skills/issue/SKILL.md +45 -0
  77. package/runtime/prime/.codex/skills/me/SKILL.md +29 -0
  78. package/runtime/prime/.codex/skills/meeting/SKILL.md +45 -0
  79. package/runtime/prime/.codex/skills/note/SKILL.md +29 -0
  80. package/runtime/prime/.codex/skills/notion-connect/SKILL.md +29 -0
  81. package/runtime/prime/.codex/skills/onboarding/SKILL.md +45 -0
  82. package/runtime/prime/.codex/skills/pr/SKILL.md +29 -0
  83. package/runtime/prime/.codex/skills/pull/SKILL.md +29 -0
  84. package/runtime/prime/.codex/skills/push/SKILL.md +29 -0
  85. package/runtime/prime/.codex/skills/quest/SKILL.md +80 -0
  86. package/runtime/prime/.codex/skills/reflect/SKILL.md +45 -0
  87. package/runtime/prime/.codex/skills/review-pr/SKILL.md +45 -0
  88. package/runtime/prime/.codex/skills/save/SKILL.md +125 -0
  89. package/runtime/prime/.codex/skills/slack-connect/SKILL.md +29 -0
  90. package/runtime/prime/.codex/skills/summon/SKILL.md +45 -0
  91. package/runtime/prime/.codex/skills/sync-repos/SKILL.md +29 -0
  92. package/runtime/prime/.codex/skills/teams-connect/SKILL.md +29 -0
  93. package/runtime/prime/.codex/skills/telegram-connect/SKILL.md +29 -0
  94. package/runtime/prime/.codex/skills/telemetry/SKILL.md +29 -0
  95. package/runtime/prime/.codex/skills/test/SKILL.md +45 -0
  96. package/runtime/prime/.codex/skills/the-spiral/SKILL.md +84 -0
  97. package/runtime/prime/.codex/skills/tui-design/SKILL.md +45 -0
  98. package/runtime/prime/.codex/skills/tutorial/SKILL.md +45 -0
  99. package/runtime/prime/.codex/skills/update/SKILL.md +29 -0
  100. package/runtime/prime/.codex/skills/view/SKILL.md +156 -0
  101. package/runtime/prime/.codex/skills/view/agents/openai.yaml +4 -0
  102. package/runtime/prime/.codex/skills/view/assets/compose-scaffold.html +221 -0
  103. package/runtime/prime/.codex/skills/visual-explain/SKILL.md +45 -0
  104. package/runtime/prime/.codex/skills/wrap/SKILL.md +58 -0
  105. package/runtime/prime/.codex/spec-manifest.json +132 -0
  106. package/runtime/prime/.prime/agent/APPEND_SYSTEM.md +393 -0
  107. package/runtime/prime/.prime/agent/extensions/egregore.ts +460 -0
  108. package/runtime/prime/.prime/agent/settings.json +4 -0
  109. package/runtime/prime/.prime/agent/skills/egregore/SKILL.md +34 -0
  110. package/runtime/prime/.prime/agent/skills/egregore/pyproject.toml +13 -0
  111. package/runtime/prime/.prime/agent/skills/egregore/src/egregore/__init__.py +156 -0
  112. package/runtime/prime/.prime/agent/spec-manifest.json +12 -0
  113. package/runtime/prime/AGENTS.md +489 -0
  114. package/runtime/prime/bin/activity-data.sh +238 -0
  115. package/runtime/prime/bin/agent.sh +775 -0
  116. package/runtime/prime/bin/attendant.sh +707 -0
  117. package/runtime/prime/bin/autosave.sh +112 -0
  118. package/runtime/prime/bin/capture-reconcile.sh +69 -0
  119. package/runtime/prime/bin/capture-run.sh +341 -0
  120. package/runtime/prime/bin/codex-install-skills.sh +78 -0
  121. package/runtime/prime/bin/codex-render-spec.mjs +440 -0
  122. package/runtime/prime/bin/codex-session-start.sh +265 -0
  123. package/runtime/prime/bin/codex-skill-render.mjs +347 -0
  124. package/runtime/prime/bin/codex-sync-skills.sh +232 -0
  125. package/runtime/prime/bin/connect-refresh.sh +33 -0
  126. package/runtime/prime/bin/dashboard-data.sh +178 -0
  127. package/runtime/prime/bin/graph-batch.sh +79 -0
  128. package/runtime/prime/bin/graph-op.sh +1102 -0
  129. package/runtime/prime/bin/graph-wal.sh +229 -0
  130. package/runtime/prime/bin/graph.sh +223 -0
  131. package/runtime/prime/bin/handoff-pr-backfill.sh +86 -0
  132. package/runtime/prime/bin/handoff-run.sh +671 -0
  133. package/runtime/prime/bin/handoff-save-egregore.sh +212 -0
  134. package/runtime/prime/bin/index-handoff.sh +322 -0
  135. package/runtime/prime/bin/ingest-graph.sh +80 -0
  136. package/runtime/prime/bin/ingest-surface.html +495 -0
  137. package/runtime/prime/bin/ingest.py +756 -0
  138. package/runtime/prime/bin/ingest.sh +279 -0
  139. package/runtime/prime/bin/ingest_graph.py +856 -0
  140. package/runtime/prime/bin/ingest_surface.py +544 -0
  141. package/runtime/prime/bin/lib/artifact-id.sh +46 -0
  142. package/runtime/prime/bin/lib/config.sh +116 -0
  143. package/runtime/prime/bin/lib/context.sh +621 -0
  144. package/runtime/prime/bin/lib/dashboard-artifact.sh +242 -0
  145. package/runtime/prime/bin/lib/ensure-develop.sh +183 -0
  146. package/runtime/prime/bin/lib/git-sync.sh +406 -0
  147. package/runtime/prime/bin/lib/greeting.sh +519 -0
  148. package/runtime/prime/bin/lib/hash.sh +13 -0
  149. package/runtime/prime/bin/lib/identity.sh +213 -0
  150. package/runtime/prime/bin/lib/metrics.sh +374 -0
  151. package/runtime/prime/bin/lib/noncode.sh +31 -0
  152. package/runtime/prime/bin/lib/permissions.sh +106 -0
  153. package/runtime/prime/bin/lib/time.sh +56 -0
  154. package/runtime/prime/bin/lib/worktree-links.sh +79 -0
  155. package/runtime/prime/bin/notify.sh +636 -0
  156. package/runtime/prime/bin/person.py +630 -0
  157. package/runtime/prime/bin/person.sh +448 -0
  158. package/runtime/prime/bin/pi-branch-policy.mjs +312 -0
  159. package/runtime/prime/bin/pi-product-workflows.mjs +394 -0
  160. package/runtime/prime/bin/prime-render-spec.mjs +123 -0
  161. package/runtime/prime/bin/prime-session-start.sh +24 -0
  162. package/runtime/prime/bin/publish-artifact.sh +271 -0
  163. package/runtime/prime/bin/publish-references.sh +144 -0
  164. package/runtime/prime/bin/repo-state.sh +96 -0
  165. package/runtime/prime/bin/search.sh +240 -0
  166. package/runtime/prime/bin/session-autosave.sh +209 -0
  167. package/runtime/prime/bin/session-log.sh +199 -0
  168. package/runtime/prime/bin/settings.sh +304 -0
  169. package/runtime/prime/bin/telemetry.sh +391 -0
  170. package/runtime/prime/bin/worktree-create.sh +128 -0
  171. package/runtime/prime/bin/worktree-remove.sh +50 -0
  172. package/runtime/prime/bin/worktree.sh +198 -0
  173. package/runtime/prime/manifest.json +178 -0
@@ -0,0 +1,271 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # publish-artifact.sh — Generate HTML artifact + upload to API
5
+ # Usage: publish-artifact.sh <type> <file> [--title "..."] [--author "..."] [--description "..."] [--id "..."] [--raw-html] [--no-references]
6
+ #
7
+ # Connected mode (API key present): publishes to /api/artifacts/publish (permanent, org-scoped)
8
+ # OSS mode (no API key): publishes to /api/artifacts/share on a PUBLIC, UNAUTHENTICATED
9
+ # relay (ephemeral, 7-day TTL). OFF unless the instance opted in — see
10
+ # "Public-relay opt-in" below and `bin/settings.sh relay on`.
11
+ #
12
+ # --id <slug>: stable artifact ID — re-publishing with the same ID upserts the content
13
+ # at the same URL (e.g. egregore.xyz/view/{org}/board). Connected mode only;
14
+ # ignored in OSS mode. Must be 1-50 chars, alphanumeric/hyphen/underscore.
15
+ #
16
+ # --raw-html: Skip the egregore-artifacts render step and upload <file> directly.
17
+ # Use for already-rendered HTML attachments referenced from a handoff.
18
+ #
19
+ # --no-references: Skip the depth-1 auto-publish of backtick-referenced memory files.
20
+ # Set automatically when publish-references.sh invokes us for a child,
21
+ # preventing recursion.
22
+ #
23
+ # Outputs artifact URL on success, exits silently on soft failure.
24
+ # Designed for fire-and-forget use: `bash bin/publish-artifact.sh handoff file.md &`
25
+ #
26
+ # Exit codes: 0 ok (or soft failure — no URL on stdout) · 1 usage/validation
27
+ # 3 hosting turned off (features.publishing=false)
28
+ # 4 nothing uploaded — public relay not enabled and no org API key,
29
+ # or egregore.json is missing/unreadable (fail closed)
30
+ # 5 renderer/fidelity validation failed (nothing uploaded)
31
+
32
+ SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
33
+ CONFIG="$SCRIPT_DIR/egregore.json"
34
+
35
+ # --- Parse arguments ---
36
+ TYPE=""
37
+ FILE=""
38
+ TITLE=""
39
+ AUTHOR=""
40
+ DESCRIPTION=""
41
+ ARTIFACT_ID=""
42
+ RAW_HTML=0
43
+ SKIP_REFERENCES=0
44
+ PAIR=""
45
+ VERIFY_FIDELITY=0
46
+ FIDELITY_SOURCE=""
47
+
48
+ while [[ $# -gt 0 ]]; do
49
+ case "$1" in
50
+ --title) TITLE="$2"; shift 2 ;;
51
+ --author) AUTHOR="$2"; shift 2 ;;
52
+ --description) DESCRIPTION="$2"; shift 2 ;;
53
+ --id) ARTIFACT_ID="$2"; shift 2 ;;
54
+ --pair) PAIR="$2"; shift 2 ;;
55
+ --verify-fidelity) VERIFY_FIDELITY=1; shift ;;
56
+ --source) FIDELITY_SOURCE="$2"; shift 2 ;;
57
+ --raw-html) RAW_HTML=1; shift ;;
58
+ --no-references) SKIP_REFERENCES=1; shift ;;
59
+ *)
60
+ if [ -z "$TYPE" ]; then
61
+ TYPE="$1"
62
+ elif [ -z "$FILE" ]; then
63
+ FILE="$1"
64
+ fi
65
+ shift ;;
66
+ esac
67
+ done
68
+
69
+ if [ -z "$TYPE" ] || [ -z "$FILE" ]; then
70
+ echo "Usage: publish-artifact.sh <type> <file> [--title ...] [--author ...] [--description ...] [--id ...]" >&2
71
+ exit 1
72
+ fi
73
+
74
+ # Validate --id format if provided (matches API regex ^[a-zA-Z0-9_-]{1,50}$)
75
+ if [ -n "$ARTIFACT_ID" ] && ! [[ "$ARTIFACT_ID" =~ ^[a-zA-Z0-9_-]{1,50}$ ]]; then
76
+ echo "--id must be 1-50 chars, alphanumeric/hyphen/underscore only" >&2
77
+ exit 1
78
+ fi
79
+
80
+ if [ ! -f "$FILE" ]; then
81
+ echo "File not found: $FILE" >&2
82
+ exit 1
83
+ fi
84
+
85
+ # --- Load config ---
86
+ if [ -f "$SCRIPT_DIR/.env" ]; then
87
+ EGREGORE_API_URL="${EGREGORE_API_URL:-$(grep '^EGREGORE_API_URL=' "$SCRIPT_DIR/.env" 2>/dev/null | cut -d'=' -f2- || true)}"
88
+ EGREGORE_API_KEY="${EGREGORE_API_KEY:-$(grep '^EGREGORE_API_KEY=' "$SCRIPT_DIR/.env" 2>/dev/null | cut -d'=' -f2- || true)}"
89
+ EGREGORE_USE_PUBLISHED="${EGREGORE_USE_PUBLISHED:-$(grep '^EGREGORE_USE_PUBLISHED=' "$SCRIPT_DIR/.env" 2>/dev/null | cut -d'=' -f2- || true)}"
90
+ fi
91
+
92
+ # A config we cannot parse is a config we cannot trust. Every routing decision
93
+ # below — authenticated org upload vs. public relay, hosting on vs. off — is
94
+ # read out of this file, so an unreadable one means we cannot tell those apart.
95
+ if [ ! -f "$CONFIG" ] || ! jq -e 'type == "object"' "$CONFIG" >/dev/null 2>&1; then
96
+ echo "Not published — nothing left this machine." >&2
97
+ echo "egregore.json is missing or unreadable, so there is no way to tell an authenticated org upload from a public one." >&2
98
+ exit 4
99
+ fi
100
+
101
+ API_URL="${EGREGORE_API_URL:-$(jq -r '.api_url // empty' "$CONFIG" 2>/dev/null)}"
102
+ API_KEY="${EGREGORE_API_KEY:-}"
103
+ ORG_SLUG="$(jq -r '.slug // empty' "$CONFIG" 2>/dev/null)"
104
+ VIEW_BASE="https://egregore.xyz/view"
105
+
106
+ # Resolve "use published renderer" from env first, then egregore.json. The
107
+ # env var lets individuals override per-shell; egregore.json lets an
108
+ # instance (e.g. the upstream dev repo) opt in for every teammate.
109
+ if [ -z "${EGREGORE_USE_PUBLISHED:-}" ]; then
110
+ CONFIG_USE_PUBLISHED="$(jq -r '.prefer_published_artifacts // empty' "$CONFIG" 2>/dev/null)"
111
+ if [ "$CONFIG_USE_PUBLISHED" = "true" ]; then
112
+ EGREGORE_USE_PUBLISHED=1
113
+ fi
114
+ fi
115
+
116
+ # Public relay for OSS share endpoint. Unauthenticated: anything posted here is
117
+ # readable by anyone holding the URL, for 7 days, with nothing in front of it.
118
+ RELAY_URL="https://egregore-production-55f2.up.railway.app"
119
+
120
+ # --- Artifact hosting off-switch (compliance / privacy) ---
121
+ # An instance can disable ALL egregore.xyz publishing via `bin/settings.sh hosting off`
122
+ # (sets features.publishing=false). Absent/true means ON, so existing instances are
123
+ # unaffected. We bail BEFORE any render or upload so "off" truly does nothing and costs
124
+ # nothing. Exit 3 is distinct from usage errors; fire-and-forget callers ignore it.
125
+ # NOTE: test `!= false`, not jq's `// "true"` — `//` treats an explicit `false` as empty
126
+ # and would return the default, silently defeating the off-switch.
127
+ PUBLISHING_ENABLED="$(jq -r 'if .features.publishing == false then "false" else "true" end' "$CONFIG" 2>/dev/null || echo "true")"
128
+ if [ "$PUBLISHING_ENABLED" = "false" ]; then
129
+ echo "Artifact hosting is off for this egregore (features.publishing=false); nothing uploaded." >&2
130
+ echo "Turn it on with: bin/settings.sh hosting on (or: egregore settings → Hosting)." >&2
131
+ exit 3
132
+ fi
133
+
134
+ # --- Public-relay opt-in (privacy) ---
135
+ # Without BOTH an api_url and an org API key there is exactly one upload route
136
+ # left: the unauthenticated public relay below. Content must not leave the
137
+ # machine for that route unless a person explicitly enabled it. The gate sits
138
+ # before rendering so the default path generates and uploads nothing.
139
+ #
140
+ # NOTE: use an explicit `== true` test, never jq's `// false`: `//` treats an
141
+ # explicit false like null and silently replaces it with the default.
142
+ if [ -z "$API_URL" ] || [ -z "$API_KEY" ]; then
143
+ PUBLIC_RELAY_ENABLED="$(jq -r 'if .features.public_relay == true then "true" else "false" end' "$CONFIG" 2>/dev/null || echo "false")"
144
+ if [ "$PUBLIC_RELAY_ENABLED" != "true" ]; then
145
+ echo "Not published — nothing left this machine." >&2
146
+ echo "Without an org API key the only sharing route is a public relay: no auth, anyone with the link can read it, expires after 7 days. It is off unless you turn it on." >&2
147
+ echo "Turn it on with: bin/settings.sh relay on" >&2
148
+ exit 4
149
+ fi
150
+ fi
151
+
152
+ # --- Prepare HTML ---
153
+ TMP_HTML="/tmp/egregore-artifacts/publish-$$.html"
154
+ mkdir -p /tmp/egregore-artifacts
155
+
156
+ if [ "$RAW_HTML" -eq 1 ]; then
157
+ # Upload the file as-is (used for pre-rendered HTML attachments).
158
+ cp "$FILE" "$TMP_HTML" 2>/dev/null || exit 0
159
+ else
160
+ # Pass --org-slug + --view-base so the renderer can emit clickable links
161
+ # for backtick `memory/*.{md,html}` references. Only when connected AND the
162
+ # slug is known — in OSS mode we leave them empty so rendering falls back
163
+ # to plain <code> and we don't produce dead links.
164
+ RENDER_ARGS=("$TYPE" "$FILE" --output "$TMP_HTML")
165
+ if [ -n "$API_KEY" ] && [ -n "$ORG_SLUG" ]; then
166
+ RENDER_ARGS+=(--org-slug "$ORG_SLUG" --view-base "$VIEW_BASE")
167
+ fi
168
+ # Palette family (meridian default | agronomic | sovereign). Role-token driven,
169
+ # so it themes any composed artifact with no extra CSS.
170
+ if [ -n "$PAIR" ]; then
171
+ RENDER_ARGS+=(--pair "$PAIR")
172
+ fi
173
+ if [ "$VERIFY_FIDELITY" -eq 1 ]; then
174
+ RENDER_ARGS+=(--verify-fidelity)
175
+ if [ "$TYPE" = "composed" ]; then
176
+ [ -n "$FIDELITY_SOURCE" ] || {
177
+ echo "Handoff fidelity check requires --source <canonical-handoff.md>" >&2
178
+ exit 1
179
+ }
180
+ RENDER_ARGS+=(--source "$FIDELITY_SOURCE")
181
+ fi
182
+ fi
183
+
184
+ # Prefer the in-repo package copy when it's present AND its dependencies
185
+ # have been installed — that way local edits to packages/egregore-artifacts
186
+ # are exercised without waiting for an npm release. Fall back to the
187
+ # published `npx egregore-artifacts` otherwise.
188
+ # Set EGREGORE_USE_PUBLISHED=1 to force the npm-published renderer even
189
+ # when a local install is present — useful in the upstream dev repo to
190
+ # dogfood what teammates and OSS users actually run.
191
+ LOCAL_CLI="$SCRIPT_DIR/packages/egregore-artifacts/bin/cli.js"
192
+ RENDER_ERROR="/tmp/egregore-artifacts/render-error-$$.log"
193
+ if [ "${EGREGORE_USE_PUBLISHED:-0}" != "1" ] && [ -f "$LOCAL_CLI" ] && [ -d "$SCRIPT_DIR/packages/egregore-artifacts/node_modules/react" ]; then
194
+ if ! node "$LOCAL_CLI" "${RENDER_ARGS[@]}" >/dev/null 2>"$RENDER_ERROR"; then
195
+ sed -n '1,4p' "$RENDER_ERROR" >&2
196
+ rm -f "$RENDER_ERROR"
197
+ exit 5
198
+ fi
199
+ else
200
+ if ! npx -y egregore-artifacts@latest "${RENDER_ARGS[@]}" >/dev/null 2>"$RENDER_ERROR"; then
201
+ sed -n '1,4p' "$RENDER_ERROR" >&2
202
+ rm -f "$RENDER_ERROR"
203
+ exit 5
204
+ fi
205
+ fi
206
+ rm -f "$RENDER_ERROR"
207
+ fi
208
+
209
+ if [ ! -f "$TMP_HTML" ]; then
210
+ exit 0
211
+ fi
212
+
213
+ # Default title from filename if not provided
214
+ if [ -z "$TITLE" ]; then
215
+ TITLE="$(basename "$FILE" | sed 's/\.[^.]*$//' | sed 's/[-_]/ /g')"
216
+ fi
217
+
218
+ # --- Upload ---
219
+ RESPONSE=""
220
+
221
+ if [ -n "$API_URL" ] && [ -n "$API_KEY" ]; then
222
+ # Connected mode: permanent, org-scoped
223
+ RESPONSE=$(curl -s -X POST "${API_URL}/api/artifacts/publish" \
224
+ -H "Authorization: Bearer $API_KEY" \
225
+ -F "file=@${TMP_HTML}" \
226
+ -F "artifact_type=${TYPE}" \
227
+ -F "title=${TITLE}" \
228
+ -F "author=${AUTHOR}" \
229
+ -F "description=${DESCRIPTION}" \
230
+ -F "artifact_id=${ARTIFACT_ID}" \
231
+ --max-time 15 2>/dev/null) || true
232
+ else
233
+ # OSS mode: ephemeral, 7-day TTL
234
+ RESPONSE=$(curl -s -X POST "${RELAY_URL}/api/artifacts/share" \
235
+ -F "file=@${TMP_HTML}" \
236
+ -F "artifact_type=${TYPE}" \
237
+ -F "title=${TITLE}" \
238
+ -F "author=${AUTHOR}" \
239
+ -F "description=${DESCRIPTION}" \
240
+ --max-time 15 2>/dev/null) || true
241
+ fi
242
+
243
+ # Clean up
244
+ rm -f "$TMP_HTML"
245
+
246
+ # Output URL if successful
247
+ URL=""
248
+ if [ -n "$RESPONSE" ]; then
249
+ URL=$(echo "$RESPONSE" | jq -r '.url // empty' 2>/dev/null)
250
+ if [ -n "$URL" ]; then
251
+ echo "$URL"
252
+ # Register in the local artifact registry (memory/artifacts/) so this hosted
253
+ # artifact is findable by CONTENT, not just name — grep/ls (Claude Code /
254
+ # Codex, OSS), and search + graph (paid). Never fatal to the publish.
255
+ bash "$SCRIPT_DIR/bin/artifact-register.sh" \
256
+ --id "$ARTIFACT_ID" --url "$URL" --type "$TYPE" --title "$TITLE" \
257
+ --author "$AUTHOR" --source "$FILE" --description "$DESCRIPTION" \
258
+ >/dev/null 2>&1 || true
259
+ fi
260
+ fi
261
+
262
+ # Depth-1 auto-publish of backtick-referenced memory files so the clickable
263
+ # links in the rendered parent resolve. Connected mode only; the helper exits
264
+ # silently in OSS mode. Skipped when:
265
+ # - parent publish failed (no URL),
266
+ # - --raw-html (HTML attachments don't embed markdown refs we'd parse),
267
+ # - --no-references (caller explicitly opts out / recursion guard).
268
+ if [ -n "$URL" ] && [ "$RAW_HTML" -eq 0 ] && [ "$SKIP_REFERENCES" -eq 0 ]; then
269
+ bash "$SCRIPT_DIR/bin/publish-references.sh" "$FILE" >/dev/null 2>&1 &
270
+ disown 2>/dev/null || true
271
+ fi
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env bash
2
+ set -uo pipefail
3
+
4
+ # publish-references.sh — Depth-1 auto-publish for referenced memory files.
5
+ #
6
+ # Usage: publish-references.sh <source-markdown-file>
7
+ #
8
+ # Reads the source markdown, extracts backtick-wrapped references to
9
+ # `memory/**/*.{md,html}` paths, and publishes each one in parallel with a
10
+ # deterministic artifact id (see bin/lib/artifact-id.sh). The deterministic id
11
+ # means the rendered parent view can construct a predictable link to each
12
+ # referenced file *before* this script finishes — so even a slight delay
13
+ # produces clickable links that resolve once the referenced publish completes.
14
+ #
15
+ # Connected mode only. Skips silently if EGREGORE_API_KEY is missing, because
16
+ # the OSS relay ignores artifact ids and would assign random slugs.
17
+ #
18
+ # Fire-and-forget: silent on errors, does not block the caller, bounded
19
+ # parallelism via EGREGORE_REF_PUBLISH_PARALLELISM (default 8).
20
+
21
+ SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
22
+ SOURCE_FILE="${1:-}"
23
+
24
+ [ -n "$SOURCE_FILE" ] || exit 0
25
+ [ -f "$SOURCE_FILE" ] || exit 0
26
+
27
+ # --- Connected-mode check ---
28
+ API_KEY="${EGREGORE_API_KEY:-}"
29
+ if [ -z "$API_KEY" ] && [ -f "$SCRIPT_DIR/.env" ]; then
30
+ API_KEY="$(grep '^EGREGORE_API_KEY=' "$SCRIPT_DIR/.env" 2>/dev/null | cut -d'=' -f2- || true)"
31
+ fi
32
+ [ -n "$API_KEY" ] || exit 0
33
+
34
+ # --- Helpers ---
35
+ # shellcheck disable=SC1091
36
+ . "$SCRIPT_DIR/bin/lib/artifact-id.sh"
37
+
38
+ PARALLELISM="${EGREGORE_REF_PUBLISH_PARALLELISM:-8}"
39
+
40
+ GIT_ROOT="$(git -C "$(dirname "$SOURCE_FILE")" rev-parse --show-toplevel 2>/dev/null || echo "$SCRIPT_DIR")"
41
+
42
+ # Absolute, symlink-resolved path of the source file. Used below to compare
43
+ # each resolved ref against the source and skip self-references. Using
44
+ # symlink-resolved absolute paths means `memory/` as a symlink into a sibling
45
+ # repo (and macOS's `/var` → `/private/var`) compare correctly — basename
46
+ # comparison alone would falsely skip unrelated files that happen to share
47
+ # a filename (e.g. date-prefixed handoffs, README.md, index.md).
48
+ SOURCE_ABS="$(cd "$(dirname "$SOURCE_FILE")" 2>/dev/null && pwd -P)/$(basename "$SOURCE_FILE")"
49
+
50
+ # Infer artifact type from path — mirrors egregore-artifacts/bin/cli.js inferType.
51
+ infer_type() {
52
+ local fp="$1"
53
+ case "$fp" in
54
+ */quests/*) echo "quest" ;;
55
+ */handoffs/*) echo "handoff" ;;
56
+ *) echo "document" ;;
57
+ esac
58
+ }
59
+
60
+ # Resolve a backtick-referenced path to a real file on disk.
61
+ resolve_ref() {
62
+ local ref="$1"
63
+ local src_dir
64
+ src_dir="$(dirname "$SOURCE_FILE")"
65
+ # Candidates: source file's repo-root resolution, then git root, then cwd.
66
+ local candidates=(
67
+ "$src_dir/../../$ref"
68
+ "$GIT_ROOT/$ref"
69
+ "$ref"
70
+ )
71
+ local c
72
+ for c in "${candidates[@]}"; do
73
+ if [ -f "$c" ]; then
74
+ printf '%s' "$c"
75
+ return 0
76
+ fi
77
+ done
78
+ return 1
79
+ }
80
+
81
+ publish_one() {
82
+ local ref="$1"
83
+ local resolved
84
+ resolved="$(resolve_ref "$ref")" || return 0
85
+ [ -n "$resolved" ] || return 0
86
+
87
+ # Self-ref guard: skip refs that resolve to the source file itself.
88
+ # Compared as symlink-resolved absolute paths so symlinked memory layouts
89
+ # (and unrelated files with the same basename) are handled correctly.
90
+ local resolved_abs
91
+ resolved_abs="$(cd "$(dirname "$resolved")" 2>/dev/null && pwd -P)/$(basename "$resolved")"
92
+ if [ "$resolved_abs" = "$SOURCE_ABS" ]; then
93
+ return 0
94
+ fi
95
+
96
+ local id
97
+ id="$(artifact_id_from_path "$ref")" || return 0
98
+ [ -n "$id" ] || return 0
99
+
100
+ case "$ref" in
101
+ *.md)
102
+ local type
103
+ type="$(infer_type "$ref")"
104
+ bash "$SCRIPT_DIR/bin/publish-artifact.sh" "$type" "$resolved" --id "$id" --no-references >/dev/null 2>&1 || true
105
+ ;;
106
+ *.html)
107
+ bash "$SCRIPT_DIR/bin/publish-artifact.sh" document "$resolved" --id "$id" --raw-html --no-references >/dev/null 2>&1 || true
108
+ ;;
109
+ esac
110
+ }
111
+
112
+ # --- Extract refs, dedupe, publish in parallel ---
113
+ # grep -Eo prints each match on its own line; sed strips the surrounding
114
+ # backticks; sort -u dedupes. No dependency on GNU grep -P.
115
+ REFS="$(grep -Eo '`memory/[^`[:space:]]+\.(md|html)`' "$SOURCE_FILE" 2>/dev/null \
116
+ | sed 's/^`//; s/`$//' \
117
+ | sort -u)"
118
+
119
+ [ -n "$REFS" ] || exit 0
120
+
121
+ # Bounded parallelism — cap concurrent jobs at PARALLELISM.
122
+ # On bash ≥ 4 (`wait -n`) this is rolling parallelism. On bash 3.2 (macOS
123
+ # default /bin/bash), `wait -n` is unsupported and the `|| wait` fallback
124
+ # drains the whole batch before spawning the next — effectively batch-parallel
125
+ # of size PARALLELISM. Correct in both cases, just slower on bash 3.2.
126
+ active=0
127
+ while IFS= read -r ref; do
128
+ [ -n "$ref" ] || continue
129
+ # Self-reference filtering happens inside publish_one, after the ref is
130
+ # resolved to an absolute path — see the SOURCE_ABS check there.
131
+ publish_one "$ref" &
132
+ active=$((active + 1))
133
+ if [ "$active" -ge "$PARALLELISM" ]; then
134
+ if wait -n 2>/dev/null; then
135
+ active=$((active - 1))
136
+ else
137
+ wait
138
+ active=0
139
+ fi
140
+ fi
141
+ done <<< "$REFS"
142
+
143
+ wait 2>/dev/null || true
144
+ exit 0
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env bash
2
+ # repo-state.sh — Capture current branch state across all repos.
3
+ # Outputs a markdown table (## Repo State) for handoff files.
4
+ # Only includes repos on non-base branches or with uncommitted changes.
5
+ #
6
+ # Usage: bash bin/repo-state.sh [--no-pr]
7
+ # --no-pr Skip the `gh pr list` lookup per repo (~400–600ms each).
8
+ # PR column will be `—`. Useful on the hot path where a detached
9
+ # backfill will fill PR numbers in later.
10
+ # Outputs the markdown section to stdout. Empty output = nothing to report.
11
+ set -euo pipefail
12
+
13
+ NO_PR=0
14
+ while [ $# -gt 0 ]; do
15
+ case "$1" in
16
+ --no-pr) NO_PR=1; shift ;;
17
+ *) shift ;;
18
+ esac
19
+ done
20
+
21
+ SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
22
+ CONFIG="$SCRIPT_DIR/egregore.json"
23
+ PARENT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
24
+
25
+ # Source config helpers for _get_base_branch
26
+ source "$SCRIPT_DIR/bin/lib/config.sh" 2>/dev/null || true
27
+
28
+ CORE_REPO=$(jq -r '.repo_name // "egregore"' "$CONFIG" 2>/dev/null)
29
+ GITHUB_ORG=$(jq -r '.github_org // empty' "$CONFIG" 2>/dev/null)
30
+ MANAGED_REPOS=$(jq -r '(.repos[]? // empty) | if type == "object" then .name else . end' "$CONFIG" 2>/dev/null)
31
+
32
+ ROWS=""
33
+
34
+ check_repo() {
35
+ local repo_name="$1"
36
+ local repo_dir="$2"
37
+ local base_branch="$3"
38
+
39
+ [ -d "$repo_dir/.git" ] || [ -f "$repo_dir/.git" ] || return 0
40
+
41
+ local branch
42
+ branch=$(git -C "$repo_dir" branch --show-current 2>/dev/null || echo "")
43
+ [ -z "$branch" ] && return 0
44
+
45
+ local dirty=""
46
+ [ -n "$(git -C "$repo_dir" status --porcelain 2>/dev/null | head -1)" ] && dirty="yes"
47
+
48
+ # Skip if on base branch with no changes
49
+ if [ "$branch" = "$base_branch" ] && [ -z "$dirty" ]; then
50
+ return 0
51
+ fi
52
+
53
+ # Count commits ahead of base
54
+ local ahead=0
55
+ ahead=$(git -C "$repo_dir" rev-list "origin/${base_branch}..HEAD" --count 2>/dev/null || echo "0")
56
+
57
+ # Skip if on base branch, no dirty files, no commits ahead
58
+ if [ "$branch" = "$base_branch" ] && [ -z "$dirty" ] && [ "$ahead" = "0" ]; then
59
+ return 0
60
+ fi
61
+
62
+ # Check for open PR (skipped with --no-pr; a detached backfill fills it in)
63
+ local pr="—"
64
+ if [ "$NO_PR" = "0" ] && command -v gh &>/dev/null && [ -n "$GITHUB_ORG" ]; then
65
+ local pr_num
66
+ pr_num=$(gh pr list --repo "$GITHUB_ORG/$repo_name" --head "$branch" --json number -q '.[0].number' 2>/dev/null || true)
67
+ [ -n "$pr_num" ] && pr="#$pr_num"
68
+ fi
69
+
70
+ ROWS="${ROWS}| ${repo_name} | ${branch} | ${pr} | ${base_branch} |\n"
71
+ }
72
+
73
+ # Check core repo
74
+ if ! CORE_BASE=$(_get_base_branch); then
75
+ echo "repo-state: could not resolve the configured base branch" >&2
76
+ exit 1
77
+ fi
78
+ check_repo "$CORE_REPO" "$SCRIPT_DIR" "$CORE_BASE"
79
+
80
+ # Check managed repos
81
+ for REPO in $MANAGED_REPOS; do
82
+ REPO_DIR="$PARENT_DIR/$REPO"
83
+ if ! BASE=$(_get_base_branch "$REPO"); then
84
+ continue
85
+ fi
86
+ check_repo "$REPO" "$REPO_DIR" "$BASE"
87
+ done
88
+
89
+ # Output
90
+ if [ -n "$ROWS" ]; then
91
+ echo "## Repo State"
92
+ echo ""
93
+ echo "| Repo | Branch | PR | Base |"
94
+ echo "|------|--------|----|------|"
95
+ printf '%b' "$ROWS"
96
+ fi