Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a084ed386b | |||
| 22bffc5fcd | |||
| 4c5cc27d52 | |||
| 031ecc6f7e | |||
| e4c46c8150 |
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: "Agent as Graduate — The Onboarding Metaphor"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [concept, analogy]
|
||||
category: "product"
|
||||
links:
|
||||
- vendor-vs-fte-who-defines-capability
|
||||
- three-learning-carriers
|
||||
- fte-maturity-threshold
|
||||
---
|
||||
|
||||
FTE 型 agent 最贴切的类比:**应届毕业生**。
|
||||
|
||||
出厂时有通用能力(底座模型 = 学历),但不懂你的业务、不知道你的偏好、没有你的流程经验。用户的角色是"带教老师"——通过日常协作,逐步把 agent 带成自己的得力助手。
|
||||
|
||||
这个类比揭示了当前 FTE 产品的核心瓶颈:**带教门槛太高**。现在只有技术背景深厚的用户才能"带"——能写 skill、能调 workflow、能 debug agent 行为。行业专家(不懂代码的人)被挡在门外。
|
||||
|
||||
真正成熟的 FTE 型产品 = 降低带教门槛,让非技术用户也能教会 agent 自己的业务。
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
title: "Deterministic Engine, Uncertain Agent"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [architecture, decision]
|
||||
category: "architecture"
|
||||
links:
|
||||
- process-discipline-from-software-engineering
|
||||
- session-isolation-as-cognitive-reset
|
||||
---
|
||||
|
||||
uwf 的架构将确定性和不确定性严格分层。
|
||||
|
||||
Engine 层(moderator 纯查表、CAS 不可变、每步原子化)是刚性的——流程骨架本身不能成为另一个不可靠的环节。LLM 的不确定性被严格约束在 agent session 内部。
|
||||
|
||||
这个选择意味着:调度逻辑完全可预测、可调试、可审计。出问题时你知道问题一定在某个 session 的产出里,不在流程逻辑里。
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
title: "Dissipative Structure — Token for Entropy Reduction"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [architecture, pattern]
|
||||
category: "architecture"
|
||||
links:
|
||||
- process-discipline-from-software-engineering
|
||||
- session-isolation-as-cognitive-reset
|
||||
---
|
||||
|
||||
uwf 本质上是一种耗散结构:通过消耗能量(token)实现熵减。
|
||||
|
||||
一个 AI session 做长了会漂移、会累积错误、会失去焦点。把一件事拆成多个有明确边界的 session,让它们从不同角度相互校验,比一个 session 从头做到尾更可靠。多花的 token 就是耗散的能量,换来的是更低的交付熵——更可预测、更高质量的产出。
|
||||
|
||||
这与人类工程实践中引入 review、测试、灰度等流程的逻辑一致:都是在用额外成本换系统可靠性。
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: "FTE Maturity Threshold — Who Can Onboard an Agent"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [concept, decision]
|
||||
category: "product"
|
||||
links:
|
||||
- agent-as-graduate
|
||||
- vendor-vs-fte-who-defines-capability
|
||||
- three-learning-carriers
|
||||
---
|
||||
|
||||
FTE 型 agent 的成熟度,归根结底看一个问题:**谁能带教它?**
|
||||
|
||||
当前阶段(2026):OpenClaw、Claude Code、Hermes 都是 FTE 型产品的雏形,三者都具备 memory/skill/workflow 三个载体。但它们的用户画像高度重叠——有较深技术能力的开发者。
|
||||
|
||||
这意味着 FTE agent 现在更像"只有技术 lead 才能带的毕业生"。要跨越鸿沟,需要降低带教门槛到**行业专家(不懂代码的人)也能带、也能教、也能调优**。
|
||||
|
||||
谁先把这个门槛降下来,谁就定义了 FTE agent 品类的分水岭。
|
||||
|
||||
可能的降低路径:
|
||||
- **自然语言 skill 定义**(不需要写代码/YAML)
|
||||
- **可视化 workflow 编辑**(拖拽而非配置)
|
||||
- **Agent 主动学习**(从用户行为中推断偏好,而非等用户显式配置)
|
||||
- **带教过程本身被 agent 化**(用 agent 辅助用户定义 skill 和 workflow)
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
title: "FTE Product Landscape — OpenClaw, Claude Code, Hermes"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [concept, comparison]
|
||||
category: "product"
|
||||
links:
|
||||
- vendor-vs-fte-who-defines-capability
|
||||
- three-learning-carriers
|
||||
- fte-maturity-threshold
|
||||
- agent-as-graduate
|
||||
---
|
||||
|
||||
2026 年中,FTE 型 agent 的代表产品对比:
|
||||
|
||||
**共性**:都有 memory、skill、workflow/多步协作机制,都面向技术用户。
|
||||
|
||||
**差异点**:
|
||||
- **OpenClaw** — uwf 引擎驱动,用 YAML 定义多角色 workflow,强调流程纪律和 session 隔离。面向团队级 agent 协作。
|
||||
- **Claude Code** — Anthropic 官方 CLI agent,CLAUDE.md 作为 memory,skill 通过项目约定积累。单 agent 深度协作,开发者体验好。
|
||||
- **Hermes** — 跨平台 agent 协调者,memory/skill/cron 体系完善,支持多 agent 调度。偏个人效率工具。
|
||||
|
||||
三者都谈不上成熟。成熟的标志不是技术完备度,而是**非技术用户能否用起来**。
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: "OPC — Why FTE Agents Matter Most"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [vision, decision]
|
||||
category: "product"
|
||||
links:
|
||||
- vendor-vs-fte-who-defines-capability
|
||||
- agent-as-graduate
|
||||
- fte-maturity-threshold
|
||||
---
|
||||
|
||||
OpenClaw 押注 FTE 型 agent 的核心判断:**AI 的终极形态不是工具,是同事。**
|
||||
|
||||
工具被使用,同事被培养。工具的价值在出厂那一刻确定,同事的价值随协作持续增长。
|
||||
|
||||
这个判断决定了产品方向:
|
||||
- 不做"最强的单次对话",做"最能被带教的长期协作者"
|
||||
- 不做"开箱即用的成品",做"越用越好用的底座"
|
||||
- 核心指标不是 benchmark 分数,是用户留存和 skill 积累量
|
||||
|
||||
uwf 是这个判断的工程实现——用流程纪律让 agent 的产出可靠,让用户敢把真正的业务交给它。
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
title: "Process Discipline from Software Engineering"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [architecture, pattern, decision]
|
||||
category: "architecture"
|
||||
links:
|
||||
- session-isolation-as-cognitive-reset
|
||||
- role-is-not-agent
|
||||
- dissipative-structure-token-for-entropy
|
||||
- deterministic-engine-uncertain-agent
|
||||
---
|
||||
|
||||
uwf 的发心是将人类软件工程的流程纪律应用到 AI agent 上。
|
||||
|
||||
人类早已验证:个体不可靠,但流程可以让不可靠的个体组成可靠的系统。Code review 不是因为不信任程序员,而是**写代码和审代码是两种认知模式**,一个人很难同时做好。测试、灰度、回滚——每一层都是在用额外成本换确定性。
|
||||
|
||||
uwf 把这套搬过来:planner 和 reviewer 可以是同一个 agent,但流程迫使它在不同 session 里切换视角,形成自我制衡。用 role 和 role 之间的流转关系,**把做一件事的步骤固定下来**。
|
||||
|
||||
PR #148 vs #142 是直接证据——不是换了更强的 agent,是同样的 agent,换了协作结构。
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
title: "Role Is Not Agent"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [architecture, decision]
|
||||
category: "architecture"
|
||||
links:
|
||||
- session-isolation-as-cognitive-reset
|
||||
- process-discipline-from-software-engineering
|
||||
---
|
||||
|
||||
在 uwf 体系里,role ≠ agent。一个 thread 跑的过程中,所有 role 往往由**同一个 agent** 扮演。
|
||||
|
||||
Role 对应的是 agent 的 **session**——为了解决一个问题,需要多个 session 从不同角度观察和行动、相互制衡。角色可以在流程中多次重入,重入时**复用**同一个 session(保持角色内记忆连续),隔离发生在角色之间,不是每一步。
|
||||
|
||||
这个区分决定了 uwf 的设计不是在做"任务分发给不同 agent",而是在做**一个 agent 的多视角自我协作**。
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
title: "Session Isolation as Cognitive Reset"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [architecture, decision, pattern]
|
||||
category: "architecture"
|
||||
links:
|
||||
- role-is-not-agent
|
||||
- dissipative-structure-token-for-entropy
|
||||
- process-discipline-from-software-engineering
|
||||
---
|
||||
|
||||
uwf 的核心机制不是"多 agent 协调",而是**用 session 隔离实现视角切换**。
|
||||
|
||||
同一个 agent 以不同 role 进入时,得到的是全新的认知上下文——没有惯性、没有确认偏误。CAS 链传递工作成果,但认知状态是重置的。Role 定义(goal、procedure、output schema)塑造每个 session 的关注点和行为边界。
|
||||
|
||||
这解释了为什么 stateless 单步设计这么重要:engine 确保每次角色切换都是一个干净的 session 入口。
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
title: "Switching Cost — Process Knowledge as Moat"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [concept, decision]
|
||||
category: "product"
|
||||
links:
|
||||
- vendor-vs-fte-who-defines-capability
|
||||
- three-learning-carriers
|
||||
- agent-as-graduate
|
||||
---
|
||||
|
||||
FTE 型 agent 的护城河不是技术壁垒,是**用户自己积累的流程知识**。
|
||||
|
||||
用得越久,agent 越懂你的业务——记忆里有你的偏好,skill 里有你验证过的做法,workflow 里有你打磨过的流程。换一个 agent = 重新带一个毕业生,之前的积累全部作废。
|
||||
|
||||
这解释了为什么 FTE 型产品的竞争逻辑和 vendor 型完全不同:
|
||||
- **Vendor 型**竞争模型能力(谁的基座更强),switching cost 低,用户随时换
|
||||
- **FTE 型**竞争生态粘性(谁让用户积累得更深),switching cost 随使用时长增长
|
||||
|
||||
风险面:如果用户的流程知识被锁死在一个平台,就变成了 vendor lock-in。开放的知识格式(如 markdown skill、YAML workflow)是对冲手段。
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
title: "Three Learning Carriers — Memory, Skill, Workflow"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [architecture, concept]
|
||||
category: "product"
|
||||
links:
|
||||
- vendor-vs-fte-who-defines-capability
|
||||
- agent-as-graduate
|
||||
- switching-cost-process-knowledge-as-moat
|
||||
---
|
||||
|
||||
FTE 型 agent 的能力积累依赖三个载体:
|
||||
|
||||
1. **Memory(记忆)**— 用户偏好、环境事实、历史上下文。跨 session 持久化,让 agent 不用每次从零开始。
|
||||
2. **Skill(技能)**— 可复用的操作程序。解决过的问题沉淀成步骤,下次直接调用。
|
||||
3. **Workflow / DW(流程)**— 多步骤协作模式。把复杂任务拆成角色和阶段,用流程纪律保障质量。
|
||||
|
||||
三者的关系:memory 是"认识你",skill 是"会做事",workflow 是"知道怎么把事做好"。
|
||||
|
||||
OpenClaw、Claude Code、Hermes 都已具备这三个载体,但成熟度各异。差异在于:用户能多容易地往这三个载体里"灌"自己的知识。
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
title: "Vendor vs FTE — Who Defines the Agent's Capability"
|
||||
created: "2026-06-07"
|
||||
source: "openclaw-xiaomo"
|
||||
tags: [architecture, decision]
|
||||
category: "architecture"
|
||||
links:
|
||||
- agent-as-graduate
|
||||
- three-learning-carriers
|
||||
- switching-cost-process-knowledge-as-moat
|
||||
- opc-why-fte-agents-matter-most
|
||||
---
|
||||
|
||||
区分 vendor 型和 FTE 型 agent 最本质的一条:**谁定义 agent 的能力。**
|
||||
|
||||
- **Vendor 型**:开发者定义能力,用户消费能力。能力边界在发布那一刻就定了,升级主动权在开发者。
|
||||
- **FTE 型**:开发者定义出厂能力(底座模型 + 基础技能包),用户持续定义能力(记忆、skill、workflow)。
|
||||
|
||||
出厂是起点不是终点。用户通过积累记忆、训练 skill、设计 workflow,持续塑造 agent 的能力。用得越久,越贴合自己的业务,越不像别人的 agent。
|
||||
|
||||
引申的两个特征:
|
||||
- **成长性** — vendor 的能力随模型升级变化,不随使用积累;FTE 的能力随使用持续积累
|
||||
- **流程适配性** — vendor 是用户适应工具;FTE 是工具适应用户的业务流程
|
||||
|
||||
这也解释了 switching cost 的来源——换掉的不是一个产品,是用户自己定义出来的能力。
|
||||
|
||||
代表产品:
|
||||
- **Vendor 型**:ChatGPT、Claude(对话式)、Midjourney(图像生成)、Perplexity(搜索问答)、各种 GPTs
|
||||
- **FTE 型**:OpenClaw、Claude Code、Hermes 都在往这个方向走——有记忆、有 skill/workflow 机制、有持续协作关系。但尚未成熟,目前都面向有较深技术能力的用户。真正成熟的 FTE 型产品,应该是行业专家(不懂代码的人)也能带、也能教、也能调优的。这个门槛什么时候降下来,谁先降下来,可能就是这个品类的分水岭。
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
"@united-workforce/cli": minor
|
||||
---
|
||||
|
||||
feat(cli): add `uwf thread poke` command
|
||||
|
||||
New subcommand `uwf thread poke <thread-id> -p <prompt>` re-runs the head step's
|
||||
agent with a supplementary prompt, replacing the head step's output. Unlike
|
||||
`thread resume`, poke skips the moderator and rewrites the new step's `prev`
|
||||
pointer so the new head replaces (not appends to) the old head. Works on idle
|
||||
and suspended threads. Resolves issue #144 (Phase 1).
|
||||
@@ -0,0 +1,549 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { putSchema } from "@ocas/core";
|
||||
import { openStore } from "@ocas/fs";
|
||||
import type {
|
||||
CasRef,
|
||||
StepNodePayload,
|
||||
ThreadId,
|
||||
ThreadIndexEntry,
|
||||
} from "@united-workforce/protocol";
|
||||
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||
import { registerUwfSchemas } from "../schemas.js";
|
||||
import { seedThreads } from "./thread-test-helpers.js";
|
||||
|
||||
const OUTPUT_SCHEMA = {
|
||||
type: "object" as const,
|
||||
properties: {
|
||||
$status: { type: "string" as const },
|
||||
note: { type: "string" as const },
|
||||
},
|
||||
required: ["$status"],
|
||||
additionalProperties: false,
|
||||
};
|
||||
|
||||
const THREAD_ID = "01POKESTEPTEST00000000" as ThreadId;
|
||||
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
tmpDir = await mkdtemp(join(tmpdir(), "cli-uwf-poke-test-"));
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await rm(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
type SetupResult = {
|
||||
casDir: string;
|
||||
oldStepHash: CasRef;
|
||||
oldStepPrev: CasRef | null;
|
||||
oldStepCompletedAtMs: number;
|
||||
startHash: CasRef;
|
||||
workflowHash: CasRef;
|
||||
mockAgentPath: string;
|
||||
failingAgentPath: string;
|
||||
promptCapturePath: string;
|
||||
envCapturePath: string;
|
||||
};
|
||||
|
||||
type SetupOpts = {
|
||||
threadStatus: ThreadIndexEntry["status"];
|
||||
multipleSteps: boolean;
|
||||
newCompletedAtMs: number;
|
||||
newStatus: string;
|
||||
// The agent name to record in the head StepNode.agent field. Defaults to mockAgentPath.
|
||||
stepAgentNameOverride: string | null;
|
||||
// Whether to seed an actual head StepNode (false → only StartNode is the head).
|
||||
withHeadStep: boolean;
|
||||
};
|
||||
|
||||
async function setupThread(opts: Partial<SetupOpts> = {}): Promise<SetupResult> {
|
||||
const cfg: SetupOpts = {
|
||||
threadStatus: opts.threadStatus ?? "idle",
|
||||
multipleSteps: opts.multipleSteps ?? false,
|
||||
newCompletedAtMs: opts.newCompletedAtMs ?? 1716600005000,
|
||||
newStatus: opts.newStatus ?? "ok",
|
||||
stepAgentNameOverride: opts.stepAgentNameOverride ?? null,
|
||||
withHeadStep: opts.withHeadStep ?? true,
|
||||
};
|
||||
|
||||
const casDir = join(tmpDir, "cas");
|
||||
await mkdir(casDir, { recursive: true });
|
||||
|
||||
const store = await openStore(casDir);
|
||||
const schemas = await registerUwfSchemas(store);
|
||||
const outputSchemaHash = await putSchema(store, OUTPUT_SCHEMA);
|
||||
|
||||
const workflowHash = await store.cas.put(schemas.workflow, {
|
||||
name: "test-poke",
|
||||
description: "poke command integration test",
|
||||
roles: {
|
||||
worker: {
|
||||
description: "Worker role",
|
||||
goal: "Work",
|
||||
capabilities: [],
|
||||
procedure: "work",
|
||||
output: "result",
|
||||
frontmatter: outputSchemaHash,
|
||||
},
|
||||
reviewer: {
|
||||
description: "Reviewer role",
|
||||
goal: "Review",
|
||||
capabilities: [],
|
||||
procedure: "review",
|
||||
output: "result",
|
||||
frontmatter: outputSchemaHash,
|
||||
},
|
||||
},
|
||||
graph: {
|
||||
$START: {
|
||||
new: { role: "worker", prompt: "Start work", location: null },
|
||||
resume: { role: "worker", prompt: "Resume the work", location: null },
|
||||
},
|
||||
worker: {
|
||||
ok: { role: "reviewer", prompt: "Review the work", location: null },
|
||||
needs_input: {
|
||||
role: "$SUSPEND",
|
||||
prompt: "Please clarify",
|
||||
location: null,
|
||||
},
|
||||
},
|
||||
reviewer: { done: { role: "$END", prompt: "Done", location: null } },
|
||||
},
|
||||
});
|
||||
|
||||
const startHash = await store.cas.put(schemas.startNode, {
|
||||
workflow: workflowHash,
|
||||
prompt: "Test poke task",
|
||||
cwd: tmpDir,
|
||||
});
|
||||
|
||||
process.env.OCAS_HOME = casDir;
|
||||
|
||||
// Paths for mock agent and capture files (set early so we can use mockAgentPath as the recorded agent name)
|
||||
const promptCapturePath = join(tmpDir, "captured-prompt.txt");
|
||||
const envCapturePath = join(tmpDir, "captured-env.txt");
|
||||
const mockAgentPath = join(tmpDir, "mock-agent.sh");
|
||||
const failingAgentPath = join(tmpDir, "failing-agent.sh");
|
||||
|
||||
// Build head StepNode chain
|
||||
let oldStepPrev: CasRef | null = null;
|
||||
if (cfg.multipleSteps) {
|
||||
// First step: prev=null
|
||||
const firstOutputHash = await store.cas.put(outputSchemaHash, { $status: "ok" });
|
||||
const firstDetailHash = await store.cas.put(schemas.text, "first detail");
|
||||
const firstStepHash = await store.cas.put(schemas.stepNode, {
|
||||
start: startHash,
|
||||
prev: null,
|
||||
role: "worker",
|
||||
output: firstOutputHash,
|
||||
detail: firstDetailHash,
|
||||
agent: cfg.stepAgentNameOverride ?? mockAgentPath,
|
||||
edgePrompt: "Start work",
|
||||
startedAtMs: 1716600000000,
|
||||
completedAtMs: 1716600001000,
|
||||
cwd: tmpDir,
|
||||
assembledPrompt: null,
|
||||
usage: null,
|
||||
});
|
||||
oldStepPrev = firstStepHash;
|
||||
}
|
||||
|
||||
let oldStepHash: CasRef = startHash;
|
||||
const oldStepCompletedAtMs = 1716600002000;
|
||||
if (cfg.withHeadStep) {
|
||||
const outputHash = await store.cas.put(outputSchemaHash, { $status: "ok" });
|
||||
const detailHash = await store.cas.put(schemas.text, "head step detail");
|
||||
oldStepHash = await store.cas.put(schemas.stepNode, {
|
||||
start: startHash,
|
||||
prev: oldStepPrev,
|
||||
role: "worker",
|
||||
output: outputHash,
|
||||
detail: detailHash,
|
||||
agent: cfg.stepAgentNameOverride ?? mockAgentPath,
|
||||
edgePrompt: "Start work",
|
||||
startedAtMs: 1716600001500,
|
||||
completedAtMs: oldStepCompletedAtMs,
|
||||
cwd: tmpDir,
|
||||
assembledPrompt: null,
|
||||
usage: null,
|
||||
});
|
||||
}
|
||||
|
||||
// Seed thread index entry. For "running" we let the test create the marker separately.
|
||||
await seedThreads(tmpDir, {
|
||||
[THREAD_ID]: {
|
||||
head: oldStepHash,
|
||||
status: cfg.threadStatus,
|
||||
suspendedRole: cfg.threadStatus === "suspended" ? "worker" : null,
|
||||
suspendMessage: cfg.threadStatus === "suspended" ? "Please clarify" : null,
|
||||
completedAt:
|
||||
cfg.threadStatus === "completed" || cfg.threadStatus === "cancelled"
|
||||
? oldStepCompletedAtMs
|
||||
: null,
|
||||
},
|
||||
});
|
||||
|
||||
// Mock agent always emits a stepNode keyed off the current thread head (which we
|
||||
// observe through OCAS_HOME). The script writes prompt/env captures and then prints
|
||||
// an adapter JSON that references a pre-built stepHash.
|
||||
// We pre-build the agent's stepHash with prev=oldStepHash (normal append behaviour).
|
||||
const newOutputHash = await store.cas.put(outputSchemaHash, {
|
||||
$status: cfg.newStatus,
|
||||
note: "poked output",
|
||||
});
|
||||
const newDetailHash = await store.cas.put(schemas.text, "poked detail");
|
||||
const agentStepHash = await store.cas.put(schemas.stepNode, {
|
||||
start: startHash,
|
||||
prev: cfg.withHeadStep ? oldStepHash : null,
|
||||
role: "worker",
|
||||
output: newOutputHash,
|
||||
detail: newDetailHash,
|
||||
agent: "mock-agent-output",
|
||||
edgePrompt: "poke prompt placeholder",
|
||||
startedAtMs: cfg.newCompletedAtMs - 100,
|
||||
completedAtMs: cfg.newCompletedAtMs,
|
||||
cwd: tmpDir,
|
||||
assembledPrompt: null,
|
||||
usage: null,
|
||||
});
|
||||
|
||||
const adapterJson = JSON.stringify({
|
||||
stepHash: agentStepHash,
|
||||
detailHash: newDetailHash,
|
||||
role: "worker",
|
||||
frontmatter: { $status: cfg.newStatus, note: "poked output" },
|
||||
body: "",
|
||||
startedAtMs: cfg.newCompletedAtMs - 100,
|
||||
completedAtMs: cfg.newCompletedAtMs,
|
||||
usage: null,
|
||||
});
|
||||
|
||||
await writeFile(
|
||||
mockAgentPath,
|
||||
`#!/bin/sh
|
||||
prompt=""
|
||||
while [ $# -gt 0 ]; do
|
||||
if [ "$1" = "--prompt" ]; then
|
||||
prompt="$2"
|
||||
shift 2
|
||||
else
|
||||
shift
|
||||
fi
|
||||
done
|
||||
printf '%s' "$prompt" > '${promptCapturePath}'
|
||||
printf 'OCAS_HOME=%s\\n' "$OCAS_HOME" > '${envCapturePath}'
|
||||
echo '${adapterJson}'
|
||||
`,
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
|
||||
await writeFile(
|
||||
failingAgentPath,
|
||||
`#!/bin/sh
|
||||
echo "boom" >&2
|
||||
exit 7
|
||||
`,
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
|
||||
const configPath = join(tmpDir, "config.yaml");
|
||||
await writeFile(
|
||||
configPath,
|
||||
`defaultAgent: uwf-hermes\ndefaultModel: test-model\nagentOverrides: null\nagents: {}\nproviders: {}\nmodels: {}\n`,
|
||||
);
|
||||
|
||||
return {
|
||||
casDir,
|
||||
oldStepHash,
|
||||
oldStepPrev,
|
||||
oldStepCompletedAtMs,
|
||||
startHash,
|
||||
workflowHash,
|
||||
mockAgentPath,
|
||||
failingAgentPath,
|
||||
promptCapturePath,
|
||||
envCapturePath,
|
||||
};
|
||||
}
|
||||
|
||||
function runUwf(
|
||||
args: string[],
|
||||
casDir: string,
|
||||
): { stdout: string; stderr: string; status: number } {
|
||||
const cliPath = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "dist", "cli.js");
|
||||
try {
|
||||
const stdout = execFileSync(process.execPath, [cliPath, ...args], {
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
env: {
|
||||
...process.env,
|
||||
UWF_HOME: tmpDir,
|
||||
OCAS_HOME: casDir,
|
||||
},
|
||||
cwd: tmpDir,
|
||||
timeout: 30000,
|
||||
});
|
||||
return { stdout, stderr: "", status: 0 };
|
||||
} catch (error) {
|
||||
const err = error as NodeJS.ErrnoException & {
|
||||
stdout?: string | Buffer;
|
||||
stderr?: string | Buffer;
|
||||
status?: number;
|
||||
};
|
||||
return {
|
||||
stdout: typeof err.stdout === "string" ? err.stdout : (err.stdout?.toString("utf8") ?? ""),
|
||||
stderr: typeof err.stderr === "string" ? err.stderr : (err.stderr?.toString("utf8") ?? ""),
|
||||
status: err.status ?? 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ── Group 1: CLI argument validation ───────────────────────────────────────
|
||||
|
||||
describe("uwf thread poke - CLI argument validation", () => {
|
||||
test("1.1 missing -p flag exits non-zero", async () => {
|
||||
const { casDir } = await setupThread();
|
||||
const result = runUwf(["thread", "poke", THREAD_ID], casDir);
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr.toLowerCase()).toMatch(/required|missing|prompt/);
|
||||
});
|
||||
|
||||
test("1.2 -p without --agent succeeds", async () => {
|
||||
const { casDir } = await setupThread();
|
||||
const result = runUwf(["thread", "poke", THREAD_ID, "-p", "do it again"], casDir);
|
||||
expect(result.status).toBe(0);
|
||||
});
|
||||
|
||||
test("1.3 -p with --agent succeeds", async () => {
|
||||
const { casDir, mockAgentPath } = await setupThread();
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "do it again", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Group 2: Guard errors ──────────────────────────────────────────────────
|
||||
|
||||
describe("uwf thread poke - guard errors", () => {
|
||||
test("2.1 thread not found", async () => {
|
||||
const { casDir } = await setupThread();
|
||||
const result = runUwf(["thread", "poke", "01NOSUCHTHREAD0000000A", "-p", "prompt"], casDir);
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr.toLowerCase()).toMatch(/not found|not active/);
|
||||
});
|
||||
|
||||
test("2.2 thread running rejects poke", async () => {
|
||||
const { casDir, workflowHash } = await setupThread();
|
||||
// Create background marker to simulate running
|
||||
const { createMarker } = await import("../background/index.js");
|
||||
await createMarker(tmpDir, {
|
||||
thread: THREAD_ID,
|
||||
workflow: workflowHash,
|
||||
pid: process.pid,
|
||||
startedAt: Date.now(),
|
||||
});
|
||||
|
||||
const result = runUwf(["thread", "poke", THREAD_ID, "-p", "prompt"], casDir);
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr.toLowerCase()).toContain("already executing");
|
||||
});
|
||||
|
||||
test("2.3 completed thread rejects poke", async () => {
|
||||
const { casDir } = await setupThread({ threadStatus: "completed" });
|
||||
const result = runUwf(["thread", "poke", THREAD_ID, "-p", "prompt"], casDir);
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr.toLowerCase()).toMatch(/cannot be poked|completed/);
|
||||
});
|
||||
|
||||
test("2.4 cancelled thread rejects poke", async () => {
|
||||
const { casDir } = await setupThread({ threadStatus: "cancelled" });
|
||||
const result = runUwf(["thread", "poke", THREAD_ID, "-p", "prompt"], casDir);
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr.toLowerCase()).toMatch(/cannot be poked|cancelled/);
|
||||
});
|
||||
|
||||
test("2.5 thread head is StartNode (no StepNode) rejects poke", async () => {
|
||||
const { casDir } = await setupThread({ withHeadStep: false });
|
||||
const result = runUwf(["thread", "poke", THREAD_ID, "-p", "prompt"], casDir);
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr.toLowerCase()).toMatch(/no step|cannot be poked/);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Group 3: Success happy path ────────────────────────────────────────────
|
||||
|
||||
describe("uwf thread poke - success", () => {
|
||||
test("3.1, 3.4 idle thread → new head differs from old, thread index updated", async () => {
|
||||
const { casDir, oldStepHash, mockAgentPath } = await setupThread();
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const cliOutput = JSON.parse(result.stdout.trim());
|
||||
expect(cliOutput.head).not.toBe(oldStepHash);
|
||||
|
||||
const { createUwfStore, getThread } = await import("../store.js");
|
||||
const uwf = await createUwfStore(tmpDir);
|
||||
const entry = getThread(uwf.varStore, THREAD_ID);
|
||||
expect(entry?.head).toBe(cliOutput.head);
|
||||
});
|
||||
|
||||
test("3.2 new step's prev equals old head's prev (replace, not append)", async () => {
|
||||
const { casDir, oldStepPrev, mockAgentPath } = await setupThread({ multipleSteps: true });
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const cliOutput = JSON.parse(result.stdout.trim());
|
||||
|
||||
const { createUwfStore } = await import("../store.js");
|
||||
const uwf = await createUwfStore(tmpDir);
|
||||
const node = uwf.store.cas.get(cliOutput.head as CasRef);
|
||||
expect(node).not.toBeNull();
|
||||
expect(node?.type).toBe(uwf.schemas.stepNode);
|
||||
const payload = node?.payload as StepNodePayload;
|
||||
expect(payload.prev).toBe(oldStepPrev);
|
||||
});
|
||||
|
||||
test("3.2b new step's prev is null when old head was the first step", async () => {
|
||||
// multipleSteps:false means oldHead.prev = null
|
||||
const { casDir, mockAgentPath } = await setupThread({ multipleSteps: false });
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const cliOutput = JSON.parse(result.stdout.trim());
|
||||
|
||||
const { createUwfStore } = await import("../store.js");
|
||||
const uwf = await createUwfStore(tmpDir);
|
||||
const node = uwf.store.cas.get(cliOutput.head as CasRef);
|
||||
const payload = node?.payload as StepNodePayload;
|
||||
expect(payload.prev).toBeNull();
|
||||
});
|
||||
|
||||
test("3.3 new step's completedAtMs is later than old", async () => {
|
||||
const { casDir, oldStepCompletedAtMs, mockAgentPath } = await setupThread();
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const cliOutput = JSON.parse(result.stdout.trim());
|
||||
|
||||
const { createUwfStore } = await import("../store.js");
|
||||
const uwf = await createUwfStore(tmpDir);
|
||||
const node = uwf.store.cas.get(cliOutput.head as CasRef);
|
||||
const payload = node?.payload as StepNodePayload;
|
||||
expect(payload.completedAtMs).toBeGreaterThan(oldStepCompletedAtMs);
|
||||
});
|
||||
|
||||
test("3.5 status remains idle after poke (no completion/suspend)", async () => {
|
||||
const { casDir, mockAgentPath } = await setupThread();
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const cliOutput = JSON.parse(result.stdout.trim());
|
||||
expect(cliOutput.status).toBe("idle");
|
||||
expect(cliOutput.done).toBe(false);
|
||||
expect(cliOutput.suspendedRole).toBeNull();
|
||||
expect(cliOutput.suspendMessage).toBeNull();
|
||||
});
|
||||
|
||||
test("3.6 currentRole unchanged after poke (no moderator re-route)", async () => {
|
||||
// Before poke: idle thread with worker step having $status=ok → moderator would route to reviewer.
|
||||
// After poke (mock returns same $status=ok), moderator routing remains the same.
|
||||
const { casDir, mockAgentPath } = await setupThread();
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const cliOutput = JSON.parse(result.stdout.trim());
|
||||
expect(cliOutput.currentRole).toBe("reviewer");
|
||||
});
|
||||
});
|
||||
|
||||
// ── Group 4: Agent resolution ──────────────────────────────────────────────
|
||||
|
||||
describe("uwf thread poke - agent resolution", () => {
|
||||
test("4.1 without --agent, agent command read from head step's agent field", async () => {
|
||||
// Head step's agent field points at mockAgentPath (default in setupThread)
|
||||
const { casDir, promptCapturePath } = await setupThread();
|
||||
const result = runUwf(["thread", "poke", THREAD_ID, "-p", "redo"], casDir);
|
||||
expect(result.status).toBe(0);
|
||||
const captured = await readFile(promptCapturePath, "utf8");
|
||||
expect(captured).toBe("redo");
|
||||
});
|
||||
|
||||
test("4.2 with --agent, explicit override is used", async () => {
|
||||
// Head step records "uwf-mock" (which is not a real binary). Override with mockAgentPath.
|
||||
const { casDir, mockAgentPath } = await setupThread({ stepAgentNameOverride: "uwf-mock" });
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Group 5: Prompt passthrough ────────────────────────────────────────────
|
||||
|
||||
describe("uwf thread poke - prompt passthrough", () => {
|
||||
test("5.1 -p value is passed to agent as --prompt", async () => {
|
||||
const { casDir, mockAgentPath, promptCapturePath } = await setupThread();
|
||||
const supplement = "Use the REST API instead.";
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", supplement, "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const captured = await readFile(promptCapturePath, "utf8");
|
||||
expect(captured).toBe(supplement);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Group 6: Edge cases ────────────────────────────────────────────────────
|
||||
|
||||
describe("uwf thread poke - edge cases", () => {
|
||||
test("6.1 poke succeeds on suspended thread", async () => {
|
||||
const { casDir, oldStepHash, mockAgentPath } = await setupThread({
|
||||
threadStatus: "suspended",
|
||||
});
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", mockAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const cliOutput = JSON.parse(result.stdout.trim());
|
||||
expect(cliOutput.head).not.toBe(oldStepHash);
|
||||
expect(cliOutput.status).toBe("idle");
|
||||
expect(cliOutput.suspendedRole).toBeNull();
|
||||
expect(cliOutput.suspendMessage).toBeNull();
|
||||
});
|
||||
|
||||
test("6.2 agent failure leaves thread head unchanged", async () => {
|
||||
const { casDir, oldStepHash, failingAgentPath } = await setupThread();
|
||||
const result = runUwf(
|
||||
["thread", "poke", THREAD_ID, "-p", "redo", "--agent", failingAgentPath],
|
||||
casDir,
|
||||
);
|
||||
expect(result.status).not.toBe(0);
|
||||
|
||||
const { createUwfStore, getThread } = await import("../store.js");
|
||||
const uwf = await createUwfStore(tmpDir);
|
||||
const entry = getThread(uwf.varStore, THREAD_ID);
|
||||
expect(entry?.head).toBe(oldStepHash);
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
cmdThreadCancel,
|
||||
cmdThreadExec,
|
||||
cmdThreadList,
|
||||
cmdThreadPoke,
|
||||
cmdThreadRead,
|
||||
cmdThreadResume,
|
||||
cmdThreadShow,
|
||||
@@ -290,6 +291,26 @@ thread
|
||||
});
|
||||
});
|
||||
|
||||
thread
|
||||
.command("poke")
|
||||
.description("Re-run the head step's agent with a supplementary prompt (replaces head step)")
|
||||
.argument("<thread-id>", "Thread ULID")
|
||||
.requiredOption("-p, --prompt <text>", "Supplementary prompt for the agent")
|
||||
.option("--agent <cmd>", "Override agent command (defaults to head step's agent)")
|
||||
.action((threadId: string, opts: { prompt: string; agent: string | undefined }) => {
|
||||
const storageRoot = resolveStorageRoot();
|
||||
runAction(async () => {
|
||||
const agentOverride = opts.agent ?? null;
|
||||
const result = await cmdThreadPoke(
|
||||
storageRoot,
|
||||
threadId as ThreadId,
|
||||
opts.prompt,
|
||||
agentOverride,
|
||||
);
|
||||
writeOutput(result);
|
||||
});
|
||||
});
|
||||
|
||||
thread
|
||||
.command("stop")
|
||||
.description("Stop background execution of a thread (keep thread active)")
|
||||
|
||||
@@ -199,6 +199,7 @@ const PL_THREAD_ARCHIVED = "F4D8Q2K5";
|
||||
const PL_STEP_ERROR = "B8T5N1V6";
|
||||
const PL_BACKGROUND_START = "X7Q4W9M2";
|
||||
const PL_THREAD_RESUME = "K2R7M4N8";
|
||||
const PL_THREAD_POKE = "P4Q9R3X7";
|
||||
|
||||
type ResumeStepConfig = {
|
||||
role: string;
|
||||
@@ -1135,6 +1136,147 @@ export async function cmdThreadResume(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a thread can be poked. Returns the existing entry and the head StepNode payload.
|
||||
* Fails (process exit) when the thread is missing, running, completed, cancelled, or has no
|
||||
* StepNode at its head.
|
||||
*/
|
||||
async function validatePokePreconditions(
|
||||
storageRoot: string,
|
||||
uwf: UwfStore,
|
||||
threadId: ThreadId,
|
||||
): Promise<{ entry: ThreadIndexEntry; oldHead: CasRef; oldHeadPayload: StepNodePayload }> {
|
||||
const runningMarker = await isThreadRunning(storageRoot, threadId);
|
||||
if (runningMarker !== null) {
|
||||
fail(`thread already executing in background (PID: ${runningMarker.pid})`);
|
||||
}
|
||||
|
||||
const entry = getThread(uwf.varStore, threadId);
|
||||
if (entry === null) {
|
||||
fail(`thread not active: ${threadId}`);
|
||||
}
|
||||
|
||||
if (entry.status === "completed" || entry.status === "cancelled") {
|
||||
fail(`thread cannot be poked: ${threadId} (status: ${entry.status})`);
|
||||
}
|
||||
|
||||
const oldHead = entry.head;
|
||||
const oldHeadNode = uwf.store.cas.get(oldHead);
|
||||
if (oldHeadNode === null) {
|
||||
fail(`CAS node not found: ${oldHead}`);
|
||||
}
|
||||
if (oldHeadNode.type !== uwf.schemas.stepNode) {
|
||||
fail("thread cannot be poked: no step to replace (head is StartNode)");
|
||||
}
|
||||
|
||||
return { entry, oldHead, oldHeadPayload: oldHeadNode.payload as StepNodePayload };
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the next role from the post-poke chain state, used for the StepOutput.currentRole field.
|
||||
* Returns null when the next role is $END, evaluation fails, or the result is a suspend.
|
||||
*/
|
||||
function resolveCurrentRoleFromChain(
|
||||
uwfAfter: UwfStore,
|
||||
workflow: WorkflowPayload,
|
||||
replacedHash: CasRef,
|
||||
): string | null {
|
||||
const chainAfter = walkChain(uwfAfter, replacedHash);
|
||||
const { lastRole, lastOutput } = resolveEvaluateArgs(uwfAfter, chainAfter);
|
||||
const afterResult = evaluate(workflow.graph, lastRole, lastOutput);
|
||||
if (!afterResult.ok || isSuspendResult(afterResult.value)) {
|
||||
return null;
|
||||
}
|
||||
if (afterResult.value.role === END_ROLE) {
|
||||
return null;
|
||||
}
|
||||
return afterResult.value.role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Poke a thread: re-run the agent on the head step with a supplementary prompt,
|
||||
* replacing the head step's output. The new step's `prev` points to the OLD head's
|
||||
* `prev` — semantically replacing (not appending to) the head. The moderator is NOT
|
||||
* re-evaluated for routing; the role of the head step is re-used.
|
||||
*/
|
||||
export async function cmdThreadPoke(
|
||||
storageRoot: string,
|
||||
threadId: ThreadId,
|
||||
prompt: string,
|
||||
agentOverride: string | null,
|
||||
): Promise<StepOutput> {
|
||||
const uwf = await createUwfStore(storageRoot);
|
||||
const { entry, oldHeadPayload } = await validatePokePreconditions(storageRoot, uwf, threadId);
|
||||
|
||||
const chain = walkChain(uwf, entry.head);
|
||||
const workflowHash = chain.start.workflow;
|
||||
const threadCwd = chain.start.cwd;
|
||||
|
||||
const plog = createProcessLogger({
|
||||
storageRoot,
|
||||
context: { thread: threadId, workflow: workflowHash },
|
||||
});
|
||||
|
||||
// Resolve the agent: --agent override wins; otherwise read from old head step's `agent` field.
|
||||
const config = await loadWorkflowConfig(storageRoot);
|
||||
const workflow = loadWorkflowPayload(uwf, workflowHash);
|
||||
const role = oldHeadPayload.role;
|
||||
const agent =
|
||||
agentOverride !== null
|
||||
? resolveAgentConfig(config, workflow, role, agentOverride)
|
||||
: parseAgentOverride(oldHeadPayload.agent);
|
||||
|
||||
const effectiveCwd = oldHeadPayload.cwd !== "" ? oldHeadPayload.cwd : threadCwd;
|
||||
|
||||
plog.log(PL_THREAD_POKE, `poke role=${role} agent=${agent.command}`, null);
|
||||
plog.log(PL_AGENT_SPAWN, `spawning agent command=${agent.command}`, {
|
||||
args: [...agent.args, threadId, role].join(" "),
|
||||
});
|
||||
|
||||
loadDotenv({ path: getEnvPath(storageRoot) });
|
||||
|
||||
// Spawn the agent. The agent will create a new StepNode with prev=oldHead (it reads
|
||||
// the active thread head). After the agent returns, we rewrite that node's prev so
|
||||
// that the new head replaces the old head instead of appending after it.
|
||||
const agentResult = spawnAgent(plog, agent, threadId, role, prompt, effectiveCwd);
|
||||
const agentStepHash = agentResult.stepHash as CasRef;
|
||||
|
||||
plog.log(PL_AGENT_DONE, `agent returned head=${agentStepHash}`, null);
|
||||
|
||||
const uwfAfter = await createUwfStore(storageRoot);
|
||||
const agentNode = uwfAfter.store.cas.get(agentStepHash);
|
||||
if (agentNode === null || agentNode.type !== uwfAfter.schemas.stepNode) {
|
||||
failStep(plog, `agent returned hash that is not a StepNode: ${agentStepHash}`);
|
||||
}
|
||||
const agentPayload = agentNode.payload as StepNodePayload;
|
||||
|
||||
// Rewrite the new step so that its `prev` points to the OLD head's prev (replace semantics).
|
||||
const replacedPayload: StepNodePayload = {
|
||||
...agentPayload,
|
||||
prev: oldHeadPayload.prev,
|
||||
};
|
||||
const replacedHash = await uwfAfter.store.cas.put(uwfAfter.schemas.stepNode, replacedPayload);
|
||||
const replacedNode = uwfAfter.store.cas.get(replacedHash);
|
||||
if (replacedNode === null || !validate(uwfAfter.store, replacedNode)) {
|
||||
failStep(plog, "rewritten StepNode failed schema validation");
|
||||
}
|
||||
|
||||
// Update thread head to the replaced step. Status becomes idle (no moderator re-route).
|
||||
setThread(uwfAfter.varStore, threadId, updateThreadHead(entry, replacedHash));
|
||||
|
||||
return {
|
||||
workflow: workflowHash,
|
||||
thread: threadId,
|
||||
head: replacedHash,
|
||||
status: "idle",
|
||||
currentRole: resolveCurrentRoleFromChain(uwfAfter, workflow, replacedHash),
|
||||
suspendedRole: null,
|
||||
suspendMessage: null,
|
||||
done: false,
|
||||
background: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function validateCount(count: number): void {
|
||||
if (count < 1 || !Number.isInteger(count)) {
|
||||
throw new Error(`--count must be a positive integer, got: ${count}`);
|
||||
|
||||
Reference in New Issue
Block a user