@netnodeag/kraftwerk 0.86.0 → 0.88.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 (45) hide show
  1. package/README.md +35 -8
  2. package/dist/cli/kraftwerk.js +1 -1
  3. package/dist/cli/routines.d.ts +4 -2
  4. package/dist/cli/routines.js +30 -13
  5. package/dist/client/routes.d.ts +5 -0
  6. package/dist/client/routes.js +5 -0
  7. package/dist/core/agent-status.js +4 -3
  8. package/dist/core/attention.js +8 -4
  9. package/dist/core/boards.d.ts +10 -0
  10. package/dist/core/boards.js +13 -0
  11. package/dist/core/chat/context.js +12 -11
  12. package/dist/core/chat/sessions.js +2 -2
  13. package/dist/core/chat/state.d.ts +1 -1
  14. package/dist/core/chat/state.js +4 -4
  15. package/dist/core/chat/types.d.ts +6 -2
  16. package/dist/core/diagnose.js +13 -5
  17. package/dist/core/routines.d.ts +37 -11
  18. package/dist/core/routines.js +79 -27
  19. package/dist/core/skills.d.ts +2 -0
  20. package/dist/core/skills.js +2 -0
  21. package/dist/server/api/agents.d.ts +1 -0
  22. package/dist/server/api/agents.js +9 -7
  23. package/dist/server/api/boards.d.ts +3 -1
  24. package/dist/server/api/boards.js +4 -1
  25. package/dist/server/api/index.d.ts +23 -11
  26. package/dist/server/api/runs.d.ts +19 -10
  27. package/dist/server/api/runs.js +45 -2
  28. package/package.json +1 -1
  29. package/web/dist/assets/{dist-DaClI4_P.js → dist-B0kpimQd.js} +1 -1
  30. package/web/dist/assets/dist-B4JfCAqZ.js +1 -0
  31. package/web/dist/assets/{dist-ciCcv6TG.js → dist-B6J2XiOw.js} +1 -1
  32. package/web/dist/assets/{dist-1mbdSunG.js → dist-BJ7cArEV.js} +1 -1
  33. package/web/dist/assets/{dist-CPeXTjYj.js → dist-BbJD-deH.js} +1 -1
  34. package/web/dist/assets/{dist-D4JsX0B8.js → dist-BebxUYjL.js} +1 -1
  35. package/web/dist/assets/{dist-60Qxhb1I.js → dist-BmEO2riK.js} +1 -1
  36. package/web/dist/assets/{dist-CYuFWOhW.js → dist-CTlewW8J.js} +1 -1
  37. package/web/dist/assets/{dist-CVzVQqDH.js → dist-Ce7w7gso.js} +1 -1
  38. package/web/dist/assets/{dist-BRwu-xz3.js → dist-DNqCNe5Z.js} +1 -1
  39. package/web/dist/assets/{dist-BmpFCYFq.js → dist-DuNyZ7cE.js} +1 -1
  40. package/web/dist/assets/{editor-CXOAhwnW.js → editor-D7Y97r7h.js} +3 -3
  41. package/web/dist/assets/{index-BpESoZpK.js → index-BGKyxvvZ.js} +15 -15
  42. package/web/dist/assets/index-DBkbrkOH.css +2 -0
  43. package/web/dist/index.html +2 -2
  44. package/web/dist/assets/dist-B89nfy4o.js +0 -1
  45. package/web/dist/assets/index-DEO_Q944.css +0 -2
@@ -3,11 +3,15 @@ import path from "node:path";
3
3
  import { parse, stringify } from "yaml";
4
4
  import { getOutputDir, workspaceRoot } from "./context.js";
5
5
  import { perWorkspace } from "./workspace.js";
6
+ import { changed } from "./changes.js";
6
7
  import { getAgent, listAgents, safeAgentSlug, agentsRoot } from "./agents.js";
8
+ import { getProject } from "./projects.js";
7
9
  import { chatAwaitingApproval, createChat, postMessage } from "./chat/sessions.js";
8
10
  import { pushNotification } from "./notifications.js";
9
11
  import { isIdentityString, localIdentity, readIdentity, identityString } from "./identity.js";
10
12
  import { gitCommit, repoRootFor } from "./git.js";
13
+ /** The owner of the workspace's routines (agents/routines.yml): never a valid agent slug. */
14
+ export const WORKSPACE_ROUTINES = "_";
11
15
  /* ---------- cron ---------- */
