@loomfsm/mcp-server 0.1.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 (60) hide show
  1. package/LICENSE +201 -0
  2. package/cc-adapter/commands/done.md +30 -0
  3. package/cc-adapter/commands/task.md +29 -0
  4. package/cc-adapter/pipeline-guard.sh +58 -0
  5. package/cc-adapter/pipeline-stop.sh +65 -0
  6. package/dist/src/bin/stdio.d.ts +2 -0
  7. package/dist/src/bin/stdio.js +43 -0
  8. package/dist/src/bin/stdio.js.map +1 -0
  9. package/dist/src/bootstrap.d.ts +4 -0
  10. package/dist/src/bootstrap.js +130 -0
  11. package/dist/src/bootstrap.js.map +1 -0
  12. package/dist/src/index.d.ts +21 -0
  13. package/dist/src/index.js +16 -0
  14. package/dist/src/index.js.map +1 -0
  15. package/dist/src/lib/parse-task-args.d.ts +4 -0
  16. package/dist/src/lib/parse-task-args.js +38 -0
  17. package/dist/src/lib/parse-task-args.js.map +1 -0
  18. package/dist/src/lib/persist-progress.d.ts +2 -0
  19. package/dist/src/lib/persist-progress.js +20 -0
  20. package/dist/src/lib/persist-progress.js.map +1 -0
  21. package/dist/src/server.d.ts +25 -0
  22. package/dist/src/server.js +257 -0
  23. package/dist/src/server.js.map +1 -0
  24. package/dist/src/tools/backup.d.ts +5 -0
  25. package/dist/src/tools/backup.js +69 -0
  26. package/dist/src/tools/backup.js.map +1 -0
  27. package/dist/src/tools/continue-task.d.ts +7 -0
  28. package/dist/src/tools/continue-task.js +156 -0
  29. package/dist/src/tools/continue-task.js.map +1 -0
  30. package/dist/src/tools/extensions-list.d.ts +2 -0
  31. package/dist/src/tools/extensions-list.js +49 -0
  32. package/dist/src/tools/extensions-list.js.map +1 -0
  33. package/dist/src/tools/issue-marker.d.ts +5 -0
  34. package/dist/src/tools/issue-marker.js +57 -0
  35. package/dist/src/tools/issue-marker.js.map +1 -0
  36. package/dist/src/tools/meta.d.ts +6 -0
  37. package/dist/src/tools/meta.js +52 -0
  38. package/dist/src/tools/meta.js.map +1 -0
  39. package/dist/src/tools/recover.d.ts +7 -0
  40. package/dist/src/tools/recover.js +243 -0
  41. package/dist/src/tools/recover.js.map +1 -0
  42. package/dist/src/tools/restore.d.ts +5 -0
  43. package/dist/src/tools/restore.js +82 -0
  44. package/dist/src/tools/restore.js.map +1 -0
  45. package/dist/src/tools/run-task.d.ts +7 -0
  46. package/dist/src/tools/run-task.js +172 -0
  47. package/dist/src/tools/run-task.js.map +1 -0
  48. package/dist/src/tools/state-get.d.ts +2 -0
  49. package/dist/src/tools/state-get.js +176 -0
  50. package/dist/src/tools/state-get.js.map +1 -0
  51. package/dist/src/transport-adapter.d.ts +6 -0
  52. package/dist/src/transport-adapter.js +94 -0
  53. package/dist/src/transport-adapter.js.map +1 -0
  54. package/dist/src/types.d.ts +171 -0
  55. package/dist/src/types.js +9 -0
  56. package/dist/src/types.js.map +1 -0
  57. package/dist/src/version.d.ts +3 -0
  58. package/dist/src/version.js +8 -0
  59. package/dist/src/version.js.map +1 -0
  60. package/package.json +45 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend, and
