create-egregore 0.19.7 → 0.19.11

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 (92) hide show
  1. package/assets/egregore-launcher.js +188 -295
  2. package/lib/local.js +11 -1
  3. package/lib/setup.js +33 -0
  4. package/package.json +1 -1
  5. package/runtime/codex/.codex/hooks/branch-guard.js +242 -34
  6. package/runtime/codex/.codex/skills/activity/SKILL.md +18 -6
  7. package/runtime/codex/.codex/skills/deep-reflect/SKILL.md +90 -55
  8. package/runtime/codex/.codex/skills/deploy-bridge/SKILL.md +25 -0
  9. package/runtime/codex/.codex/skills/handoff/SKILL.md +6 -2
  10. package/runtime/codex/.codex/skills/save/SKILL.md +21 -3
  11. package/runtime/codex/.codex/skills/scroll/SKILL.md +54 -3
  12. package/runtime/codex/.codex/skills/task/SKILL.md +25 -0
  13. package/runtime/codex/.codex/skills/tui-design/SKILL.md +1 -1
  14. package/runtime/codex/.codex/skills/wrap/SKILL.md +4 -1
  15. package/runtime/codex/.codex/spec-manifest.json +15 -3
  16. package/runtime/codex/AGENTS.md +45 -9
  17. package/runtime/codex/bin/activity-data.sh +1 -1
  18. package/runtime/codex/bin/agent.sh +66 -23
  19. package/runtime/codex/bin/attendant.sh +525 -0
  20. package/runtime/codex/bin/capture-reconcile.sh +67 -0
  21. package/runtime/codex/bin/capture-run.sh +341 -0
  22. package/runtime/codex/bin/codex-render-spec.mjs +15 -4
  23. package/runtime/codex/bin/codex-session-start.sh +45 -3
  24. package/runtime/codex/bin/codex-skill-render.mjs +23 -4
  25. package/runtime/codex/bin/graph-op.sh +719 -49
  26. package/runtime/codex/bin/graph-wal.sh +3 -2
  27. package/runtime/codex/bin/handoff-run.sh +72 -0
  28. package/runtime/codex/bin/handoff-save-egregore.sh +51 -11
  29. package/runtime/codex/bin/index-handoff.sh +26 -17
  30. package/runtime/codex/bin/ingest-graph.sh +80 -0
  31. package/runtime/codex/bin/ingest-surface.html +429 -0
  32. package/runtime/codex/bin/ingest.py +614 -0
  33. package/runtime/codex/bin/ingest.sh +231 -0
  34. package/runtime/codex/bin/ingest_graph.py +776 -0
  35. package/runtime/codex/bin/ingest_surface.py +464 -0
  36. package/runtime/codex/bin/lib/git-sync.sh +2 -6
  37. package/runtime/codex/bin/lib/greeting.sh +157 -22
  38. package/runtime/codex/bin/lib/identity.sh +50 -29
  39. package/runtime/codex/bin/lib/noncode.sh +31 -0
  40. package/runtime/codex/bin/person.py +610 -0
  41. package/runtime/codex/bin/person.sh +448 -0
  42. package/runtime/codex/bin/session-autosave.sh +184 -0
  43. package/runtime/codex/bin/session-log.sh +199 -0
  44. package/runtime/codex/bin/settings.sh +1 -1
  45. package/runtime/codex/manifest.json +19 -1
  46. package/runtime/pi/.codex/hooks/branch-guard.js +242 -34
  47. package/runtime/pi/.codex/skills/activity/SKILL.md +18 -6
  48. package/runtime/pi/.codex/skills/deep-reflect/SKILL.md +90 -55
  49. package/runtime/pi/.codex/skills/deploy-bridge/SKILL.md +25 -0
  50. package/runtime/pi/.codex/skills/handoff/SKILL.md +6 -2
  51. package/runtime/pi/.codex/skills/save/SKILL.md +21 -3
  52. package/runtime/pi/.codex/skills/scroll/SKILL.md +54 -3
  53. package/runtime/pi/.codex/skills/task/SKILL.md +25 -0
  54. package/runtime/pi/.codex/skills/tui-design/SKILL.md +1 -1
  55. package/runtime/pi/.codex/skills/wrap/SKILL.md +4 -1
  56. package/runtime/pi/.codex/spec-manifest.json +15 -3
  57. package/runtime/pi/.pi/APPEND_SYSTEM.md +41 -5
  58. package/runtime/pi/.pi/extensions/egregore.ts +98 -8
  59. package/runtime/pi/.pi/spec-manifest.json +2 -2
  60. package/runtime/pi/AGENTS.md +45 -9
  61. package/runtime/pi/bin/activity-data.sh +1 -1
  62. package/runtime/pi/bin/agent.sh +66 -23
  63. package/runtime/pi/bin/attendant.sh +525 -0
  64. package/runtime/pi/bin/capture-reconcile.sh +67 -0
  65. package/runtime/pi/bin/capture-run.sh +341 -0
  66. package/runtime/pi/bin/codex-render-spec.mjs +15 -4
  67. package/runtime/pi/bin/codex-session-start.sh +45 -3
  68. package/runtime/pi/bin/codex-skill-render.mjs +23 -4
  69. package/runtime/pi/bin/graph-op.sh +719 -49
  70. package/runtime/pi/bin/graph-wal.sh +3 -2
  71. package/runtime/pi/bin/handoff-run.sh +72 -0
  72. package/runtime/pi/bin/handoff-save-egregore.sh +51 -11
  73. package/runtime/pi/bin/index-handoff.sh +26 -17
  74. package/runtime/pi/bin/ingest-graph.sh +80 -0
  75. package/runtime/pi/bin/ingest-surface.html +429 -0
  76. package/runtime/pi/bin/ingest.py +614 -0
  77. package/runtime/pi/bin/ingest.sh +231 -0
  78. package/runtime/pi/bin/ingest_graph.py +776 -0
  79. package/runtime/pi/bin/ingest_surface.py +464 -0
  80. package/runtime/pi/bin/lib/git-sync.sh +2 -6
  81. package/runtime/pi/bin/lib/greeting.sh +157 -22
  82. package/runtime/pi/bin/lib/identity.sh +50 -29
  83. package/runtime/pi/bin/lib/noncode.sh +31 -0
  84. package/runtime/pi/bin/person.py +610 -0
  85. package/runtime/pi/bin/person.sh +448 -0
  86. package/runtime/pi/bin/pi-branch-policy.mjs +164 -4
  87. package/runtime/pi/bin/pi-product-workflows.mjs +31 -2
  88. package/runtime/pi/bin/publish-artifact.sh +14 -0
  89. package/runtime/pi/bin/session-autosave.sh +184 -0
  90. package/runtime/pi/bin/session-log.sh +199 -0
  91. package/runtime/pi/bin/settings.sh +274 -0
  92. package/runtime/pi/manifest.json +20 -1