12
16
  const ALIASES = {
13
17
  "@hourly": "0 * * * *",
@@ -89,8 +93,10 @@ export function nextRun(schedule, from = new Date()) {
89
93
  return undefined;
90
94
  }
91
95
  /* ---------- definition CRUD (agents/<slug>/routines.yml) ---------- */
92
- async function routinesFile(slug) {
93
- return path.join(await agentsRoot(), safeAgentSlug(slug), "routines.yml");
96
+ async function routinesFile(owner) {
97
+ if (owner === WORKSPACE_ROUTINES)
98
+ return path.join(await agentsRoot(), "routines.yml");
99
+ return path.join(await agentsRoot(), safeAgentSlug(owner), "routines.yml");
94
100
  }
95
101
  function normalizeRoutine(raw) {
96
102
  const id = String(raw.id ?? "").trim();
@@ -104,6 +110,8 @@ function normalizeRoutine(raw) {
104
110
  enabled: raw.enabled !== false,
105
111
  ...(typeof raw.runs_on === "string" && raw.runs_on.trim() ? { runsOn: raw.runs_on.trim() } : {}),
106
112
  ...(typeof raw.private === "boolean" ? { private: raw.private } : {}),
113
+ ...(typeof raw.project === "string" && raw.project.trim() ? { project: raw.project.trim() } : {}),
114
+ ...(typeof raw.agent === "string" && raw.agent.trim() ? { agent: raw.agent.trim() } : {}),
107
115
  };
108
116
  }
109
117
  /** The file's own spelling: snake_case `runs_on`, optional keys only when set. */
@@ -116,28 +124,37 @@ function serializeRoutine(r) {
116
124
  enabled: r.enabled,
117
125
  ...(r.runsOn ? { runs_on: r.runsOn } : {}),
118
126
  ...(r.private !== undefined ? { private: r.private } : {}),
127
+ ...(r.project ? { project: r.project } : {}),
128
+ ...(r.agent ? { agent: r.agent } : {}),
119
129
  };
120
130
  }
121
131
  /** Why a runs_on value is refused, or undefined. */
122
132
  function runsOnError(value) {
123
133
  return isIdentityString(value) ? undefined : `runs_on must be <handle>@<machine> (lowercase letters, digits, ".", "_", "-"), got "${value}"`;
124
134
  }
125
- export async function listRoutines(slug) {
135
+ export async function listRoutines(owner) {
126
136
  let raw;
127
137
  try {
128
- raw = parse(await fs.readFile(await routinesFile(slug), "utf8"));
138
+ raw = parse(await fs.readFile(await routinesFile(owner), "utf8"));
129
139
  }
130
140
  catch {
131
141
  return [];
132
142
  }
133
143
  if (!Array.isArray(raw))
134
144
  return [];
135
- return raw
136
- .map((r) => normalizeRoutine((r ?? {})))
137
- .filter(Boolean);
145
+ const all = raw.map((r) => normalizeRoutine((r ?? {}))).filter(Boolean);
146
+ // An agent's own routine is that agent's: an `agent` key in its file means nothing.
147
+ return owner === WORKSPACE_ROUTINES ? all : all.map(({ agent: _ignored, ...r }) => r);
148
+ }
149
+ /** Every place routines are defined: the agents (archived ones too — the scheduler fires theirs), then the workspace. */
150
+ async function routineOwners() {
151
+ return [...(await listAgents()).map((a) => a.slug), WORKSPACE_ROUTINES];
138
152
  }
139
153
  async function writeRoutines(slug, routines) {
140
- await fs.writeFile(await routinesFile(slug), stringify(routines.map(serializeRoutine)));
154
+ const file = await routinesFile(slug);
155
+ await fs.mkdir(path.dirname(file), { recursive: true });
156
+ await fs.writeFile(file, stringify(routines.map(serializeRoutine)));
157
+ changed();
141
158
  }
142
159
  export async function saveRoutine(slug, input) {
143
160
  const name = input.name?.trim();
@@ -165,6 +182,14 @@ export async function saveRoutine(slug, input) {
165
182
  const existing = i >= 0 ? routines[i] : undefined;
166
183
  const runsOn = given === undefined ? (existing ? existing.runsOn : await localIdentity()) : given || undefined;
167
184
  const priv = input.private ?? existing?.private;
185
+ // Who and where: an unknown project or agent is refused here, not at 9 the next morning.
186
+ const pick = (v, kept) => (v === undefined ? kept : v?.trim() || undefined);
187
+ const project = pick(input.project, existing?.project);
188
+ if (project && project !== existing?.project && !(await getProject(project)))
189
+ throw new Error(`project "${project}" not found`);
190
+ const agent = slug === WORKSPACE_ROUTINES ? pick(input.agent, existing?.agent) : undefined;
191
+ if (agent && agent !== existing?.agent && !(await getAgent(agent).catch(() => null)))
192
+ throw new Error(`agent "${agent}" not found`);
168
193
  const routine = {
169
194
  id,
170
195
  name,
@@ -173,6 +198,8 @@ export async function saveRoutine(slug, input) {
173
198
  enabled: input.enabled !== false,
174
199
  ...(runsOn ? { runsOn } : {}),
175
200
  ...(priv !== undefined ? { private: priv } : {}),
201
+ ...(project ? { project } : {}),
202
+ ...(agent ? { agent } : {}),
176
203
  };
177
204
  if (i >= 0)
178
205
  routines[i] = routine;
@@ -197,6 +224,7 @@ async function readState() {
197
224
  async function writeState(state) {
198
225
  await fs.mkdir(getOutputDir(), { recursive: true });
199
226
  await fs.writeFile(stateFile(), JSON.stringify(state, null, 2));
227
+ changed();
200
228
  }
201
229
  /**
202
230
  * Whether a routine's prompt names a workflow: its slug or its name as a whole word
@@ -212,13 +240,19 @@ export function mentionsWorkflow(prompt, w) {
212
240
  return new RegExp(`(^|[^a-z0-9_-])${esc}($|[^a-z0-9_-])`).test(text);
213
241
  });
214
242
  }
215
- /** Every agent's routines with their run state, each with the workflows its prompt names (GET /api/routines). */
243
+ /** Every routine — the agents' and the workspace's — with its run state and the workflows its prompt names (GET /api/routines). */
216
244
  export async function allRoutines(workflows) {
217
245
  const agents = (await listAgents()).filter((a) => !a.archived);
218
- const per = await Promise.all(agents.map(async (a) => (await routineStatuses(a.slug).catch(() => [])).map((r) => ({
246
+ const face = (slug) => {
247
+ const a = agents.find((x) => x.slug === slug);
248
+ return a ? { agent: { slug: a.slug, name: a.name, emoji: a.emoji } } : {};
249
+ };
250
+ const names = (prompt) => workflows.filter((w) => mentionsWorkflow(prompt, w)).map((w) => w.slug);
251
+ const per = await Promise.all([...agents.map((a) => a.slug), WORKSPACE_ROUTINES].map(async (owner) => (await routineStatuses(owner).catch(() => [])).map(({ agent, ...r }) => ({
219
252
  ...r,
220
- agent: { slug: a.slug, name: a.name, emoji: a.emoji },
221
- workflows: workflows.filter((w) => mentionsWorkflow(r.prompt, w)).map((w) => w.slug),
253
+ owner,
254
+ ...face(owner === WORKSPACE_ROUTINES ? agent : owner),
255
+ workflows: names(r.prompt),
222
256
  }))));
223
257
  return per.flat();
224
258
  }
@@ -243,14 +277,30 @@ export async function routineStatuses(slug) {
243
277
  });
244
278
  }
245
279
  /* ---------- firing ---------- */
246
- /** Open a fresh session for the agent and post the routine's prompt. */
247
- async function fireRoutine(slug, routine) {
248
- const def = await getAgent(slug);
249
- if (!def)
250
- throw new Error(`agent "${slug}" not found`);
280
+ /**
281
+ * Where a routine's run happens: the agent's own session (filed under the
282
+ * project when it names one), else the project's assistant, else Ralv.
283
+ */
284
+ async function routineTarget(owner, routine) {
285
+ const project = routine.project ? await getProject(routine.project) : null;
286
+ if (routine.project && !project)
287
+ throw new Error(`project "${routine.project}" not found`);
288
+ const slug = owner === WORKSPACE_ROUTINES ? routine.agent : owner;
289
+ if (slug) {
290
+ const def = await getAgent(slug).catch(() => null);
291
+ if (!def)
292
+ throw new Error(`agent "${slug}" not found`);
293
+ return { agent: def.harness, scope: { kind: "agent", slug: def.slug, routine: routine.id }, ...(project ? { project: project.slug } : {}) };
294
+ }
295
+ if (project)
296
+ return { agent: project.harness, scope: { kind: "project", slug: project.slug, routine: routine.id } };
297
+ return { agent: "claude", scope: { kind: "kraftwerk", routine: routine.id } };
298
+ }
299
+ /** Open a fresh session where the routine runs and post its prompt. */
300
+ async function fireRoutine(owner, routine) {
301
+ const target = await routineTarget(owner, routine);
251
302
  const meta = await createChat({
252
- agent: def.harness,
253
- scope: { kind: "agent", slug: slug, routine: routine.id },
303
+ ...target,
254
304
  title: `⏰ ${routine.name}`,
255
305
  ...(routine.private ? { private: true } : {}),
256
306
  });
@@ -259,14 +309,16 @@ async function fireRoutine(slug, routine) {
259
309
  throw new Error(error);
260
310
  return meta.id;
261
311
  }
312
+ /** Where a routine is looked at and fixed: its agent's profile, or Artifacts for the workspace's. */
313
+ export const routineHref = (owner, id) => owner === WORKSPACE_ROUTINES ? `/artifacts?kind=routines&open=${encodeURIComponent(`routines:${owner}:${id}`)}` : `/agents/${owner}`;
262
314
  /** A routine could not even start (agent gone, harness missing): the bell says so. */
263
315
  function notifyRoutineFailed(slug, routine, message) {
264
316
  return pushNotification({
265
317
  kind: "routine_failed",
266
318
  title: `⏰ ${routine.name} could not start`,
267
319
  body: message,
268
- href: `/agents/${slug}`,
269
- diagnose: { kind: "routine", agent: slug, routine: routine.id },
320
+ href: routineHref(slug, routine.id),
321
+ diagnose: { kind: "routine", agent: slug === WORKSPACE_ROUTINES ? (routine.agent ?? "") : slug, routine: routine.id },
270
322
  }).catch(() => { });
271
323
  }
272
324
  export async function runRoutineNow(slug, id) {
@@ -325,13 +377,13 @@ const scheduler = perWorkspace(() => ({ timer: null }));
325
377
  export async function dueRoutines(now, me) {
326
378
  const identity = me ?? (await localIdentity());
327
379
  const out = [];
328
- for (const m of await listAgents()) {
329
- for (const r of await listRoutines(m.slug).catch(() => [])) {
380
+ for (const owner of await routineOwners()) {
381
+ for (const r of await listRoutines(owner).catch(() => [])) {
330
382
  if (!firesHere(r, identity))
331
383
  continue;
332
384
  try {
333
385
  if (cronMatches(parseCron(r.schedule), now))
334
- out.push({ slug: m.slug, routine: r });
386
+ out.push({ slug: owner, routine: r });
335
387
  }
336
388
  catch {
337
389
  // invalid schedule — surfaced by validation on save, skip here
@@ -380,7 +432,7 @@ export async function runnerFindings() {
380
432
  const out = { unassigned: [], retired: [] };
381
433
  let since = 0;
382
434
  // Archived agents included: the scheduler fires their routines too.
383
- for (const a of await listAgents()) {
435
+ for (const a of (await routineOwners()).map((slug) => ({ slug }))) {
384
436
  const routines = await listRoutines(a.slug).catch(() => []);
385
437
  let hit = false;
386
438
  for (const r of routines) {
@@ -414,7 +466,7 @@ export async function adoptRoutines(pick, message) {
414
466
  const me = identityString(id);
415
467
  const adopted = [];
416
468
  const written = [];
417
- for (const a of await listAgents()) {
469
+ for (const a of (await routineOwners()).map((slug) => ({ slug }))) {
418
470
  const routines = await listRoutines(a.slug).catch(() => []);
419
471
  let changed = false;
420
472
  for (const r of routines) {
@@ -453,7 +505,7 @@ async function commitFiles(abs, message) {
453
505
  }
454
506
  /** Adopt one routine (whatever its runs_on said). */
455
507
  export async function adoptRoutine(slug, id) {
456
- const safe = safeAgentSlug(slug);
508
+ const safe = slug === WORKSPACE_ROUTINES ? slug : safeAgentSlug(slug);
457
509
  if (!(await listRoutines(safe)).some((r) => r.id === id))
458
510
  throw new Error("routine not found");
459
511
  const result = await adoptRoutines((agent, r) => agent === safe && r.id === id);
@@ -33,6 +33,8 @@ export interface SkillInfo {
33
33
  source: "workspace" | "project" | "user" | "agent";
34
34
  /** For source "agent": the owning agent's slug. */
35
35
  agent?: string;
36
+ /** SKILL.md's last change (lists sort by it). */
37
+ updatedAt?: string;
36
38
  }
37
39
  export interface SkillDetail extends SkillInfo {
38
40
  /** Full SKILL.md contents. */
@@ -49,12 +49,14 @@ async function scanRoot(root, source) {
49
49
  const name = String(fm.name ?? dirName).trim() || dirName;
50
50
  if (!NAME_RE.test(name))
51
51
  return null;
52
+ const mtime = await fs.stat(file).then((st) => st.mtime.toISOString(), () => undefined);
52
53
  return {
53
54
  name,
54
55
  description: String(fm.description ?? "").trim(),
55
56
  path: file,
56
57
  dir,
57
58
  source,
59
+ ...(mtime ? { updatedAt: mtime } : {}),
58
60
  };
59
61
  }));
60
62
  return skills.filter(Boolean).sort((a, b) => a.name.localeCompare(b.name));
@@ -72,6 +72,7 @@ export declare const agentRoutes: (import("./router.js").Route<"agents.addJourna
72
72
  dir: string;
73
73
  source: "workspace" | "project" | "user" | "agent";
74
74
  agent?: string;
75
+ updatedAt?: string;
75
76
  content: string;
76
77
  }, "/api/agents/:slug/skills/:name", undefined> | import("./router.js").Route<"agents.skills", {
77
78
  skills: import("../../core/skills.js").SkillInfo[];
@@ -1,5 +1,5 @@
1
1
  import * as z from "zod";
2
- import { agentsRoot, deleteAgent, getAgent, listAgents, saveAgent, setAgentArchived } from "../../core/agents.js";
2
+ import { agentsRoot, deleteAgent, getAgent, listAgents, safeAgentSlug, saveAgent, setAgentArchived } from "../../core/agents.js";
3
3
  import { appendJournal, readJournal } from "../../core/journal.js";
4
4
  import { UI_ACTOR } from "../../core/knowledge.js";
5
5
  import { adoptRoutine, deleteRoutine, listRoutines, routineStatuses, runRoutineNow, saveRoutine } from "../../core/routines.js";
@@ -35,6 +35,8 @@ const RoutineFields = z.object({
35
35
  runsOn: z.string().nullable().optional(),
36
36
  private: z.boolean().optional(),
37
37
  });
38
+ /** An agent's slug, checked: these routes are for an agent's own routines, never the workspace's (owner "_", see /api/routines). */
39
+ const own = (slug) => safeAgentSlug(slug);
38
40
  /** Agents (team members): definition, own skills, journal, routines. */
39
41
  export const agentRoutes = [
40
42
  route({ name: "agents.list", method: "GET", path: "/api/agents", summary: "every member" }, async () => ({ root: await agentsRoot(), agents: await listAgents() })),
@@ -91,11 +93,11 @@ export const agentRoutes = [
91
93
  return { journal: await appendJournal(c.params.slug, entry, { kind, actor: UI_ACTOR }) };
92
94
  }),
93
95
  route({ name: "agents.routines", method: "GET", path: "/api/agents/:slug/routines", summary: "the agent's routines with run state", errors: 400 }, async (c) => ({
94
- routines: await routineStatuses(c.params.slug),
96
+ routines: await routineStatuses(own(c.params.slug)),
95
97
  })),
96
- route({ name: "agents.saveRoutine", method: "POST", path: "/api/agents/:slug/routines", summary: "create or update a routine", errors: 400, body: RoutineFields }, async (c) => saveRoutine(c.params.slug, (await c.body()))),
98
+ route({ name: "agents.saveRoutine", method: "POST", path: "/api/agents/:slug/routines", summary: "create or update a routine", errors: 400, body: RoutineFields }, async (c) => saveRoutine(own(c.params.slug), (await c.body()))),
97
99
  route({ name: "agents.deleteRoutine", method: "DELETE", path: "/api/agents/:slug/routines/:id", summary: "delete a routine", errors: 400 }, async (c) => {
98
- await deleteRoutine(c.params.slug, c.params.id);
100
+ await deleteRoutine(own(c.params.slug), c.params.id);
99
101
  return { ok: true };
100
102
  }),
101
103
  route({
@@ -105,9 +107,9 @@ export const agentRoutes = [
105
107
  summary: "run this routine here: runs_on = this machine's identity, routines.yml committed",
106
108
  errors: 400,
107
109
  }, async (c) => {
108
- if (!(await listRoutines(c.params.slug)).some((r) => r.id === c.params.id))
110
+ if (!(await listRoutines(own(c.params.slug))).some((r) => r.id === c.params.id))
109
111
  fail(404, "routine not found");
110
- return adoptRoutine(c.params.slug, c.params.id);
112
+ return adoptRoutine(own(c.params.slug), c.params.id);
111
113
  }),
112
- route({ name: "agents.runRoutine", method: "POST", path: "/api/agents/:slug/routines/:id/run", summary: "run a routine now", errors: 400 }, async (c) => runRoutineNow(c.params.slug, c.params.id)),
114
+ route({ name: "agents.runRoutine", method: "POST", path: "/api/agents/:slug/routines/:id/run", summary: "run a routine now", errors: 400 }, async (c) => runRoutineNow(own(c.params.slug), c.params.id)),
113
115
  ];
@@ -77,7 +77,9 @@ export declare const boardRoutes: (import("./router.js").Route<"boards.create",
77
77
  board: string;
78
78
  project?: string;
79
79
  sessions: import("../../core/board-wake.js").TaskSession[];
80
- }, "/api/boards/:board/tasks/:task", undefined> | import("./router.js").Route<"tasks.log", import("../../core/boards.js").TaskDetail, "/api/boards/:board/tasks/:task/log", z.ZodObject<{
80
+ }, "/api/boards/:board/tasks/:task", undefined> | import("./router.js").Route<"tasks.list", {
81
+ tasks: import("../../core/boards.js").ListedTask[];
82
+ }, "/api/tasks", undefined> | import("./router.js").Route<"tasks.log", import("../../core/boards.js").TaskDetail, "/api/boards/:board/tasks/:task/log", z.ZodObject<{
81
83
  entry: z.ZodString;
82
84
  actor: z.ZodOptional<z.ZodString>;
83
85
  }, z.core.$strip>> | import("./router.js").Route<"tasks.move", import("../../core/boards.js").TaskDetail, "/api/boards/:board/tasks/:task/move", z.ZodObject<{
@@ -1,5 +1,5 @@
1
1
  import * as z from "zod";
2
- import { appendTaskLog, assignTask, createBoard, createTask, deleteBoard, deleteTask, ensureDefaultBoard, getBoard, getTask, listAllBoards, listBoards, moveTask, openBoards, pickTask, saveBoard, saveTask, } from "../../core/boards.js";
2
+ import { appendTaskLog, assignTask, createBoard, createTask, deleteBoard, deleteTask, ensureDefaultBoard, getBoard, getTask, listAllBoards, listAllTasks, listBoards, moveTask, openBoards, pickTask, saveBoard, saveTask, } from "../../core/boards.js";
3
3
  import { taskSessions } from "../../core/board-wake.js";
4
4
  import { fail, reply, route, statusByMessage } from "./router.js";
5
5
  /**
@@ -94,6 +94,9 @@ export const boardRoutes = [
94
94
  await requireOn();
95
95
  return reply(201, await createTask(refOf(c), (await c.body())));
96
96
  }),
97
+ route({ name: "tasks.list", method: "GET", path: "/api/tasks", summary: "every task of every board, the workspace's and the projects', each with its board and column" }, async () => {
98
+ return { tasks: (await openBoards()).off ? [] : await listAllTasks() };
99
+ }),
97
100
  route({ name: "tasks.get", method: "GET", path: "/api/boards/:board/tasks/:task", summary: "the task: fields, markdown, files, log and the sessions that worked on it (:task = folder name or number)", errors: boardErrors }, async (c) => {
98
101
  await requireOn();
99
102
  const task = (await getTask(refOf(c), c.params.task)) ?? fail(404, `no task "${c.params.task}"`);
@@ -101,6 +101,7 @@ export declare const routes: (Route<"agents.addJournal", {
101
101
  dir: string;
102
102
  source: "workspace" | "project" | "user" | "agent";
103
103
  agent?: string;
104
+ updatedAt?: string;
104
105
  content: string;
105
106
  }, "/api/agents/:slug/skills/:name", undefined> | Route<"agents.skills", {
106
107
  skills: import("../../core/skills.js").SkillInfo[];
@@ -744,16 +745,25 @@ export declare const routes: (Route<"agents.addJournal", {
744
745
  repo?: import("../../core/repos.js").RepoInfo;
745
746
  }>, "/api/repos/:slug/update", undefined> | Route<"routines.adopt", import("../../core/routines.js").AdoptResult, "/api/routines/adopt", z.ZodObject<{
746
747
  retired: z.ZodDefault<z.ZodBoolean>;
747
- }, z.core.$strip>> | Route<"routines.list", {
748
- routines: (import("../../core/routines.js").RoutineStatus & {
749
- agent: {
750
- slug: string;
751
- name: string;
752
- emoji: string;
753
- };
754
- workflows: string[];
755
- })[];
756
- }, "/api/routines", undefined> | Route<"runs.decide", import("../../core/decisions.js").DecisionAnswer, "/api/runs/:id/decision", z.ZodObject<{
748
+ }, z.core.$strip>> | Route<"routines.adoptOne", import("../../core/routines.js").AdoptResult & {
749
+ routine: import("../../core/routines.js").RoutineStatus;
750
+ }, "/api/routines/:id/adopt", undefined> | Route<"routines.delete", {
751
+ ok: true;
752
+ }, "/api/routines/:id", undefined> | Route<"routines.list", {
753
+ routines: import("../../core/routines.js").ListedRoutine[];
754
+ }, "/api/routines", undefined> | Route<"routines.run", {
755
+ chatId: string;
756
+ }, "/api/routines/:id/run", undefined> | Route<"routines.save", import("../../core/routines.js").Routine, "/api/routines", z.ZodObject<{
757
+ id: z.ZodOptional<z.ZodString>;
758
+ name: z.ZodOptional<z.ZodString>;
759
+ schedule: z.ZodOptional<z.ZodString>;
760
+ prompt: z.ZodOptional<z.ZodString>;
761
+ enabled: z.ZodOptional<z.ZodBoolean>;
762
+ runsOn: z.ZodOptional<z.ZodNullable<z.ZodString>>;
763
+ private: z.ZodOptional<z.ZodBoolean>;
764
+ project: z.ZodOptional<z.ZodNullable<z.ZodString>>;
765
+ agent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
766
+ }, z.core.$strip>> | Route<"runs.decide", import("../../core/decisions.js").DecisionAnswer, "/api/runs/:id/decision", z.ZodObject<{
757
767
  decision: z.ZodOptional<z.ZodString>;
758
768
  note: z.ZodOptional<z.ZodString>;
759
769
  }, z.core.$strip>> | Route<"runs.delete", {
@@ -867,7 +877,9 @@ export declare const routes: (Route<"agents.addJournal", {
867
877
  board: string;
868
878
  project?: string;
869
879
  sessions: import("../../core/board-wake.js").TaskSession[];
870
- }, "/api/boards/:board/tasks/:task", undefined> | Route<"tasks.log", import("../../core/boards.js").TaskDetail, "/api/boards/:board/tasks/:task/log", z.ZodObject<{
880
+ }, "/api/boards/:board/tasks/:task", undefined> | Route<"tasks.list", {
881
+ tasks: import("../../core/boards.js").ListedTask[];
882
+ }, "/api/tasks", undefined> | Route<"tasks.log", import("../../core/boards.js").TaskDetail, "/api/boards/:board/tasks/:task/log", z.ZodObject<{
871
883
  entry: z.ZodString;
872
884
  actor: z.ZodOptional<z.ZodString>;
873
885
  }, z.core.$strip>> | Route<"tasks.move", import("../../core/boards.js").TaskDetail, "/api/boards/:board/tasks/:task/move", z.ZodObject<{
@@ -2,16 +2,25 @@ import * as z from "zod";
2
2
  /** Workflows, their runs, and the routines that start them. */
3
3
  export declare const runRoutes: (import("./router.js").Route<"routines.adopt", import("../../core/routines.js").AdoptResult, "/api/routines/adopt", z.ZodObject<{
4
4
  retired: z.ZodDefault<z.ZodBoolean>;
5
- }, z.core.$strip>> | import("./router.js").Route<"routines.list", {
6
- routines: (import("../../core/routines.js").RoutineStatus & {
7
- agent: {
8
- slug: string;
9
- name: string;
10
- emoji: string;
11
- };
12
- workflows: string[];
13
- })[];
14
- }, "/api/routines", undefined> | import("./router.js").Route<"runs.decide", import("../../core/decisions.js").DecisionAnswer, "/api/runs/:id/decision", z.ZodObject<{
5
+ }, z.core.$strip>> | import("./router.js").Route<"routines.adoptOne", import("../../core/routines.js").AdoptResult & {
6
+ routine: import("../../core/routines.js").RoutineStatus;
7
+ }, "/api/routines/:id/adopt", undefined> | import("./router.js").Route<"routines.delete", {
8
+ ok: true;
9
+ }, "/api/routines/:id", undefined> | import("./router.js").Route<"routines.list", {
10
+ routines: import("../../core/routines.js").ListedRoutine[];
11
+ }, "/api/routines", undefined> | import("./router.js").Route<"routines.run", {
12
+ chatId: string;
13
+ }, "/api/routines/:id/run", undefined> | import("./router.js").Route<"routines.save", import("../../core/routines.js").Routine, "/api/routines", z.ZodObject<{
14
+ id: z.ZodOptional<z.ZodString>;
15
+ name: z.ZodOptional<z.ZodString>;
16
+ schedule: z.ZodOptional<z.ZodString>;
17
+ prompt: z.ZodOptional<z.ZodString>;
18
+ enabled: z.ZodOptional<z.ZodBoolean>;
19
+ runsOn: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
+ private: z.ZodOptional<z.ZodBoolean>;
21
+ project: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
+ agent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
23
+ }, z.core.$strip>> | import("./router.js").Route<"runs.decide", import("../../core/decisions.js").DecisionAnswer, "/api/runs/:id/decision", z.ZodObject<{
15
24
  decision: z.ZodOptional<z.ZodString>;
16
25
  note: z.ZodOptional<z.ZodString>;
17
26
  }, z.core.$strip>> | import("./router.js").Route<"runs.delete", {
@@ -2,7 +2,7 @@ import { promises as fs } from "node:fs";
2
2
  import * as z from "zod";
3
3
  import { getOutputDir } from "../../core/context.js";
4
4
  import { decide } from "../../core/decisions.js";
5
- import { adoptUnassigned, allRoutines } from "../../core/routines.js";
5
+ import { adoptRoutine, adoptUnassigned, allRoutines, deleteRoutine, listRoutines, runRoutineNow, saveRoutine, WORKSPACE_ROUTINES } from "../../core/routines.js";
6
6
  import { dockerStatus, stopRun, triggerRun } from "../../core/runner.js";
7
7
  import { deleteRun, getRun, listRuns, readRunFile, safeRunDir } from "../../core/runs.js";
8
8
  import { deleteWorkflow, getWorkflow, listWorkflows } from "../../core/workflows.js";
@@ -28,6 +28,21 @@ const validRun = (p, message = "invalid run id") => p.catch((err) => {
28
28
  const RunInput = z.object({ request: z.string().default(""), sandbox: z.boolean().default(true), ssh: z.boolean().default(false) });
29
29
  /** A person's answer; decide() checks it against the offered options and the note rule. */
30
30
  const DecisionInput = z.object({ decision: z.string().optional(), note: z.string().optional() });
31
+ /**
32
+ * A workspace routine: the fields of an agent's (see agents.ts), plus where it runs and who gets the prompt.
33
+ * project / agent absent keep what is stored; null or "" clears (globally / the project's assistant, or Ralv).
34
+ */
35
+ const WorkspaceRoutine = z.object({
36
+ id: z.string().optional(),
37
+ name: z.string().optional(),
38
+ schedule: z.string().optional(),
39
+ prompt: z.string().optional(),
40
+ enabled: z.boolean().optional(),
41
+ runsOn: z.string().nullable().optional(),
42
+ private: z.boolean().optional(),
43
+ project: z.string().nullable().optional(),
44
+ agent: z.string().nullable().optional(),
45
+ });
31
46
  /** Workflows, their runs, and the routines that start them. */
32
47
  export const runRoutes = [
33
48
  route({ name: "workflows.list", method: "GET", path: "/api/workflows", summary: "every workflow, with validation errors" }, async () => listWorkflows()),
@@ -56,9 +71,37 @@ export const runRoutes = [
56
71
  throw new ApiError(503, err.message);
57
72
  }
58
73
  }),
59
- route({ name: "routines.list", method: "GET", path: "/api/routines", summary: "every agent's routines with run state and the workflows each one names" }, async () => ({
74
+ route({ name: "routines.list", method: "GET", path: "/api/routines", summary: "every routine — the agents' and the workspace's (owner \"_\") — with run state and the workflows each one names" }, async () => ({
60
75
  routines: await allRoutines((await listWorkflows()).workflows),
61
76
  })),
77
+ route({
78
+ name: "routines.save",
79
+ method: "POST",
80
+ path: "/api/routines",
81
+ summary: "create or update a workspace routine (agents/routines.yml): one defined on its own, with the project it runs in (none: globally) and the agent it messages (none: the project's assistant, or Ralv)",
82
+ errors: 400,
83
+ body: WorkspaceRoutine,
84
+ }, async (c) => saveRoutine(WORKSPACE_ROUTINES, (await c.body()))),
85
+ route({ name: "routines.delete", method: "DELETE", path: "/api/routines/:id", summary: "delete a workspace routine", errors: 400 }, async (c) => {
86
+ await deleteRoutine(WORKSPACE_ROUTINES, c.params.id);
87
+ return { ok: true };
88
+ }),
89
+ route({ name: "routines.run", method: "POST", path: "/api/routines/:id/run", summary: "run a workspace routine now", errors: 400 }, async (c) => {
90
+ if (!(await listRoutines(WORKSPACE_ROUTINES)).some((r) => r.id === c.params.id))
91
+ fail(404, "routine not found");
92
+ return runRoutineNow(WORKSPACE_ROUTINES, c.params.id);
93
+ }),
94
+ route({
95
+ name: "routines.adoptOne",
96
+ method: "POST",
97
+ path: "/api/routines/:id/adopt",
98
+ summary: "run this workspace routine here: runs_on = this machine's identity, routines.yml committed",
99
+ errors: 400,
100
+ }, async (c) => {
101
+ if (!(await listRoutines(WORKSPACE_ROUTINES)).some((r) => r.id === c.params.id))
102
+ fail(404, "routine not found");
103
+ return adoptRoutine(WORKSPACE_ROUTINES, c.params.id);
104
+ }),
62
105
  route({
63
106
  name: "routines.adopt",
64
107
  method: "POST",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netnodeag/kraftwerk",
3
- "version": "0.86.0",
3
+ "version": "0.88.0",
4
4
  "description": "Open-source agentic workspace for teams — where people and AI agents get work done together: agents (Claude Code, Codex, Pi), skills, shared knowledge, repeatable workflows, and deterministic verification",
5
5
  "keywords": [
6
6
  "agents",