@synadia-ai/agent-fabric-claude-code 0.3.0 → 0.3.1
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/.claude-plugin/plugin.json +1 -1
- package/BUILD +3 -3
- package/hooks/session-event.js +12 -12
- package/package.json +1 -1
- package/runtime/server.js +27 -27
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nats-channel",
|
|
3
|
-
"version": "0.6.0+fabric.
|
|
3
|
+
"version": "0.6.0+fabric.a204518.95f67d6",
|
|
4
4
|
"description": "NATS channel plugin for Claude Code — bridges NATS messaging to Claude Code sessions, with the Synadia Agent Fabric add-on and ScratchPad",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Synadia"
|
package/BUILD
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
plugin nats-channel 0.6.0
|
|
2
|
-
synadia-agents
|
|
3
|
-
agent-fabric-sdk
|
|
4
|
-
built 2026-10-
|
|
2
|
+
synadia-agents a204518
|
|
3
|
+
agent-fabric-sdk 95f67d6
|
|
4
|
+
built 2026-10-27T07:45:52.971Z
|
package/hooks/session-event.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{writeSync as
|
|
4
|
-
`)}function F(n,t,
|
|
5
|
-
`),"session"}if(
|
|
6
|
-
`),
|
|
7
|
-
`),"tool"}return}function
|
|
8
|
-
`)}function L(n,t
|
|
9
|
-
`)}function
|
|
10
|
-
`)){if(
|
|
11
|
-
`).trim();return
|
|
12
|
-
`);for(let
|
|
13
|
-
`)){if(
|
|
14
|
-
`)}else F(
|
|
3
|
+
import{writeSync as mn}from"fs";import{homedir as _n}from"os";import{join as yn}from"path";import{appendFileSync as D,existsSync as xn,mkdirSync as _,readdirSync as hn,readFileSync as E,renameSync as G,rmSync as X,writeFileSync as W}from"fs";import{join as a}from"path";var Q=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,K=/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/,V=["discover_agents","prompt_agent","wait_agent","answer_agent","cancel_agent","list_agent_calls"];function p(n){return typeof n==="string"&&Q.test(n)}function Y(n){return typeof n==="string"&&K.test(n)}function f(n){return a(n,"sessions")}function M(n,e){return a(f(n),String(e))}function h(n,e){return a(f(n),`${e}.stop`)}function k(n,e){return a(f(n),`${e}.nudge`)}function A(n,e){return a(f(n),`${e}.turn`)}function nn(n,e){return a(f(n),`${e}.open`)}function q(n,e){return a(f(n),`${e}.tools`)}function v(n,e){return a(f(n),`${e}.events`)}function b(n,e){let t=`${n}.${process.pid}.tmp`;W(t,e),G(t,n)}var en=new RegExp(`^mcp__.+__(${V.join("|")})$`);function tn(n){return en.test(n)}function P(n){if(!("background_tasks"in n)&&!("session_crons"in n))return;return N(n.background_tasks)||N(n.session_crons)}function N(n){if(n===void 0||n===null||n===!1||n===0||n==="")return!1;if(Array.isArray(n))return n.length>0;if(typeof n==="object")return Object.keys(n).length>0;return!0}var J=/^plugin:[^"]+:nats$/,O=/^[A-Za-z0-9_-]{1,64}$/,rn=1024,U=64,j=200;function sn(n){if(typeof n!=="string"||!n.startsWith("<channel "))return;let e=n.indexOf(">");if(e<0||e>rn)return;let t=n.slice(0,e),r=/\ssource="([^"]*)"/.exec(t)?.[1],s=/\srequest_id="([^"]*)"/.exec(t)?.[1];if(r===void 0||s===void 0)return;if(!J.test(r)||!O.test(s))return;return{requestId:s,source:r}}function x(n,e){if(typeof n!=="string")return;let t=Array.from(n.replace(/[\u0000-\u001f\u007f]+/g," ").trim()).slice(0,e).join("");return t.length>0?t:void 0}function w(n,e,t){_(f(n),{recursive:!0}),D(v(n,e),`${JSON.stringify(t)}
|
|
4
|
+
`)}function F(n,e,t,r=Date.now()){let s=t.hook_event_name,o=p(t.session_id)?t.session_id:void 0,d=p(t.prompt_id)?t.prompt_id:void 0;if(s==="UserPromptSubmit"){let i=sn(t.prompt);return w(n,e,{event:"submit",...o?{session_id:o}:{},...d?{prompt_id:d}:{},...i?{request_id:i.requestId,source:i.source}:{},at_ms:r}),"submit"}if(s==="StopFailure"){let i=x(t.error,U),u=x(t.error_details,j);return w(n,e,{event:"failure",...o?{session_id:o}:{},...d?{prompt_id:d}:{},...i!==void 0?{error:i}:{},...u!==void 0?{error_details:u}:{},at_ms:r}),"failure"}if(s==="SessionStart"){if(t.source==="startup")gn(n,e);if(o===void 0)return;let i=typeof t.source==="string"?t.source:"unknown";return _(f(n),{recursive:!0}),b(M(n,e),`${JSON.stringify({session_id:o,source:i,at_ms:r})}
|
|
5
|
+
`),"session"}if(s==="Stop"){let i=P(t),u=H(n,e,t),c=u===void 0||u.length>0?dn(n,e)??z(t):void 0,m={...o?{session_id:o}:{},...i!==void 0?{background:i}:{},...c!==void 0?{final_text:c}:{},at_ms:r};return _(f(n),{recursive:!0}),b(h(n,e),`${JSON.stringify(m)}
|
|
6
|
+
`),w(n,e,{event:"stop",...d?{prompt_id:d}:{},...m}),Z(k(n,e)),"stop"}if(s==="PreToolUse"){let{tool_use_id:i,tool_name:u}=t;if(typeof u!=="string"||u.length===0)return;if(_(f(n),{recursive:!0}),on(n,e,t.prompt_id,r),!tn(u)||!Y(i))return"turn";let c=q(n,e);return _(c,{recursive:!0}),b(a(c,i),`${JSON.stringify({tool_use_id:i,tool_name:u,tool_input:t.tool_input??null,...d?{prompt_id:d}:{},at_ms:r})}
|
|
7
|
+
`),"tool"}return}function on(n,e,t,r){let s=p(t)?t:void 0,o=S(A(n,e)),d=l(o?.at_ms),i=l(o?.first_ms),u=l(S(h(n,e))?.at_ms),c=o!==void 0&&o.prompt_id===s&&d!==void 0&&i!==void 0&&(u===void 0||d>u);b(A(n,e),`${JSON.stringify({...s!==void 0?{prompt_id:s}:{},first_ms:c?i:r,at_ms:r})}
|
|
8
|
+
`)}function L(n,e,t){if(t.hook_event_name!=="Stop"||t.stop_hook_active===!0)return;if(P(t)!==!1)return;let r=H(n,e,t);if(r===void 0||r.length===0)return;let s=r.map((o)=>`"${o}"`).join(", ");return`The NATS channel ${r.length===1?"request":"requests"} ${s} ${r.length===1?"is":"are"} still open: the sender has not received an answer, and cannot see this session's own output. Send your answer with the reply tool (load it with ToolSearch if it is deferred), with the request_id and done: true.`}function C(n,e,t,r=Date.now()){let s=z(t);_(f(n),{recursive:!0}),b(k(n,e),`${JSON.stringify({...s!==void 0?{final_text:s}:{},at_ms:r})}
|
|
9
|
+
`)}function dn(n,e){let t=S(k(n,e)),r=l(t?.at_ms);if(t===void 0||r===void 0)return;let s=l(S(h(n,e))?.at_ms);if(s!==void 0&&r<=s)return;let o=t.final_text;return typeof o==="string"&&o.length>0?o:void 0}function un(n,e){let t=S(nn(n,e));if(!t)return;let r=t.server_pid,s=T(t.request_ids),o=t.open_ids===void 0?s:T(t.open_ids);if(typeof r!=="number"||!Number.isSafeInteger(r)||r<=0)return;if(s===void 0||o===void 0)return;if(!ln(r))return;return{requestIds:s,openIds:o}}function T(n){return Array.isArray(n)&&n.every((e)=>typeof e==="string"&&O.test(e))?n:void 0}function H(n,e,t){let r=un(n,e);if(r===void 0)return;let s=p(t.prompt_id)?t.prompt_id:void 0;if(s===void 0)return r.requestIds;let o=pn(n,e);if(!o.some((u)=>u.kind==="submit"&&u.submit.promptId!==void 0))return r.requestIds;let d=new Map,i;for(let u of o){if(u.kind!=="submit"||u.submit.requestId===void 0){i=void 0;continue}let{requestId:c,promptId:m,atMs:I}=u.submit,g=i!==void 0&&I-i.atMs<=cn?i.promptIds:new Set;g.add(m),d.set(c,g),i={atMs:I,promptIds:g}}return r.openIds.filter((u)=>d.get(u)?.has(s)===!0)}var cn=30000;function z(n){if("last_assistant_message"in n){let d=n.last_assistant_message;return typeof d==="string"&&d.trim().length>0?d.trim():void 0}let e=n.transcript_path;if(typeof e!=="string"||e.length===0)return;let t;try{t=E(e,"utf8")}catch{return}let r,s=[];for(let d of t.split(`
|
|
10
|
+
`)){if(d.trim().length===0)continue;let i;try{i=JSON.parse(d)}catch{continue}if(typeof i!=="object"||i===null)continue;let{type:u,message:c,uuid:m}=i;if(u!=="assistant"||typeof c!=="object"||c===null)continue;let{id:I,content:y}=c,g=I??m;if(g===void 0||g!==r)r=g,s=[];if(typeof y==="string")s.push(y);else if(Array.isArray(y))for(let B of y){let R=B;if(R?.type==="text"&&typeof R.text==="string")s.push(R.text)}}let o=s.join(`
|
|
11
|
+
`).trim();return o.length>0?o:void 0}function S(n){let e;try{e=E(n,"utf8")}catch{return}try{let t=JSON.parse(e);return typeof t==="object"&&t!==null&&!Array.isArray(t)?t:void 0}catch{return}}function l(n){return typeof n==="number"&&Number.isSafeInteger(n)&&n>=0?n:void 0}function fn(n){if(!n)return;let e=l(n.at_ms);if(e===void 0)return;return{...p(n.session_id)?{sessionId:n.session_id}:{},...p(n.prompt_id)?{promptId:n.prompt_id}:{},...typeof n.background==="boolean"?{background:n.background}:{},...typeof n.final_text==="string"&&n.final_text.length>0?{finalText:n.final_text}:{},atMs:e}}function an(n){let e;try{e=JSON.parse(n)}catch{return}if(typeof e!=="object"||e===null||Array.isArray(e))return;let t=e,r=l(t.at_ms);if(r===void 0)return;let s={...p(t.session_id)?{sessionId:t.session_id}:{},...p(t.prompt_id)?{promptId:t.prompt_id}:{}};switch(t.event){case"submit":{let o=typeof t.request_id==="string"&&O.test(t.request_id)&&typeof t.source==="string"&&J.test(t.source)?{requestId:t.request_id,source:t.source}:{};return{kind:"submit",submit:{...s,...o,atMs:r}}}case"stop":{let o=fn(t);return o?{kind:"stop",stop:o}:void 0}case"failure":{let o=x(t.error,U),d=x(t.error_details,j);return{kind:"failure",failure:{...s,...o!==void 0?{error:o}:{},...d!==void 0?{errorDetails:d}:{},atMs:r}}}default:return}}function pn(n,e){let t;try{t=E(v(n,e),"utf8")}catch{return[]}let r=[],s=t.lastIndexOf(`
|
|
12
|
+
`);for(let o of t.slice(0,s+1).split(`
|
|
13
|
+
`)){if(o.length===0)continue;let d=an(o);if(d)r.push(d)}return r}function Z(n){try{X(n,{recursive:!0,force:!0})}catch{}}function gn(n,e){for(let t of[M(n,e),h(n,e),A(n,e),v(n,e),k(n,e),q(n,e)])Z(t)}function ln(n){try{return process.kill(n,0),!0}catch(e){return e.code==="EPERM"}}var bn=5000;setTimeout(()=>process.exit(0),bn).unref();async function Sn(){let n=[];for await(let e of process.stdin)n.push(Buffer.from(e));return Buffer.concat(n).toString("utf8")}try{let n=process.env.CLAUDE_PID;if(n!==void 0&&/^\d+$/.test(n)){let e=JSON.parse(await Sn());if(typeof e==="object"&&e!==null&&!Array.isArray(e)){let t=process.env.NATS_STATE_DIR??yn(_n(),".claude","channels","nats"),r=e,s=L(t,n,r);if(s!==void 0){try{C(t,n,r)}catch{}mn(1,`${JSON.stringify({decision:"block",reason:s})}
|
|
14
|
+
`)}else F(t,n,r)}}}catch{}process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synadia-ai/agent-fabric-claude-code",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Claude Code on the Synadia Agent Fabric: the NATS channel plugin for Claude Code with the fabric's tracing and ScratchPad, in one plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|