@tini-works/inv-node 0.1.5 → 0.1.7

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 (2) hide show
  1. package/dist/cli.js +44 -5
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env bun
1
2
  // @bun
2
3
  // src/cli.ts
3
4
  import * as readline from "readline";
@@ -1254,11 +1255,15 @@ class WSHandlers {
1254
1255
  engine;
1255
1256
  store;
1256
1257
  eventBus;
1258
+ sendFn = null;
1257
1259
  constructor(engine, store, eventBus) {
1258
1260
  this.engine = engine;
1259
1261
  this.store = store;
1260
1262
  this.eventBus = eventBus;
1261
1263
  }
1264
+ setSendFn(fn) {
1265
+ this.sendFn = fn;
1266
+ }
1262
1267
  handle(envelope) {
1263
1268
  const { payload } = envelope;
1264
1269
  switch (payload.type) {
@@ -1269,7 +1274,7 @@ class WSHandlers {
1269
1274
  this.handleSweep(payload);
1270
1275
  break;
1271
1276
  case "trace_resolve_request":
1272
- this.handleTraceResolveRequest(payload);
1277
+ this.handleTraceResolveRequest(envelope, payload);
1273
1278
  break;
1274
1279
  case "query_ask":
1275
1280
  this.handleQueryAsk(envelope, payload);
@@ -1293,7 +1298,10 @@ class WSHandlers {
1293
1298
  case "error":
1294
1299
  break;
1295
1300
  }
1296
- this.eventBus.emit(payload.type, payload);
1301
+ this.eventBus.emit(payload.type, {
1302
+ ...payload,
1303
+ fromNode: envelope.fromNode
1304
+ });
1297
1305
  }
1298
1306
  handleSignalChange(payload) {
1299
1307
  try {
@@ -1319,16 +1327,20 @@ class WSHandlers {
1319
1327
  });
1320
1328
  }
1321
1329
  }
1322
- handleTraceResolveRequest(payload) {
1330
+ handleTraceResolveRequest(envelope, payload) {
1323
1331
  try {
1324
1332
  const item = this.engine.getItem(payload.itemId);
1325
- this.eventBus.emit("trace_resolve_response", {
1333
+ const response = {
1326
1334
  type: "trace_resolve_response",
1327
1335
  itemId: item.id,
1328
1336
  title: item.title,
1329
1337
  kind: item.kind,
1330
1338
  state: item.state
1331
- });
1339
+ };
1340
+ this.eventBus.emit("trace_resolve_response", response);
1341
+ if (this.sendFn) {
1342
+ this.sendFn(envelope.fromNode, response);
1343
+ }
1332
1344
  } catch (err) {
1333
1345
  const message = err instanceof Error ? err.message : String(err);
1334
1346
  this.eventBus.emit("error", {
@@ -1345,6 +1357,22 @@ class WSHandlers {
1345
1357
  askerNode: envelope.fromNode,
1346
1358
  question: payload.question
1347
1359
  });
1360
+ if (this.sendFn) {
1361
+ const nodes = this.store.listNodes(envelope.projectId);
1362
+ const allItems = nodes.flatMap((n) => this.store.listItems(n.id));
1363
+ const summary = allItems.map((i) => ({
1364
+ id: i.id,
1365
+ kind: i.kind,
1366
+ title: i.title,
1367
+ state: i.state,
1368
+ externalRef: i.externalRef || undefined
1369
+ }));
1370
+ this.sendFn(envelope.fromNode, {
1371
+ type: "query_respond",
1372
+ answer: JSON.stringify({ items: summary, count: summary.length }),
1373
+ responderId: payload.askerId
1374
+ });
1375
+ }
1348
1376
  } catch (err) {
1349
1377
  const message = err instanceof Error ? err.message : String(err);
1350
1378
  this.eventBus.emit("error", {
@@ -1948,6 +1976,11 @@ async function startChannelServer(configPath) {
1948
1976
  wsClient.onMessage((envelope) => {
1949
1977
  wsHandlers.handle(envelope);
1950
1978
  });
1979
+ wsHandlers.setSendFn((toNode, payload) => {
1980
+ if (wsClient?.connected) {
1981
+ wsClient.sendMessage(toNode, payload);
1982
+ }
1983
+ });
1951
1984
  try {
1952
1985
  await wsClient.connect();
1953
1986
  } catch {
@@ -2001,6 +2034,7 @@ Use the inv_* tools to manage inventory, propose changes, vote, challenge items,
2001
2034
  "checklist_update",
2002
2035
  "error"
2003
2036
  ];
2037
+ const log = new Logger("channel-bridge");
2004
2038
  for (const eventType of channelEvents) {
2005
2039
  eventBus.on(eventType, (data) => {
2006
2040
  mcp.notification({
@@ -2009,6 +2043,11 @@ Use the inv_* tools to manage inventory, propose changes, vote, challenge items,
2009
2043
  content: JSON.stringify(data),
2010
2044
  meta: { source: "inventory", eventType }
2011
2045
  }
2046
+ }).catch((err) => {
2047
+ log.error("Failed to send channel notification", {
2048
+ eventType,
2049
+ error: err instanceof Error ? err.message : String(err)
2050
+ });
2012
2051
  });
2013
2052
  });
2014
2053
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tini-works/inv-node",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "bin": {
5
5
  "inv-node": "./dist/cli.js"
6
6
  },
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "build": "bun build src/index.ts --target=bun --outdir=dist --entry-naming=cli.js --external=@modelcontextprotocol/sdk"
11
+ "build": "bun build src/index.ts --target=bun --outdir=dist --entry-naming=cli.js --external=@modelcontextprotocol/sdk && echo '#!/usr/bin/env bun' | cat - dist/cli.js > dist/cli.tmp && mv dist/cli.tmp dist/cli.js && chmod +x dist/cli.js"
12
12
  },
13
13
  "dependencies": {
14
14
  "@modelcontextprotocol/sdk": "^1.28.0"