@volter/teams 0.2.30 → 0.2.31

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/board-owner.mjs +18 -6
  2. package/package.json +1 -1
package/board-owner.mjs CHANGED
@@ -46,6 +46,14 @@ export const BOARD_OPERATION_VERBS = new Set(['serve', 'daemon', 'dispatch', 'in
46
46
  export const CALLER_FACTS = ['SUPERCODE_AGENT_ID', 'SUPERCODE_AUTOMATION', 'SUPERCODE_CONTEXT', 'HERMES_PROFILE', 'USER', 'SUPERCODE_CALLER', 'SUPERCODE_RUN_LAUNCH'];
47
47
  export const callerFacts = (env = process.env) => Object.fromEntries(CALLER_FACTS.filter((key) => env[key]).map((key) => [key, env[key]]));
48
48
 
49
+ /**
50
+ * What a caller says of an answer marked `unanswered` (the owner took the request and the call ended with no answer):
51
+ * the outcome is unknown, and the card is read before the verb is run again. `what` names the verb or tool.
52
+ */
53
+ export function unansweredText(answer, what) {
54
+ return `${String(answer.stderr ?? '').trim() || 'the board owner gave no answer'}; whether ${what} ran is unknown: read the card with \`supercode workflow show <id>\` before running it again\n`;
55
+ }
56
+
49
57
  /**
50
58
  * Send one verb to the owner of the home at `root`: answers `{ code, stdout, stderr }`. A home whose owner is not
51
59
  * running answers that, with what starts it; nothing else runs the verb.
@@ -56,25 +64,29 @@ export function askBoardOwner(root, request) {
56
64
  return new Promise((done) => {
57
65
  let answer = '';
58
66
  let settled = false;
67
+ // once the request is written the owner may have run the verb: a failure after that is `unanswered` (whether it
68
+ // ran is unknown), never a plain failure a caller would take as "nothing happened" and run again
69
+ let sent = false;
59
70
  const finish = (value) => { if (!settled) { settled = true; done(value); } };
71
+ const lost = (stderr) => finish({ code: 1, stdout: '', stderr, ...(sent ? { unanswered: true } : {}) });
60
72
  const socket = connect(path);
61
73
  socket.setEncoding('utf8');
62
74
  // The request is one line, and the connection stays open both ways until the answer's line has come: an answer that
63
75
  // takes its time (a Teams lookup, a reread home) is never lost to a closed side.
64
- socket.on('connect', () => socket.write(`${JSON.stringify({ v: 1, ...request })}\n`));
76
+ socket.on('connect', () => { sent = true; socket.write(`${JSON.stringify({ v: 1, ...request })}\n`); });
65
77
  socket.on('data', (chunk) => {
66
78
  answer += chunk;
67
79
  const end = answer.indexOf('\n');
68
80
  if (end < 0) return;
69
81
  socket.end();
70
- try { finish(JSON.parse(answer.slice(0, end))); } catch { finish({ code: 1, stdout: '', stderr: `the board owner of ${root} answered nothing readable\n` }); }
82
+ try { finish(JSON.parse(answer.slice(0, end))); } catch { lost(`the board owner of ${root} answered nothing readable\n`); }
71
83
  });
72
- socket.on('close', () => finish({ code: 1, stdout: '', stderr: `the board owner of ${root} closed the call before answering\n` }));
84
+ socket.on('close', () => lost(`the board owner of ${root} closed the call before answering\n`));
73
85
  socket.on('error', (error) => {
74
- const down = ['ENOENT', 'ECONNREFUSED'].includes(error.code);
75
- finish({ code: 1, stdout: '', stderr: down
86
+ const down = !sent && ['ENOENT', 'ECONNREFUSED'].includes(error.code);
87
+ lost(down
76
88
  ? `the boards of ${root} have no running owner: \`supercode workflow serve --root ${root}\` is it (an install's keeper runs it)\n`
77
- : `the board owner of ${root} could not be reached: ${error.message}\n` });
89
+ : sent ? `the board owner of ${root} dropped the call after it was sent: ${error.message}\n` : `the board owner of ${root} could not be reached: ${error.message}\n`);
78
90
  });
79
91
  });
80
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.2.30",
3
+ "version": "0.2.31",
4
4
  "type": "module",
5
5
  "description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
6
6
  "license": "MIT",