Skip to content

Commit 553aebd

Browse files
committed
chore(workflow): remove the dead workflow/say surface
The stage composer that called workflow/say went away in #1461 (owner decision in #1459), so nothing in the product can send one. What was left still lied when called: say() always recorded the text and, while a node ran, invented a "收到。我继续处理「…」" receipt no Bot ever said. Delete the registration (index.js), the say() method and that fabricated line (service.js), the endpoint token in docs/subsystems/workflow.md and the bare `say` in the plugin README. The read-only assign test keeps its half; the say half and its /Planner|收到/ assertion go. A new host test boots the real ctx.flybot and pins the acceptance shape: the plugin is loaded (workflow/state answers), and flybot/workflow/say is unknown to the host — `Unknown FlyBot endpoint workflow/say` with code bot/not-found, not { ok: true } and not an empty object. Fixes #1475
1 parent 1b6f588 commit 553aebd

9 files changed

Lines changed: 154 additions & 30 deletions

File tree

‎docs/subsystems/workflow.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Everything in `plugins/workflow/`: the graph rules, the run store, the matcher,
3838
## Entry points
3939

4040
- Endpoint `workflow/state` and `workflow/templates` are reads.
41-
- `workflow/create`, `workflow/rename`, `workflow/delete`, `workflow/assign`, `workflow/concurrency`, `workflow/graph`, `workflow/advance`, `workflow/reset`, `workflow/say`, `workflow/ingest` write. `workflow/concurrency` sets that workflow's `maxConcurrent` (an integer from 1 to 8). `workflow/rename` updates a workflow's name and optional description; read-only hosts are refused. `workflow/delete` removes a workflow from state, releases its ephemeral Bots if a run exists, and cleans logs/runs/routes.
41+
- `workflow/create`, `workflow/rename`, `workflow/delete`, `workflow/assign`, `workflow/concurrency`, `workflow/graph`, `workflow/advance`, `workflow/reset`, `workflow/ingest` write. `workflow/concurrency` sets that workflow's `maxConcurrent` (an integer from 1 to 8). `workflow/rename` updates a workflow's name and optional description; read-only hosts are refused. `workflow/delete` removes a workflow from state, releases its ephemeral Bots if a run exists, and cleans logs/runs/routes.
4242
- Tool `run_workflow` starts a named run with a brief. Tool `define_workflow` writes the same graph the canvas edits.
4343
- `flybot.tasks.onWrite` calls `ingest`. A new Bot match returns `{ ownerBotId }`. A Workflow match starts the run inside the plugin and leaves the card's owner to the host.
4444

