@wjarka/cezarion 0.17.0-pr2079.3192 → 0.17.0-pr2079.3205.2
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/dist/runs/run-title.d.ts +8 -0
- package/dist/runs/run-title.js +28 -0
- package/dist/runs/run-title.js.map +1 -0
- package/dist/workflows/run/prompts.d.ts +74 -0
- package/dist/workflows/run/prompts.js +140 -0
- package/dist/workflows/run/prompts.js.map +1 -0
- package/dist/workflows/run/steps.d.ts +13 -0
- package/dist/workflows/run/steps.js +14 -0
- package/dist/workflows/run/steps.js.map +1 -0
- package/dist/workflows/run/turn-markers.d.ts +85 -0
- package/dist/workflows/run/turn-markers.js +262 -0
- package/dist/workflows/run/turn-markers.js.map +1 -0
- package/dist/workflows/run.d.ts +8 -143
- package/dist/workflows/run.js +13 -451
- package/dist/workflows/run.js.map +1 -1
- package/dist/workflows/turn-end.d.ts +10 -0
- package/dist/workflows/turn-end.js +10 -0
- package/dist/workflows/turn-end.js.map +1 -1
- package/package.json +3 -3
- package/web/dist/assets/{diff-D6cqOCLW2.js → diff-Bu5Zcy1K2.js} +2 -2
- package/web/dist/assets/{diff-view-Dybmn9Qn.js → diff-view-Qwy6l5Ff.js} +1 -1
- package/web/dist/assets/{git-toolbar-Do32iiRu.js → git-toolbar-BNeVCcch.js} +1 -1
- package/web/dist/assets/{github-DySVDHbL.js → github-Ca9FjltU.js} +1 -1
- package/web/dist/assets/{index-BeSxh84W.js → index-BWWbSsVD.js} +3 -3
- package/web/dist/assets/{preview-pane-connected-C2UIBtAp.js → preview-pane-connected-K1fzlGyo.js} +1 -1
- package/web/dist/assets/{repo-git-DP2xKh5v.js → repo-git-DqKEMfiO.js} +1 -1
- package/web/dist/assets/{run-header-3sbYX6aF.js → run-header-DEQBzSue.js} +1 -1
- package/web/dist/assets/{skills-lDb6ACKS.js → skills-B1vJpfwo.js} +1 -1
- package/web/dist/assets/{task-changes-DrF8vQQm.js → task-changes-BwnZWikA.js} +1 -1
- package/web/dist/assets/{task-commits-BDQ3ffG0.js → task-commits-Co7Sp-m7.js} +1 -1
- package/web/dist/assets/{task-files-ObS4FJZ2.js → task-files-CNUcKgS-.js} +1 -1
- package/web/dist/assets/{task-github-item-Bk_e5QoR.js → task-github-item-ChOuHe1O.js} +1 -1
- package/web/dist/assets/{task-thread-BFPg0VS2.js → task-thread-pIkyRPD_.js} +1 -1
- package/web/dist/assets/{thread-state-CvsNPsQv.js → thread-state-DU2z1ov1.js} +1 -1
- package/web/dist/assets/{use-hand-to-agent-state-DmdB69eP.js → use-hand-to-agent-state-DMwn5rSx.js} +1 -1
- package/web/dist/assets/{workflows-DQfQkUNp.js → workflows-BzsK3-Tv.js} +1 -1
- package/web/dist/index.html +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type WorkflowDef } from '../workflows/types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Immediate title shown while a run is queued. The namer's `titleSummary`
|
|
4
|
+
* replaces it once the model answers; this is the honest, permanent fallback
|
|
5
|
+
* when no model is available (#432, spec 2026-07-17-task-auto-naming). When
|
|
6
|
+
* the task references a PR/issue, the number leads: `469: /om-auto-review-pr`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function makeRunTitle(task: string, workflow: WorkflowDef): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { stepKind } from '../workflows/types.js';
|
|
2
|
+
import { extractTaskRefs, refineTaskRefs, titleRefNumber } from './task-refs.js';
|
|
3
|
+
/**
|
|
4
|
+
* Immediate title shown while a run is queued. The namer's `titleSummary`
|
|
5
|
+
* replaces it once the model answers; this is the honest, permanent fallback
|
|
6
|
+
* when no model is available (#432, spec 2026-07-17-task-auto-naming). When
|
|
7
|
+
* the task references a PR/issue, the number leads: `469: /om-auto-review-pr`.
|
|
8
|
+
*/
|
|
9
|
+
export function makeRunTitle(task, workflow) {
|
|
10
|
+
const firstLine = task.trim().split('\n')[0] ?? '';
|
|
11
|
+
const skill = workflow.steps.find((step) => stepKind(step) === 'agent' && step.skill)?.skill?.trim();
|
|
12
|
+
const contextual = skill && !firstLine.startsWith(`/${skill}`)
|
|
13
|
+
? `/${skill}${firstLine ? ` ${firstLine}` : ''}`
|
|
14
|
+
: firstLine;
|
|
15
|
+
const refNumber = titleRefNumber(refineTaskRefs(extractTaskRefs(task), skill));
|
|
16
|
+
// `469` or `/om-auto-review-pr 469` reads as `469: /om-auto-review-pr` — the
|
|
17
|
+
// number leads so it survives the tasks table's narrow truncation.
|
|
18
|
+
const skillArg = skill && contextual.startsWith(`/${skill}`) ? contextual.slice(skill.length + 1).trim() : null;
|
|
19
|
+
const body = refNumber !== undefined && skill && (skillArg === '' || /^#?\d+$/.test(skillArg ?? ''))
|
|
20
|
+
? `/${skill}`
|
|
21
|
+
: contextual;
|
|
22
|
+
const prefixed = refNumber !== undefined && !body.trimStart().replace(/^#/, '').startsWith(String(refNumber))
|
|
23
|
+
? `${refNumber}: ${body}`
|
|
24
|
+
: body;
|
|
25
|
+
const chars = [...(prefixed || '(untitled task)')];
|
|
26
|
+
return chars.length > 80 ? `${chars.slice(0, 79).join('').trimEnd()}…` : chars.join('');
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=run-title.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-title.js","sourceRoot":"","sources":["../../src/runs/run-title.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,QAAqB;IAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAA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AI,iBAAiB,CAAC,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ContentBlock } from '../../core/agent-runner.ts';
|
|
2
|
+
import type { RunRecord } from '../../runs/store.ts';
|
|
3
|
+
import type { Skill } from '../../skills.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The effective "extra" system prompt for a run (spec §protocol v2, R2 2.3):
|
|
6
|
+
* the per-run override (`POST /api/runs` `systemPrompt`) REPLACES the
|
|
7
|
+
* `config.json` default — they are the same knob at two scopes, so the more
|
|
8
|
+
* specific one wins outright; they never concatenate. Whichever wins is
|
|
9
|
+
* ADDITIVE to the skill body and the handoff contract, which always ride
|
|
10
|
+
* along (see `composeSystemPrompt`). Blank strings count as unset.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveExtraSystemPrompt(override: string | undefined, configDefault: string | undefined): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Joins the parts of one agent step's system prompt in fixed order — skill
|
|
15
|
+
* body (most task-specific), then the run's extra prompt (user guidance, can
|
|
16
|
+
* amend the skill), then the handoff contract (always last, never optional in
|
|
17
|
+
* practice). Blank parts drop out; survivors join with the same `\n\n---\n\n`
|
|
18
|
+
* divider the skill+handoff composition has always used.
|
|
19
|
+
*/
|
|
20
|
+
export declare function composeSystemPrompt(...parts: Array<string | undefined>): string;
|
|
21
|
+
/**
|
|
22
|
+
* The directories a spawned agent may reach outside its worktree: the run-state
|
|
23
|
+
* folder that holds its handoff file, plus its own temp directory when this run
|
|
24
|
+
* got one (#785). Handing an agent a `TMPDIR` its file tools are not allowed to
|
|
25
|
+
* write would trade one silent failure for another, so the two travel together;
|
|
26
|
+
* under `CEZ_AGENT_TMPDIR=0` there is no per-run directory and the list is
|
|
27
|
+
* exactly what it always was.
|
|
28
|
+
*/
|
|
29
|
+
export declare function agentDirectories(runsDir: string, env: Record<string, string>): string[];
|
|
30
|
+
/** Compose only at delivery. The durable continuation retains its original text/attachments. */
|
|
31
|
+
export declare function withResumeContext(prompt: string, message: RunRecord['continuationMessage']): string;
|
|
32
|
+
export declare function applyTemplate(template: string, task: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Skill identity is context, while the Markdown body remains instructions.
|
|
35
|
+
*
|
|
36
|
+
* For an on-disk skill we also hand the agent the ABSOLUTE directory of the
|
|
37
|
+
* installed copy. A run executes in an isolated worktree that has no local
|
|
38
|
+
* `.agents/skills` (gitignored, absent in a fresh checkout), so without this
|
|
39
|
+
* the agent cannot read the skill's companion files (`references/*.md`) — or,
|
|
40
|
+
* worse, reads a stale copy materialized from the team-repo cache. The path
|
|
41
|
+
* resolves against the MAIN project root (`discoverSkills(repoRoot)`), i.e. the
|
|
42
|
+
* current `npx skills`-installed copy, so a worktree agent and the main
|
|
43
|
+
* checkout read the exact same, up-to-date files. A team skill's `path` is not
|
|
44
|
+
* on disk: its files are materialized per run (`RunManager.provisionRunSkills`).
|
|
45
|
+
* Inside the run's task worktree they need no pointer; a run without one, or
|
|
46
|
+
* whose worktree took no copy, gets a per-commit cache copy, passed here as
|
|
47
|
+
* `teamFilesDir` (#1024). A worktree that took only some of its copies passes
|
|
48
|
+
* the first one it did take.
|
|
49
|
+
*/
|
|
50
|
+
export declare function skillSystemPrompt(skill: Pick<Skill, 'name' | 'description' | 'body'> & Partial<Pick<Skill, 'path' | 'source'>>, teamFilesDir?: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Expand a registry-backed slash skill in one prompt string before it reaches a
|
|
53
|
+
* backend. Claude otherwise intercepts an unknown leading slash command, and
|
|
54
|
+
* Codex/OpenCode have no native slash-skill lookup at all (#676).
|
|
55
|
+
*
|
|
56
|
+
* Only a match at character zero counts, and unknown commands pass through
|
|
57
|
+
* byte-for-byte — a backend's OWN slash commands must keep working. The caller
|
|
58
|
+
* persists the original user text before applying this delivery-only rewrite.
|
|
59
|
+
*
|
|
60
|
+
* All delivery seams route through here: live-session messages via
|
|
61
|
+
* `expandRegistrySlashSkill`, and fresh or continuation opening prompts, which
|
|
62
|
+
* become the session's `userPrompt` without passing through `deliverMessage`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function expandRegistrySlashSkillText(text: string, skills: readonly Skill[],
|
|
65
|
+
/** Per team skill, the cache or partial copy its prompt names (#1118). */
|
|
66
|
+
teamFilesDir?: ReadonlyMap<string, string>): string;
|
|
67
|
+
/** The `name` of a prompt's leading `/name` slash command, else undefined. */
|
|
68
|
+
export declare function leadingSlashSkillName(text: string): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* `expandRegistrySlashSkillText` over a live chat message: only the first text
|
|
71
|
+
* block is eligible, and an unchanged block returns the caller's array
|
|
72
|
+
* identity untouched.
|
|
73
|
+
*/
|
|
74
|
+
export declare function expandRegistrySlashSkill(content: ContentBlock[], skills: readonly Skill[]): ContentBlock[];
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { dirname } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* The effective "extra" system prompt for a run (spec §protocol v2, R2 2.3):
|
|
4
|
+
* the per-run override (`POST /api/runs` `systemPrompt`) REPLACES the
|
|
5
|
+
* `config.json` default — they are the same knob at two scopes, so the more
|
|
6
|
+
* specific one wins outright; they never concatenate. Whichever wins is
|
|
7
|
+
* ADDITIVE to the skill body and the handoff contract, which always ride
|
|
8
|
+
* along (see `composeSystemPrompt`). Blank strings count as unset.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveExtraSystemPrompt(override, configDefault) {
|
|
11
|
+
return override?.trim() || configDefault?.trim() || undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Joins the parts of one agent step's system prompt in fixed order — skill
|
|
15
|
+
* body (most task-specific), then the run's extra prompt (user guidance, can
|
|
16
|
+
* amend the skill), then the handoff contract (always last, never optional in
|
|
17
|
+
* practice). Blank parts drop out; survivors join with the same `\n\n---\n\n`
|
|
18
|
+
* divider the skill+handoff composition has always used.
|
|
19
|
+
*/
|
|
20
|
+
export function composeSystemPrompt(...parts) {
|
|
21
|
+
return parts
|
|
22
|
+
.map((p) => p?.trim())
|
|
23
|
+
.filter((p) => Boolean(p))
|
|
24
|
+
.join('\n\n---\n\n');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The directories a spawned agent may reach outside its worktree: the run-state
|
|
28
|
+
* folder that holds its handoff file, plus its own temp directory when this run
|
|
29
|
+
* got one (#785). Handing an agent a `TMPDIR` its file tools are not allowed to
|
|
30
|
+
* write would trade one silent failure for another, so the two travel together;
|
|
31
|
+
* under `CEZ_AGENT_TMPDIR=0` there is no per-run directory and the list is
|
|
32
|
+
* exactly what it always was.
|
|
33
|
+
*/
|
|
34
|
+
export function agentDirectories(runsDir, env) {
|
|
35
|
+
return env.TMPDIR ? [runsDir, env.TMPDIR] : [runsDir];
|
|
36
|
+
}
|
|
37
|
+
/** Compose only at delivery. The durable continuation retains its original text/attachments. */
|
|
38
|
+
export function withResumeContext(prompt, message) {
|
|
39
|
+
const context = message?.resumeContext;
|
|
40
|
+
if (!context?.failure && !context?.restarted)
|
|
41
|
+
return prompt;
|
|
42
|
+
const parts = [];
|
|
43
|
+
if (context.restarted)
|
|
44
|
+
parts.push('The cezar process restarted while you were working on this task. Read the handoff file (CEZ_HANDOFF_FILE) to recover context.');
|
|
45
|
+
if (context.failure) {
|
|
46
|
+
const { stepId, error } = context.failure;
|
|
47
|
+
// Error messages can contain newlines; keep the diagnostic on one line without changing
|
|
48
|
+
// the saved error, or the human text that follows it.
|
|
49
|
+
parts.push(`The previous ${stepId ? `step ${JSON.stringify(stepId)}` : 'turn'} failed: ${error.replace(/[\r\n\u2028\u2029]+/g, ' ')}`);
|
|
50
|
+
}
|
|
51
|
+
parts.push('Background commands from that session may have stopped; verify their state before restarting them.');
|
|
52
|
+
return `${parts.join(' ')}\n${prompt}`;
|
|
53
|
+
}
|
|
54
|
+
export function applyTemplate(template, task) {
|
|
55
|
+
return template.replaceAll('{{task}}', task);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Skill identity is context, while the Markdown body remains instructions.
|
|
59
|
+
*
|
|
60
|
+
* For an on-disk skill we also hand the agent the ABSOLUTE directory of the
|
|
61
|
+
* installed copy. A run executes in an isolated worktree that has no local
|
|
62
|
+
* `.agents/skills` (gitignored, absent in a fresh checkout), so without this
|
|
63
|
+
* the agent cannot read the skill's companion files (`references/*.md`) — or,
|
|
64
|
+
* worse, reads a stale copy materialized from the team-repo cache. The path
|
|
65
|
+
* resolves against the MAIN project root (`discoverSkills(repoRoot)`), i.e. the
|
|
66
|
+
* current `npx skills`-installed copy, so a worktree agent and the main
|
|
67
|
+
* checkout read the exact same, up-to-date files. A team skill's `path` is not
|
|
68
|
+
* on disk: its files are materialized per run (`RunManager.provisionRunSkills`).
|
|
69
|
+
* Inside the run's task worktree they need no pointer; a run without one, or
|
|
70
|
+
* whose worktree took no copy, gets a per-commit cache copy, passed here as
|
|
71
|
+
* `teamFilesDir` (#1024). A worktree that took only some of its copies passes
|
|
72
|
+
* the first one it did take.
|
|
73
|
+
*/
|
|
74
|
+
export function skillSystemPrompt(skill, teamFilesDir) {
|
|
75
|
+
const lines = [
|
|
76
|
+
`Selected skill: /${skill.name}`,
|
|
77
|
+
...(skill.description ? [`Description: ${skill.description}`] : []),
|
|
78
|
+
];
|
|
79
|
+
if (skill.source && skill.source !== 'team' && skill.source !== 'builtin' && skill.path) {
|
|
80
|
+
const dir = dirname(skill.path);
|
|
81
|
+
lines.push('', `Skill files are installed on disk at: ${dir}`, `Read any file this skill references (for example references/*.md) from that absolute directory. ` +
|
|
82
|
+
`It is the current installed copy — use it even though your working directory is a separate worktree that does not contain the skill.`);
|
|
83
|
+
}
|
|
84
|
+
else if (skill.source === 'team' && teamFilesDir) {
|
|
85
|
+
lines.push('', `Skill files are installed on disk at: ${teamFilesDir}`, `Read any file this skill references (for example references/*.md) from that absolute directory. ` +
|
|
86
|
+
`It is a copy of the skill at the commit this run uses.`);
|
|
87
|
+
}
|
|
88
|
+
lines.push('', 'Skill instructions:', skill.body.trim());
|
|
89
|
+
return lines.join('\n');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Expand a registry-backed slash skill in one prompt string before it reaches a
|
|
93
|
+
* backend. Claude otherwise intercepts an unknown leading slash command, and
|
|
94
|
+
* Codex/OpenCode have no native slash-skill lookup at all (#676).
|
|
95
|
+
*
|
|
96
|
+
* Only a match at character zero counts, and unknown commands pass through
|
|
97
|
+
* byte-for-byte — a backend's OWN slash commands must keep working. The caller
|
|
98
|
+
* persists the original user text before applying this delivery-only rewrite.
|
|
99
|
+
*
|
|
100
|
+
* All delivery seams route through here: live-session messages via
|
|
101
|
+
* `expandRegistrySlashSkill`, and fresh or continuation opening prompts, which
|
|
102
|
+
* become the session's `userPrompt` without passing through `deliverMessage`.
|
|
103
|
+
*/
|
|
104
|
+
export function expandRegistrySlashSkillText(text, skills,
|
|
105
|
+
/** Per team skill, the cache or partial copy its prompt names (#1118). */
|
|
106
|
+
teamFilesDir) {
|
|
107
|
+
const name = leadingSlashSkillName(text);
|
|
108
|
+
if (!name)
|
|
109
|
+
return text;
|
|
110
|
+
const skill = skills.find((candidate) => candidate.name === name);
|
|
111
|
+
if (!skill)
|
|
112
|
+
return text;
|
|
113
|
+
const playbook = skillSystemPrompt(skill, teamFilesDir?.get(skill.name));
|
|
114
|
+
const request = text.slice(name.length + 1).trim();
|
|
115
|
+
return request ? `${playbook}\n\nUser request:\n${request}` : playbook;
|
|
116
|
+
}
|
|
117
|
+
/** The `name` of a prompt's leading `/name` slash command, else undefined. */
|
|
118
|
+
export function leadingSlashSkillName(text) {
|
|
119
|
+
return /^\/([A-Za-z0-9][A-Za-z0-9._-]*)(?=\s|$)/.exec(text)?.[1];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* `expandRegistrySlashSkillText` over a live chat message: only the first text
|
|
123
|
+
* block is eligible, and an unchanged block returns the caller's array
|
|
124
|
+
* identity untouched.
|
|
125
|
+
*/
|
|
126
|
+
export function expandRegistrySlashSkill(content, skills) {
|
|
127
|
+
const textIndex = content.findIndex((block) => block.type === 'text');
|
|
128
|
+
if (textIndex < 0)
|
|
129
|
+
return content;
|
|
130
|
+
const block = content[textIndex];
|
|
131
|
+
if (!block || block.type !== 'text')
|
|
132
|
+
return content;
|
|
133
|
+
const text = expandRegistrySlashSkillText(block.text, skills);
|
|
134
|
+
if (text === block.text)
|
|
135
|
+
return content;
|
|
136
|
+
const expanded = [...content];
|
|
137
|
+
expanded[textIndex] = { type: 'text', text };
|
|
138
|
+
return expanded;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/workflows/run/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA4B,EAC5B,aAAiC;IAEjC,OAAO,QAAQ,EAAE,IAAI,EAAE,IAAI,aAAa,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAG,KAAgC;IACrE,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;SACrB,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SACtC,IAAI,CAAC,aAAa,CAAC,CAAC;AACzB,CAAC;AAED;;;;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@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentSession } from '../../core/claude-cli-runner.ts';
|
|
2
|
+
import type { ActiveRun } from '../active-run.ts';
|
|
3
|
+
import type { WorkflowStepDef } from '../types.ts';
|
|
4
|
+
/** The session whose done completes a step that is not the last, and the step it starts next. */
|
|
5
|
+
export declare function stepScope(session: AgentSession, next: WorkflowStepDef | undefined): ActiveRun['nextStep'];
|
|
6
|
+
/** A step a successful settlement completes: still open, and not the one kept for a resume. */
|
|
7
|
+
export declare function settlesAsDone(step: {
|
|
8
|
+
id: string;
|
|
9
|
+
status: string;
|
|
10
|
+
}, keepStepId: string | undefined): boolean;
|
|
11
|
+
/** How `cezar_done` names the step its done starts: the rail's name, else the id. A workflow file
|
|
12
|
+
* may give a step an empty name, and the done answer's `next_step` must not be empty. */
|
|
13
|
+
export declare function stepLabel(step: WorkflowStepDef): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The session whose done completes a step that is not the last, and the step it starts next. */
|
|
2
|
+
export function stepScope(session, next) {
|
|
3
|
+
return next ? { session, label: stepLabel(next) } : undefined;
|
|
4
|
+
}
|
|
5
|
+
/** A step a successful settlement completes: still open, and not the one kept for a resume. */
|
|
6
|
+
export function settlesAsDone(step, keepStepId) {
|
|
7
|
+
return (step.status === 'running' || step.status === 'waiting') && step.id !== keepStepId;
|
|
8
|
+
}
|
|
9
|
+
/** How `cezar_done` names the step its done starts: the rail's name, else the id. A workflow file
|
|
10
|
+
* may give a step an empty name, and the done answer's `next_step` must not be empty. */
|
|
11
|
+
export function stepLabel(step) {
|
|
12
|
+
return step.name?.trim() ? step.name : step.id;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=steps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.js","sourceRoot":"","sources":["../../../src/workflows/run/steps.ts"],"names":[],"mappings":"AAIA,iGAAiG;AACjG,MAAM,UAAU,SAAS,CAAC,OAAqB,EAAE,IAAiC;IAChF,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,aAAa,CAAC,IAAoC,EAAE,UAA8B;IAChG,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,IAAI,IAAI,CAAC,EAAE,KAAK,UAAU,CAAC;AAC5F,CAAC;AAED;0FAC0F;AAC1F,MAAM,UAAU,SAAS,CAAC,IAAqB;IAC7C,OAAO,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { HumanWaitEntry } from '../../contract/index.js';
|
|
2
|
+
import { type AskRequest } from '../../core/ask.ts';
|
|
3
|
+
import type { AgentSession } from '../../core/claude-cli-runner.ts';
|
|
4
|
+
import type { AgentEvent, RunnerId } from '../../core/agent-runner.ts';
|
|
5
|
+
import type { UiEvent } from '../../core/ui-events.ts';
|
|
6
|
+
import type { UiEventSink } from '../../runs/ui-event-sink.ts';
|
|
7
|
+
import type { TurnTail } from './types.ts';
|
|
8
|
+
/** Claude's native scheduler is the backend-level equivalent of the textual
|
|
9
|
+
* monitoring marker. Keep this recognition here, at the workflow boundary,
|
|
10
|
+
* so the v1 event protocol stays unchanged and other backends do not acquire
|
|
11
|
+
* semantics from a coincidentally named tool (#46). Undefined: not the scheduler; null: the
|
|
12
|
+
* scheduler without a usable `delaySeconds`; otherwise that delay (hearsay-tools/cezarion#1233). */
|
|
13
|
+
export declare function claudeScheduleWakeupDelay(event: AgentEvent, backend: RunnerId): number | null | undefined;
|
|
14
|
+
/** A parked backend has resumed only when the parent owns a new turn.
|
|
15
|
+
* Nested Codex/Pi subagent `item.*` streams are not a parent turn — treating
|
|
16
|
+
* them as activity cancelled the only on-by-default wake (#121). Session
|
|
17
|
+
* diagnostics and completed-turn metadata stay passive for the same reason. */
|
|
18
|
+
export declare function isRunnerActivity(event: UiEvent): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Preserve boundaries between complete assistant text blocks while a turn is
|
|
21
|
+
* accumulated for marker parsing. The runners join these same v1 blocks with
|
|
22
|
+
* newlines in `AgentRunResult`; matching that contract here prevents a
|
|
23
|
+
* trailing `CEZ:TITLE=` block from absorbing later commentary (#623).
|
|
24
|
+
*/
|
|
25
|
+
export declare function appendTurnText(current: string, next: string): string;
|
|
26
|
+
/** The v2 item is the complete assistant message the cockpit persists. Keep it
|
|
27
|
+
* as a fallback when a runner's legacy v1 text omitted a trailing CEZ:ASK. */
|
|
28
|
+
export declare function appendCompletedAssistantText(current: string, event: UiEvent): string;
|
|
29
|
+
/** Last top-level completed item: a non-empty assistant message is a visible tail; reasoning or a tool is silent even after earlier visible text (#544). An empty turn stays `none` and never nudges. */
|
|
30
|
+
export declare function trackTurnTail(tail: TurnTail, event: UiEvent): TurnTail;
|
|
31
|
+
/** Strip a trailing marker from one text event so transcripts stay free of
|
|
32
|
+
* protocol noise. Delta backends may split the marker across events — then
|
|
33
|
+
* it stays visible; detection above is unaffected. */
|
|
34
|
+
export declare function stripDoneMarker(text: string): string;
|
|
35
|
+
/** Strip a trailing `CEZ:MONITORING` marker from one text event (see
|
|
36
|
+
* `stripDoneMarker`; same delta-backend caveat). */
|
|
37
|
+
export declare function stripMonitoringMarker(text: string): string;
|
|
38
|
+
/** Emit the v2 `ask.requested` event for a parsed marker (the cockpit renders
|
|
39
|
+
* it as an ask card, #473). Returns the minted request id. */
|
|
40
|
+
export declare function emitAskRequested(sink: UiEventSink, ask: AskRequest): string;
|
|
41
|
+
/** A card's stored fields: its questions and, when it has one, its context (hearsay-tools/cezarion#1458).
|
|
42
|
+
* A card always replaces both, so a card without context never keeps an older card's. */
|
|
43
|
+
export declare function askCardFields(card: AskRequest): AskRequest;
|
|
44
|
+
/** The card a human wait holds, or none for a wait without questions. */
|
|
45
|
+
export declare function humanWaitCard(wait: Pick<HumanWaitEntry, 'questions' | 'context'> | undefined): AskRequest | undefined;
|
|
46
|
+
/** What a turn's active `CEZ:ASK` declaration resolves to: the card to raise, and
|
|
47
|
+
* the notes to persist alongside it. */
|
|
48
|
+
type AskTurnOutcome = {
|
|
49
|
+
ask: AskRequest | null;
|
|
50
|
+
/** Emitted in order by the caller, which owns how a note is persisted. */
|
|
51
|
+
notes: Array<{
|
|
52
|
+
message: string;
|
|
53
|
+
tone?: 'danger';
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
/** How a turn end reads its turn (`classifyTurnEnd`). */
|
|
57
|
+
export type TurnEndRead = AskTurnOutcome & {
|
|
58
|
+
done: boolean;
|
|
59
|
+
monitoring: boolean;
|
|
60
|
+
humanGate: boolean;
|
|
61
|
+
waitCard: boolean;
|
|
62
|
+
};
|
|
63
|
+
/** One turn-end decision for fresh and Continue, also retained until an input
|
|
64
|
+
* ACK settles. DONE and human gates take precedence over a quiet
|
|
65
|
+
* declaration or live workers; a false pending-ASK flag alone proves nothing.
|
|
66
|
+
* A human wait this turn registered and nobody has seen yet (hearsay-tools/cezarion#1234)
|
|
67
|
+
* raises its card, or the human gate when it has none, unless DONE wins or a valid ask line
|
|
68
|
+
* replaces its card; `waitCard` says the card is the wait's own. An accepted `cezar_done` is DONE
|
|
69
|
+
* whatever the text says, and beats any ask line in it. Only markers and waits count: no prose
|
|
70
|
+
* raises the gate, and a rejected ask line is a turn end with no wait. */
|
|
71
|
+
export declare function classifyTurnEnd(turnText: string, completedAssistantText: string, options: {
|
|
72
|
+
sessionOpen: boolean;
|
|
73
|
+
pendingHumanAsk: boolean;
|
|
74
|
+
scheduledWake: boolean;
|
|
75
|
+
liveWorkers: boolean;
|
|
76
|
+
humanWait?: Pick<HumanWaitEntry, 'questions' | 'context'> | undefined;
|
|
77
|
+
doneRequested?: boolean | undefined;
|
|
78
|
+
}): TurnEndRead;
|
|
79
|
+
/** An active ASK marker — valid card or rejected payload — means the user
|
|
80
|
+
* must answer. Drop follow-ups queued mid-turn so they cannot start a new
|
|
81
|
+
* turn the moment idle fires (OpenCode serializes `sendMessage` that way). */
|
|
82
|
+
export declare function discardQueuedMessagesOnAsk(session: AgentSession | undefined, outcome: AskTurnOutcome & {
|
|
83
|
+
humanGate?: boolean;
|
|
84
|
+
}): void;
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { defined } from '../../core/defined.js';
|
|
3
|
+
import { parseAskMarkerResult, uiAskQuestions } from '../../core/ask.js';
|
|
4
|
+
/**
|
|
5
|
+
* Task-completion marker from the agent contract (HANDOFF_ONLY_INSTRUCTIONS):
|
|
6
|
+
* an active `CEZ:DONE` declaration means "goal achieved, nothing to ask" —
|
|
7
|
+
* the session is closed right away instead of parking at `waiting` (#347).
|
|
8
|
+
* Detection runs on the accumulated turn text so delta-streaming backends
|
|
9
|
+
* (codex, opencode) can't split the marker across text events.
|
|
10
|
+
*/
|
|
11
|
+
/** Find the turn's active markers: quoted/indented examples and fenced code declare
|
|
12
|
+
* nothing. A standalone monitoring line belongs to this turn even when a later
|
|
13
|
+
* assistant block acknowledges a new instruction. The prose itself is never read
|
|
14
|
+
* (hearsay-tools/cezarion#1234). */
|
|
15
|
+
function turnParkSignals(text) {
|
|
16
|
+
let fence;
|
|
17
|
+
let monitoring = false;
|
|
18
|
+
let done = false;
|
|
19
|
+
let askResult = { kind: 'none' };
|
|
20
|
+
let previous = '';
|
|
21
|
+
for (const raw of text.split('\n')) {
|
|
22
|
+
const delimiter = raw.match(/^ {0,3}(`{3,}|~{3,})/);
|
|
23
|
+
if (delimiter) {
|
|
24
|
+
previous = ''; // a fenced example consumes its heading, not the next declaration
|
|
25
|
+
const token = delimiter[1];
|
|
26
|
+
if (!fence)
|
|
27
|
+
fence = { char: token[0], length: token.length };
|
|
28
|
+
else if (token[0] === fence.char && token.length >= fence.length)
|
|
29
|
+
fence = undefined;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (fence)
|
|
33
|
+
continue;
|
|
34
|
+
if (/^(?: {4}|\t|\s*>)/.test(raw)) {
|
|
35
|
+
if (raw.trim())
|
|
36
|
+
previous = '';
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
// Lists and emphasis format active prose; they do not quote it. Exclude
|
|
40
|
+
// fenced/indented/blockquote examples before removing their decoration.
|
|
41
|
+
const line = raw.trim().replace(/^(?:[-+*]|\d+[.)])\s+(?:\[[ xX]\]\s+)?/, '')
|
|
42
|
+
.replace(/^#{1,6}\s+/, '').replace(/\*{1,2}|_{1,2}/g, '');
|
|
43
|
+
if (!line)
|
|
44
|
+
continue;
|
|
45
|
+
const example = /\b(?:example|sample|literal|quoted)(?: marker)?\s*:\s*$/i.test(previous);
|
|
46
|
+
if (!example && raw.trim() === 'CEZ:MONITORING') {
|
|
47
|
+
monitoring = true;
|
|
48
|
+
done = false;
|
|
49
|
+
}
|
|
50
|
+
if (!example && raw.trim() === 'CEZ:DONE') {
|
|
51
|
+
done = true;
|
|
52
|
+
askResult = { kind: 'none' }; // retain the existing later-DONE precedence
|
|
53
|
+
}
|
|
54
|
+
// Preserve the existing payload validation/repair and latest malformed
|
|
55
|
+
// marker diagnostics. Only active declarations participate: an ACK after
|
|
56
|
+
// a real ASK must not erase its card, nor turn examples into questions.
|
|
57
|
+
const candidate = example ? { kind: 'none' } : parseAskMarkerResult(raw);
|
|
58
|
+
if (candidate.kind !== 'none') {
|
|
59
|
+
askResult = candidate;
|
|
60
|
+
done = false;
|
|
61
|
+
}
|
|
62
|
+
previous = line;
|
|
63
|
+
}
|
|
64
|
+
return { monitoring, done, askResult };
|
|
65
|
+
}
|
|
66
|
+
/** Claude's native scheduler is the backend-level equivalent of the textual
|
|
67
|
+
* monitoring marker. Keep this recognition here, at the workflow boundary,
|
|
68
|
+
* so the v1 event protocol stays unchanged and other backends do not acquire
|
|
69
|
+
* semantics from a coincidentally named tool (#46). Undefined: not the scheduler; null: the
|
|
70
|
+
* scheduler without a usable `delaySeconds`; otherwise that delay (hearsay-tools/cezarion#1233). */
|
|
71
|
+
export function claudeScheduleWakeupDelay(event, backend) {
|
|
72
|
+
if (backend !== 'claude' || event.type !== 'tool-call' || event.tool !== 'ScheduleWakeup')
|
|
73
|
+
return undefined;
|
|
74
|
+
const delay = event.input?.delaySeconds;
|
|
75
|
+
return typeof delay === 'number' && Number.isFinite(delay) ? delay : null;
|
|
76
|
+
}
|
|
77
|
+
/** A parked backend has resumed only when the parent owns a new turn.
|
|
78
|
+
* Nested Codex/Pi subagent `item.*` streams are not a parent turn — treating
|
|
79
|
+
* them as activity cancelled the only on-by-default wake (#121). Session
|
|
80
|
+
* diagnostics and completed-turn metadata stay passive for the same reason. */
|
|
81
|
+
export function isRunnerActivity(event) {
|
|
82
|
+
return event.type === 'turn.started';
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Preserve boundaries between complete assistant text blocks while a turn is
|
|
86
|
+
* accumulated for marker parsing. The runners join these same v1 blocks with
|
|
87
|
+
* newlines in `AgentRunResult`; matching that contract here prevents a
|
|
88
|
+
* trailing `CEZ:TITLE=` block from absorbing later commentary (#623).
|
|
89
|
+
*/
|
|
90
|
+
export function appendTurnText(current, next) {
|
|
91
|
+
if (!current)
|
|
92
|
+
return next;
|
|
93
|
+
if (!next)
|
|
94
|
+
return current;
|
|
95
|
+
return `${current}\n${next}`;
|
|
96
|
+
}
|
|
97
|
+
/** The v2 item is the complete assistant message the cockpit persists. Keep it
|
|
98
|
+
* as a fallback when a runner's legacy v1 text omitted a trailing CEZ:ASK. */
|
|
99
|
+
export function appendCompletedAssistantText(current, event) {
|
|
100
|
+
if (event.type !== 'item.completed' ||
|
|
101
|
+
event.item.kind !== 'message' ||
|
|
102
|
+
event.item.role !== 'assistant' ||
|
|
103
|
+
event.item.parentItemId !== undefined) {
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
return appendTurnText(current, event.item.text);
|
|
107
|
+
}
|
|
108
|
+
/** Last top-level completed item: a non-empty assistant message is a visible tail; reasoning or a tool is silent even after earlier visible text (#544). An empty turn stays `none` and never nudges. */
|
|
109
|
+
export function trackTurnTail(tail, event) {
|
|
110
|
+
if (event.type !== 'item.completed' || event.item.parentItemId !== undefined)
|
|
111
|
+
return tail;
|
|
112
|
+
const item = event.item;
|
|
113
|
+
if (item.kind === 'message' && item.role === 'assistant' && item.text.trim() !== '')
|
|
114
|
+
return 'visible';
|
|
115
|
+
if (item.kind === 'reasoning' || item.kind === 'tool')
|
|
116
|
+
return 'silent';
|
|
117
|
+
return tail;
|
|
118
|
+
}
|
|
119
|
+
/** Strip a trailing marker from one text event so transcripts stay free of
|
|
120
|
+
* protocol noise. Delta backends may split the marker across events — then
|
|
121
|
+
* it stays visible; detection above is unaffected. */
|
|
122
|
+
export function stripDoneMarker(text) {
|
|
123
|
+
return text.replace(/\s*CEZ:DONE\s*$/, '');
|
|
124
|
+
}
|
|
125
|
+
/** Strip a trailing `CEZ:MONITORING` marker from one text event (see
|
|
126
|
+
* `stripDoneMarker`; same delta-backend caveat). */
|
|
127
|
+
export function stripMonitoringMarker(text) {
|
|
128
|
+
return text.replace(/\s*CEZ:MONITORING\s*$/, '');
|
|
129
|
+
}
|
|
130
|
+
/** Emit the v2 `ask.requested` event for a parsed marker (the cockpit renders
|
|
131
|
+
* it as an ask card, #473). Returns the minted request id. */
|
|
132
|
+
export function emitAskRequested(sink, ask) {
|
|
133
|
+
const requestId = randomUUID();
|
|
134
|
+
sink.handle({ type: 'ask.requested', requestId, ...defined(askCardFields(ask)), questions: uiAskQuestions(ask.questions) });
|
|
135
|
+
return requestId;
|
|
136
|
+
}
|
|
137
|
+
/** A card's stored fields: its questions and, when it has one, its context (hearsay-tools/cezarion#1458).
|
|
138
|
+
* A card always replaces both, so a card without context never keeps an older card's. */
|
|
139
|
+
export function askCardFields(card) {
|
|
140
|
+
return { questions: card.questions, ...(card.context !== undefined ? { context: card.context } : {}) };
|
|
141
|
+
}
|
|
142
|
+
/** The card a human wait holds, or none for a wait without questions. */
|
|
143
|
+
export function humanWaitCard(wait) {
|
|
144
|
+
return wait?.questions ? askCardFields({ questions: wait.questions, context: wait.context }) : undefined;
|
|
145
|
+
}
|
|
146
|
+
/** A persisted, non-fatal explanation for protocol-shaped text that could not
|
|
147
|
+
* become an ask card. Never include the raw payload in this diagnostic. */
|
|
148
|
+
function askMarkerRejection(result) {
|
|
149
|
+
if (result.kind === 'invalid-json') {
|
|
150
|
+
return 'structured question ignored — CEZ:ASK payload is not valid JSON';
|
|
151
|
+
}
|
|
152
|
+
if (result.kind !== 'invalid-structure')
|
|
153
|
+
return undefined;
|
|
154
|
+
const issue = result.issues[0];
|
|
155
|
+
const location = issue?.path.length ? ` at ${issue.path.join('.')}` : '';
|
|
156
|
+
return `structured question ignored — CEZ:ASK payload failed validation${location}${issue ? `: ${issue.message}` : ''}`;
|
|
157
|
+
}
|
|
158
|
+
/** A persisted, auditable trace for a card that only rendered because the
|
|
159
|
+
* payload's missing closers were appended (#936) — a repair can only lose what
|
|
160
|
+
* the truncation already removed, so the recovery must stay visible rather than
|
|
161
|
+
* passing for a clean parse. Carries `tone: 'danger'` for the same reason the
|
|
162
|
+
* rejection does: it is the ONLY signal that the card may be missing a trailing
|
|
163
|
+
* option or a trailing `multiSelect` the cut took with it, and the raw payload
|
|
164
|
+
* is stripped along with the card, so a dim footnote could not be acted on. */
|
|
165
|
+
function askMarkerRecovery(result) {
|
|
166
|
+
return result.kind === 'valid' && result.repaired
|
|
167
|
+
? 'structured question recovered from an unbalanced CEZ:ASK payload — check the options, and how many you may pick, match what was asked'
|
|
168
|
+
: undefined;
|
|
169
|
+
}
|
|
170
|
+
/** Resolve the ask marker for one finished turn. Both turn-end handlers
|
|
171
|
+
* (`runAgentStep` and `runContinuation`) route through this single function:
|
|
172
|
+
* they are hand-duplicated, and `AGENTS.md` warns that a lifecycle change
|
|
173
|
+
* applied to only one of them ships half a fix — the notes and their tones are
|
|
174
|
+
* exactly that kind of change. `enabled` is the caller's own precondition (the
|
|
175
|
+
* session is open and the turn is not a terminating `CEZ:DONE`); when false
|
|
176
|
+
* there is no marker to look for. Intermediate steps can ask too (#427). */
|
|
177
|
+
function resolveAskTurn(v1Result, v2Result, enabled) {
|
|
178
|
+
if (!enabled)
|
|
179
|
+
return { ask: null, notes: [] };
|
|
180
|
+
// For unreconciled channels, v1 remains authoritative when it carries an
|
|
181
|
+
// ASK; a marker absent from v1 can still come from the complete v2 message.
|
|
182
|
+
const result = v1Result.kind === 'none' ? v2Result : v1Result;
|
|
183
|
+
const notes = [];
|
|
184
|
+
const rejection = askMarkerRejection(result);
|
|
185
|
+
if (rejection)
|
|
186
|
+
notes.push({ message: rejection, tone: 'danger' });
|
|
187
|
+
const recovery = askMarkerRecovery(result);
|
|
188
|
+
if (recovery)
|
|
189
|
+
notes.push({ message: recovery, tone: 'danger' });
|
|
190
|
+
return { ask: result.kind === 'valid' ? result.request : null, notes };
|
|
191
|
+
}
|
|
192
|
+
/** A partial channel cannot keep an earlier gate alive when the other carries
|
|
193
|
+
* the same transcript plus later declarations. Compare raw lines in order,
|
|
194
|
+
* preserving fences/examples and ACKs between declarations. Neither channel
|
|
195
|
+
* always wins: v1 reconstructs omitted snapshots, v2 can retain refreshed ones.
|
|
196
|
+
* Incomparable transcripts keep the existing conservative channel policy. */
|
|
197
|
+
function orderedTurnText(v1, v2) {
|
|
198
|
+
if (!v1)
|
|
199
|
+
return v2;
|
|
200
|
+
if (!v2 || v1 === v2)
|
|
201
|
+
return v1;
|
|
202
|
+
const contains = (full, partial) => {
|
|
203
|
+
const lines = partial.split('\n');
|
|
204
|
+
let next = 0;
|
|
205
|
+
for (const line of full.split('\n')) {
|
|
206
|
+
if (line === lines[next])
|
|
207
|
+
next++;
|
|
208
|
+
}
|
|
209
|
+
return next === lines.length;
|
|
210
|
+
};
|
|
211
|
+
if (contains(v2, v1))
|
|
212
|
+
return v2;
|
|
213
|
+
if (contains(v1, v2))
|
|
214
|
+
return v1;
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
/** Read the turn's markers once from the channel that holds the whole turn, or from each channel
|
|
218
|
+
* when neither holds the other (`orderedTurnText`). A done line counts only when no channel
|
|
219
|
+
* carries an ask line. */
|
|
220
|
+
function readTurnMarkers(turnText, completedAssistantText) {
|
|
221
|
+
const complete = orderedTurnText(turnText, completedAssistantText);
|
|
222
|
+
const v1 = turnParkSignals(complete ?? turnText);
|
|
223
|
+
const v2 = complete === undefined ? turnParkSignals(completedAssistantText) : v1;
|
|
224
|
+
return {
|
|
225
|
+
v1Ask: v1.askResult, v2Ask: v2.askResult,
|
|
226
|
+
doneLine: (v1.done || v2.done) && v1.askResult.kind === 'none' && v2.askResult.kind === 'none',
|
|
227
|
+
monitoringLine: v1.monitoring || v2.monitoring,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/** Read the turn's ask: its ask line, else the card of the human wait it registered, else the
|
|
231
|
+
* human gate when that wait has no card. A done reads no ask. */
|
|
232
|
+
function readTurnAsk(markers, options, done) {
|
|
233
|
+
const askTurn = resolveAskTurn(markers.v1Ask, markers.v2Ask, options.sessionOpen && !done);
|
|
234
|
+
const surfaced = options.humanWait && options.sessionOpen && !done && !askTurn.ask ? options.humanWait : undefined;
|
|
235
|
+
const waitCard = !!surfaced?.questions;
|
|
236
|
+
return { ...askTurn, ask: askTurn.ask ?? humanWaitCard(surfaced) ?? null, humanGate: !!surfaced && !waitCard, waitCard };
|
|
237
|
+
}
|
|
238
|
+
/** One turn-end decision for fresh and Continue, also retained until an input
|
|
239
|
+
* ACK settles. DONE and human gates take precedence over a quiet
|
|
240
|
+
* declaration or live workers; a false pending-ASK flag alone proves nothing.
|
|
241
|
+
* A human wait this turn registered and nobody has seen yet (hearsay-tools/cezarion#1234)
|
|
242
|
+
* raises its card, or the human gate when it has none, unless DONE wins or a valid ask line
|
|
243
|
+
* replaces its card; `waitCard` says the card is the wait's own. An accepted `cezar_done` is DONE
|
|
244
|
+
* whatever the text says, and beats any ask line in it. Only markers and waits count: no prose
|
|
245
|
+
* raises the gate, and a rejected ask line is a turn end with no wait. */
|
|
246
|
+
export function classifyTurnEnd(turnText, completedAssistantText, options) {
|
|
247
|
+
const markers = readTurnMarkers(turnText, completedAssistantText);
|
|
248
|
+
const done = options.sessionOpen && (!!options.doneRequested || markers.doneLine);
|
|
249
|
+
const { humanGate, waitCard, ...askTurn } = readTurnAsk(markers, options, done);
|
|
250
|
+
const monitoring = options.sessionOpen && !done && !askTurn.ask &&
|
|
251
|
+
!options.pendingHumanAsk && !humanGate &&
|
|
252
|
+
(markers.monitoringLine || options.scheduledWake || options.liveWorkers);
|
|
253
|
+
return { ...askTurn, done, monitoring, humanGate, waitCard };
|
|
254
|
+
}
|
|
255
|
+
/** An active ASK marker — valid card or rejected payload — means the user
|
|
256
|
+
* must answer. Drop follow-ups queued mid-turn so they cannot start a new
|
|
257
|
+
* turn the moment idle fires (OpenCode serializes `sendMessage` that way). */
|
|
258
|
+
export function discardQueuedMessagesOnAsk(session, outcome) {
|
|
259
|
+
if (outcome.ask || outcome.notes.length || outcome.humanGate)
|
|
260
|
+
session?.discardQueuedMessages();
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=turn-markers.js.map
|