gcf-board 0.4.1 → 0.6.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 (36) hide show
  1. package/README.md +9 -8
  2. package/dist/server/app.js +259 -25
  3. package/dist/server/chat.js +67 -0
  4. package/dist/server/cli.js +11 -4
  5. package/dist/server/desktop.js +17 -3
  6. package/dist/server/events.js +15 -1
  7. package/dist/server/files.js +8 -4
  8. package/dist/server/mcp.js +28 -0
  9. package/dist/server/moves.js +11 -0
  10. package/dist/server/propose.js +96 -0
  11. package/dist/server/relay.js +50 -0
  12. package/dist/server/runs.js +237 -166
  13. package/dist/server/talks.js +498 -0
  14. package/dist/web/assets/{index-DCkdSzDJ.css → index-BYAEKw51.css} +1 -1
  15. package/dist/web/assets/index-D_F7OEyk.js +36 -0
  16. package/dist/web/index.html +2 -2
  17. package/node_modules/gcf-session/lib/activity.js +371 -0
  18. package/node_modules/gcf-session/lib/adapter/claude.js +226 -0
  19. package/node_modules/gcf-session/lib/adapter/index.js +33 -0
  20. package/node_modules/gcf-session/lib/chat-input.js +260 -0
  21. package/node_modules/gcf-session/lib/chat.js +832 -0
  22. package/node_modules/gcf-session/lib/cli.js +52 -0
  23. package/node_modules/gcf-session/lib/cost.js +29 -0
  24. package/node_modules/gcf-session/lib/index.js +58 -0
  25. package/node_modules/gcf-session/lib/job.js +417 -0
  26. package/node_modules/gcf-session/lib/limit.js +132 -0
  27. package/node_modules/gcf-session/lib/lock.js +81 -0
  28. package/node_modules/gcf-session/lib/proc.js +93 -0
  29. package/node_modules/gcf-session/lib/session.js +320 -0
  30. package/node_modules/gcf-session/lib/store.js +28 -0
  31. package/node_modules/gcf-session/lib/thread.js +423 -0
  32. package/node_modules/gcf-session/lib/windows.js +46 -0
  33. package/node_modules/gcf-session/package.json +23 -0
  34. package/node_modules/gcf-session/types/index.d.ts +152 -0
  35. package/package.json +10 -3
  36. package/dist/web/assets/index-CCeftHBL.js +0 -34
@@ -0,0 +1,28 @@
1
+ // `node mcp.js <moves file>`: the center's MCP server `gcf` (docs/Session-Engine.md AD-12…AD-15),
2
+ // on stdio. A project chat's agent starts it from the MCP config the board writes beside the
3
+ // thread (talks.ts); the moves file holds the domain's moves with `propose`. Each is a tool,
4
+ // `propose_<key>`: it checks the fields and answers, nothing more. The session engine sees the
5
+ // call succeed and writes the `proposal` event; the operator's click makes the move.
6
+ import { readFileSync } from 'node:fs';
7
+ import { McpServer, fromJsonSchema } from '@modelcontextprotocol/server';
8
+ import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
9
+ import { checkProposal, toolOf, toolSchema } from './propose.js';
10
+ const PROPOSED = 'Proposed. The operator sees it as a card in the chat and makes it with one click, or edits ' +
11
+ 'it first. Do not make the move yourself.';
12
+ const moves = JSON.parse(readFileSync(process.argv[2], 'utf8'));
13
+ const server = new McpServer({ name: 'gcf', version: '1.0.0' });
14
+ for (const [key, spec] of Object.entries(moves))
15
+ server.registerTool(toolOf(key), {
16
+ description: `Propose to the operator: ${spec.label}. ${spec.help ?? ''} ` +
17
+ 'The operator decides; nothing changes until they click.',
18
+ inputSchema: fromJsonSchema(toolSchema(spec)),
19
+ }, async (args) => {
20
+ const problems = checkProposal(spec, args);
21
+ return problems.length
22
+ ? {
23
+ isError: true,
24
+ content: [{ type: 'text', text: `Not proposed: ${problems.join('; ')}.` }],
25
+ }
26
+ : { content: [{ type: 'text', text: PROPOSED }] };
27
+ });
28
+ await server.connect(new StdioServerTransport());
@@ -98,6 +98,9 @@ function fieldArgs(f, b) {
98
98
  return tagList(b, f.key, flag);
99
99
  if (f.kind === 'choice')
100
100
  return choice(f, b, flag);
101
+ // Its text goes on stdin (moveInput): the file `-`.
102
+ if (f.stdin)
103
+ return (f.required ? required(b, f.key) : text(b, f.key)) ? [`--${flag}-file=-`] : [];
101
104
  return f.required ? [`--${flag}=${required(b, f.key)}`] : opt(b, f.key, flag);
102
105
  }
