lampson 0.5.1 → 0.5.2

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/README.md CHANGED
@@ -117,6 +117,8 @@ import { Lampson } from "lampson"; // also: pip install lampson
117
117
  const lampson = new Lampson({ local: { workspace: "./my-project" } }); // or { url, key } for a running Lampson
118
118
  const r = await lampson.ask({ agent: "shop", thread: "customer-42", text: "do you have whole-wheat bread?" });
119
119
 
120
+ // tools are the AI SDK shape: zod 4, zod 3 (objects, strings, numbers, enums, arrays, optional… — for the rest add
121
+ // zod-to-json-schema) or a plain JSON Schema
120
122
  // an agent for your customers: only the tools you give it — no bash, read, write or fetch of Lampson's own
121
123
  const shop = new Lampson({ agent: "shop", local: { workspace: "./my-project", lampsonTools: false } });
122
124
  shop.tool("stock", { description: "Units in stock", inputSchema: z.object({ product: z.string() }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lampson",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "A coding agent written in Synsema: terminal + web, tools confined to the mounted project, plugins (your own tools, any language), LSP, MCP, sub-agents. Also an SDK: import { Lampson } from \"lampson\" (server or local mode).",
5
5
  "license": "MIT",
6
6
  "repository": {
package/sdk/index.d.ts CHANGED
@@ -40,7 +40,7 @@ export interface LocalOptions {
40
40
  export interface CommonOptions {
41
41
  /** The agent that answers when a message does not say `agent`. Without it: the workspace default ("build"). */
42
42
  agent?: string;
43
- /** Local mode: called once per tool an agent lists but will not have (plugin off, typo). Default console.warn; null = silent. */
43
+ /** Local mode: called once per tool an agent lists but will not have (plugin off, typo). Default console.warn, each distinct message once per process; null = silent. */
44
44
  onWarning?: ((message: string) => void) | null;
45
45
  }
46
46
 
package/sdk/index.js CHANGED
@@ -13,7 +13,7 @@
13
13
  // the same conversation (agent + thread) are answered in order. `home` and `workspace` resolve against
14
14
  // process.cwd().
15
15
  // An agent that lists a tool it will not have (typo, plugin off) is reported through onWarning
16
- // (default console.warn) and in lampson.warnings.
16
+ // (default console.warn, each message once per process) and in lampson.warnings.
17
17
  // `lampsonTools: false` → no tool of Lampson's own exists in that process (bash, read, write, fetch…),
18
18
  // not even for the built-in agents: your agents get only the tools you give them.
19
19
  // A .syn tool runs only once approved (`lampson tools approve`, its sha256); `approveTools: true`
@@ -139,8 +139,38 @@ class HttpTransport {
139
139
  const TOOL_NAME = /^[a-z][a-z0-9_]{0,39}$/;
140
140
  const TAKEN = ['read', 'write', 'edit', 'ls', 'find', 'grep', 'lsp', 'fetch', 'bash', 'process', 'memory', 'todo', 'skill', 'mcp', 'plugin', 'schedule', 'computer_use', 'delegate', 'send', 'board', 'objective'];
141
141
 
142
- // a JSON Schema from what the AI SDK world passes: jsonSchema(...) wrappers, zod (v4: z.toJSONSchema, v3 needs
143
- // zod-to-json-schema in the app) or a plain JSON Schema object
142
+ // zod 3 has no toJSONSchema: the common shapes from its _def (typeName), without adding zod-to-json-schema. Anything
143
+ // else (unions, records, refinements…) → null, and the caller says how to fix it
144
+ function zod3Schema(s) {
145
+ const d = s && s._def;
146
+ if (!d || typeof d.typeName !== 'string') return null;
147
+ const desc = x => (d.description ? Object.assign(x, { description: d.description }) : x);
148
+ switch (d.typeName) {
149
+ case 'ZodString': return desc({ type: 'string' });
150
+ case 'ZodNumber': return desc({ type: (d.checks || []).some(c => c.kind === 'int') ? 'integer' : 'number' });
151
+ case 'ZodBoolean': return desc({ type: 'boolean' });
152
+ case 'ZodEnum': return desc({ type: 'string', enum: d.values });
153
+ case 'ZodArray': { const it = zod3Schema(d.type); return it && desc({ type: 'array', items: it }); }
154
+ case 'ZodNullable': { const it = zod3Schema(d.innerType); return it && desc({ anyOf: [it, { type: 'null' }] }); }
155
+ case 'ZodOptional': case 'ZodDefault': { const it = zod3Schema(d.innerType); return it && (d.description ? desc(it) : it); }
156
+ case 'ZodObject': {
157
+ const shape = typeof d.shape === 'function' ? d.shape() : d.shape;
158
+ const properties = {}, required = [];
159
+ for (const [k, v] of Object.entries(shape || {})) {
160
+ const it = zod3Schema(v);
161
+ if (!it) return null;
162
+ properties[k] = it;
163
+ const t = v._def.typeName;
164
+ if (t !== 'ZodOptional' && t !== 'ZodDefault') required.push(k);
165
+ }
166
+ return desc(Object.assign({ type: 'object', properties }, required.length ? { required } : {}));
167
+ }
168
+ default: return null;
169
+ }
170
+ }
171
+
172
+ // a JSON Schema from what the AI SDK world passes: jsonSchema(...) wrappers, zod (v4: z.toJSONSchema; v3: its
173
+ // zod-to-json-schema if the app has it, else zod3Schema) or a plain JSON Schema object
144
174
  function toJsonSchema(s, name) {
145
175
  if (s == null) return { type: 'object', properties: {} };
146
176
  if (s.jsonSchema && typeof s.jsonSchema === 'object') return s.jsonSchema;
@@ -150,7 +180,9 @@ function toJsonSchema(s, name) {
150
180
  const req = createRequire(path.join(process.cwd(), 'noop.js'));
151
181
  try { const z = req('zod'); if (typeof z.toJSONSchema === 'function') return z.toJSONSchema(s); } catch {}
152
182
  try { return req('zod-to-json-schema').zodToJsonSchema(s); } catch {}
153
- throw new TypeError('tool ' + name + ': cannot turn this zod schema into JSON Schema (zod 4 has z.toJSONSchema; with zod 3 install zod-to-json-schema), or pass `parameters` as a JSON Schema');
183
+ const own = zod3Schema(s);
184
+ if (own) return own;
185
+ throw new TypeError('tool ' + name + ': cannot turn this zod schema into JSON Schema (zod 3 here covers object, string, number, boolean, enum, array, optional, nullable and describe; for the rest use zod 4, or install zod-to-json-schema), or pass `parameters` as a JSON Schema');
154
186
  }
155
187
  if (typeof s === 'object') return s;
156
188
  throw new TypeError('tool ' + name + ': inputSchema/parameters must be a zod schema or a JSON Schema object');
@@ -222,7 +254,8 @@ async function readNodeBody(req) {
222
254
  function killTree(child) {
223
255
  try {
224
256
  if (process.platform === 'win32') spawn('taskkill', ['/PID', String(child.pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true });
225
- else child.kill('SIGKILL');
257
+ // Linux/Mac: the child leads its own process group (spawn detached), so -pid reaches the launcher, npx and synsema
258
+ else { try { process.kill(-child.pid, 'SIGKILL'); } catch { child.kill('SIGKILL'); } }
226
259
  } catch {}
227
260
  }
228
261
 
@@ -256,7 +289,8 @@ class LocalTransport {
256
289
  this.warnings = [];
257
290
  this.onWarning = onWarning;
258
291
  this.tools = new Map(); // name → { wire, schema, execute }
259
- this.child = spawn(command, args, { cwd, env: childEnv, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true });
292
+ // detached on Linux/Mac = its own process group, for killTree (on Windows it would open a console; taskkill /T there)
293
+ this.child = spawn(command, args, { cwd, env: childEnv, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, detached: process.platform !== 'win32' });
260
294
  this.pending = new Map(); // id → { onEvent, done }
261
295
  this.seq = 0;
262
296
  this.stderr = [];
@@ -366,14 +400,23 @@ class LocalTransport {
366
400
  }
367
401
  }
368
402
 
403
+ // the default onWarning: each distinct message once per process (ready lists them, and every new Lampson, or a
404
+ // restarted one, would print them again). The stream's `warning` events are data for the app and do not change
405
+ const shownWarnings = new Set();
406
+ function defaultWarning(w) {
407
+ if (shownWarnings.has(w)) return;
408
+ shownWarnings.add(w);
409
+ console.warn('lampson: ' + w);
410
+ }
411
+
369
412
  class Lampson {
370
413
  /**
371
414
  * @param {object} opts { url, key, toolsUrl?, toolsSecret? } for server mode, or
372
415
  * { local: { workspace, home?, env?, lampsonTools?, tools?, spawn? } };
373
- * agent? — the default agent; onWarning?(message) — default console.warn
416
+ * agent? — the default agent; onWarning?(message) — default console.warn, each message once per process
374
417
  */
375
418
  constructor(opts = {}) {
376
- const onWarning = opts.onWarning === undefined ? (w => console.warn('lampson: ' + w)) : opts.onWarning;
419
+ const onWarning = opts.onWarning === undefined ? defaultWarning : opts.onWarning;
377
420
  this.transport = opts.local ? new LocalTransport(opts.local, onWarning) : new HttpTransport(opts);
378
421
  this.mode = opts.local ? 'local' : 'server';
379
422
  this.agent = opts.agent || '';