@@ -0,0 +1,231 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ # Org-scoped intake plane. Shared manifests live in memory/; normalized bodies
5
+ # stay in this checkout's gitignored cache; qmd uses a separate per-org index.
6
+
7
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
8
+ export NODE_NO_WARNINGS=1
9
+ PY="$ROOT/bin/ingest.py"
10
+ SURFACE="$ROOT/bin/ingest_surface.py"
11
+ SLUG="$(jq -r '.slug // "egregore"' "$ROOT/egregore.json")"
12
+ INDEX="${SLUG}-ingest"
13
+ COLLECTION="${SLUG}-ingest"
14
+ INGEST_ROOT="${EGREGORE_INGEST_ROOT:-$ROOT/.egregore/ingest}"
15
+ INGEST_META_ROOT="${EGREGORE_INGEST_META_ROOT:-$ROOT/memory/ingest}"
16
+ QMD_VERSION="2.5.3"
17
+ GRAPH_PROJECTOR="${EGREGORE_INGEST_GRAPH_PROJECTOR:-$ROOT/bin/ingest-graph.sh}"
18
+
19
+ _qmd() {
20
+ if command -v qmd >/dev/null 2>&1; then
21
+ qmd --index "$INDEX" "$@"
22
+ else
23
+ npx -y "@tobilu/qmd@${QMD_VERSION}" --index "$INDEX" "$@"
24
+ fi
25
+ }
26
+
27
+ _ensure_index() {
28
+ mkdir -p "$INGEST_ROOT"
29
+ if ! _qmd collection list 2>/dev/null | grep -q "^${COLLECTION} "; then
30
+ _qmd collection add "$INGEST_ROOT" --name "$COLLECTION" >/dev/null
31
+ fi
32
+ _qmd update >/dev/null
33
+ }
34
+
35
+ _graph_sync() {
36
+ local source="${1:-}" manifest result status
37
+ local total=0 succeeded=0 failed=0 stored=0 queries=0
38
+ local manifests=()
39
+ if [ -n "$source" ]; then
40
+ manifests+=("$INGEST_META_ROOT/sources/$source/manifest.json")
41
+ else
42
+ while IFS= read -r manifest; do manifests+=("$manifest"); done < <(
43
+ find "$INGEST_META_ROOT/sources" "$INGEST_META_ROOT/knowledge" \
44
+ -type f -name '*.json' 2>/dev/null | sort
45
+ )
46
+ fi
47
+ for manifest in "${manifests[@]}"; do
48
+ [ -f "$manifest" ] || continue
49
+ total=$((total + 1))
50
+ if result="$(bash "$GRAPH_PROJECTOR" apply "$manifest")"; then
51
+ status="$(printf '%s' "$result" | jq -r '.status')"
52
+ queries=$((queries + $(printf '%s' "$result" | jq -r '.queries // 0')))
53
+ if [ "$status" = "stored" ]; then stored=$((stored + 1)); else succeeded=$((succeeded + 1)); fi
54
+ else
55
+ failed=$((failed + 1))
56
+ fi
57
+ done
58
+ if [ "$failed" -gt 0 ]; then
59
+ jq -cn --argjson manifests "$total" --argjson succeeded "$succeeded" --argjson stored "$stored" --argjson failed "$failed" --argjson queries "$queries" \
60
+ '{status:"partial",manifests:$manifests,succeeded:$succeeded,stored:$stored,failed:$failed,queries:$queries,replayable:true}'
61
+ return 1
62
+ fi
63
+ if [ "$total" -eq 0 ]; then
64
+ printf '%s\n' '{"status":"nothing-to-project","manifests":0,"failed":0,"queries":0,"replayable":true}'
65
+ elif [ "$stored" -eq "$total" ]; then
66
+ jq -cn --argjson manifests "$total" --argjson queries "$queries" \
67
+ '{status:"stored-local",manifests:$manifests,failed:0,queries:$queries,replayable:true}'
68
+ else
69
+ jq -cn --argjson manifests "$total" --argjson queries "$queries" \
70
+ '{status:"synced",manifests:$manifests,failed:0,queries:$queries,replayable:true}'
71
+ fi
72
+ }
73
+
74
+ _journal() {
75
+ local source="$1" phase="$2" detail="${3:-}"
76
+ [ -n "$detail" ] || detail='{}'
77
+ python3 "$PY" journal --source "$source" --phase "$phase" --detail "$detail"
78
+ }
79
+
80
+ _journal_clear() {
81
+ python3 "$PY" journal --source "$1" --clear
82
+ }
83
+
84
+ _notify_receipt() {
85
+ local url="$1" token="$2" payload="$3"
86
+ [ -z "$url" ] && return 0
87
+ python3 - "$url" "$token" "$payload" <<'PY' >/dev/null 2>&1 || true
88
+ import sys, urllib.request
89
+ body = sys.argv[3].encode()
90
+ request = urllib.request.Request(
91
+ sys.argv[1] + "/api/result",
92
+ data=body,
93
+ method="POST",
94
+ headers={"Content-Type": "application/json", "X-Egregore-Token": sys.argv[2]},
95
+ )
96
+ urllib.request.urlopen(request, timeout=5).read()
97
+ PY
98
+ }
99
+
100
+ cmd_add() {
101
+ local source="" summary graph final qmd_status
102
+ local args=("$@")
103
+ local i
104
+ for ((i=0; i<${#args[@]}; i++)); do
105
+ if [ "${args[$i]}" = "--source" ] && [ $((i+1)) -lt ${#args[@]} ]; then source="${args[$((i+1))]}"; fi
106
+ done
107
+ summary="$(python3 "$PY" add "$@")"
108
+ _journal "$source" "normalized" "$(printf '%s' "$summary" | jq -c '{ingested,unchanged,metadata_updated,skipped,pruned}')"
109
+ if ! _ensure_index; then
110
+ qmd_status='{"status":"failed"}'
111
+ _journal "$source" "index_failed" "$qmd_status"
112
+ printf '%s\n' "$summary" | jq --argjson qmd "$qmd_status" '. + {status:"failed",qmd:$qmd,graph:{status:"not-attempted"}}'
113
+ return 1
114
+ fi
115
+ qmd_status='{"status":"indexed"}'
116
+ if graph="$(_graph_sync "$source")"; then :; else :; fi
117
+ if [ "$(printf '%s' "$summary" | jq -r .skipped)" -gt 0 ]; then
118
+ _journal "$source" "extraction_attention" "$(printf '%s' "$summary" | jq -c '{skipped}')"
119
+ final="$(printf '%s' "$summary" | jq --argjson qmd "$qmd_status" --argjson graph "$graph" '. + {status:"attention",qmd:$qmd,graph:$graph}')"
120
+ elif [ "$(printf '%s' "$graph" | jq -r .status)" = "partial" ]; then
121
+ _journal "$source" "graph_pending" "$graph"
122
+ final="$(printf '%s' "$summary" | jq --argjson qmd "$qmd_status" --argjson graph "$graph" '. + {status:"attention",qmd:$qmd,graph:$graph}')"
123
+ else
124
+ _journal_clear "$source"
125
+ final="$(printf '%s' "$summary" | jq --argjson qmd "$qmd_status" --argjson graph "$graph" '. + {status:"complete",qmd:$qmd,graph:$graph}')"
126
+ fi
127
+ printf '%s\n' "$final"
128
+ }
129
+
130
+ cmd_add_selection() {
131
+ local manifest="${1:?usage: bin/ingest.sh add-selection MANIFEST}"
132
+ local source receipt_url receipt_token summary graph qmd_status outcome final message contract
133
+ contract="$(python3 - "$manifest" <<'PY'
134
+ import json, sys
135
+ value = json.load(open(sys.argv[1], encoding="utf-8"))
136
+ print(json.dumps({"source": value["source"]["id"], "url": value.get("receipt", {}).get("url", ""), "token": value.get("receipt", {}).get("token", "")}))
137
+ PY
138
+ )"
139
+ source="$(printf '%s' "$contract" | jq -r .source)"
140
+ receipt_url="$(printf '%s' "$contract" | jq -r .url)"
141
+ receipt_token="$(printf '%s' "$contract" | jq -r .token)"
142
+ if ! summary="$(python3 "$PY" add-selection "$manifest")"; then
143
+ final="$(jq -cn --arg source "$source" '{status:"failed",outcome:"normalization failed",source:$source,message:"The selection failed validation or extraction. Its staging directory was retained for diagnosis."}')"
144
+ _notify_receipt "$receipt_url" "$receipt_token" "$final"
145
+ return 2
146
+ fi
147
+ _journal "$source" "normalized" "$(printf '%s' "$summary" | jq -c '{ingested,unchanged,metadata_updated,skipped,pruned}')"
148
+ if _ensure_index; then
149
+ qmd_status='{"status":"indexed"}'
150
+ else
151
+ qmd_status='{"status":"failed"}'
152
+ _journal "$source" "index_failed" "$qmd_status"
153
+ fi
154
+ if [ "$(printf '%s' "$qmd_status" | jq -r .status)" = "indexed" ]; then
155
+ if graph="$(_graph_sync "$source")"; then :; else :; fi
156
+ else
157
+ graph='{"status":"not-attempted","batches":0,"failed":0}'
158
+ fi
159
+ if [ "$(printf '%s' "$qmd_status" | jq -r .status)" != "indexed" ]; then
160
+ outcome="index failed"
161
+ message="The normalized source was retained, but QMD did not finish indexing it. Run bin/ingest.sh reindex to repair it."
162
+ final="$(printf '%s' "$summary" | jq --argjson qmd "$qmd_status" --argjson graph "$graph" --arg outcome "$outcome" --arg message "$message" '. + {status:"failed",outcome:$outcome,message:$message,qmd:$qmd,graph:$graph}')"
163
+ elif [ "$(printf '%s' "$summary" | jq -r '.skipped')" -gt 0 ]; then
164
+ outcome="indexed with skipped files"
165
+ message="Searchable files were indexed, but one or more files still need a compatible extractor. Their staging bytes were retained."
166
+ _journal "$source" "extraction_attention" "$(printf '%s' "$summary" | jq -c '{skipped,selection_path}')"
167
+ final="$(printf '%s' "$summary" | jq --argjson qmd "$qmd_status" --argjson graph "$graph" --arg outcome "$outcome" --arg message "$message" '. + {status:"attention",outcome:$outcome,message:$message,qmd:$qmd,graph:$graph}')"
168
+ elif [ "$(printf '%s' "$graph" | jq -r .status)" = "partial" ]; then
169
+ outcome="indexed · graph pending"
170
+ message="The source is searchable now. Graph projection was incomplete and is recorded for retry."
171
+ _journal "$source" "graph_pending" "$graph"
172
+ final="$(printf '%s' "$summary" | jq --argjson qmd "$qmd_status" --argjson graph "$graph" --arg outcome "$outcome" --arg message "$message" '. + {status:"attention",outcome:$outcome,message:$message,qmd:$qmd,graph:$graph}')"
173
+ else
174
+ outcome="indexed · org-scoped · unverified"
175
+ message="The files were validated, normalized, and added to this organization’s retrieval index."
176
+ _journal_clear "$source"
177
+ final="$(printf '%s' "$summary" | jq --argjson qmd "$qmd_status" --argjson graph "$graph" --arg outcome "$outcome" --arg message "$message" '. + {status:"complete",outcome:$outcome,message:$message,qmd:$qmd,graph:$graph}')"
178
+ fi
179
+ _notify_receipt "$receipt_url" "$receipt_token" "$final"
180
+ printf '%s\n' "$final"
181
+ }
182
+
183
+ cmd_search() {
184
+ local query="${1:?usage: bin/ingest.sh search \"query\" [--source id] [--boundary key=value] [-n N]}"
185
+ shift
186
+ local limit=8 raw filtered filter_args=() qmd_n=200
187
+ while [ $# -gt 0 ]; do
188
+ case "$1" in
189
+ -n) limit="$2"; shift 2 ;;
190
+ --source) filter_args+=(--source "$2"); shift 2 ;;
191
+ --boundary) filter_args+=(--boundary "$2"); shift 2 ;;
192
+ *) echo "unknown search option: $1" >&2; exit 2 ;;
193
+ esac
194
+ done
195
+ _ensure_index
196
+ raw="$(_qmd search "$query" -c "$COLLECTION" -n "$qmd_n" --all --json 2>/dev/null || echo '[]')"
197
+ if [ ${#filter_args[@]} -gt 0 ]; then
198
+ filtered="$(printf '%s' "$raw" | python3 "$PY" filter-results "${filter_args[@]}" --limit "$limit")"
199
+ else
200
+ filtered="$(printf '%s' "$raw" | python3 "$PY" filter-results --limit "$limit")"
201
+ fi
202
+ printf '%s' "$filtered" | jq -r --arg org "$SLUG" '
203
+ "⌕ ingest · keyword · \(length) hit\(if length == 1 then "" else "s" end) · org=" + $org,
204
+ (.[] | "\n### " + (.title // .file) + "\n" + .file + "\n\n" + (.snippet // ""))'
205
+ }
206
+
207
+ case "${1:-}" in
208
+ select) shift; python3 "$SURFACE" "$@" ;;
209
+ add) shift; cmd_add "$@" ;;
210
+ add-selection) shift; cmd_add_selection "$@" ;;
211
+ register-extraction) shift; python3 "$PY" register-extraction "$@" ;;
212
+ search) shift; cmd_search "$@" ;;
213
+ reindex)
214
+ _ensure_index
215
+ if graph="$(_graph_sync "")"; then
216
+ find "$INGEST_ROOT/.state" -type f -name '*.json' -delete 2>/dev/null || true
217
+ fi
218
+ printf '%s\n' "$graph"
219
+ ;;
220
+ graph-sync) shift; _graph_sync "${1:-}" ;;
221
+ status) python3 "$PY" status; _qmd status 2>/dev/null || true ;;
222
+ *)
223
+ echo 'usage: bash bin/ingest.sh {select|add|add-selection|register-extraction|search|reindex|graph-sync|status}' >&2
224
+ echo ' select [--no-open] [--timeout SECONDS]' >&2
225
+ echo ' add PATH --source ID [--name NAME] [--kind TYPE] [--boundary key=value]... [--prune]' >&2
226
+ echo ' add-selection MANIFEST' >&2
227
+ echo ' register-extraction MANIFEST RELATIVE_PATH --extractor NAME < normalized.txt' >&2
228
+ echo ' search "QUERY" [--source ID] [--boundary key=value]... [-n N]' >&2
229
+ exit 2
230
+ ;;
231
+ esac