103
106
  /** A move by its domain form: its words with the target, then each field that goes. */
@@ -105,6 +108,14 @@ function domainMoveArgs(spec, b) {
105
108
  const words = spec.args.flatMap((w) => w === '{id}' ? [id(b)] : w === '{ids}' ? runIds(b) : [w]);
106
109
  return [...words, ...spec.fields.filter((f) => applies(f, b)).flatMap((f) => fieldArgs(f, b))];
107
110
  }
111
+ /** The text a move's `stdin` field sends on stdin (AD-39), or undefined. */
112
+ export function moveInput(b, moves = {}) {
113
+ const cmd = typeof b.cmd === 'string' ? b.cmd : '';
114
+ if (!Object.hasOwn(moves, cmd))
115
+ return undefined;
116
+ const f = moves[cmd].fields.find((x) => x.stdin && applies(x, b));
117
+ return f ? text(b, f.key) : undefined;
118
+ }
108
119
  /** Whether a move is the center's own: its arguments need no domain. */
109
120
  export const isCenterMove = (cmd) => typeof cmd === 'string' && Object.hasOwn(MOVES, cmd);
110
121
  /**
@@ -0,0 +1,96 @@
1
+ /** The fields of a run an agent does not choose: the operator's run settings. */
2
+ const NOT_PROPOSED = new Set(['model', 'effort']);
3
+ const SLUG = '^[a-z0-9]+(-[a-z0-9]+)*$';
4
+ const TAG = '^[a-z0-9][a-z0-9:-]{0,39}$';
5
+ /** The tool's name for a move. */
6
+ export const toolOf = (key) => `propose_${key.replaceAll('-', '_')}`;
7
+ /** The fields an agent may propose: the form's, without the hidden ones and the run's. */
8
+ export const proposed = (spec) => spec.fields.filter((f) => !f.hidden && !NOT_PROPOSED.has(f.key));
9
+ /** The schema of one field by its kind; every kind has one (`never` holds the switch whole). */
10
+ export function fieldSchema(f) {
11
+ const about = [f.label, f.help].filter(Boolean).join(': ');
12
+ const kind = f.kind;
13
+ let s;
14
+ switch (kind) {
15
+ case 'slug':
16
+ s = { type: 'string', pattern: SLUG };
17
+ break;
18
+ case 'text':
19
+ case 'longtext':
20
+ s = { type: 'string', ...(f.max ? { maxLength: f.max } : {}) };
21
+ break;
22
+ case 'choice':
23
+ // An empty option means "the default": leaving the field out says it.
24
+ s = { type: 'string', enum: (f.options ?? []).map((o) => o.value).filter(Boolean) };
25
+ break;
26
+ case 'list':
27
+ s = { type: 'array', items: { type: 'string' } };
28
+ break;
29
+ case 'ids':
30
+ s = { type: 'array', items: { type: 'string', pattern: SLUG } };
31
+ break;
32
+ case 'tags':
33
+ s = { type: 'array', items: { type: 'string', pattern: TAG } };
34
+ break;
35
+ case 'remove':
36
+ s = { type: 'boolean' };
37
+ break;
38
+ case 'rank':
39
+ s = { type: 'integer', minimum: 1 };
40
+ break;
41
+ default: {
42
+ const none = kind;
43
+ throw new Error(`no schema for a field of kind ${String(none)}`);
44
+ }
45
+ }
46
+ const choices = (f.options ?? []).filter((o) => o.value && o.help);
47
+ const helps = choices.length
48
+ ? ` (${choices.map((o) => `${o.value}: ${o.help}`).join('; ')})`
49
+ : '';
50
+ const when = f.when ? ` Only when ${f.when.key} is ${f.when.is.join(' or ')}.` : '';
51
+ return { ...s, description: `${about}${helps}.${when}` };
52
+ }
53
+ /** A move's tool input schema: an object of its proposed fields, nothing else. */
54
+ export function toolSchema(spec) {
55
+ const fields = proposed(spec);
56
+ return {
57
+ type: 'object',
58
+ properties: Object.fromEntries(fields.map((f) => [f.key, fieldSchema(f)])),
59
+ required: fields.filter((f) => f.required && !f.when).map((f) => f.key),
60
+ additionalProperties: false,
61
+ };
62
+ }
63
+ const given = (v) => v !== undefined && v !== null && v !== '';
64
+ /**
65
+ * The problems of a proposal the schema cannot see (AD-36), each a sentence for the agent: a
66
+ * field it may not fill, one that goes only with another's value, one that value requires.
67
+ * The defaults count as given. Empty when it holds.
68
+ */
69
+ export function checkProposal(spec, args) {
70
+ const fields = new Map(spec.fields.map((f) => [f.key, f]));
71
+ const values = Object.fromEntries(spec.fields.filter((f) => f.default !== undefined).map((f) => [f.key, f.default]));
72
+ const problems = [];
73
+ for (const [key, v] of Object.entries(args)) {
74
+ const f = fields.get(key);
75
+ if (!f)
76
+ problems.push(`${key} is not a field of this move`);
77
+ else if (f.hidden || NOT_PROPOSED.has(key))
78
+ problems.push(`${key} is the operator's to set, not proposed`);
79
+ else if (given(v))
80
+ values[key] = v;
81
+ }
82
+ for (const f of proposed(spec)) {
83
+ if (!f.when)
84
+ continue;
85
+ const holds = f.when.is.includes(String(values[f.when.key] ?? ''));
86
+ const is = `${f.when.key} ${f.when.is.join(' or ')}`;
87
+ if (!holds && given(args[f.key]))
88
+ problems.push(`${f.key} goes only with ${is}`);
89
+ if (holds && f.required && !given(values[f.key]))
90
+ problems.push(`${f.key} is required for ${is}`);
91
+ }
92
+ for (const f of proposed(spec))
93
+ if (typeof args[f.key] === 'string' && f.max && args[f.key].length > f.max)
94
+ problems.push(`${f.key} is up to ${f.max} characters`);
95
+ return problems;
96
+ }
@@ -0,0 +1,50 @@
1
+ // `node relay.js <record> <end file> <ai-factory entry> <harness> run <ids> --json …`: the process
2
+ // a board run lives in (runs.ts). The board starts it detached, so the run outlives the board
3
+ // (Ctrl+C in its console, its window closed, a restart); it starts the harness with
4
+ // `windowsHide`, so the harness and all it starts share one hidden console: a detached process
5
+ // has none, and each console program it started would open a window of its own. The harness's
6
+ // code, stdout and stderr go to the end file once, whole, when it ends. While it runs, the relay
7
+ // touches the record: a board started again tells it from a dead relay whose pid another took.
8
+ import { spawn } from 'node:child_process';
9
+ import { rmSync, utimesSync, writeFileSync } from 'node:fs';
10
+ import { writeAtomic } from './atomic.js';
11
+ // A board that finds the run at its start counts the relay dead after three missed beats
12
+ // (BEAT_STALE_MS in runs.ts).
13
+ const BEAT_MS = 30_000;
14
+ const [record, end, ...args] = process.argv.slice(2);
15
+ const beat = setInterval(() => {
16
+ try {
17
+ const now = new Date();
18
+ utimesSync(record, now, now);
19
+ }
20
+ catch {
21
+ // Its write failed, or a board took it already: nothing to touch.
22
+ }
23
+ }, BEAT_MS);
24
+ beat.unref();
25
+ const child = spawn(process.execPath, args, {
26
+ stdio: ['ignore', 'pipe', 'pipe'],
27
+ windowsHide: true,
28
+ });
29
+ child.stdout.setEncoding('utf8');
30
+ child.stderr.setEncoding('utf8');
31
+ let out = '';
32
+ let err = '';
33
+ child.stdout.on('data', (d) => (out += d));
34
+ child.stderr.on('data', (d) => (err += d));
35
+ let done = false;
36
+ const finish = (code, message = '') => {
37
+ // A spawn that fails fires both error and close: one end only.
38
+ if (done)
39
+ return;
40
+ done = true;
41
+ const text = JSON.stringify({ code, out, err: err + message });
42
+ // A rename a scanner holds up: the end still goes, written in place.
43
+ writeAtomic(end, text).catch(() => {
44
+ writeFileSync(end, text);
45
+ // writeAtomic's own temporary file, left by the rename that failed.
46
+ rmSync(`${end}.${process.pid}.tmp`, { force: true });
47
+ });
48
+ };
49
+ child.on('error', (e) => finish(null, e.message));
50
+ child.on('close', (code) => finish(code));