@netnodeag/kraftwerk 0.11.0 → 0.12.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.
@@ -25,6 +25,7 @@ async function loadState(id) {
25
25
  busy: false,
26
26
  pendingPermissions: new Map(),
27
27
  writeChain: Promise.resolve(),
28
+ needsContext: true,
28
29
  };
29
30
  // Two racing loads: keep whichever registered first.
30
31
  return states.get(id) ?? (states.set(id, state), state);
@@ -211,15 +212,25 @@ async function baseScopeContext(scope, agent) {
211
212
  }
212
213
  return "";
213
214
  }
215
+ /**
216
+ * Every chat renders in the inspector UI, so agents should know two things:
217
+ * replies are markdown, and run artifacts are addressable over the
218
+ * inspector's own file endpoint (relative URLs keep working wherever the
219
+ * inspector is reachable — localhost, LAN, tunnel).
220
+ */
221
+ const RENDERING_BLOCK = `## Chat rendering\n` +
222
+ `Your replies render as markdown in the inspector chat: headings, lists, tables, code blocks, ` +
223
+ `links and images all work. Files inside a workflow run's output folder are served by the ` +
224
+ `inspector itself at /api/runs/<run-id>/file?name=<relative-path>&raw=1 — embed an image inline ` +
225
+ `with ![alt](/api/runs/<run-id>/file?name=picture.png&raw=1), or link any artifact the same way. ` +
226
+ `Prefer these relative /api/... URLs over file paths when showing results: they render directly ` +
227
+ `in this chat and keep working wherever the inspector is reachable.`;
214
228
  async function scopeContext(scope, agent) {
215
229
  const [base, skills] = await Promise.all([
216
230
  baseScopeContext(scope, agent),
217
231
  availableSkills(scope),
218
232
  ]);
219
- const block = skillsBlock(skills);
220
- if (!block)
221
- return base;
222
- return base ? `${base}\n\n${block}` : block;
233
+ return [base, RENDERING_BLOCK, skillsBlock(skills)].filter(Boolean).join("\n\n");
223
234
  }
224
235
  /* ---------- backend lifecycle ---------- */
225
236
  /** Team chats carry the member's model/effort; resolved live so edits apply to new backends. */
@@ -280,6 +291,9 @@ async function ensureBackend(state) {
280
291
  agent === "pi"
281
292
  ? startPiBackend(cwd, hooks, tuning)
282
293
  : await startAcpBackend(agent, cwd, hooks, tuning);
294
+ // Fresh process = fresh context window: re-send scope context with the
295
+ // next prompt (matters for chats resumed after an inspector restart).
296
+ state.needsContext = true;
283
297
  return state.backend;
284
298
  }
285
299
  /* ---------- public API (used by server.ts) ---------- */
@@ -304,6 +318,7 @@ export async function createChat(opts) {
304
318
  busy: false,
305
319
  pendingPermissions: new Map(),
306
320
  writeChain: Promise.resolve(),
321
+ needsContext: true,
307
322
  });
308
323
  return meta;
309
324
  }
@@ -338,7 +353,10 @@ export async function postMessage(id, text) {
338
353
  void (async () => {
339
354
  try {
340
355
  const backend = await ensureBackend(state);
341
- const context = isFirst ? await scopeContext(state.meta.scope, state.meta.agent) : "";
356
+ const context = state.needsContext
357
+ ? await scopeContext(state.meta.scope, state.meta.agent)
358
+ : "";
359
+ state.needsContext = false;
342
360
  // "/<skill> args" expands to the skill's instructions for the agent;
343
361
  // the thread keeps the short form the user typed.
344
362
  const body = await expandSkillInvocation(state.meta.scope, text);