‎plugins/workflow/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ npx -y @deepseek-ai/dsh@0.2.0-rc.2 plugin --profile web add "github:ThinkFlowLab
7171
npm test
7272
```
7373

74-
Endpoints, all under `flybot/workflow/`: `state`, `templates` (read), `create`, `assign`, `concurrency`, `advance`, `reset`, `say`, `graph`, `ingest`.
74+
Endpoints, all under `flybot/workflow/`: `state`, `templates` (read), `create`, `assign`, `concurrency`, `advance`, `reset`, `graph`, `ingest`.
7575

7676
## 中文
7777

‎plugins/workflow/index.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export function apply(ctx, config = {}) {
102102
fb.api.handle('workflow/reset', body => service.reset(body)),
103103
fb.api.handle('workflow/pause', body => service.pause(body)),
104104
fb.api.handle('workflow/resume', body => service.resume(body)),
105-
fb.api.handle('workflow/say', body => service.say(body)),
106105
fb.api.handle('workflow/graph', body => service.saveGraph(body)),
107106
fb.api.handle('workflow/templates', () => ({ ok: true, templates: service.state().templates }), { read: true }),
108107
fb.api.handle('workflow/ingest', body => service.ingest(body)),

‎plugins/workflow/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"cordis.patch.yml"
2727
],
2828
"scripts": {
29-
"test": "node --test \"test/*.test.js\""
29+
"test": "node --import ./test/resolve.mjs --test \"test/*.test.js\""
3030
},
3131
"peerDependencies": {
3232
"ds-bot": ">=0.1.5-flybot.1"

‎plugins/workflow/src/service.js‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -909,21 +909,6 @@ export function createWorkflowService({ dir, persist = true, now = () => Date.no
909909
return present()
910910
})
911911
},
912-
say(body = {}) {
913-
return mutate(String(body.workflowId ?? ''), (item) => {
914-
const text = cleanLine(body.text, 2000)
915-
if (!text) throw new Error('A message needs text')
916-
const at = now()
917-
const lines = [{ kind: 'user', text }]
918-
const run = displayRun(item.id)
919-
const running = run?.live === true ? orderedIds(item, run.nodeStatus, 'running')[0] : undefined
920-
if (running) {
921-
const node = nodeById(item, running)
922-
lines.push({ kind: 'bot', botId: running, step: '进行中', text: `${node?.name ?? running}:收到。我继续处理「${run.task?.title ?? ''}」。` })
923-
}
924-
push(item.id, lines, at)
925-
})
926-
},
927912
// Replace the graph the canvas and the run share. Positions and edges
928913
// persist; a node that remains keeps its run status, a new one waits.
929914
saveGraph(body = {}) {

‎plugins/workflow/test/assign.test.js‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,11 @@ test('create seats a local Bot and refuses a remote one', () => {
122122
}).ok, false)
123123
})
124124

125-
test('a read-only host refuses assign, and a say lands in the workflow chat', () => {
125+
test('a read-only host refuses assign', () => {
126126
const svc = service({ readOnly: () => true })
127127
const refused = svc.assign({ workflowId: DELIVERY_ID, taskId: '#1', title: 'No' })
128128
assert.equal(refused.ok, false)
129129
assert.equal(refused.code, 'read-only')
130-
131-
const live = service()
132-
const said = live.say({ workflowId: DELIVERY_ID, text: '请把 notice 再短一点' })
133-
const messages = delivery(said).messages
134-
assert.ok(messages.some(message => message.kind === 'user' && message.text.includes('请把 notice 再短一点')))
135-
live.assign({ workflowId: DELIVERY_ID, taskId: '#say', title: 'Notice tweak' })
136-
const withRun = live.say({ workflowId: DELIVERY_ID, text: '继续' })
137-
const tail = delivery(withRun).messages
138-
assert.equal(tail.at(-2).kind, 'user')
139-
assert.match(tail.at(-1).text, /Planner|收到/)
140130
})
141131

142132
test('the store reloads a workflow file and drops a file that does not parse', () => {
@@ -298,6 +288,7 @@ test('apply registers the workflow endpoints and stays quiet when disabled', ()
298288
assert.ok(names.some(([name]) => name === 'workflow/assign'))
299289
assert.ok(names.some(([name]) => name === 'workflow/graph'))
300290
assert.ok(names.some(([name, read]) => name === 'workflow/templates' && read))
291+
assert.ok(!names.some(([name]) => name === 'workflow/say'), 'the removed say endpoint is not registered')
301292
assert.equal(writes.length, 1)
302293
assert.deepEqual(writes[0]({ id: '#9', title: 'please', status: 'open', assignee: 'Coder' }), { ownerBotId: 'bot-coder' })
303294
assert.equal(writes[0]({ id: '#10', title: 'nothing', status: 'open' }), null)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// A minimal Cordis-like context for @flybot/workflow's host test, shipped with the plugin (#34):
2+
// enough of the services ds-bot's apply() needs to boot, plus ctx.plugin(plugin, config),
3+
// which runs a plugin in its own scope (its ctx.effect cleanups run when that scope is disposed)
4+
// and only after the services in plugin.inject are provided. No ds-bot test helpers are used.
5+
export function fakeCordis() {
6+
const services = {}
7+
const disposers = []
8+
const registeredTools = new Map()
9+
const listeners = new Map()
10+
const scope = (cleanups) => ({
11+
logger: { warn() {}, info() {}, debug() {}, error() {} },
12+
effect(execute) {
13+
const dispose = execute()
14+
if (typeof dispose === 'function') cleanups.push(dispose)
15+
return dispose
16+
},
17+
})
18+
const ctx = {
19+
...scope(disposers),
20+
registeredTools,
21+
get: name => services[name],
22+
set(name, value) { services[name] = value; ctx[name] = value },
23+
provide(name, value) { ctx.set(name, value) },
24+
on(name, listener) {
25+
listeners.set(name, [...(listeners.get(name) ?? []), listener])
26+
return () => listeners.set(name, (listeners.get(name) ?? []).filter(l => l !== listener))
27+
},
28+
emit(name, payload) { for (const l of listeners.get(name) ?? []) if (l.length < 2) l(payload) },
29+
tools: {
30+
register(tool) { registeredTools.set(tool.name, tool); return () => registeredTools.delete(tool.name) },
31+
guard() { return () => {} },
32+
schemas: () => [],
33+
},
34+
systemPrompt: { section() { return () => {} } },
35+
connection: { fetch: { register() { return () => {} } } },
36+
llm: { listProviders: () => [] },
37+
// Loads a plugin as Cordis would: in a child scope that sees the parent's services.
38+
plugin(plugin, config) {
39+
const missing = (plugin.inject ?? []).filter(name => services[name] === undefined)
40+
if (missing.length) throw new Error(`${plugin.name}: missing services ${missing.join(', ')}`)
41+
const cleanups = []
42+
const child = Object.assign(Object.create(ctx), scope(cleanups))
43+
let active = true
44+
const dispose = () => {
45+
if (!active) return
46+
active = false
47+
for (const d of cleanups.splice(0).reverse()) d()
48+
}
49+
plugin.apply(child, config)
50+
disposers.push(dispose)
51+
return { dispose }
52+
},
53+
dispose() {
54+
return Promise.allSettled(disposers.splice(0).reverse().map(dispose => dispose()))
55+
},
56+
}
57+
return ctx
58+
}

‎plugins/workflow/test/host.test.js‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// @flybot/workflow against the real ctx.flybot host (ds-bot's hooks.js), not the mock
2+
// (ThinkFlowLab/FlyBot#34). #1475 removed the dead `workflow/say` surface: the bot route strips
3+
// its `flybot/` prefix and asks the host for `workflow/say` (core/src/host/channel.js:701), and a
4+
// name no plugin registered is answered by the host itself (core/src/host/hooks.js:1044). So the
5+
// removed endpoint must come back as `Unknown FlyBot endpoint workflow/say` with code
6+
// `bot/not-found` — never `{ ok: true }`, never an empty object.
7+
import assert from 'node:assert/strict'
8+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
9+
import { tmpdir } from 'node:os'
10+
import { join } from 'node:path'
11+
import { test } from 'node:test'
12+
import { apply } from 'ds-bot'
13+
import * as workflow from '../index.js'
14+
import { fakeCordis } from './fake-cordis.js'
15+
16+
const team = () => ({
17+
version: 1,
18+
mainBotIds: ['a'],
19+
bots: {
20+
a: { id: 'a', name: 'Chief', role: 'Boss', sessionId: 'a', createdAt: 1 },
21+
b: { id: 'b', name: 'Writer', role: 'Write', sessionId: 'b', createdAt: 2 },
22+
},
23+
rooms: {}, agents: {}, exchanges: [], exchangeTurns: {}, questions: {}, prefs: {}, revision: 0,
24+
})
25+
26+
async function start() {
27+
const home = mkdtempSync(join(tmpdir(), 'flybot-workflow-host-'))
28+
writeFileSync(join(home, 'state.json'), JSON.stringify(team()))
29+
const ctx = fakeCordis()
30+
Object.assign(ctx, {
31+
llm: { listProviders: () => [], listModels: async () => [], resolveModelInfo: async () => ({}) },
32+
workspaceRegistry: { get: () => undefined, resolveByPath: async () => undefined, create: async path => ({ id: 'w1', path }), archiveSession: async () => {} },
33+
sessionController: { create: async () => ({ sessionId: 's1' }), resolveAgent: async () => undefined, selectModel: async () => {}, page: async () => ({ records: [], hasMore: false }) },
34+
sessionTitle: { rename: async () => {} },
35+
sessions: { flush: async () => {} },
36+
})
37+
let route
38+
const register = ctx.connection.fetch.register
39+
ctx.connection.fetch.register = (options) => { if (options.path.endsWith('bot')) route = options; return register(options) }
40+
apply(ctx, { home })
41+
const call = async (endpoint, payload) => (await route.fetch(new Request('http://localhost/api/bot', { method: 'POST', body: JSON.stringify({ endpoint, payload }) }))).json()
42+
const stop = async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) }
43+
return { ctx, call, stop }
44+
}
45+
46+
test('workflow plugin on the real host: the removed say endpoint is unknown, not an empty answer', async (t) => {
47+
const h = await start()
48+
t.after(h.stop)
49+
h.ctx.plugin(workflow, { persist: false })
50+
const state = await h.call('flybot/workflow/state')
51+
assert.equal(state.ok, true, 'the plugin is loaded, so the name is the only thing missing')
52+
assert.ok(state.value.workflows.length > 0)
53+
assert.deepEqual(await h.call('flybot/workflow/say', { workflowId: 'delivery', text: 'hi' }), {
54+
ok: false,
55+
error: { code: 'bot/not-found', message: 'Unknown FlyBot endpoint workflow/say', details: {} },
56+
})
57+
})

‎plugins/workflow/test/resolve.mjs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Test-only module resolution for @flybot/workflow (ThinkFlowLab/FlyBot#34).
2+
// - `ds-bot` resolves to the FlyBot core checkout, the way a DSH profile supplies the peer:
3+
// FLYBOT_CORE, else the repo-root `core/` (pristine ds-bot/ + patches/ds-bot/, generated by
4+
// scripts/ds-bot-patches.mjs). Never `ds-bot/`: that is unpatched upstream, with no flybot API.
5+
// - `@deepseek-ai/*` imported from inside that core resolves from a DeepSeek Harness:
6+
// DSH_HARNESS, else <core>/dev/harness (`npm run harness` in the core).
7+
// Workflow's own code never imports ds-bot; only test/host.test.js does, by its public entry.
8+
import { existsSync } from 'node:fs'
9+
import { registerHooks } from 'node:module'
10+
import { join, resolve } from 'node:path'
11+
import { pathToFileURL } from 'node:url'
12+
13+
const repo = resolve(import.meta.dirname, '../../..')
14+
const core = process.env.FLYBOT_CORE
15+
? resolve(process.env.FLYBOT_CORE)
16+
: join(repo, 'core')
17+
if (!existsSync(join(core, 'package.json'))) throw new Error(`@flybot/workflow tests: no FlyBot core at ${core} (set FLYBOT_CORE)`)
18+
const harness = process.env.DSH_HARNESS ?? join(core, 'dev', 'harness')
19+
process.env.DSH_HARNESS = harness
20+
process.env.FLYBOT_CORE = core // tests read interface-layer files (flybot-registry.js) from here
21+
const base = resolve(harness, 'packages/bundle/base/package.json')
22+
const anchor = pathToFileURL(existsSync(base) ? base : resolve(harness, 'package.json')).href
23+
const coreUrl = `${pathToFileURL(core).href}/`
24+
const entry = pathToFileURL(join(core, 'index.js')).href
25+
26+
registerHooks({
27+
resolve(specifier, context, nextResolve) {
28+
if (specifier === 'ds-bot') return { url: entry, format: 'module', shortCircuit: true }
29+
if (specifier.startsWith('@deepseek-ai/') && context.parentURL?.startsWith(coreUrl)) {
30+
return nextResolve(specifier, { ...context, parentURL: anchor })
31+
}
32+
return nextResolve(specifier, context)
33+
},
34+
})

0 commit comments

Comments
 (0)