172
+ hold each Contributor harmless for any liability incurred by, or
173
+ claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 teaarte
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing permissions
201
+ and limitations under the License.
@@ -0,0 +1,30 @@
1
+ ---
2
+ mcp_protocol_required: "^3.0"
3
+ ---
4
+
5
+ # /done — review a finished task
6
+
7
+ <!--
8
+ Read-only by design. The task is already finalized by the server when it
9
+ reaches its terminal step; this command never mutates state and never
10
+ acts on the user's behalf. If the task is stuck, the only repair path is
11
+ the server-issued recovery options — never a hand-edit of the state DB.
12
+
13
+ Bundle-neutral: it renders whatever the kernel's summary carries
14
+ (verdict, counts, outputs) and never assumes a particular kind of work.
15
+ Any "next step" it offers (a commit, a publish, a hand-off) is a
16
+ suggestion the user acts on, not something this command performs.
17
+
18
+ `loom` below is the alias this MCP server is registered under in the
19
+ host's MCP config; swap the `mcp__loom__` prefix if you registered it
20
+ under a different name.
21
+ -->
22
+
23
+ Call `mcp__loom__pipeline_state_get({ project_dir: <cwd>, format: "summary" })` to check readiness.
24
+
25
+ - If the task is in an **error / stuck** state (or still has pending agents or an unanswered gate) → display the recovery options verbatim and call `mcp__loom__pipeline_recover({ project_dir, driver_state_id, choice })` with the option the user picks. Stop here; rerun `/done` once the task settles.
26
+ - Otherwise (in progress with nothing pending, or already completed):
27
+ 1. Call `mcp__loom__pipeline_state_get({ project_dir, format: "json" })` for the final metrics.
28
+ 2. Display the kernel summary to the user verbatim — verdict, agent count, outputs, key findings.
29
+ 3. Optionally suggest a sensible next step for that result (for a code task that is usually a commit message). It is a suggestion only — the user acts on it.
30
+ 4. Do **not** perform the next step yourself, do **not** auto-commit, and do **not** mutate state.
@@ -0,0 +1,29 @@
1
+ ---
2
+ mcp_protocol_required: "^3.0"
3
+ ---
4
+
5
+ # /task — start or drive a pipeline task
6
+
7
+ <!--
8
+ This file is a dumb router. It does no flag parsing, no output
9
+ interpretation, and knows zero gate vocabulary: every semantic decision
10
+ (which preset a flag maps to, what a gate's answers are, how to recover)
11
+ lives server-side. That is why adding a new preset, gate role, or bundle
12
+ never edits this file — the server ships the schema, the router renders it.
13
+
14
+ `loom` below is the alias this MCP server is registered under in the
15
+ host's MCP config; if you registered it under a different name, swap the
16
+ `mcp__loom__` prefix to match. No other host detail is assumed.
17
+ -->
18
+
19
+ Call `mcp__loom__pipeline_run_task({ project_dir: <cwd>, task: "$ARGUMENTS", client_idempotency_uuid: <one crypto.randomUUID() bound to this invocation; reuse it verbatim on any transport-retry>, client_capabilities: { honors_shuttle: true } })`. Pass `$ARGUMENTS` exactly as typed — the server parses any leading flag.
20
+
21
+ Then loop on the returned response's `status`:
22
+
23
+ - **`spawn-agent`** → run the spawn with the Task tool using `spawn_request.{description, prompt, model}` (plus `subagent_type` from `spawn_request.extras` when present). Deliver the result back: `mcp__loom__pipeline_continue_task({ project_dir, driver_state_id, input: { type: "agent-result", agent_run_id, agent_output } })`.
24
+ - **`spawn-agents-parallel`** → run every entry in `spawns` the same way, then deliver all results together: `mcp__loom__pipeline_continue_task({ project_dir, driver_state_id, input: { type: "agents-results", results: [{ agent_run_id, agent_output }, …] } })`.
25
+ - **`ask-user`** → show `message` and `valid_answers` to the user **verbatim** (the schema names exactly which replies are accepted and what each produces — do not invent or filter options). Deliver their choice: `mcp__loom__pipeline_continue_task({ project_dir, driver_state_id, input: { type: "user-answer", gate_event_id, … } })` with the fields the chosen option declares.
26
+ - **`complete`** → display `summary`, suggest `/done`, and stop.
27
+ - **`error`** → display `message` and `recovery_options` verbatim, then call `mcp__loom__pipeline_recover({ project_dir, driver_state_id, choice })` with the option the user picks (passing `agent_run_ids` when that option lists them).
28
+
29
+ After any `pipeline_continue_task` or `pipeline_recover`, loop again on the new response's `status`. Never edit the state DB by hand — `pipeline_recover` is the only repair path.
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env bash
2
+ # pipeline-guard.sh — Claude Code PreToolUse hook (ADVISORY ONLY).
3
+ #
4
+ # Blocks the obvious accidental shell mutations of the pipeline state DB
5
+ # (`.claude/state.db`): a direct `rm`, `mv`, output-redirect (`>`), or
6
+ # in-place `sed -i`. It is belt-and-suspenders for fat-fingered keystrokes
7
+ # — NOT a security boundary. It is trivially bypassed by any non-shell
8
+ # write path (a Python/Node one-liner, a symlink, a wrapper script). The
9
+ # real integrity boundary is the kernel's atomic transactions plus its
10
+ # on-commit invariants: a write that does not go through them leaves the
11
+ # DB failing invariant checks on the next kernel touch, which recovery
12
+ # rolls back. Treat this script accordingly.
13
+ #
14
+ # Contract: reads Claude Code's PreToolUse JSON on stdin, inspects only the
15
+ # Bash tool's command string, and denies the four mutations above when the
16
+ # target path ends in `.claude/state.db`. Everything else passes through.
17
+ # Parsing is defensive — a missing/unknown field falls back to allow.
18
+
19
+ set -u
20
+
21
+ payload="$(cat 2>/dev/null || true)"
22
+
23
+ # Extract the shell command. Prefer jq; fall back to a minimal extractor so
24
+ # the hook still functions if jq is absent. Either failure → empty → allow.
25
+ command_str=""
26
+ if command -v jq >/dev/null 2>&1; then
27
+ command_str="$(printf '%s' "$payload" | jq -r '.tool_input.command // empty' 2>/dev/null || true)"
28
+ else
29
+ command_str="$(printf '%s' "$payload" \
30
+ | sed -n 's/.*"command"[[:space:]]*:[[:space:]]*"\(.*\)".*/\1/p' \
31
+ | head -n1)"
32
+ fi
33
+
34
+ # Only the state DB is in scope. No mention → allow.
35
+ case "$command_str" in
36
+ *".claude/state.db"*) : ;;
37
+ *) exit 0 ;;
38
+ esac
39
+
40
+ # Match the four accidental-mutation shapes against the state DB path.
41
+ is_mutation=0
42
+ case "$command_str" in
43
+ *"rm "*".claude/state.db"*) is_mutation=1 ;;
44
+ *"mv "*".claude/state.db"*) is_mutation=1 ;;
45
+ *">"*".claude/state.db"*) is_mutation=1 ;;
46
+ *"sed -i"*".claude/state.db"*) is_mutation=1 ;;
47
+ esac
48
+
49
+ if [ "$is_mutation" -eq 1 ]; then
50
+ reason="refused: direct shell mutation of .claude/state.db — use pipeline_recover. (advisory guard; the real boundary is the kernel's transactional invariants)"
51
+ # Emit Claude Code's structured deny decision on stdout AND exit non-zero,
52
+ # so either contract interpretation treats this as a block.
53
+ printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"%s"}}\n' "$reason"
54
+ printf '%s\n' "$reason" >&2
55
+ exit 2
56
+ fi
57
+
58
+ exit 0
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env bash
2
+ # pipeline-stop.sh — Claude Code Stop hook (ADVISORY, NON-BLOCKING).
3
+ #
4
+ # Prints a short human-readable hint about the pipeline's state when a
5
+ # session stops — never blocks the stop, never writes the DB. It is a
6
+ # courtesy note, not enforcement: the kernel owns task lifecycle and
7
+ # integrity through its transactions and invariants.
8
+ #
9
+ # `sqlite3` is a SOFT dependency: if the CLI is missing, the DB does not
10
+ # exist, or any read fails, the hook degrades to a generic note and exits
11
+ # 0. Parsing of Claude Code's Stop payload is defensive — a missing field
12
+ # never aborts the hook.
13
+
14
+ set -u
15
+
16
+ payload="$(cat 2>/dev/null || true)"
17
+
18
+ # Working dir from the payload if present, else the current directory.
19
+ cwd=""
20
+ session_id=""
21
+ if command -v jq >/dev/null 2>&1; then
22
+ cwd="$(printf '%s' "$payload" | jq -r '.cwd // empty' 2>/dev/null || true)"
23
+ session_id="$(printf '%s' "$payload" | jq -r '.session_id // empty' 2>/dev/null || true)"
24
+ fi
25
+ [ -n "$cwd" ] || cwd="$(pwd)"
26
+
27
+ db="$cwd/.claude/state.db"
28
+
29
+ note() { printf 'pipeline: %s\n' "$1"; exit 0; }
30
+
31
+ # Soft-dependency + existence guards → generic note, never a failure.
32
+ command -v sqlite3 >/dev/null 2>&1 || note "state hint unavailable (sqlite3 CLI not on PATH)."
33
+ [ -f "$db" ] || note "no task state for this project."
34
+
35
+ # Best-effort single read. Any failure degrades to the generic note.
36
+ row="$(sqlite3 "$db" \
37
+ "SELECT COALESCE(p.owner_id,''), p.status,
38
+ COALESCE((SELECT COUNT(*) FROM pending_agents), 0),
39
+ COALESCE((SELECT pending_user_answer FROM driver_state WHERE id = 1), '')
40
+ FROM pipeline_state p WHERE p.id = 1;" 2>/dev/null || true)"
41
+ [ -n "$row" ] || note "no task state for this project."
42
+
43
+ owner="$(printf '%s' "$row" | cut -d'|' -f1)"
44
+ status="$(printf '%s' "$row" | cut -d'|' -f2)"
45
+ pending_agents="$(printf '%s' "$row" | cut -d'|' -f3)"
46
+ pending_answer="$(printf '%s' "$row" | cut -d'|' -f4)"
47
+
48
+ owner_hint=""
49
+ if [ -n "$owner" ] && [ -n "$session_id" ] && [ "$owner" != "$session_id" ]; then
50
+ owner_hint=" (owned by another session)"
51
+ fi
52
+
53
+ # Tri-state hint, derived top-down. Terminal states short-circuit first.
54
+ case "$status" in
55
+ completed|abandoned)
56
+ note "task is finalized (status=$status)$owner_hint." ;;
57
+ esac
58
+
59
+ if [ -n "$pending_answer" ]; then
60
+ note "gate-paused — a checkpoint is awaiting your answer$owner_hint."
61
+ elif [ "${pending_agents:-0}" -gt 0 ]; then
62
+ note "in-flight — $pending_agents agent(s) still executing$owner_hint."
63
+ else
64
+ note "accept-pending — task in progress, nothing dispatched$owner_hint."
65
+ fi
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ // Stdio entrypoint a host's MCP config spawns. Connects the server over
3
+ // stdin/stdout and exits non-zero if the transport fails to connect.
4
+ //
5
+ // This is where the production dependencies wire in: `assembleRegistry`
6
+ // loads the installed bundle + the zero-config shuttle provider for a
7
+ // project (so the active-task tools have a real flow to tick), and the
8
+ // operator-authored project-dir allowlist gates which projects are
9
+ // reachable. The allowlist is default-deny — a project is permitted only
10
+ // after its absolute path is added to the file (see SETUP.md). This
11
+ // entrypoint ensures the file and its parent directory exist so the
12
+ // operator has a place to add entries, but it NEVER auto-enrolls a
13
+ // project: a self-enrolling transport would defeat the gate.
14
+ import { mkdirSync, writeFileSync } from "node:fs";
15
+ import { homedir } from "node:os";
16
+ import { dirname, join } from "node:path";
17
+ import { assembleRegistry } from "../bootstrap.js";
18
+ import { runStdioServer } from "../server.js";
19
+ // Mirror the kernel's default allowlist location so the path the gate
20
+ // reads and the path this entrypoint seeds are the same file.
21
+ function resolveAllowlistPath() {
22
+ const home = process.env.HOME ?? homedir();
23
+ return join(home, ".claude", "projects.allow");
24
+ }
25
+ function ensureAllowlistExists(path) {
26
+ try {
27
+ mkdirSync(dirname(path), { recursive: true });
28
+ // `wx` creates the file only when it is absent — an operator-authored
29
+ // allowlist is never overwritten.
30
+ writeFileSync(path, "", { flag: "wx" });
31
+ }
32
+ catch {
33
+ // Already present (the common case) or unwritable; either way the
34
+ // gate treats a missing/empty file as default-deny.
35
+ }
36
+ }
37
+ const allowlistPath = resolveAllowlistPath();
38
+ ensureAllowlistExists(allowlistPath);
39
+ runStdioServer({ resolveRegistry: assembleRegistry, allowlistPath }).catch((err) => {
40
+ process.stderr.write(`mcp-server failed to start: ${String(err)}\n`);
41
+ process.exit(1);
42
+ });
43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AAE,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;IAC1F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type LLMProvider, type Registry } from "@loomfsm/kernel";
2
+ export declare function createAssembleRegistry(providers: LLMProvider[]): (projectDir: string) => Promise<Registry>;
3
+ export declare function assembleRegistry(projectDir: string): Promise<Registry>;
4
+ export declare function _resetRegistryCacheForTest(): void;
@@ -0,0 +1,130 @@
1
+ // Production registry assembly — the wiring the active-task tools need
2
+ // to tick a real flow.
3
+ //
4
+ // `assembleRegistry(projectDir)` is the resolver the stdio entrypoint
5
+ // injects as `ServerDeps.resolveRegistry`. It does the three things a
6
+ // project needs before its first FSM tick:
7
+ //
8
+ // 1. Resolve the bundle's source root (where `agents/` and the prompt
9
+ // templates live) so the loader can read every agent's `.md` body
10
+ // off disk into the prompt map.
11
+ // 2. Open the project DB (kernel migrations apply on first open) and
12
+ // idempotently reconcile the bundle's manifest into the project's
13
+ // installed-extensions table — the loader refuses a bundle whose
14
+ // manifest row is absent, and a re-run with an unchanged manifest
15
+ // is a no-op (no duplicate rows, no spurious change event).
16
+ // 3. Load the bundle with the zero-config shuttle provider and return
17
+ // the assembled Registry.
18
+ //
19
+ // The Registry is cached per project for the process lifetime: the FSM
20
+ // reads a fresh state snapshot every tick, but the registry itself is a
21
+ // static product of (bundle source + installed manifest) that does not
22
+ // change between ticks, so building it once is safe. A rejected build is
23
+ // evicted so a transient failure (e.g. a not-yet-built bundle dist) does
24
+ // not poison every later call.
25
+ //
26
+ // This lives in the transport package for now; a shared runtime home is
27
+ // the natural next move once a second entrypoint wants the same wiring.
28
+ import { readFileSync } from "node:fs";
29
+ import { createRequire } from "node:module";
30
+ import { dirname, join, resolve } from "node:path";
31
+ import codeBundle, { codeManifest } from "@loomfsm/bundle-code";
32
+ import { captureNow, loadBundle, openDb, reconcileExtensions, } from "@loomfsm/kernel";
33
+ import { claudeCodeShuttleProvider } from "@loomfsm/provider-claude-code-shuttle";
34
+ // Resolve the bundle package root through Node's own resolver so it works
35
+ // both from an installed `node_modules/@loomfsm/bundle-code` and from a
36
+ // workspace symlink in the monorepo. `package.json` is always resolvable
37
+ // regardless of any `exports` map; its directory is the source root the
38
+ // loader resolves each agent's `template_path` against.
39
+ const bundleSourceDir = dirname(createRequire(import.meta.url).resolve("@loomfsm/bundle-code/package.json"));
40
+ // Synthetic source tag for the reconciled manifest. The reconcile core
41
+ // treats this as an opaque label (it only surfaces in a fallback id when
42
+ // validation fails, which cannot happen for the curated bundle manifest).
43
+ const BUNDLE_MANIFEST_SOURCE = "@loomfsm/bundle-code:manifest";
44
+ // Build a per-project registry resolver over a fixed provider set. The
45
+ // provider SET is a deployment choice the entrypoint owns — the generic
46
+ // server bundles only the zero-config shuttle default; a deployment that
47
+ // wants other backends (a local model, a hosted API) injects them here
48
+ // rather than the server hardcoding every provider package. Per-agent /
49
+ // per-phase routing among the registered set is then a project-level
50
+ // `.claude/providers.json` (read at build).
51
+ //
52
+ // Concurrent first calls share one in-flight build via the cached promise;
53
+ // a rejected build is evicted so a transient failure does not poison later
54
+ // calls.
55
+ export function createAssembleRegistry(providers) {
56
+ return makeResolver(providers, new Map());
57
+ }
58
+ function makeResolver(providers, cache) {
59
+ return function assemble(projectDir) {
60
+ const key = resolve(projectDir);
61
+ const cached = cache.get(key);
62
+ if (cached !== undefined)
63
+ return cached;
64
+ const building = buildRegistry(projectDir, providers).catch((err) => {
65
+ cache.delete(key);
66
+ throw err;
67
+ });
68
+ cache.set(key, building);
69
+ return building;
70
+ };
71
+ }
72
+ // The default resolver's cache is module-level so the test seam can clear
73
+ // it; resolvers from `createAssembleRegistry` own private caches.
74
+ const defaultResolverCache = new Map();
75
+ const defaultResolver = makeResolver([claudeCodeShuttleProvider], defaultResolverCache);
76
+ // The production resolver the stdio entrypoint injects: zero-config shuttle
77
+ // only. Per-agent provider routing still works for any provider in this
78
+ // set; to route to other backends, an entrypoint builds its own resolver
79
+ // via `createAssembleRegistry([...])`.
80
+ export function assembleRegistry(projectDir) {
81
+ return defaultResolver(projectDir);
82
+ }
83
+ async function buildRegistry(projectDir, providers) {
84
+ const now = captureNow();
85
+ // Open the project DB so kernel migrations apply before the loader
86
+ // reads the installed-extensions table.
87
+ openDb(projectDir);
88
+ // Idempotent: an unchanged manifest row is left as-is.
89
+ await reconcileExtensions({
90
+ manifests: [{ path: BUNDLE_MANIFEST_SOURCE, raw: codeManifest }],
91
+ project_dir: projectDir,
92
+ now,
93
+ });
94
+ return await loadBundle({
95
+ bundle: codeBundle,
96
+ bundle_source_dir: bundleSourceDir,
97
+ project_dir: projectDir,
98
+ providers,
99
+ providers_config: readProvidersConfig(projectDir),
100
+ now,
101
+ });
102
+ }
103
+ // Optional per-project provider routing, read from `.claude/providers.json`
104
+ // (the same `.claude/` dir the state DB lives in). Absent → no routing
105
+ // (every agent resolves to the default provider). Present-but-malformed is
106
+ // surfaced as an error rather than silently ignored; the kernel router
107
+ // validates the parsed shape and refuses unknown providers/tiers.
108
+ function readProvidersConfig(projectDir) {
109
+ const path = join(projectDir, ".claude", "providers.json");
110
+ let raw;
111
+ try {
112
+ raw = readFileSync(path, "utf8");
113
+ }
114
+ catch {
115
+ return undefined; // absent → no routing config
116
+ }
117
+ try {
118
+ return JSON.parse(raw);
119
+ }
120
+ catch (err) {
121
+ throw new Error(`invalid provider routing config at ${path}: ${err.message}`);
122
+ }
123
+ }
124
+ // Test seam: drop the default resolver's per-project cache so a suite can
125
+ // rebuild a registry for a reused project path. Resolvers built via
126
+ // `createAssembleRegistry` own their own caches (fresh per construction).
127
+ export function _resetRegistryCacheForTest() {
128
+ defaultResolverCache.clear();
129
+ }
130
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+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AmB,CAAC;QACxB,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC;QAChE,WAAW,EAAE,UAAU;QACvB,GAAG;KACJ,CAAC,CAAC;IAEH,OAAO,MAAM,UAAU,CAAC;QACtB,MAAM,EAAE,UAAU;QAClB,iBAAiB,EAAE,eAAe;QAClC,WAAW,EAAE,UAAU;QACvB,SAAS;QACT,gBAAgB,EAAE,mBAAmB,CAAC,UAAU,CAAC;QACjD,GAAG;KACJ,CAAC,CAAC;AACL,CAAC;AAED,4EAA4E;AAC5E,uEAAuE;AACvE,2EAA2E;AAC3E,uEAAuE;AACvE,kEAAkE;AAClE,SAAS,mBAAmB,CAAC,UAAkB;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;IAC3D,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC,CAAC,6BAA6B;IACjD,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAoB,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sCAAsC,IAAI,KAAM,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3F,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,oEAAoE;AACpE,0EAA0E;AAC1E,MAAM,UAAU,0BAA0B;IACxC,oBAAoB,CAAC,KAAK,EAAE,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,21 @@
1
+ export { createServer, runStdioServer } from "./server.js";
2
+ export type { CreateServerHandle, ServerDeps, ToolRegistry } from "./server.js";
3
+ export { createMetaTool } from "./tools/meta.js";
4
+ export type { MetaInputWithProject } from "./tools/meta.js";
5
+ export { createStateGetTool } from "./tools/state-get.js";
6
+ export { createExtensionsListTool } from "./tools/extensions-list.js";
7
+ export { createRunTaskTool } from "./tools/run-task.js";
8
+ export type { RunTaskDeps } from "./tools/run-task.js";
9
+ export { createContinueTaskTool } from "./tools/continue-task.js";
10
+ export type { ContinueTaskDeps } from "./tools/continue-task.js";
11
+ export { createRecoverTool } from "./tools/recover.js";
12
+ export type { RecoverDeps } from "./tools/recover.js";
13
+ export { createIssueCrossOwnerMarkerTool } from "./tools/issue-marker.js";
14
+ export type { IssueMarkerDeps } from "./tools/issue-marker.js";
15
+ export { createBackupTool } from "./tools/backup.js";
16
+ export type { BackupDeps } from "./tools/backup.js";
17
+ export { createRestoreTool } from "./tools/restore.js";
18
+ export type { RestoreDeps } from "./tools/restore.js";
19
+ export { createTransportAdapter, shape } from "./transport-adapter.js";
20
+ export { FLAG_TO_PRESET, parseTaskArgs } from "./lib/parse-task-args.js";
21
+ export type { BackupInput, BackupResponse, BypassMarkerInput, ClientCapabilities, ContinueTaskRequestInput, ContinueTaskResponse, ExtensionsListEntry, ExtensionsListInput, ExtensionsListResponse, ExtensionStatus, IssueCrossOwnerMarkerInput, IssueCrossOwnerMarkerResponse, MetaBundle, MetaInput, MetaProviders, MetaSandbox, MetaTransports, ParsedTaskArgs, PipelineMetaResponse, PipelineStateView, RecoverTaskInput, RecoverTaskResponse, RecoveryChoiceInput, RestoreInput, RestoreResponse, RunTaskInput, RunTaskResponse, SpawnRequest, StateGetFormat, StateGetInput, ToolHandler, TransportResponse, } from "./types.js";
@@ -0,0 +1,16 @@
1
+ // Public barrel — anything callers import as `@loomfsm/mcp-server` lives
2
+ // here. Internal tool modules and the version constants stay private
3
+ // to the package layout.
4
+ export { createServer, runStdioServer } from "./server.js";
5
+ export { createMetaTool } from "./tools/meta.js";
6
+ export { createStateGetTool } from "./tools/state-get.js";
7
+ export { createExtensionsListTool } from "./tools/extensions-list.js";
8
+ export { createRunTaskTool } from "./tools/run-task.js";
9
+ export { createContinueTaskTool } from "./tools/continue-task.js";
10
+ export { createRecoverTool } from "./tools/recover.js";
11
+ export { createIssueCrossOwnerMarkerTool } from "./tools/issue-marker.js";
12
+ export { createBackupTool } from "./tools/backup.js";
13
+ export { createRestoreTool } from "./tools/restore.js";
14
+ export { createTransportAdapter, shape } from "./transport-adapter.js";
15
+ export { FLAG_TO_PRESET, parseTaskArgs } from "./lib/parse-task-args.js";
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qEAAqE;AACrE,yBAAyB;AAEzB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ParsedTaskArgs } from "../types.js";
2
+ export type { ParsedTaskArgs };
3
+ export declare const FLAG_TO_PRESET: Record<string, string>;
4
+ export declare function parseTaskArgs(raw: string): ParsedTaskArgs;