@sigmacamellia/dsh-dynamic-workflow 0.1.3 → 0.1.5

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/lib/index.js CHANGED
@@ -210777,9 +210777,9 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
210777
210777
  });
210778
210778
 
210779
210779
  // src/index.ts
210780
- import { existsSync as existsSync4, mkdirSync as mkdirSync4 } from "node:fs";
210780
+ import { existsSync as existsSync5, mkdirSync as mkdirSync4 } from "node:fs";
210781
210781
  import { homedir as homedir2 } from "node:os";
210782
- import { dirname as dirname2, join as join7 } from "node:path";
210782
+ import { dirname as dirname2, join as join8 } from "node:path";
210783
210783
  import { fileURLToPath } from "node:url";
210784
210784
 
210785
210785
  // src/dsh/messages.ts
@@ -215646,8 +215646,8 @@ function evalCall(ev, node2, ctx) {
215646
215646
  if (hole !== void 0) return handleHole(ev, node2, hole, ctx);
215647
215647
  const world = ev.s.worldByCall.get(node2);
215648
215648
  if (world !== void 0) return handleWorldRead(ev, world.id, world.args, ctx);
215649
- const join8 = ev.s.joinByCall.get(node2);
215650
- if (join8 !== void 0) return handleJoin(ev, node2, join8.id, join8.arg, ctx);
215649
+ const join9 = ev.s.joinByCall.get(node2);
215650
+ if (join9 !== void 0) return handleJoin(ev, node2, join9.id, join9.arg, ctx);
215651
215651
  if (import_typescript22.default.isPropertyAccessExpression(node2.expression)) {
215652
215652
  const cand = ev.s.candByCall.get(node2);
215653
215653
  if (cand !== void 0) return handleArrayMethod(ev, node2, cand, ctx);
@@ -225018,14 +225018,24 @@ function topLevelSchemaProperties(schema) {
225018
225018
  return new Set(Object.keys(properties));
225019
225019
  }
225020
225020
  function subagentPreamble(input2) {
225021
- const who = input2.actorName === void 0 ? "a subagent" : `the subagent "${input2.actorName}"`;
225022
- const run = input2.runName === void 0 ? "a dynamic workflow" : `the dynamic workflow "${input2.runName}"`;
225021
+ const name2 = input2.actorName?.trim();
225022
+ const named = name2 ? `, named "${name2}"` : "";
225023
+ const opening = `You are a subagent inside a dynamic workflow run${named}. A script created you and hands you work one ask at a time; the script \u2014 not a person \u2014 consumes what you return. There is no user in this conversation to talk to.`;
225024
+ const persona = input2.persona?.trim();
225025
+ const contract = [
225026
+ "# Working inside a workflow",
225027
+ "- You have the regular working tools \u2014 reading, searching, editing, running commands \u2014 plus `submit_result` and `escalate`. There is no tool that asks a person anything.",
225028
+ "- Each ask states what to do. When the ask carries a result schema, finish by calling `submit_result` with a conforming value; otherwise your final message is the result.",
225029
+ "- Ground every claim in something you read or ran in this session, or in the material the ask gave you, and say which. Cite code as `path:line`. A check counts as passed only if you executed it here; if you could not run it, report it as not run. Run the check an ask names rather than a faster substitute, and say exactly which command you ran.",
225030
+ "- Report outcomes faithfully. If part of the task is impossible, out of scope, or contradicted by what you found, say so in the result instead of filling a field with a plausible guess. Never fake a passing result to satisfy an instruction.",
225031
+ "- When you are blocked by something outside your reach \u2014 a gate that cannot pass, instructions that contradict each other, a fact only the run's owner knows \u2014 call `escalate`. Questions written in prose reach nobody.",
225032
+ "- Do not write report or summary files on your own initiative; findings go in the result. When the ask names an output path, write exactly there and return that path in the result \u2014 the script publishes it to the user."
225033
+ ].join("\n");
225023
225034
  return [
225024
- `You are ${who} in ${run}: a script written by the main agent hands you tasks one at a time and reads your answers.`,
225025
- "Each user message in this conversation is one task. Work it to completion with your tools, then answer.",
225026
- "When a task has a typed result, you MUST finish by calling `submit_result` with a value that matches the schema; plain text does not count as the result of a typed task.",
225027
- "Your results are read by the user, in their language. Be concrete: cite files with path and line, commands with their real output.",
225028
- "You cannot ask the user anything directly. If something outside your reach blocks you, call `escalate` with one focused question."
225035
+ opening,
225036
+ ...persona ? ["", persona] : [],
225037
+ "",
225038
+ contract
225029
225039
  ].join("\n");
225030
225040
  }
225031
225041
  function toWorkflowError(error62) {
@@ -225482,10 +225492,11 @@ var DshWorkflowDriver = class {
225482
225492
  name: "dynamic-workflow:subagent",
225483
225493
  order: order("DEPLOYMENT_PERSONA_PREFIX", 50) + 1,
225484
225494
  interpolate: false,
225485
- text: [
225486
- subagentPreamble({ ...this.deps.runName === void 0 ? {} : { runName: this.deps.runName }, ...input2.actorName === void 0 ? {} : { actorName: input2.actorName } }),
225487
- ...persona.system === void 0 || persona.system.length === 0 ? [] : ["", "## Your role", persona.system]
225488
- ].join("\n")
225495
+ text: subagentPreamble({
225496
+ ...this.deps.runName === void 0 ? {} : { runName: this.deps.runName },
225497
+ ...input2.actorName === void 0 ? {} : { actorName: input2.actorName },
225498
+ ...persona.system === void 0 || persona.system.length === 0 ? {} : { persona: persona.system }
225499
+ })
225489
225500
  });
225490
225501
  const tools = childCtx.tools;
225491
225502
  const inheritedKnown = new Set(tools.definitions(child).map((definition) => definition.name));
@@ -249331,6 +249342,13 @@ function describePath(cwd, path) {
249331
249342
  const rel = relative4(cwd, path);
249332
249343
  return rel.startsWith("..") || isAbsolute4(rel) ? path : rel;
249333
249344
  }
249345
+ var SAVED_WORKFLOW_NAME_PATTERN = /^[A-Za-z0-9_.-]+$/u;
249346
+ var SAVED_WORKFLOW_NAME_MAX_CHARS = 64;
249347
+ function isValidSavedWorkflowName(name2) {
249348
+ if (name2.length === 0 || name2.length > SAVED_WORKFLOW_NAME_MAX_CHARS) return false;
249349
+ if (!SAVED_WORKFLOW_NAME_PATTERN.test(name2)) return false;
249350
+ return name2.replaceAll(".", "").length > 0;
249351
+ }
249334
249352
  var HEADER = /^\s*\/\*\s*dsh-workflow\s*([\s\S]*?)\*\/\s*/u;
249335
249353
  function stripSavedHeader(text) {
249336
249354
  const match = HEADER.exec(text);
@@ -249362,7 +249380,16 @@ function listSavedAll(cwd) {
249362
249380
  try {
249363
249381
  const { meta: meta3, script } = stripSavedHeader(readFileSync(path, "utf8"));
249364
249382
  const name2 = meta3?.name ?? file2.slice(0, -".dwf.ts".length);
249365
- out.push({ name: name2, description: meta3?.description ?? "", ...meta3?.whenToUse === void 0 ? {} : { whenToUse: meta3.whenToUse }, ...meta3?.args === void 0 ? {} : { args: meta3.args }, scope, path, script });
249383
+ out.push({
249384
+ name: name2,
249385
+ description: meta3?.description ?? "",
249386
+ ...meta3?.whenToUse === void 0 ? {} : { whenToUse: meta3.whenToUse },
249387
+ ...meta3?.fromRunId === void 0 ? {} : { fromRunId: meta3.fromRunId },
249388
+ ...meta3?.args === void 0 ? {} : { args: meta3.args },
249389
+ scope,
249390
+ path,
249391
+ script
249392
+ });
249366
249393
  } catch {
249367
249394
  }
249368
249395
  }
@@ -249380,7 +249407,16 @@ function listSaved(cwd) {
249380
249407
  try {
249381
249408
  const { meta: meta3, script } = stripSavedHeader(readFileSync(path, "utf8"));
249382
249409
  const name2 = meta3?.name ?? file2.slice(0, -".dwf.ts".length);
249383
- out.set(name2, { name: name2, description: meta3?.description ?? "", ...meta3?.whenToUse === void 0 ? {} : { whenToUse: meta3.whenToUse }, ...meta3?.args === void 0 ? {} : { args: meta3.args }, scope, path, script });
249410
+ out.set(name2, {
249411
+ name: name2,
249412
+ description: meta3?.description ?? "",
249413
+ ...meta3?.whenToUse === void 0 ? {} : { whenToUse: meta3.whenToUse },
249414
+ ...meta3?.fromRunId === void 0 ? {} : { fromRunId: meta3.fromRunId },
249415
+ ...meta3?.args === void 0 ? {} : { args: meta3.args },
249416
+ scope,
249417
+ path,
249418
+ script
249419
+ });
249384
249420
  } catch {
249385
249421
  }
249386
249422
  }
@@ -249936,7 +249972,8 @@ ${result.diagnostics.map((d) => `L${d.line}:C${d.column} ${d.message}`).join("\n
249936
249972
  scope: { type: "string", enum: ["project", "global"] },
249937
249973
  script: { type: "string" },
249938
249974
  script_path: { type: "string" },
249939
- run_id: { type: "string", description: "Save the effective script of this run." },
249975
+ run_id: { type: "string", description: "Save the effective script of this run (when neither script nor script_path is given), or link provenance to that run." },
249976
+ from_run_id: { type: "string", description: "Provenance only: the id of the run this workflow was distilled from, so that run knows it has been saved." },
249940
249977
  args: { type: "object", description: "Declared arguments: { name: { type, description, default, required } }." }
249941
249978
  },
249942
249979
  required: ["name", "description", "scope"],
@@ -249969,10 +250006,12 @@ ${diagnosticsText(analysis)}` };
249969
250006
  if (decision.kind !== "allow") {
249970
250007
  return { ok: false, text: "The user declined to save this workflow. Nothing was written." };
249971
250008
  }
250009
+ const fromRunId = str(args.from_run_id) ?? str(args.run_id);
249972
250010
  const path = writeSaved(cwd, scope, {
249973
250011
  name: workflowName,
249974
250012
  description,
249975
250013
  ...typeof args.whenToUse === "string" ? { whenToUse: args.whenToUse } : {},
250014
+ ...fromRunId === void 0 ? {} : { fromRunId },
249976
250015
  ...typeof args.args === "object" && args.args !== null ? { args: args.args } : {}
249977
250016
  }, script);
249978
250017
  return { ok: true, text: `Saved "${workflowName}" at ${describePath(cwd, path)}. Run it with create_workflow { saved: { name: "${workflowName}" } }.` };
@@ -250055,8 +250094,9 @@ Revise the script accordingly and call ${tool} again.${pathNote}`,
250055
250094
  }
250056
250095
 
250057
250096
  // src/web/routes.ts
250058
- import { createReadStream } from "node:fs";
250097
+ import { createReadStream, existsSync as existsSync3 } from "node:fs";
250059
250098
  import { stat as stat3 } from "node:fs/promises";
250099
+ import { join as join6 } from "node:path";
250060
250100
 
250061
250101
  // src/dsh/owner.ts
250062
250102
  async function resolveOwnerAgent(ctx, sessionId) {
@@ -250140,6 +250180,39 @@ async function listModelIds(ctx) {
250140
250180
  }
250141
250181
  return out;
250142
250182
  }
250183
+ function buildDistillSavePrompt(input2) {
250184
+ const name2 = input2.name.trim();
250185
+ const description = input2.description.trim();
250186
+ const runName = input2.runName?.trim();
250187
+ if (input2.locale === "zh") {
250188
+ const target2 = input2.scope === "global" ? '\u4FDD\u5B58\u4E3A\u5168\u5C40\u5DE5\u4F5C\u6D41\uFF08scope: "global"\uFF09' : "\u4FDD\u5B58\u5230\u672C\u9879\u76EE";
250189
+ return [
250190
+ `/${WORKFLOW_SKILL_NAME} \u8BF7\u628A\u521A\u8DD1\u5B8C\u7684\u5DE5\u4F5C\u6D41${runName ? `\u300C${runName}\u300D` : ""}\u63D0\u70BC\u6210\u53EF\u4EE5\u590D\u7528\u7684\u5DE5\u4F5C\u6D41\uFF0C\u7528 save_workflow ${target2}\uFF1A`,
250191
+ "1. \u811A\u672C\u4EE5\u8FD9\u6B21\u8FD0\u884C\u5B9E\u9645\u6267\u884C\u7684\u90A3\u4E00\u4EFD\u4E3A\u51C6\uFF0C\u4E0D\u8981\u6539\u52A8\u5B83\u7684\u903B\u8F91\u3002",
250192
+ "2. \u628A\u4E24\u6B21\u8FD0\u884C\u4E4B\u95F4\u4F1A\u53D8\u5316\u7684\u503C\u62BD\u6210 args\uFF08\u5199\u597D\u8BF4\u660E\u4E0E\u5408\u7406\u9ED8\u8BA4\u503C\uFF09\uFF0C\u5E76\u8865\u9F50 description \u4E0E whenToUse\u3002",
250193
+ name2.length > 0 ? `3. \u540D\u5B57\u7528 \`${name2}\`\u3002` : "3. \u540D\u5B57\u8BF7\u4F60\u6765\u53D6\uFF08\u53EA\u80FD\u7528\u5B57\u6BCD\u3001\u6570\u5B57\u548C - _ .\uFF09\u3002",
250194
+ description.length > 0 ? `4. \u8BF4\u660E\u53EF\u4EE5\u53C2\u8003\uFF1A${description}` : "",
250195
+ `5. \u8C03\u7528 save_workflow \u65F6\u5E26\u4E0A from_run_id: "${input2.runId}"\u2014\u2014\u8FD9\u6B21\u8FD0\u884C\u8981\u636E\u6B64\u8BA4\u51FA\u81EA\u5DF1\u5DF2\u88AB\u4FDD\u5B58\u3002`
250196
+ ].filter((line) => line.length > 0).join("\n");
250197
+ }
250198
+ const target = input2.scope === "global" ? 'save it as a global workflow (scope: "global")' : "save it to this project";
250199
+ return [
250200
+ `/${WORKFLOW_SKILL_NAME} Please distill the workflow that just finished${runName ? ` ("${runName}")` : ""} into a reusable one and ${target} with save_workflow:`,
250201
+ "1. Use the script this run actually executed; do not change its logic.",
250202
+ "2. Lift the values that change between runs into args (with descriptions and sensible defaults), and write description and whenToUse.",
250203
+ name2.length > 0 ? `3. Name it \`${name2}\`.` : "3. Pick the name yourself (letters, digits and - _ . only).",
250204
+ description.length > 0 ? `4. For the description, start from: ${description}` : "",
250205
+ `5. Pass from_run_id: "${input2.runId}" to save_workflow, so that run can tell it has been saved.`
250206
+ ].filter((line) => line.length > 0).join("\n");
250207
+ }
250208
+ function findSavedForRun(cwd, runId, runName) {
250209
+ if (cwd === void 0) return null;
250210
+ const all = listSavedAll(cwd);
250211
+ const hit = [...all].reverse().find((item) => item.fromRunId === runId) ?? (runName !== void 0 && isValidSavedWorkflowName(runName) ? [...all].reverse().find((item) => item.name === runName) : void 0);
250212
+ if (hit === void 0) return null;
250213
+ const hasRequiredArgs = Object.values(hit.args ?? {}).some((spec) => spec.required === true && spec.default === void 0);
250214
+ return { name: hit.name, scope: hit.scope, hasRequiredArgs };
250215
+ }
250143
250216
  function registerWorkflowRoutes(ctx, deps) {
250144
250217
  ctx.inject(["webServer"], (scope) => {
250145
250218
  const webServer = scope.get("webServer");
@@ -250190,7 +250263,26 @@ function registerWorkflowRoutes(ctx, deps) {
250190
250263
  const snapshot = deps.service.snapshot(runId);
250191
250264
  const row = deps.service.journal.getRun(runId);
250192
250265
  const script = deps.service.liveRun(runId)?.scriptText ?? row?.scriptText ?? null;
250193
- json2(res, 200, { snapshot, script, graph: script === null ? null : graphOfScript(script), parentSessionId: row?.parentSessionId ?? null });
250266
+ const spans = deps.service.journal.listRunLifeSpans(runId);
250267
+ const durationMs = spans.length === 0 ? null : spans.reduce((sum, s) => sum + Math.max(0, s.lastActivityAt - s.startedAt), 0);
250268
+ const savedAs = findSavedForRun(row?.cwd, runId, snapshot.name);
250269
+ const canSave = script !== null && (row?.cwd !== void 0 || row?.parentSessionId !== void 0);
250270
+ json2(res, 200, { snapshot, script, graph: script === null ? null : graphOfScript(script), parentSessionId: row?.parentSessionId ?? null, durationMs, savedAs, canSave });
250271
+ return;
250272
+ }
250273
+ if (method === "GET" && segments[0] === "runs" && segments[2] === "save-probe" && segments.length === 3) {
250274
+ const runId = segments[1];
250275
+ const row = deps.service.journal.getRun(runId);
250276
+ const name2 = (url2.searchParams.get("name") ?? "").trim();
250277
+ const scope2 = url2.searchParams.get("scope") === "global" ? "global" : "project";
250278
+ if (row?.cwd === void 0 || !isValidSavedWorkflowName(name2)) {
250279
+ json2(res, 200, { taken: false, shadowing: false });
250280
+ return;
250281
+ }
250282
+ const other = scope2 === "global" ? "project" : "global";
250283
+ const taken = existsSync3(join6(savedDir(row.cwd, scope2), `${name2}.dwf.ts`));
250284
+ const shadowing = existsSync3(join6(savedDir(row.cwd, other), `${name2}.dwf.ts`));
250285
+ json2(res, 200, { taken, shadowing });
250194
250286
  return;
250195
250287
  }
250196
250288
  if (method === "GET" && segments[0] === "runs" && segments[2] === "nodes") {
@@ -250268,8 +250360,9 @@ function registerWorkflowRoutes(ctx, deps) {
250268
250360
  description: item.description,
250269
250361
  scope: item.scope,
250270
250362
  ...item.whenToUse === void 0 ? {} : { whenToUse: item.whenToUse },
250363
+ ...item.fromRunId === void 0 ? {} : { fromRunId: item.fromRunId },
250271
250364
  ...item.args === void 0 ? {} : { args: item.args },
250272
- runs: history.filter((row) => row.name === item.name).slice(0, 5).map((row) => ({ runId: row.runId, status: row.status, ...row.stopReason === void 0 ? {} : { stopReason: row.stopReason }, updated: row.updated, spentTokens: row.spentTokens, mine: row.parentSessionId === segments[1] }))
250365
+ runs: history.filter((row) => row.name === item.name || row.runId === item.fromRunId).slice(0, 5).map((row) => ({ runId: row.runId, status: row.status, ...row.stopReason === void 0 ? {} : { stopReason: row.stopReason }, updated: row.updated, spentTokens: row.spentTokens, mine: row.parentSessionId === segments[1] }))
250273
250366
  }));
250274
250367
  json2(res, 200, { saved, available: true, canRun: deps.access?.enabled !== false });
250275
250368
  return;
@@ -250372,6 +250465,70 @@ function registerWorkflowRoutes(ctx, deps) {
250372
250465
  json2(res, 200, await deps.service.configure(runId, parent, { ...max === void 0 ? {} : { maxConcurrency: max }, ...model === void 0 ? {} : { subagentModel: model } }));
250373
250466
  return;
250374
250467
  }
250468
+ if (action === "save") {
250469
+ const body = await readBody(req);
250470
+ const name2 = typeof body.name === "string" ? body.name.trim() : "";
250471
+ if (!isValidSavedWorkflowName(name2)) {
250472
+ json2(res, 400, { ok: false, reason: "invalid_name", message: "Invalid workflow file name." });
250473
+ return;
250474
+ }
250475
+ const scope2 = body.scope === "global" ? "global" : "project";
250476
+ const row = deps.service.journal.getRun(runId);
250477
+ const script = deps.service.liveRun(runId)?.scriptText ?? row?.scriptText;
250478
+ const parent = row?.parentSessionId === void 0 ? void 0 : await resolveOwnerAgent(ctx, row.parentSessionId);
250479
+ const cwd = row?.cwd ?? parent?.session.header.cwd;
250480
+ if (script === void 0 || cwd === void 0) {
250481
+ json2(res, 404, { ok: false, reason: "missing_run", message: "Run script or workspace is not available." });
250482
+ return;
250483
+ }
250484
+ const analysis = analyzeWorkflowScript(script);
250485
+ if (!analysis.ok) {
250486
+ json2(res, 422, { ok: false, reason: "compile_failed", message: "The run script does not compile." });
250487
+ return;
250488
+ }
250489
+ const targetPath = join6(savedDir(cwd, scope2), `${name2}.dwf.ts`);
250490
+ if (existsSync3(targetPath) && body.overwrite !== true) {
250491
+ json2(res, 200, { ok: false, reason: "target_exists" });
250492
+ return;
250493
+ }
250494
+ const description = typeof body.description === "string" && body.description.trim() !== "" ? body.description.trim() : row?.name ?? name2;
250495
+ const written = writeSaved(cwd, scope2, { name: name2, description, fromRunId: runId }, script);
250496
+ json2(res, 200, { ok: true, name: name2, scope: scope2, path: describePath(cwd, written) });
250497
+ return;
250498
+ }
250499
+ if (action === "distill") {
250500
+ if (deps.access?.enabled === false) {
250501
+ json2(res, 409, { ok: false, message: "Dynamic workflows are disabled in this deployment." });
250502
+ return;
250503
+ }
250504
+ const body = await readBody(req);
250505
+ const row = deps.service.journal.getRun(runId);
250506
+ const parent = row?.parentSessionId === void 0 ? void 0 : await resolveOwnerAgent(ctx, row.parentSessionId);
250507
+ if (parent === void 0) {
250508
+ json2(res, 409, { ok: false, message: "The session that owns this run is not available." });
250509
+ return;
250510
+ }
250511
+ const name2 = typeof body.name === "string" ? body.name.trim() : "";
250512
+ const scope2 = body.scope === "global" ? "global" : "project";
250513
+ const description = typeof body.description === "string" ? body.description.trim() : "";
250514
+ const rawLocale = typeof body.locale === "string" ? body.locale.toLowerCase() : "";
250515
+ const locale = rawLocale.startsWith("en") ? "en" : rawLocale.startsWith("zh") ? "zh" : /[\u4e00-\u9fff]/u.test(row?.name ?? description) ? "zh" : "en";
250516
+ const prompt = buildDistillSavePrompt({
250517
+ locale,
250518
+ runId,
250519
+ ...row?.name === void 0 ? {} : { runName: row.name },
250520
+ name: name2,
250521
+ scope: scope2,
250522
+ description
250523
+ });
250524
+ deps.access?.activate(parent);
250525
+ const message = userMessage(prompt, { kind: "user" });
250526
+ const live = parent;
250527
+ if (live.status === "idle" || live.steer === void 0) live.followup(message);
250528
+ else live.steer(message);
250529
+ json2(res, 200, { ok: true, sessionId: row?.parentSessionId });
250530
+ return;
250531
+ }
250375
250532
  if (action === "resume") {
250376
250533
  if (deps.access?.enabled === false) {
250377
250534
  json2(res, 409, { ok: false, message: "Dynamic workflows are disabled in this deployment; existing runs can be viewed but not resumed." });
@@ -252518,11 +252675,11 @@ function installGovernor(ctx, governor) {
252518
252675
  }
252519
252676
 
252520
252677
  // src/skill.ts
252521
- import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
252522
- import { join as join6 } from "node:path";
252678
+ import { existsSync as existsSync4, readFileSync as readFileSync2 } from "node:fs";
252679
+ import { join as join7 } from "node:path";
252523
252680
  function loadSkillContent(dir) {
252524
- const file2 = join6(dir, "SKILL.md");
252525
- if (!existsSync3(file2)) return void 0;
252681
+ const file2 = join7(dir, "SKILL.md");
252682
+ if (!existsSync4(file2)) return void 0;
252526
252683
  const text = readFileSync2(file2, "utf8");
252527
252684
  const match = /^---\n([\s\S]*?)\n---\n/.exec(text);
252528
252685
  if (match === null) return { description: "Authoring contract for dynamic-workflow scripts (create_workflow).", content: text };
@@ -252542,11 +252699,11 @@ function loadSkillContent(dir) {
252542
252699
  const description = field("description") ?? "Authoring contract for dynamic-workflow scripts (create_workflow).";
252543
252700
  const whenToUse = field("when_to_use");
252544
252701
  const body = text.slice(match[0].length);
252545
- const resources = ["patterns.md", "examples.md"].filter((name2) => existsSync3(join6(dir, name2)));
252702
+ const resources = ["patterns.md", "examples.md"].filter((name2) => existsSync4(join7(dir, name2)));
252546
252703
  const footer = resources.length === 0 ? "" : `
252547
252704
 
252548
252705
  ---
252549
- Resources next to this skill (read them with the read tool when \xA7"Going deeper" points at them): ${resources.map((name2) => join6(dir, name2)).join(", ")}`;
252706
+ Resources next to this skill (read them with the read tool when \xA7"Going deeper" points at them): ${resources.map((name2) => join7(dir, name2)).join(", ")}`;
252550
252707
  return { description, ...whenToUse === void 0 ? {} : { whenToUse }, content: body + footer };
252551
252708
  }
252552
252709
 
@@ -252784,15 +252941,15 @@ var name = "dynamic-workflow";
252784
252941
  var inject = ["tools", "agents", "systemPrompt"];
252785
252942
  var PROGRESS_EVENT = "plugin:dynamic-workflow/progress";
252786
252943
  function dshHome2() {
252787
- return process.env.DSH_HOME ?? join7(homedir2(), ".dsh");
252944
+ return process.env.DSH_HOME ?? join8(homedir2(), ".dsh");
252788
252945
  }
252789
252946
  function packageRoot() {
252790
- return join7(dirname2(fileURLToPath(import.meta.url)), "..");
252947
+ return join8(dirname2(fileURLToPath(import.meta.url)), "..");
252791
252948
  }
252792
252949
  function apply(ctx, config2 = {}) {
252793
- const stateDir = config2.stateDir ?? join7(dshHome2(), "state", "dynamic-workflow");
252950
+ const stateDir = config2.stateDir ?? join8(dshHome2(), "state", "dynamic-workflow");
252794
252951
  mkdirSync4(stateDir, { recursive: true });
252795
- const db = openJournalDatabase(join7(stateDir, "journal.sqlite"));
252952
+ const db = openJournalDatabase(join8(stateDir, "journal.sqlite"));
252796
252953
  try {
252797
252954
  applyWithDatabase(ctx, config2, stateDir, db);
252798
252955
  } catch (error62) {
@@ -252806,7 +252963,7 @@ function apply(ctx, config2 = {}) {
252806
252963
  function applyWithDatabase(ctx, config2, stateDir, db) {
252807
252964
  const journal = createSqliteJournal(db);
252808
252965
  const escalations = createEscalationRegistry();
252809
- const artifacts = createArtifactStore(join7(stateDir, "artifacts"));
252966
+ const artifacts = createArtifactStore(join8(stateDir, "artifacts"));
252810
252967
  const logger = ctx.logger;
252811
252968
  let service;
252812
252969
  let governor;
@@ -252901,7 +253058,7 @@ function applyWithDatabase(ctx, config2, stateDir, db) {
252901
253058
  interpolate: false,
252902
253059
  text: (context) => context.agent === void 0 ? "" : service.runtimeStatus(context.agent.id)
252903
253060
  });
252904
- const skillDir = join7(packageRoot(), "skills", WORKFLOW_SKILL_NAME);
253061
+ const skillDir = join8(packageRoot(), "skills", WORKFLOW_SKILL_NAME);
252905
253062
  if (access.enabled) ctx.inject(["skills"], (scope) => {
252906
253063
  const skills = scope.get("skills");
252907
253064
  const loaded = loadSkillContent(skillDir);
@@ -252915,7 +253072,7 @@ function applyWithDatabase(ctx, config2, stateDir, db) {
252915
253072
  ...loaded.whenToUse === void 0 ? {} : { whenToUse: loaded.whenToUse },
252916
253073
  content: loaded.content,
252917
253074
  source: "runtime",
252918
- ...existsSync4(skillDir) ? { resourceBase: { kind: "directory", path: skillDir } } : {}
253075
+ ...existsSync5(skillDir) ? { resourceBase: { kind: "directory", path: skillDir } } : {}
252919
253076
  }));
252920
253077
  });
252921
253078
  ctx.inject(["commands"], (scope) => {
@@ -252929,12 +253086,11 @@ function applyWithDatabase(ctx, config2, stateDir, db) {
252929
253086
  if (instructions.length === 0) return { kind: "error", text: "Usage: /workflow <what the workflow should do>" };
252930
253087
  access.activate(invocation.agent);
252931
253088
  invocation.agent.followup(userMessage(
252932
- `/${WORKFLOW_SKILL_NAME} Use a dynamic workflow for this request. If the \`${WORKFLOW_SKILL_NAME}\` skill content is not in this conversation yet, load it with the skill tool first.
253089
+ `/${WORKFLOW_SKILL_NAME} Use the \`${WORKFLOW_SKILL_NAME}\` skill to design and launch a dynamic workflow for this request:
252933
253090
 
252934
- Request:
252935
253091
  ${instructions}
252936
253092
 
252937
- Decide the subagent topology before writing any code: how many subagents, which of them share a context vs. need fresh eyes (for example: design/plan review, independent verification or audit), what typed result each one returns, and what deterministic \`world.run\` gates decide completion. Then write the script and submit it with \`create_workflow\` (do not use DSH's plain-JS \`workflow\` tool, and do not substitute \`subagent\`).`,
253093
+ Decide the subagent topology before writing any code: how many subagents, which of them share a context, what result each one returns. Then write the script and call the \`create_workflow\` tool. (\`create_workflow\` is the dynamic-workflow tool. Do not use DSH's plain-JS \`workflow\` tool, and do not substitute the \`subagent\` tool.)`,
252938
253094
  { kind: "user" }
252939
253095
  ));
252940
253096
  return { kind: "success" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigmacamellia/dsh-dynamic-workflow",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Typechecked TypeScript multi-agent dynamic workflow plugin for DeepSeek Harness (DSH): parallel subagents, SQLite durable journal (resume / amend / holes / escalations), vertical spine timeline, and live dashboard artifacts. Ported from ZCode (Apache-2.0).",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -774,9 +774,8 @@ reported item. Do other work, unless the user asked you to wait.
774
774
 
775
775
  When you genuinely need to look at a run:
776
776
 
777
- - `get_workflow_run` blocks until a run *this session started* finishes: the waiting tool.
778
- - `get_workflow_run` is an instant snapshot; use it when you must not block, or for a run
779
- another session owns, which `get_workflow_run` cannot see.
777
+ - `get_workflow_run` is an instant snapshot (never blocks, and sees runs started by this or
778
+ another session). Do not call it in a loop to wait — completion arrives through notifications.
780
779
  - `list_workflow_runs` enumerates the project's runs, including other sessions'.
781
780
 
782
781
  Read the terminal state precisely. A run ends in exactly one of three states:
@@ -1578,6 +1577,9 @@ Saves a script with its metadata so it can be run again by name — through `cre
1578
1577
  directory, a depth. Each declaration gives a `type` (`string`, `number`,
1579
1578
  `boolean`, or `json` for anything else), and optionally a `description`, `required: true`
1580
1579
  and a `default`; every future call is validated against them.
1580
+ - `from_run_id`: provenance only — the id of the run this workflow was distilled from, when
1581
+ saving a workflow that just ran. Pass it whenever you know it; it lets that run's card show
1582
+ that it has been saved.
1581
1583
 
1582
1584
  The saved file is valid TypeScript: a `/* dsh-workflow` block of JSON metadata, then the
1583
1585
  script verbatim. The script is typechecked by the same compiler as `create_workflow`, before