@rubytech/create-maxy-code 0.1.174 → 0.1.177
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -4
- package/package.json +1 -1
- package/payload/platform/neo4j/schema.cypher +49 -10
- package/payload/platform/plugins/docs/references/voice-mirror-guide.md +18 -16
- package/payload/platform/plugins/email/skills/email-composition/SKILL.md +1 -1
- package/payload/platform/plugins/memory/mcp/dist/index.js +1 -1
- package/payload/platform/plugins/memory/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/section-types.d.ts +11 -2
- package/payload/platform/plugins/memory/mcp/dist/lib/section-types.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-ingest-body-server-sliced.test.d.ts +2 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-ingest-body-server-sliced.test.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-ingest-body-server-sliced.test.js +95 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-ingest-body-server-sliced.test.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.d.ts +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.js +98 -15
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.js.map +1 -1
- package/payload/platform/plugins/memory/skills/document-ingest/SKILL.md +3 -2
- package/payload/platform/plugins/substack-import/skills/substack-import/SKILL.md +1 -0
- package/payload/platform/scripts/setup-account.sh +8 -0
- package/payload/platform/scripts/verify-skill-tool-surface.sh +27 -8
- package/payload/premium-plugins/venture-studio/skills/investor-data-room/SKILL.md +1 -1
- package/payload/premium-plugins/writer-craft/PLUGIN.md +11 -7
- package/payload/premium-plugins/writer-craft/hooks/__tests__/voice-session-end-text.test.sh +284 -0
- package/payload/premium-plugins/writer-craft/hooks/voice-session-end-text.sh +75 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.d.ts +3 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.d.ts.map +1 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.js +58 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.js.map +1 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/index.d.ts.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/index.js +95 -18
- package/payload/premium-plugins/writer-craft/mcp/dist/index.js.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/lib/voice-corpus.d.ts +47 -6
- package/payload/premium-plugins/writer-craft/mcp/dist/lib/voice-corpus.d.ts.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/lib/voice-corpus.js +69 -6
- package/payload/premium-plugins/writer-craft/mcp/dist/lib/voice-corpus.js.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-distil-profile.d.ts +8 -2
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-distil-profile.d.ts.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-distil-profile.js +82 -53
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-distil-profile.js.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-ingest-session-text.d.ts +23 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-ingest-session-text.d.ts.map +1 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-ingest-session-text.js +191 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-ingest-session-text.js.map +1 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-record-feedback.d.ts +6 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-record-feedback.d.ts.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-record-feedback.js +14 -6
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-record-feedback.js.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-retrieve-conditioning.d.ts +12 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-retrieve-conditioning.d.ts.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-retrieve-conditioning.js +23 -12
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-retrieve-conditioning.js.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-tag-content.d.ts +3 -0
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-tag-content.d.ts.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-tag-content.js +33 -5
- package/payload/premium-plugins/writer-craft/mcp/dist/tools/voice-tag-content.js.map +1 -1
- package/payload/premium-plugins/writer-craft/mcp/scripts/smoke.mjs +289 -28
- package/payload/premium-plugins/writer-craft/mcp/src/cli/ingest-session-text.ts +65 -0
- package/payload/premium-plugins/writer-craft/mcp/src/index.ts +108 -18
- package/payload/premium-plugins/writer-craft/mcp/src/lib/voice-corpus.ts +78 -6
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-distil-profile.ts +115 -56
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-ingest-session-text.ts +229 -0
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-record-feedback.ts +20 -6
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-retrieve-conditioning.ts +38 -13
- package/payload/premium-plugins/writer-craft/mcp/src/tools/voice-tag-content.ts +42 -5
- package/payload/premium-plugins/writer-craft/skills/voice-mirror/SKILL.md +65 -31
|
@@ -16,6 +16,9 @@ tools:
|
|
|
16
16
|
- name: voice-record-feedback
|
|
17
17
|
publicAllowlist: false
|
|
18
18
|
adminAllowlist: true
|
|
19
|
+
- name: voice-ingest-session-text
|
|
20
|
+
publicAllowlist: false
|
|
21
|
+
adminAllowlist: true
|
|
19
22
|
always: false
|
|
20
23
|
embed: false
|
|
21
24
|
mcp:
|
|
@@ -87,7 +90,7 @@ The user is:
|
|
|
87
90
|
|
|
88
91
|
| Skill | Purpose |
|
|
89
92
|
|-------|---------|
|
|
90
|
-
| `voice-mirror` | Capture the operator's voice from their own writing (`human-only` corpus) and condition agent drafts on it.
|
|
93
|
+
| `voice-mirror` | Capture the operator's voice from their own writing (`human-only` corpus) and condition agent drafts on it. Five tools: tag historical content (with auto-derived format), distil a per-format style card, retrieve conditioning for a drafting brief (requires `brief.format`), record operator edits as feedback, and auto-ingest PTY turns at SessionEnd. Other drafting skills (email composition, Postiz, property-brochure, prospectus) call it transparently — opt-out via `voiceMirror: false` in the calling skill's frontmatter. |
|
|
91
94
|
|
|
92
95
|
## Specialist Agent
|
|
93
96
|
|
|
@@ -99,14 +102,15 @@ The manuscript-reviewer agent operates in its own context window with file tools
|
|
|
99
102
|
|
|
100
103
|
## Tools
|
|
101
104
|
|
|
102
|
-
Voice-mirror introduces
|
|
105
|
+
Voice-mirror introduces five deterministic plugin tools. They route writes through `memory-write` so the graph-write gate stamps provenance on every node.
|
|
103
106
|
|
|
104
107
|
| Tool | Purpose |
|
|
105
108
|
|------|---------|
|
|
106
|
-
| `voice-tag-content` | Stamp `authorshipMode ∈ {human-only, human-led-agent-assisted, agent-led-human-reviewed, agent-only, unknown}` on one or many `:KnowledgeDocument | :Message | :SocialPost` nodes (email threads live as `:KnowledgeDocument {source:'email'}` since Task 321). Bulk-mode for backfill batches. |
|
|
107
|
-
| `voice-distil-profile` | Walk the operator's `human-only` corpus and persist a `:VoiceProfile {styleCard, generatedAt, corpusSize, feedbackEntries}` linked to the `:AdminUser`. Cadence-guarded: re-runs on ≥20% corpus growth or ≥30 days, otherwise no-op. |
|
|
108
|
-
| `voice-retrieve-conditioning` | Return `{styleCard, exemplars[]}` for a drafting brief. K=5 short-form, K=15 long-form. Token-budget bounded. Graceful degradation: empty profile → `{styleCard: null, exemplars: []}`. |
|
|
109
|
-
| `voice-record-feedback` | Capture an operator edit on an agent draft as a `:VoiceEdit` with a Haiku-summarised `intent`, linked back to the operator's `:VoiceProfile` via `:FEEDBACK_FOR`. |
|
|
109
|
+
| `voice-tag-content` | Stamp `authorshipMode ∈ {human-only, human-led-agent-assisted, agent-led-human-reviewed, agent-only, unknown}` and derived `format ∈ {text, email, social-post, article, note, marketing-copy}` on one or many `:KnowledgeDocument | :Message | :SocialPost` nodes (email threads live as `:KnowledgeDocument {source:'email'}` since Task 321). Bulk-mode for backfill batches. Pass `format` explicitly to override auto-derivation. |
|
|
110
|
+
| `voice-distil-profile` | Walk the operator's `human-only` corpus for the given `format` and persist a `:VoiceProfile {styleCard, generatedAt, corpusSize, feedbackEntries, format}` linked to the `:AdminUser`. Omit `format` to enumerate all formats in the corpus and distil each. Cadence-guarded per format: re-runs on ≥20% corpus growth or ≥30 days, otherwise no-op. |
|
|
111
|
+
| `voice-retrieve-conditioning` | Return `{styleCard, exemplars[]}` for a drafting brief. Requires `brief.format` (one of the six corpus formats). K=5 short-form (`brief.length:'short'`), K=15 long-form (`brief.length:'long'`). Token-budget bounded. Graceful degradation: empty profile → `{styleCard: null, exemplars: []}`. |
|
|
112
|
+
| `voice-record-feedback` | Capture an operator edit on an agent draft as a `:VoiceEdit {format}` with a Haiku-summarised `intent`, linked back to the operator's per-format `:VoiceProfile` via `:FEEDBACK_FOR`. Requires `format`. |
|
|
113
|
+
| `voice-ingest-session-text` | Ingest operator PTY turns from a JSONL transcript as `:Message {format:'text', authorshipMode:'human-only'}` corpus nodes. Deduplicates via SHA256 `contentHash`. Called by `voice-session-end-text.sh` at SessionEnd; not intended for direct agent invocation. |
|
|
110
114
|
|
|
111
115
|
The non-voice skills continue to operate via existing platform tools (`memory-search` for knowledge retrieval). Structured choices are still presented as numbered lists in plain chat — the platform has no inline-UI component primitive on the admin / native-CC surface.
|
|
112
116
|
|
|
@@ -127,4 +131,4 @@ Domain knowledge files loaded on demand by each skill. See individual skill file
|
|
|
127
131
|
| `review-manuscript` | `review-manuscript-checklist.md` |
|
|
128
132
|
| `review-scene` | `scene-analysis-framework.md` |
|
|
129
133
|
| `review-prose` | `prose-review-checklist.md` |
|
|
130
|
-
| `voice-mirror` | No external references; the skill body defines the
|
|
134
|
+
| `voice-mirror` | No external references; the skill body defines the five tool contracts. Developer notes in `maxy-code/.docs/voice-mirror.md`. |
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# voice-session-end-text.sh hook test suite.
|
|
3
|
+
#
|
|
4
|
+
# Pattern: a local Python HTTP server stands in for /api/admin/log-ingest
|
|
5
|
+
# and records every POST so the assertions can inspect every log line the
|
|
6
|
+
# hook emitted. The CLI is stubbed with a mock node script so tests run
|
|
7
|
+
# without a live Neo4j connection.
|
|
8
|
+
#
|
|
9
|
+
# Contract under test:
|
|
10
|
+
# - Hook skips with reason=role-not-admin when MAXY_SESSION_ROLE != admin.
|
|
11
|
+
# - Hook skips with reason=is-specialist when MAXY_SPECIALIST is set.
|
|
12
|
+
# - Hook skips with reason=empty-stdin when no stdin is piped.
|
|
13
|
+
# - Hook skips with reason=missing-transcript when the JSONL path in the
|
|
14
|
+
# stdin envelope does not exist.
|
|
15
|
+
# - Hook skips with reason=cli-not-found when the compiled CLI is absent.
|
|
16
|
+
# - Happy path: hook emits trigger + result=ok when all guards pass and the
|
|
17
|
+
# stub CLI exits 0.
|
|
18
|
+
# - Dedupe path: stub CLI returns turns=0 skipped=3 → result=ok with those
|
|
19
|
+
# counts (verifying the hook forwards the CLI stdout to the log-ingest).
|
|
20
|
+
|
|
21
|
+
set -u
|
|
22
|
+
|
|
23
|
+
HOOK="$(cd "$(dirname "$0")/.." && pwd)/voice-session-end-text.sh"
|
|
24
|
+
if [[ ! -f "$HOOK" ]]; then
|
|
25
|
+
echo "FAIL: hook not found at $HOOK" >&2
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
PASS=0
|
|
30
|
+
FAIL=0
|
|
31
|
+
TMPFILES=()
|
|
32
|
+
LISTENER_PIDS=()
|
|
33
|
+
|
|
34
|
+
cleanup() {
|
|
35
|
+
for pid in "${LISTENER_PIDS[@]:-}"; do
|
|
36
|
+
[[ -n "$pid" ]] && { kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; }
|
|
37
|
+
done
|
|
38
|
+
for f in "${TMPFILES[@]:-}"; do
|
|
39
|
+
[[ -n "$f" ]] && rm -f "$f" 2>/dev/null || true
|
|
40
|
+
done
|
|
41
|
+
}
|
|
42
|
+
trap cleanup EXIT
|
|
43
|
+
|
|
44
|
+
# ---- helpers ---------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
make_tmp_file() {
|
|
47
|
+
local tmp
|
|
48
|
+
tmp=$(mktemp)
|
|
49
|
+
TMPFILES+=("$tmp")
|
|
50
|
+
echo "$tmp"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# Start a listener on a random port; capture every POST body.
|
|
54
|
+
# Sets LISTENER_PORT and LISTENER_LOG globals.
|
|
55
|
+
start_listener() {
|
|
56
|
+
LISTENER_LOG=$(make_tmp_file)
|
|
57
|
+
LISTENER_PORT=$(python3 -c 'import socket; s=socket.socket(); s.bind(("",0)); print(s.getsockname()[1]); s.close()')
|
|
58
|
+
python3 - "$LISTENER_PORT" "$LISTENER_LOG" <<'PY' &
|
|
59
|
+
import sys, http.server, json
|
|
60
|
+
|
|
61
|
+
port = int(sys.argv[1])
|
|
62
|
+
log = sys.argv[2]
|
|
63
|
+
|
|
64
|
+
class H(http.server.BaseHTTPRequestHandler):
|
|
65
|
+
def do_POST(self):
|
|
66
|
+
n = int(self.headers.get("Content-Length", 0))
|
|
67
|
+
body = self.rfile.read(n).decode()
|
|
68
|
+
with open(log, "a") as f:
|
|
69
|
+
f.write(body + "\n")
|
|
70
|
+
self.send_response(200)
|
|
71
|
+
self.end_headers()
|
|
72
|
+
def log_message(self, *a): pass
|
|
73
|
+
|
|
74
|
+
http.server.HTTPServer(("127.0.0.1", port), H).serve_forever()
|
|
75
|
+
PY
|
|
76
|
+
local pid=$!
|
|
77
|
+
LISTENER_PIDS+=("$pid")
|
|
78
|
+
sleep 0.3 # let the server start
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Run the hook with given env overrides and optional stdin.
|
|
82
|
+
# Returns: HOOK_EXIT, LISTENER_LINES (array of log-ingest line bodies).
|
|
83
|
+
run_hook() {
|
|
84
|
+
local env_args=("$@")
|
|
85
|
+
local stdin_data="${HOOK_STDIN:-}"
|
|
86
|
+
local hook_exit=0
|
|
87
|
+
if [[ -n "$stdin_data" ]]; then
|
|
88
|
+
printf '%s' "$stdin_data" | env \
|
|
89
|
+
MAXY_UI_INTERNAL_PORT="$LISTENER_PORT" \
|
|
90
|
+
MAXY_SESSION_ROLE="${MAXY_SESSION_ROLE:-admin}" \
|
|
91
|
+
MAXY_SPECIALIST="${MAXY_SPECIALIST:-}" \
|
|
92
|
+
PLATFORM_ROOT="${FAKE_PLATFORM_ROOT:-}" \
|
|
93
|
+
ACCOUNT_ID="${ACCOUNT_ID:-acct-test}" \
|
|
94
|
+
USER_ID="${USER_ID:-user-test}" \
|
|
95
|
+
SESSION_ID="" \
|
|
96
|
+
NEO4J_URI="bolt://localhost:7688" \
|
|
97
|
+
NEO4J_USER="neo4j" \
|
|
98
|
+
NEO4J_PASSWORD="test" \
|
|
99
|
+
${env_args[@]+"${env_args[@]}"} \
|
|
100
|
+
bash "$HOOK" >/dev/null 2>/dev/null || hook_exit=$?
|
|
101
|
+
else
|
|
102
|
+
env \
|
|
103
|
+
MAXY_UI_INTERNAL_PORT="$LISTENER_PORT" \
|
|
104
|
+
MAXY_SESSION_ROLE="${MAXY_SESSION_ROLE:-admin}" \
|
|
105
|
+
MAXY_SPECIALIST="${MAXY_SPECIALIST:-}" \
|
|
106
|
+
PLATFORM_ROOT="${FAKE_PLATFORM_ROOT:-}" \
|
|
107
|
+
ACCOUNT_ID="${ACCOUNT_ID:-acct-test}" \
|
|
108
|
+
USER_ID="${USER_ID:-user-test}" \
|
|
109
|
+
SESSION_ID="" \
|
|
110
|
+
NEO4J_URI="bolt://localhost:7688" \
|
|
111
|
+
NEO4J_USER="neo4j" \
|
|
112
|
+
NEO4J_PASSWORD="test" \
|
|
113
|
+
${env_args[@]+"${env_args[@]}"} \
|
|
114
|
+
bash "$HOOK" </dev/null >/dev/null 2>/dev/null || hook_exit=$?
|
|
115
|
+
fi
|
|
116
|
+
HOOK_EXIT=$hook_exit
|
|
117
|
+
# Read all log-ingest POSTs.
|
|
118
|
+
LISTENER_LINES=()
|
|
119
|
+
while IFS= read -r raw; do
|
|
120
|
+
[[ -z "$raw" ]] && continue
|
|
121
|
+
LISTENER_LINES+=("$raw")
|
|
122
|
+
done < "$LISTENER_LOG"
|
|
123
|
+
# Reset log for next run.
|
|
124
|
+
> "$LISTENER_LOG"
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
assert_contains_line() {
|
|
128
|
+
local test_name="$1"
|
|
129
|
+
local fragment="$2"
|
|
130
|
+
for line in "${LISTENER_LINES[@]:-}"; do
|
|
131
|
+
if [[ "$line" == *"$fragment"* ]]; then
|
|
132
|
+
echo " PASS: $test_name"
|
|
133
|
+
PASS=$((PASS + 1))
|
|
134
|
+
return 0
|
|
135
|
+
fi
|
|
136
|
+
done
|
|
137
|
+
echo " FAIL: $test_name (expected fragment: '$fragment' not found in log lines)"
|
|
138
|
+
printf ' lines:\n'
|
|
139
|
+
for line in "${LISTENER_LINES[@]:-}"; do printf ' %s\n' "$line"; done
|
|
140
|
+
FAIL=$((FAIL + 1))
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
assert_exit() {
|
|
144
|
+
local test_name="$1"
|
|
145
|
+
local expected="$2"
|
|
146
|
+
if [[ "$HOOK_EXIT" -eq "$expected" ]]; then
|
|
147
|
+
echo " PASS: $test_name (exit $expected)"
|
|
148
|
+
PASS=$((PASS + 1))
|
|
149
|
+
else
|
|
150
|
+
echo " FAIL: $test_name (expected exit $expected, got $HOOK_EXIT)"
|
|
151
|
+
FAIL=$((FAIL + 1))
|
|
152
|
+
fi
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# ---- setup -----------------------------------------------------------------
|
|
156
|
+
|
|
157
|
+
start_listener
|
|
158
|
+
|
|
159
|
+
# Create a fake platform root structure so the lib source works.
|
|
160
|
+
FAKE_PLATFORM_ROOT=$(mktemp -d)
|
|
161
|
+
TMPFILES+=("$FAKE_PLATFORM_ROOT")
|
|
162
|
+
mkdir -p "$FAKE_PLATFORM_ROOT/plugins/admin/hooks/lib"
|
|
163
|
+
# Copy the real lib so guards work correctly.
|
|
164
|
+
REAL_LIB="$(cd "$(dirname "$0")/../../../../platform/plugins/admin/hooks/lib" && pwd)/admin-graph-pass-common.sh"
|
|
165
|
+
if [[ ! -f "$REAL_LIB" ]]; then
|
|
166
|
+
echo "FAIL: admin-graph-pass-common.sh not found at $REAL_LIB" >&2
|
|
167
|
+
exit 1
|
|
168
|
+
fi
|
|
169
|
+
cp "$REAL_LIB" "$FAKE_PLATFORM_ROOT/plugins/admin/hooks/lib/admin-graph-pass-common.sh"
|
|
170
|
+
|
|
171
|
+
# Create a minimal fake JSONL transcript.
|
|
172
|
+
FAKE_TRANSCRIPT=$(make_tmp_file)
|
|
173
|
+
printf '{"type":"user","message":{"role":"user","content":"Hello world"}}\n' > "$FAKE_TRANSCRIPT"
|
|
174
|
+
|
|
175
|
+
# Create a stub CLI that exits 0 with a canned result.
|
|
176
|
+
FAKE_CLI_DIR=$(mktemp -d)
|
|
177
|
+
TMPFILES+=("$FAKE_CLI_DIR")
|
|
178
|
+
STUB_CLI="$FAKE_CLI_DIR/ingest-session-text.js"
|
|
179
|
+
cat > "$STUB_CLI" <<'STUB'
|
|
180
|
+
process.stdout.write("turns=3 skipped=0 sessionId=test-session\n");
|
|
181
|
+
process.exit(0);
|
|
182
|
+
STUB
|
|
183
|
+
|
|
184
|
+
# Stub CLI for dedupe scenario (turns=0).
|
|
185
|
+
STUB_CLI_DEDUP="$FAKE_CLI_DIR/ingest-dedup.js"
|
|
186
|
+
cat > "$STUB_CLI_DEDUP" <<'STUB'
|
|
187
|
+
process.stdout.write("turns=0 skipped=3 sessionId=test-session\n");
|
|
188
|
+
process.exit(0);
|
|
189
|
+
STUB
|
|
190
|
+
|
|
191
|
+
# Stub CLI that exits 1 (error).
|
|
192
|
+
STUB_CLI_ERR="$FAKE_CLI_DIR/ingest-error.js"
|
|
193
|
+
cat > "$STUB_CLI_ERR" <<'STUB'
|
|
194
|
+
process.stderr.write("simulated error\n");
|
|
195
|
+
process.exit(1);
|
|
196
|
+
STUB
|
|
197
|
+
|
|
198
|
+
# Valid stdin envelope for the SessionEnd hook.
|
|
199
|
+
valid_envelope() {
|
|
200
|
+
local transcript="${1:-$FAKE_TRANSCRIPT}"
|
|
201
|
+
printf '{"session_id":"test-session","transcript_path":"%s","hook_event_name":"SessionEnd"}' "$transcript"
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
# Override CLI path by symlinking ingest-session-text.js inside a fake platform layout.
|
|
205
|
+
make_platform_with_cli() {
|
|
206
|
+
local stub="$1"
|
|
207
|
+
local proot
|
|
208
|
+
proot=$(mktemp -d)
|
|
209
|
+
TMPFILES+=("$proot")
|
|
210
|
+
cp "$FAKE_PLATFORM_ROOT/plugins/admin/hooks/lib/admin-graph-pass-common.sh" \
|
|
211
|
+
"$proot/plugins/admin/hooks/lib/" 2>/dev/null || \
|
|
212
|
+
{ mkdir -p "$proot/plugins/admin/hooks/lib"; cp "$REAL_LIB" "$proot/plugins/admin/hooks/lib/admin-graph-pass-common.sh"; }
|
|
213
|
+
mkdir -p "$proot/../premium-plugins/writer-craft/mcp/dist/cli" 2>/dev/null || \
|
|
214
|
+
mkdir -p "$(dirname "$proot")/../premium-plugins/writer-craft/mcp/dist/cli" 2>/dev/null || true
|
|
215
|
+
# Simpler: build the expected path from $PLATFORM_ROOT/../premium-plugins/...
|
|
216
|
+
# The hook computes: ${PLATFORM_ROOT}/../premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.js
|
|
217
|
+
# So parent of $proot + /premium-plugins/writer-craft/mcp/dist/cli/
|
|
218
|
+
local parent
|
|
219
|
+
parent=$(dirname "$proot")
|
|
220
|
+
mkdir -p "$parent/premium-plugins/writer-craft/mcp/dist/cli"
|
|
221
|
+
cp "$stub" "$parent/premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.js"
|
|
222
|
+
echo "$proot"
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
# ---- tests -----------------------------------------------------------------
|
|
226
|
+
echo "[voice-session-end-text.test] starting"
|
|
227
|
+
|
|
228
|
+
# T1: non-admin role → skip
|
|
229
|
+
MAXY_SESSION_ROLE="public" HOOK_STDIN=$(valid_envelope) run_hook
|
|
230
|
+
assert_exit "T1: non-admin exits 0" 0
|
|
231
|
+
assert_contains_line "T1: non-admin emits trigger-skipped" "trigger-skipped"
|
|
232
|
+
|
|
233
|
+
# T2: specialist → skip
|
|
234
|
+
unset MAXY_SESSION_ROLE 2>/dev/null || true
|
|
235
|
+
MAXY_SESSION_ROLE="admin" MAXY_SPECIALIST="database-operator" HOOK_STDIN=$(valid_envelope) run_hook
|
|
236
|
+
assert_exit "T2: specialist exits 0" 0
|
|
237
|
+
assert_contains_line "T2: specialist emits trigger-skipped" "trigger-skipped"
|
|
238
|
+
|
|
239
|
+
# T3: empty stdin → skip
|
|
240
|
+
MAXY_SPECIALIST="" MAXY_SESSION_ROLE="admin"
|
|
241
|
+
HOOK_STDIN="" run_hook # no stdin piped
|
|
242
|
+
assert_exit "T3: empty-stdin exits 0" 0
|
|
243
|
+
assert_contains_line "T3: empty-stdin emits trigger-skipped" "trigger-skipped"
|
|
244
|
+
|
|
245
|
+
# T4: missing transcript → skip
|
|
246
|
+
FAKE_MISSING=$(make_tmp_file)
|
|
247
|
+
rm -f "$FAKE_MISSING"
|
|
248
|
+
HOOK_STDIN=$(valid_envelope "$FAKE_MISSING") run_hook
|
|
249
|
+
assert_exit "T4: missing-transcript exits 0" 0
|
|
250
|
+
assert_contains_line "T4: missing-transcript emits trigger-skipped" "trigger-skipped"
|
|
251
|
+
|
|
252
|
+
# T5: CLI not found → skip
|
|
253
|
+
FAKE_PLATFORM_ROOT="$FAKE_PLATFORM_ROOT" HOOK_STDIN=$(valid_envelope) run_hook
|
|
254
|
+
assert_exit "T5: cli-not-found exits 0" 0
|
|
255
|
+
assert_contains_line "T5: cli-not-found emits trigger-skipped" "cli-not-found"
|
|
256
|
+
|
|
257
|
+
# T6: happy path — stub CLI exits 0
|
|
258
|
+
HAPPY_PROOT=$(make_platform_with_cli "$STUB_CLI")
|
|
259
|
+
FAKE_PLATFORM_ROOT="$HAPPY_PROOT" HOOK_STDIN=$(valid_envelope) run_hook
|
|
260
|
+
assert_exit "T6: happy path exits 0" 0
|
|
261
|
+
assert_contains_line "T6: happy path emits trigger" "trigger"
|
|
262
|
+
assert_contains_line "T6: happy path emits result=ok" "result=ok"
|
|
263
|
+
|
|
264
|
+
# T7: dedupe — stub returns turns=0 skipped=3
|
|
265
|
+
DEDUP_PROOT=$(make_platform_with_cli "$STUB_CLI_DEDUP")
|
|
266
|
+
FAKE_PLATFORM_ROOT="$DEDUP_PROOT" HOOK_STDIN=$(valid_envelope) run_hook
|
|
267
|
+
assert_exit "T7: dedupe exits 0" 0
|
|
268
|
+
assert_contains_line "T7: dedupe emits result=ok" "result=ok"
|
|
269
|
+
|
|
270
|
+
# T8: CLI error — stub exits 1
|
|
271
|
+
ERR_PROOT=$(make_platform_with_cli "$STUB_CLI_ERR")
|
|
272
|
+
FAKE_PLATFORM_ROOT="$ERR_PROOT" HOOK_STDIN=$(valid_envelope) run_hook
|
|
273
|
+
assert_exit "T8: cli-error exits 0" 0
|
|
274
|
+
assert_contains_line "T8: cli-error emits result=err" "result=err"
|
|
275
|
+
|
|
276
|
+
# ---- summary ---------------------------------------------------------------
|
|
277
|
+
echo ""
|
|
278
|
+
if [[ "$FAIL" -eq 0 ]]; then
|
|
279
|
+
echo "[voice-session-end-text.test] all $PASS tests passed"
|
|
280
|
+
exit 0
|
|
281
|
+
else
|
|
282
|
+
echo "[voice-session-end-text.test] FAILED — $FAIL/$((PASS + FAIL)) tests failed"
|
|
283
|
+
exit 1
|
|
284
|
+
fi
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# SessionEnd hook — auto-ingests operator PTY turns as :Message {format:'text'}
|
|
3
|
+
# corpus nodes in the writer-craft voice corpus.
|
|
4
|
+
#
|
|
5
|
+
# Fired by Claude Code after each PTY session terminates. Receives the full
|
|
6
|
+
# session envelope from stdin:
|
|
7
|
+
# { "session_id": "...", "transcript_path": "...", "hook_event_name": "SessionEnd", ... }
|
|
8
|
+
#
|
|
9
|
+
# Guards (shared logic via admin-graph-pass-common.sh):
|
|
10
|
+
# - role != admin → exit 0 (trigger-skipped reason=role-not-admin)
|
|
11
|
+
# - MAXY_SPECIALIST set → exit 0 (trigger-skipped reason=is-specialist)
|
|
12
|
+
# - empty stdin → exit 0 (trigger-skipped reason=empty-stdin)
|
|
13
|
+
# - missing transcript → exit 0 (trigger-skipped reason=missing-transcript)
|
|
14
|
+
#
|
|
15
|
+
# Additional guard:
|
|
16
|
+
# - CLI not found → exit 0 (trigger-skipped reason=cli-not-found)
|
|
17
|
+
# Graceful: accounts without writer-craft installed skip silently.
|
|
18
|
+
#
|
|
19
|
+
# Environment (inherited from PTY spawn — set by session manager systemd unit):
|
|
20
|
+
# PLATFORM_ROOT — used to locate the admin hooks lib and the CLI
|
|
21
|
+
# ACCOUNT_ID — operator's account identifier
|
|
22
|
+
# USER_ID — operator's userId
|
|
23
|
+
# SESSION_ID — parsed from stdin envelope by agp_parse_stdin
|
|
24
|
+
# NEO4J_URI — bolt URI (propagated from systemd unit env)
|
|
25
|
+
# NEO4J_USER — neo4j username
|
|
26
|
+
# NEO4J_PASSWORD — neo4j password
|
|
27
|
+
#
|
|
28
|
+
# Observability:
|
|
29
|
+
# [voice-session-end-hook] trigger-skipped sessionId=<id> reason=<reason>
|
|
30
|
+
# [voice-session-end-hook] trigger sessionId=<id>
|
|
31
|
+
# [voice-session-end-hook] result=ok sessionId=<id> turns=<n> skipped=<m>
|
|
32
|
+
# [voice-session-end-hook] result=err sessionId=<id> reason=<detail>
|
|
33
|
+
|
|
34
|
+
set -uo pipefail
|
|
35
|
+
|
|
36
|
+
AGP_LOG_TAG="voice-session-end-hook"
|
|
37
|
+
|
|
38
|
+
# Locate the shared plumbing library via PLATFORM_ROOT (set at PTY spawn).
|
|
39
|
+
# This is more robust than a relative path from the hook's own directory.
|
|
40
|
+
AGP_LIB="${PLATFORM_ROOT:-}/plugins/admin/hooks/lib/admin-graph-pass-common.sh"
|
|
41
|
+
if [ ! -f "$AGP_LIB" ]; then
|
|
42
|
+
echo "[${AGP_LOG_TAG}] trigger-skipped sessionId=unknown reason=missing-helper path=${AGP_LIB}" >&2
|
|
43
|
+
exit 0
|
|
44
|
+
fi
|
|
45
|
+
# shellcheck source=../../../platform/plugins/admin/hooks/lib/admin-graph-pass-common.sh
|
|
46
|
+
source "$AGP_LIB"
|
|
47
|
+
|
|
48
|
+
agp_setup_logging
|
|
49
|
+
agp_read_stdin
|
|
50
|
+
agp_parse_stdin
|
|
51
|
+
agp_guard_role_specialist
|
|
52
|
+
agp_guard_transcript require-stdin
|
|
53
|
+
|
|
54
|
+
# Locate the ingest CLI. Built alongside the MCP server — lives in dist/cli/.
|
|
55
|
+
CLI_PATH="${PLATFORM_ROOT:-}/../premium-plugins/writer-craft/mcp/dist/cli/ingest-session-text.js"
|
|
56
|
+
if [ ! -f "$CLI_PATH" ]; then
|
|
57
|
+
agp_emit_log "trigger-skipped sessionId=${SESSION_ID_REPORTED} reason=cli-not-found path=${CLI_PATH}"
|
|
58
|
+
exit 0
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
agp_emit_log "trigger sessionId=${SESSION_ID_REPORTED}"
|
|
62
|
+
|
|
63
|
+
# Invoke the CLI. All required context is in the inherited env:
|
|
64
|
+
# ACCOUNT_ID, USER_ID, NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD
|
|
65
|
+
# SESSION_ID is passed explicitly since agp_parse_stdin sets it from stdin.
|
|
66
|
+
result=$(SESSION_ID="${SESSION_ID}" node "$CLI_PATH" "$TRANSCRIPT_PATH" 2>&1)
|
|
67
|
+
exit_code=$?
|
|
68
|
+
|
|
69
|
+
if [ "$exit_code" -eq 0 ]; then
|
|
70
|
+
agp_emit_log "result=ok sessionId=${SESSION_ID_REPORTED} ${result}"
|
|
71
|
+
else
|
|
72
|
+
agp_emit_log "result=err sessionId=${SESSION_ID_REPORTED} reason=${result}"
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
exit 0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-session-text.d.ts","sourceRoot":"","sources":["../../src/cli/ingest-session-text.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI wrapper for voice-ingest-session-text.
|
|
4
|
+
*
|
|
5
|
+
* Invoked by the SessionEnd hook after each admin PTY session:
|
|
6
|
+
* node dist/cli/ingest-session-text.js <transcript_path>
|
|
7
|
+
*
|
|
8
|
+
* All other parameters are read from environment variables inherited from
|
|
9
|
+
* the PTY session (which inherits from the session manager's systemd unit):
|
|
10
|
+
*
|
|
11
|
+
* ACCOUNT_ID — operator's account identifier
|
|
12
|
+
* USER_ID — operator's userId (= adminUserId)
|
|
13
|
+
* SESSION_ID — session identifier (parsed by hook from stdin)
|
|
14
|
+
* NEO4J_URI — neo4j bolt URI
|
|
15
|
+
* NEO4J_USER — neo4j username
|
|
16
|
+
* NEO4J_PASSWORD — neo4j password
|
|
17
|
+
*
|
|
18
|
+
* Exit codes:
|
|
19
|
+
* 0 — success (includes no-new-turns case)
|
|
20
|
+
* 1 — error (missing required env, JSONL not found, DB error)
|
|
21
|
+
*
|
|
22
|
+
* stdout: one-line result summary ("turns=N skipped=M") for the hook to
|
|
23
|
+
* capture and forward to the log-ingest endpoint.
|
|
24
|
+
* stderr: detailed diagnostics (tool log lines).
|
|
25
|
+
*/
|
|
26
|
+
import { voiceIngestSessionText } from "../tools/voice-ingest-session-text.js";
|
|
27
|
+
import { closeDriver } from "../lib/neo4j.js";
|
|
28
|
+
const transcriptPath = process.argv[2];
|
|
29
|
+
if (!transcriptPath) {
|
|
30
|
+
process.stderr.write("[ingest-session-text] error: transcript path required as argv[2]\n");
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const accountId = process.env.ACCOUNT_ID ?? "";
|
|
34
|
+
const userId = process.env.USER_ID ?? "";
|
|
35
|
+
const sessionId = process.env.SESSION_ID ?? undefined;
|
|
36
|
+
if (!accountId || !userId) {
|
|
37
|
+
process.stderr.write(`[ingest-session-text] error: ACCOUNT_ID and USER_ID must be set in env (accountId=${accountId || "empty"} userId=${userId || "empty"})\n`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const result = await voiceIngestSessionText({
|
|
42
|
+
sessionJsonlPath: transcriptPath,
|
|
43
|
+
accountId,
|
|
44
|
+
userId,
|
|
45
|
+
sessionId,
|
|
46
|
+
});
|
|
47
|
+
// Emit one-line summary to stdout for the hook to capture.
|
|
48
|
+
process.stdout.write(`turns=${result.ingestedCount} skipped=${result.skippedCount} sessionId=${result.sessionId ?? "unknown"}\n`);
|
|
49
|
+
process.exit(0);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
process.stderr.write(`[ingest-session-text] error: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
await closeDriver();
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ingest-session-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest-session-text.js","sourceRoot":"","sources":["../../src/cli/ingest-session-text.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvC,IAAI,CAAC,cAAc,EAAE,CAAC;IACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oEAAoE,CAAC,CAAC;IAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;AAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;AACzC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,SAAS,CAAC;AAEtD,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,qFAAqF,SAAS,IAAI,OAAO,WAAW,MAAM,IAAI,OAAO,KAAK,CAC3I,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC;QAC1C,gBAAgB,EAAE,cAAc;QAChC,SAAS;QACT,MAAM;QACN,SAAS;KACV,CAAC,CAAC;IACH,2DAA2D;IAC3D,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,SAAS,MAAM,CAAC,aAAa,YAAY,MAAM,CAAC,YAAY,cAAc,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,CAC5G,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,gCAAgC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CACrF,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;QAAS,CAAC;IACT,MAAM,WAAW,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,gBAAgB,EAAuB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,gBAAgB,EAAuB,MAAM,8BAA8B,CAAC;AAoXtG,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|