@rt-tools/agent-kit 0.37.1 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/assets/checks/action-of.mjs +154 -0
- package/assets/checks/board-runs.github.mjs +40 -5
- package/assets/checks/check-board.github.mjs +38 -7
- package/assets/checks/check-state-next.mjs +22 -10
- package/assets/checks/check-turn-map.mjs +26 -6
- package/assets/checks/check-work-steps.mjs +4 -173
- package/assets/checks/decide.mjs +285 -0
- package/assets/checks/decision-table.json +21432 -0
- package/assets/checks/decision-table.mjs +495 -0
- package/assets/checks/epic-window.mjs +98 -0
- package/assets/checks/flow-condition.mjs +64 -0
- package/assets/checks/flow-data.mjs +135 -0
- package/assets/checks/flow-forecast.mjs +334 -0
- package/assets/checks/flow-guard-run.mjs +90 -0
- package/assets/checks/flow-guard.mjs +496 -0
- package/assets/checks/flow-model.mjs +271 -0
- package/assets/checks/flow-override.mjs +130 -0
- package/assets/checks/flow-plan.mjs +206 -0
- package/assets/checks/flow-scaffold.mjs +224 -0
- package/assets/checks/flow-step.mjs +495 -0
- package/assets/checks/flow-sync.mjs +296 -0
- package/assets/checks/flow-syntax.mjs +292 -0
- package/assets/checks/flow-verdict.mjs +227 -0
- package/assets/checks/merge-read.mjs +239 -0
- package/assets/checks/owner-nudges.mjs +389 -0
- package/assets/checks/push-inputs.mjs +59 -16
- package/assets/checks/record-count.mjs +437 -0
- package/assets/checks/record-recount.mjs +187 -0
- package/assets/checks/record-turn.mjs +155 -0
- package/assets/checks/task-flow-script.mjs +318 -0
- package/assets/checks/tree-assignment.mjs +26 -7
- package/assets/checks/work-result.mjs +362 -0
- package/assets/checks/work-steps-lib.mjs +205 -0
- package/assets/commands/night.md +6 -6
- package/assets/defaults/gate-map.sh +39 -12
- package/assets/defaults/merges.sh +48 -0
- package/assets/defaults/project.sh +6 -5
- package/assets/defaults/turn-map.md +23 -22
- package/assets/docs/GLOSSARY.md +5 -1
- package/assets/hooks/ask-judge.md +67 -0
- package/assets/hooks/browser-guard-device-id.sh +11 -9
- package/assets/hooks/browser-guard-no-asking.sh +12 -6
- package/assets/hooks/browser-guard-no-listing.sh +13 -7
- package/assets/hooks/browser-guard-no-other-drivers.sh +25 -17
- package/assets/hooks/browser-guard-require-select.sh +15 -15
- package/assets/hooks/commit-msg.sh +13 -3
- package/assets/hooks/conscience-guard.sh +9 -25
- package/assets/hooks/decide.sh +141 -0
- package/assets/hooks/deny-tail.sh +16 -11
- package/assets/hooks/dev-server-guard.sh +27 -20
- package/assets/hooks/dispatch.sh +47 -4
- package/assets/hooks/docs-guard.sh +31 -200
- package/assets/hooks/end-conversation-guard.sh +12 -21
- package/assets/hooks/epic-stop-guard.sh +54 -152
- package/assets/hooks/exam-guard.sh +32 -65
- package/assets/hooks/facts-docs.sh +221 -0
- package/assets/hooks/facts-flow.sh +173 -0
- package/assets/hooks/facts.sh +374 -0
- package/assets/hooks/flow-step-guard.sh +93 -0
- package/assets/hooks/git-guard-delivery-body.sh +4 -4
- package/assets/hooks/git-guard-delivery-conflict.sh +16 -10
- package/assets/hooks/git-guard-delivery-draft.sh +3 -3
- package/assets/hooks/git-guard-delivery-epic.sh +18 -9
- package/assets/hooks/git-guard-delivery-folder.sh +32 -7
- package/assets/hooks/git-guard-delivery-merge.sh +2 -2
- package/assets/hooks/git-guard-delivery-merged.sh +12 -1
- package/assets/hooks/git-guard-delivery-pipeline.sh +1 -1
- package/assets/hooks/git-guard-delivery-rerun.sh +44 -0
- package/assets/hooks/git-guard-delivery-signature.sh +82 -45
- package/assets/hooks/git-guard-delivery-task.sh +47 -0
- package/assets/hooks/git-guard-delivery.sh +112 -101
- package/assets/hooks/git-guard-discard.sh +8 -18
- package/assets/hooks/git-guard-main.sh +13 -19
- package/assets/hooks/git-guard-no-verify.sh +56 -16
- package/assets/hooks/git-guard-push-ahead.sh +39 -6
- package/assets/hooks/git-guard-push-marks.sh +262 -13
- package/assets/hooks/git-guard-push-tests.sh +58 -52
- package/assets/hooks/git-guard-tree-assignment.sh +7 -4
- package/assets/hooks/guard-note.sh +8 -6
- package/assets/hooks/handoff-entry-guard.sh +19 -38
- package/assets/hooks/handoff-write.sh +3 -1
- package/assets/hooks/hook-input.sh +0 -41
- package/assets/hooks/metric-marks.sh +19 -7
- package/assets/hooks/observe.sh +1 -1
- package/assets/hooks/override-write-guard.sh +27 -9
- package/assets/hooks/pre-push.sh +40 -12
- package/assets/hooks/prose-style-guard.sh +6 -19
- package/assets/hooks/pull-merges.sh +76 -0
- package/assets/hooks/push-ahead-call-guard.sh +447 -0
- package/assets/hooks/push-set.sh +38 -8
- package/assets/hooks/qa-dataid-guard.sh +7 -17
- package/assets/hooks/record-turn.sh +52 -0
- package/assets/hooks/rerun-guard.sh +11 -16
- package/assets/hooks/reuse-first-guard.sh +7 -21
- package/assets/hooks/role-calls.sh +25 -3
- package/assets/hooks/rule-source-guard.sh +54 -21
- package/assets/hooks/skill-gate-rearm.sh +18 -5
- package/assets/hooks/skill-gate.sh +156 -20
- package/assets/hooks/skill-loaded.sh +18 -3
- package/assets/hooks/sql-guard-target.sh +2 -2
- package/assets/hooks/sql-guard-write.sh +12 -12
- package/assets/hooks/sql-guard.sh +58 -16
- package/assets/hooks/task-context-load.sh +3 -1
- package/assets/hooks/task-flow-context.sh +5 -18
- package/assets/hooks/task-flow-draft-guard.sh +25 -74
- package/assets/hooks/task-flow-guard.sh +28 -130
- package/assets/hooks/tree-assignment-guard.sh +25 -14
- package/assets/hooks/turn-entry-load.sh +3 -1
- package/assets/hooks/turn-exit-guard.sh +92 -452
- package/assets/hooks/turn-exit-role.sh +3 -1
- package/assets/hooks/turn-judge.md +113 -0
- package/assets/hooks/window-fill-guard.sh +22 -41
- package/assets/patterns/doc-style-human.md +36 -76
- package/assets/patterns/git-workflow-commit.azure.md +9 -155
- package/assets/patterns/git-workflow-commit.github.md +11 -269
- package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
- package/assets/patterns/git-workflow-docker.md +8 -231
- package/assets/patterns/git-workflow-freshness.md +8 -56
- package/assets/patterns/git-workflow-merge.md +6 -176
- package/assets/patterns/git-workflow-migration.md +5 -75
- package/assets/patterns/git-workflow-pr-body.github.md +6 -159
- package/assets/patterns/git-workflow-pr-ready.md +9 -70
- package/assets/patterns/git-workflow-pr.azure.md +13 -285
- package/assets/patterns/git-workflow-pr.github.md +13 -251
- package/assets/patterns/git-workflow-pr.gitlab.md +13 -286
- package/assets/patterns/git-workflow-restart.md +5 -42
- package/assets/patterns/git-workflow-secrets.md +10 -76
- package/assets/patterns/git-workflow-stack.md +7 -207
- package/assets/patterns/status-report-table.github.md +1 -1
- package/assets/patterns/task-flow-archive.md +12 -233
- package/assets/patterns/task-flow-close.md +16 -292
- package/assets/patterns/task-flow-cycle.md +13 -39
- package/assets/patterns/task-flow-graph.needs-graph.md +8 -62
- package/assets/patterns/task-flow-handoff.md +13 -161
- package/assets/patterns/task-flow-resume.md +18 -218
- package/assets/patterns/task-flow-start.md +9 -247
- package/assets/patterns/turn-entry-map.md +2 -2
- package/assets/pitfalls/agent-kit-extend.md +200 -0
- package/assets/pitfalls/agent-kit.2.md +323 -0
- package/assets/pitfalls/angular-patterns.md +98 -0
- package/assets/pitfalls/browser-verification.md +265 -0
- package/assets/pitfalls/component-structure.md +98 -0
- package/assets/pitfalls/dependencies.md +92 -0
- package/assets/pitfalls/deploy-flow.azure.md +171 -0
- package/assets/pitfalls/deploy-flow.github.md +211 -0
- package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
- package/assets/pitfalls/doc-style-human.md +112 -0
- package/assets/pitfalls/doc-style.2.md +286 -0
- package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
- package/assets/pitfalls/entity-models.md +89 -0
- package/assets/pitfalls/epic-flow.md +92 -0
- package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
- package/assets/pitfalls/git-workflow-commit.github.md +307 -0
- package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
- package/assets/pitfalls/git-workflow-docker.md +275 -0
- package/assets/pitfalls/git-workflow-freshness.md +88 -0
- package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
- package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
- package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
- package/assets/pitfalls/git-workflow-merge.md +220 -0
- package/assets/pitfalls/git-workflow-migration.md +103 -0
- package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
- package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
- package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
- package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
- package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
- package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
- package/assets/pitfalls/git-workflow-pr.github.md +107 -0
- package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
- package/assets/pitfalls/git-workflow-push.azure.md +30 -0
- package/assets/pitfalls/git-workflow-push.github.md +30 -0
- package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
- package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
- package/assets/pitfalls/git-workflow-queue.github.md +30 -0
- package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
- package/assets/pitfalls/git-workflow-restart.md +72 -0
- package/assets/pitfalls/git-workflow-secrets.md +114 -0
- package/assets/pitfalls/git-workflow-stack.md +254 -0
- package/assets/pitfalls/git-workflow.2.azure.md +291 -0
- package/assets/pitfalls/git-workflow.2.github.md +294 -0
- package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
- package/assets/pitfalls/lib-layers.md +114 -0
- package/assets/pitfalls/lists.md +117 -0
- package/assets/pitfalls/mockups.needs-mockups.md +87 -0
- package/assets/pitfalls/navigation.md +94 -0
- package/assets/pitfalls/observability.needs-app.md +186 -0
- package/assets/pitfalls/platform-access.md +94 -0
- package/assets/pitfalls/queue-audit.github.md +78 -0
- package/assets/pitfalls/reuse-first.md +201 -0
- package/assets/pitfalls/spec-driven.2.md +318 -0
- package/assets/pitfalls/styling-bem.2.md +125 -0
- package/assets/pitfalls/task-flow-archive.md +265 -0
- package/assets/pitfalls/task-flow-close.2.md +166 -0
- package/assets/pitfalls/task-flow-close.md +167 -0
- package/assets/pitfalls/task-flow-cycle.md +73 -0
- package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
- package/assets/pitfalls/task-flow-handoff.md +200 -0
- package/assets/pitfalls/task-flow-handover.md +30 -0
- package/assets/pitfalls/task-flow-owner.md +58 -0
- package/assets/pitfalls/task-flow-plan.md +29 -0
- package/assets/pitfalls/task-flow-resume.md +257 -0
- package/assets/pitfalls/task-flow-start.md +287 -0
- package/assets/pitfalls/task-flow.2.md +303 -0
- package/assets/pitfalls/task-flow.md +4 -4
- package/assets/pitfalls/testing.2.md +279 -0
- package/assets/pitfalls/turn-conduct.md +16 -17
- package/assets/pitfalls/typescript-conventions.md +161 -0
- package/assets/pitfalls/write-a-skill.md +128 -0
- package/assets/rules/angular-patterns.md +21 -86
- package/assets/rules/autonomous-work.md +2 -2
- package/assets/rules/browser-verification.md +28 -256
- package/assets/rules/component-structure.md +25 -87
- package/assets/rules/dependencies.md +20 -78
- package/assets/rules/deploy-flow.azure.md +26 -156
- package/assets/rules/deploy-flow.github.md +34 -200
- package/assets/rules/deploy-flow.gitlab.md +27 -159
- package/assets/rules/doc-style.md +32 -286
- package/assets/rules/entity-conventions.needs-admin.md +26 -82
- package/assets/rules/entity-models.md +14 -63
- package/assets/rules/epic-flow.md +24 -63
- package/assets/rules/git-workflow-hosting.azure.md +26 -0
- package/assets/rules/git-workflow-hosting.github.md +38 -0
- package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
- package/assets/rules/git-workflow-push.azure.md +28 -0
- package/assets/rules/git-workflow-push.github.md +28 -0
- package/assets/rules/git-workflow-push.gitlab.md +28 -0
- package/assets/rules/git-workflow-queue.azure.md +23 -0
- package/assets/rules/git-workflow-queue.github.md +30 -0
- package/assets/rules/git-workflow-queue.gitlab.md +23 -0
- package/assets/rules/git-workflow.azure.md +21 -282
- package/assets/rules/git-workflow.github.md +24 -284
- package/assets/rules/git-workflow.gitlab.md +21 -269
- package/assets/rules/lib-layers.md +30 -103
- package/assets/rules/lists.md +21 -105
- package/assets/rules/mockups.needs-mockups.md +25 -64
- package/assets/rules/navigation.md +10 -69
- package/assets/rules/observability.needs-app.md +43 -172
- package/assets/rules/platform-access.md +28 -75
- package/assets/rules/queue-audit.github.md +25 -52
- package/assets/rules/reuse-first.md +20 -195
- package/assets/rules/spec-driven.md +35 -308
- package/assets/rules/styling-bem.md +20 -117
- package/assets/rules/task-flow-handover.md +24 -0
- package/assets/rules/task-flow-owner.md +34 -0
- package/assets/rules/task-flow-plan.md +38 -0
- package/assets/rules/task-flow.md +22 -300
- package/assets/rules/testing.md +32 -273
- package/assets/rules/turn-conduct.md +105 -106
- package/assets/rules/turn-entry.md +2 -2
- package/assets/rules/typescript-conventions.md +41 -147
- package/assets/samples/tasks/_template/plan.md +30 -6
- package/assets/samples/tasks/_template/progress.md +0 -1
- package/assets/skills/agent-kit-extend.md +25 -168
- package/assets/skills/agent-kit.md +27 -299
- package/assets/skills/write-a-skill.md +20 -106
- package/assets/task-flow/flow.js +184 -0
- package/assets/task-flow/flow.md +101 -0
- package/assets/task-flow/measure/agreement.mjs +24 -0
- package/assets/task-flow/measure/ci.mjs +184 -0
- package/assets/task-flow/measure/copy.mjs +22 -0
- package/assets/task-flow/measure/epic-of.mjs +50 -0
- package/assets/task-flow/measure/epic-text.mjs +35 -0
- package/assets/task-flow/measure/epic.mjs +114 -0
- package/assets/task-flow/measure/folder.mjs +16 -0
- package/assets/task-flow/measure/footprint.mjs +28 -0
- package/assets/task-flow/measure/grill.mjs +21 -0
- package/assets/task-flow/measure/host.mjs +8 -0
- package/assets/task-flow/measure/owner.mjs +27 -0
- package/assets/task-flow/measure/plan.mjs +27 -0
- package/assets/task-flow/measure/pr.mjs +20 -0
- package/assets/task-flow/measure/progress.mjs +50 -0
- package/assets/task-flow/measure/session.mjs +252 -0
- package/assets/task-flow/measure/task.mjs +23 -0
- package/assets/task-flow/measure/text.mjs +77 -0
- package/assets/task-flow/source/git.mjs +254 -0
- package/assets/task-flow/source/host.mjs +277 -0
- package/assets/task-flow/source/marks.mjs +56 -0
- package/assets/task-flow/source/owner.mjs +94 -0
- package/assets/task-flow/source/records.mjs +116 -0
- package/assets/task-flow/source/session.mjs +269 -0
- package/assets/task-flow/source/steps.mjs +28 -0
- package/assets/task-flow/source/tree.mjs +42 -0
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +30 -0
- package/bin/agent-kit.js.map +1 -1
- package/lib/agent-checks.d.ts +55 -0
- package/lib/agent-checks.d.ts.map +1 -0
- package/lib/agent-checks.js +221 -0
- package/lib/agent-checks.js.map +1 -0
- package/lib/assets.d.ts.map +1 -1
- package/lib/assets.js +7 -2
- package/lib/assets.js.map +1 -1
- package/lib/cargo.d.ts +29 -0
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +27 -1
- package/lib/cargo.js.map +1 -1
- package/lib/cascade.d.ts.map +1 -1
- package/lib/cascade.js +3 -1
- package/lib/cascade.js.map +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +78 -2
- package/lib/commands.js.map +1 -1
- package/lib/config.d.ts +18 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +18 -1
- package/lib/config.js.map +1 -1
- package/lib/epic-window-send.d.ts +74 -0
- package/lib/epic-window-send.d.ts.map +1 -0
- package/lib/epic-window-send.js +166 -0
- package/lib/epic-window-send.js.map +1 -0
- package/lib/hooks-map.d.ts +4 -0
- package/lib/hooks-map.d.ts.map +1 -1
- package/lib/hooks-map.js +2 -2
- package/lib/hooks-map.js.map +1 -1
- package/lib/integrity.d.ts +3 -0
- package/lib/integrity.d.ts.map +1 -1
- package/lib/integrity.js +7 -0
- package/lib/integrity.js.map +1 -1
- package/lib/metric-lines.d.ts +2 -1
- package/lib/metric-lines.d.ts.map +1 -1
- package/lib/metric-lines.js +49 -1
- package/lib/metric-lines.js.map +1 -1
- package/lib/metric-send-mark.d.ts +6 -3
- package/lib/metric-send-mark.d.ts.map +1 -1
- package/lib/metric-send-mark.js +15 -5
- package/lib/metric-send-mark.js.map +1 -1
- package/lib/metric-send.d.ts +6 -2
- package/lib/metric-send.d.ts.map +1 -1
- package/lib/metric-send.js +47 -13
- package/lib/metric-send.js.map +1 -1
- package/lib/metrics.d.ts +17 -0
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +26 -15
- package/lib/metrics.js.map +1 -1
- package/lib/observations.js +3 -3
- package/lib/observations.js.map +1 -1
- package/lib/outcomes.d.ts +5 -2
- package/lib/outcomes.d.ts.map +1 -1
- package/lib/outcomes.js +5 -4
- package/lib/outcomes.js.map +1 -1
- package/lib/push-gate.d.ts +13 -0
- package/lib/push-gate.d.ts.map +1 -1
- package/lib/push-gate.js +11 -7
- package/lib/push-gate.js.map +1 -1
- package/lib/push-set-usefulness.d.ts +78 -0
- package/lib/push-set-usefulness.d.ts.map +1 -0
- package/lib/push-set-usefulness.js +225 -0
- package/lib/push-set-usefulness.js.map +1 -0
- package/lib/sync.d.ts +10 -0
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +14 -1
- package/lib/sync.js.map +1 -1
- package/lib/work-result.d.ts +43 -0
- package/lib/work-result.d.ts.map +1 -0
- package/lib/work-result.js +39 -0
- package/lib/work-result.js.map +1 -0
- package/package.json +1 -1
- package/assets/hooks/claim-guard.sh +0 -212
- package/assets/hooks/grill-gate-ask.sh +0 -26
- package/assets/hooks/grill-gate-bypass.sh +0 -61
- package/assets/hooks/grill-gate-options.sh +0 -50
- package/assets/hooks/grill-gate.sh +0 -482
- package/assets/hooks/postmortem-guard.sh +0 -124
- package/assets/hooks/proposal-guard.sh +0 -154
- package/assets/hooks/stand-login-guard.sh +0 -107
- package/assets/hooks/turn-exit-epic.sh +0 -173
- package/assets/hooks/turn-exit-patterns.sh +0 -123
- package/assets/hooks/turn-exit-verdict.sh +0 -149
- package/assets/hooks/waiting-turn-guard.sh +0 -320
- package/assets/hooks/work-start-guard.sh +0 -175
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source «source.marks» of the task flow description: the marks the engine writes into the
|
|
3
|
+
* common directory of git, `rt-kit/` under `git rev-parse --git-common-dir`. Every working copy of
|
|
4
|
+
* the tree sees the same marks: an approval given in one copy holds in another.
|
|
5
|
+
*
|
|
6
|
+
* approval(branch) the approval mark of the plan of the branch: { answer, plan }, or null
|
|
7
|
+
* step(branch, number) the mark of a step of the plan: { matched, … }, or null
|
|
8
|
+
* writeApproval(branch, mark) writes the approval mark
|
|
9
|
+
* writeStep(branch, number, mark) writes the mark of a step
|
|
10
|
+
* dropStep(branch, number) removes the mark of a step, if one lies
|
|
11
|
+
*
|
|
12
|
+
* A mark that does not parse as JSON reads as absent: a broken mark never reads as a met exit. Only
|
|
13
|
+
* the engine writes the marks.
|
|
14
|
+
*/
|
|
15
|
+
import { spawnSync } from 'node:child_process';
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
17
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
18
|
+
|
|
19
|
+
/** The directory of the marks, or null outside a repository. */
|
|
20
|
+
export function marksDir() {
|
|
21
|
+
const out = spawnSync('git', ['rev-parse', '--git-common-dir'], { encoding: 'utf8' });
|
|
22
|
+
if (out.status !== 0) return null;
|
|
23
|
+
const common = out.stdout.trim();
|
|
24
|
+
return join(isAbsolute(common) ? common : join(process.cwd(), common), 'rt-kit');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const readMark = (file) => {
|
|
28
|
+
if (!file || !existsSync(file)) return null;
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const writeMark = (file, mark) => {
|
|
37
|
+
if (!file) throw new Error('source.marks: no repository, no place for a mark');
|
|
38
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
39
|
+
writeFileSync(file, `${JSON.stringify(mark, null, 2)}\n`);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function open() {
|
|
43
|
+
const dir = marksDir();
|
|
44
|
+
const approvalFile = (branch) => dir && join(dir, 'approval', `${branch}.json`);
|
|
45
|
+
const stepFile = (branch, number) => dir && join(dir, 'steps', branch, `${number}.json`);
|
|
46
|
+
return {
|
|
47
|
+
approval: (branch) => readMark(approvalFile(branch)),
|
|
48
|
+
step: (branch, number) => readMark(stepFile(branch, number)),
|
|
49
|
+
writeApproval: (branch, mark) => writeMark(approvalFile(branch), mark),
|
|
50
|
+
writeStep: (branch, number, mark) => writeMark(stepFile(branch, number), mark),
|
|
51
|
+
dropStep: (branch, number) => {
|
|
52
|
+
const file = stepFile(branch, number);
|
|
53
|
+
if (file) rmSync(file, { force: true });
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source «source.owner» of the task flow description: the words of the owner in this session,
|
|
3
|
+
* read from the record of the conversation the hook names in `RT_FLOW_TRANSCRIPT`.
|
|
4
|
+
*
|
|
5
|
+
* messages() the texts the owner typed, oldest first, during a turn too; a tool result is
|
|
6
|
+
* not a message
|
|
7
|
+
* said(quote) a typed message holds the quote
|
|
8
|
+
* last() the owner's last word: the last message typed or the options chosen in a menu,
|
|
9
|
+
* or null
|
|
10
|
+
*
|
|
11
|
+
* What the owner typed is read by the shared rule of the owner's words, `typedOf` of the laid-out
|
|
12
|
+
* `record-count.mjs`: a message typed before a turn or queued during one, a pasted text included; a
|
|
13
|
+
* wrapper or a notice of the harness, a message of a hook, a summary of a compaction and a meta entry
|
|
14
|
+
* are no word. The mark of Esc is a word of its own here: it is the owner's interrupt. Without a
|
|
15
|
+
* record the owner said nothing: an interrupt not found keeps the turn held — the stricter reading.
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { dirname, join } from 'node:path';
|
|
19
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
20
|
+
|
|
21
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
// Next to the laid-out engine one level up, or among the checks of the package.
|
|
23
|
+
const SHARED = [join(HERE, '..', '..', 'record-count.mjs'), join(HERE, '..', '..', 'checks', 'record-count.mjs')].find((p) => existsSync(p));
|
|
24
|
+
const { typedOf } = await import(pathToFileURL(SHARED).href);
|
|
25
|
+
|
|
26
|
+
/** The menu answer as the text of a tool result carries it. */
|
|
27
|
+
const ANSWERED = /^(?:The user answered|Your questions have been answered):/;
|
|
28
|
+
|
|
29
|
+
/** The mark the host writes when the owner presses Esc. */
|
|
30
|
+
const INTERRUPT_MARK = /^\[Request interrupted by user/;
|
|
31
|
+
|
|
32
|
+
const ownerEntry = (entry) =>
|
|
33
|
+
entry?.type === 'user' && !entry.isMeta && !entry.isCompactSummary && (entry.origin?.kind ?? 'human') === 'human';
|
|
34
|
+
|
|
35
|
+
const resultText = (content) =>
|
|
36
|
+
typeof content === 'string' ? content : Array.isArray(content) ? content.map((part) => (typeof part === 'object' ? (part.text ?? '') : '')).join(' ') : '';
|
|
37
|
+
|
|
38
|
+
/** The mark of Esc of a user entry, or null. */
|
|
39
|
+
const interruptOf = (entry) => {
|
|
40
|
+
if (!ownerEntry(entry)) return null;
|
|
41
|
+
const content = entry.message?.content;
|
|
42
|
+
const text = typeof content === 'string' ? content : Array.isArray(content) ? content.filter((part) => part?.type === 'text').map((part) => part.text).join('\n') : '';
|
|
43
|
+
return INTERRUPT_MARK.test(text.trim()) ? text : null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The word of one entry of the record: typed text, the mark of Esc or chosen options; null when it carries none. */
|
|
47
|
+
export function wordOf(entry) {
|
|
48
|
+
const typed = typedOf(entry);
|
|
49
|
+
if (typed) return typed.text;
|
|
50
|
+
const mark = interruptOf(entry);
|
|
51
|
+
if (mark) return mark;
|
|
52
|
+
if (!ownerEntry(entry)) return null;
|
|
53
|
+
if (entry.toolUseResult?.answers) return Object.values(entry.toolUseResult.answers).join('\n');
|
|
54
|
+
const content = entry.message?.content;
|
|
55
|
+
if (!Array.isArray(content)) return null;
|
|
56
|
+
const answers = content
|
|
57
|
+
.filter((part) => part?.type === 'tool_result' && ANSWERED.test(resultText(part.content)))
|
|
58
|
+
.map((part) => [...resultText(part.content).matchAll(/"=\s*"([^"]*)"/g)].map((match) => match[1]).join('\n'));
|
|
59
|
+
return answers.length > 0 ? answers.join('\n') : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const parse = (file) => {
|
|
63
|
+
const entries = [];
|
|
64
|
+
if (!file || !existsSync(file)) return entries;
|
|
65
|
+
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
66
|
+
if (!line.trim()) continue;
|
|
67
|
+
try {
|
|
68
|
+
entries.push(JSON.parse(line));
|
|
69
|
+
} catch {
|
|
70
|
+
// A line that does not parse is no entry.
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return entries;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export function open() {
|
|
77
|
+
let cached = null;
|
|
78
|
+
const entries = () => (cached ??= parse(process.env.RT_FLOW_TRANSCRIPT));
|
|
79
|
+
const messages = () =>
|
|
80
|
+
entries()
|
|
81
|
+
.map((entry) => typedOf(entry)?.text ?? null)
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
// Esc stops the order typed just before it too: the host sends no queued message after the mark,
|
|
84
|
+
// and over 14–22.11 none of 17 marks within five seconds of a word was followed by it again.
|
|
85
|
+
const last = () => {
|
|
86
|
+
const all = entries();
|
|
87
|
+
for (let index = all.length - 1; index >= 0; index -= 1) {
|
|
88
|
+
const word = wordOf(all[index]);
|
|
89
|
+
if (word !== null) return word;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
};
|
|
93
|
+
return { messages, said: (quote) => messages().some((text) => text.includes(quote)), last };
|
|
94
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The record directories of this repository: the directories where the harness keeps the session
|
|
3
|
+
* records of every working copy, one per copy. The harness names a directory by the path of its copy
|
|
4
|
+
* with every slash and dot turned into a dash, under `~/.claude/projects`; `RT_FLOW_RECORDS_HOME`
|
|
5
|
+
* names another home, as the suites do. The copies are those `git worktree list` names.
|
|
6
|
+
*
|
|
7
|
+
* dirs() the record directories that exist, the main copy first
|
|
8
|
+
* records() the session records in them: the files ending in .jsonl, not the memory
|
|
9
|
+
* holds(path) the path is a session record in one of the record directories
|
|
10
|
+
* said(quote) a message the owner typed in any of the records holds the quote
|
|
11
|
+
* entry(path, uuid) the entry with that uuid in a record of the record directories, or null
|
|
12
|
+
* approvalFault(mark, planSha, task) why the approval mark does not hold here, or null
|
|
13
|
+
*
|
|
14
|
+
* A record outside these directories is no record of this repository: a path a caller names in
|
|
15
|
+
* `RT_FLOW_TRANSCRIPT` counts only when it lies in one of them.
|
|
16
|
+
*/
|
|
17
|
+
import { spawnSync } from 'node:child_process';
|
|
18
|
+
import { existsSync, readdirSync, realpathSync } from 'node:fs';
|
|
19
|
+
import { homedir } from 'node:os';
|
|
20
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
21
|
+
import { wordOf } from './owner.mjs';
|
|
22
|
+
import { linesOf } from './session.mjs';
|
|
23
|
+
|
|
24
|
+
/** The approving answer: a menu option or a message that begins so. */
|
|
25
|
+
const APPROVE = /^\s*Одобряю/u;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Why an approval mark does not hold, or null when it does: the mark names the commit of the plan
|
|
29
|
+
* and the place of the answer — a session record of this repository and the uuid of its entry — and
|
|
30
|
+
* the entry there is the owner's answer that begins with «Одобряю» and names `plan.md` or the task.
|
|
31
|
+
* The move of every reason is the same: ask the owner again and run `plan-red`.
|
|
32
|
+
*/
|
|
33
|
+
export function approvalFault(mark, planSha, task, records) {
|
|
34
|
+
if (!mark || typeof mark.answer !== 'string') return 'there is no approval mark';
|
|
35
|
+
if (!mark.place?.record || !mark.place?.uuid) return 'the approval mark names no place of the answer';
|
|
36
|
+
if (mark.plan !== planSha) return 'the approval mark names another commit of the plan';
|
|
37
|
+
if (!records.holds(mark.place.record)) return 'the place of the answer is not a session record of this repository';
|
|
38
|
+
if (!existsSync(mark.place.record)) return 'the session record of the answer is gone';
|
|
39
|
+
const entry = records.entry(mark.place.record, mark.place.uuid);
|
|
40
|
+
if (!entry) return 'the session record no longer holds the entry of the answer';
|
|
41
|
+
const word = wordOf(entry) ?? '';
|
|
42
|
+
if (!APPROVE.test(word) || !new RegExp(`plan\\.md|${task}(?!\\d)`).test(word)) return 'the entry at the place is no approving answer of the owner';
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The name of the record directory of a working copy. */
|
|
47
|
+
export const encodeCopy = (path) => resolve(path).replace(/[/.]/g, '-');
|
|
48
|
+
|
|
49
|
+
/** The path with the links of its existing part resolved: a home under a link names one directory. */
|
|
50
|
+
const real = (path) => {
|
|
51
|
+
const full = resolve(path);
|
|
52
|
+
if (existsSync(full)) return realpathSync(full);
|
|
53
|
+
const parent = dirname(full);
|
|
54
|
+
return parent === full ? full : join(real(parent), basename(full));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const home = () => process.env.RT_FLOW_RECORDS_HOME || join(homedir(), '.claude', 'projects');
|
|
58
|
+
|
|
59
|
+
const copies = (root) => {
|
|
60
|
+
const out = spawnSync('git', ['-C', root, 'worktree', 'list', '--porcelain'], { encoding: 'utf8' });
|
|
61
|
+
if (out.status !== 0) return [resolve(root)];
|
|
62
|
+
return out.stdout
|
|
63
|
+
.split('\n')
|
|
64
|
+
.filter((line) => line.startsWith('worktree '))
|
|
65
|
+
.map((line) => line.slice('worktree '.length));
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const parse = (file) => {
|
|
69
|
+
const entries = [];
|
|
70
|
+
// By pieces: a record longer than one string of the runtime is never held whole.
|
|
71
|
+
for (const line of linesOf(file)) {
|
|
72
|
+
if (!line.trim()) continue;
|
|
73
|
+
try {
|
|
74
|
+
entries.push(JSON.parse(line));
|
|
75
|
+
} catch {
|
|
76
|
+
// A line that does not parse is no entry.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return entries;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function open() {
|
|
83
|
+
return openAt(process.cwd());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The same for the working copy at `root`: the guard reads the tree of the call, not its own. */
|
|
87
|
+
export function openAt(root) {
|
|
88
|
+
const dirs = () => copies(root).map((copy) => join(home(), encodeCopy(copy))).filter((dir) => existsSync(dir)).map((dir) => realpathSync(dir));
|
|
89
|
+
const records = () =>
|
|
90
|
+
dirs().flatMap((dir) =>
|
|
91
|
+
readdirSync(dir)
|
|
92
|
+
.filter((name) => name.endsWith('.jsonl'))
|
|
93
|
+
.map((name) => join(dir, name)),
|
|
94
|
+
);
|
|
95
|
+
const holds = (path) => {
|
|
96
|
+
if (!path || !path.endsWith('.jsonl')) return false;
|
|
97
|
+
const full = real(path);
|
|
98
|
+
// Directly in a record directory: a subagent record one level down is no session record.
|
|
99
|
+
return dirs().some((dir) => full.startsWith(`${dir}/`) && !full.slice(dir.length + 1).includes('/'));
|
|
100
|
+
};
|
|
101
|
+
const said = (quote) => {
|
|
102
|
+
const files = records();
|
|
103
|
+
if (!quote || files.length === 0) return false;
|
|
104
|
+
// The text is searched first, the entries are read only in the records that hold it.
|
|
105
|
+
const out = spawnSync('grep', ['-lF', '--', quote, ...files], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
|
|
106
|
+
const hits = (out.stdout ?? '').split('\n').filter(Boolean);
|
|
107
|
+
return hits.some((file) => parse(file).some((entry) => (wordOf(entry) ?? '').includes(quote)));
|
|
108
|
+
};
|
|
109
|
+
const entry = (path, uuid) => {
|
|
110
|
+
if (!holds(path) || !existsSync(path)) return null;
|
|
111
|
+
return parse(path).find((e) => e.uuid === uuid) ?? null;
|
|
112
|
+
};
|
|
113
|
+
const api = { dirs, records, holds, said, entry };
|
|
114
|
+
api.approvalFault = (mark, planSha, task) => approvalFault(mark, planSha, task, api);
|
|
115
|
+
return api;
|
|
116
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source «source.session» of the task flow description: what this session did, read from the
|
|
3
|
+
* record of the conversation the hook names in `RT_FLOW_TRANSCRIPT`, and the role it runs as, named
|
|
4
|
+
* by the hook in `RT_FLOW_AGENT`.
|
|
5
|
+
*
|
|
6
|
+
* toolUses() the calls of the agent, oldest first: { name, input }
|
|
7
|
+
* events() what happened in the record, oldest first: a refusal at the end of a turn
|
|
8
|
+
* { kind: 'refusal', text, by } — `by` is the hook that refused, see `refusalBy`
|
|
9
|
+
* — a menu { kind: 'menu', answered }, a call of a tool
|
|
10
|
+
* { kind: 'call', id, name, input, blocked, at, branch, doneAt, failed } — `branch` is
|
|
11
|
+
* the branch of its record entry, `doneAt` the time of its result, `failed` an
|
|
12
|
+
* error result — a refusal of a call by a hook { kind: 'blocked', by, reason }, the
|
|
13
|
+
* start of a background task { kind: 'background', id, task, at, output, agent,
|
|
14
|
+
* command } — `command` is the command of its call — its end { kind: 'backgroundEnd', id,
|
|
15
|
+
* task, output, status, stopped } — `stopped` when the session stopped it itself —
|
|
16
|
+
* and a turn that ended { kind: 'ended' }
|
|
17
|
+
* now() the time the session is judged at, in milliseconds
|
|
18
|
+
* agent() the role the session runs as, or null
|
|
19
|
+
* roleTools(role) the `tools:` line of the role's header, or null
|
|
20
|
+
*
|
|
21
|
+
* Without a record the session did nothing: no write, no refusal, no menu.
|
|
22
|
+
*/
|
|
23
|
+
import { closeSync, existsSync, openSync, readFileSync, readSync } from 'node:fs';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
/** The text a refusal at the end of a turn arrives with. */
|
|
27
|
+
const STOP_FEEDBACK = /^Stop hook feedback:/;
|
|
28
|
+
/** The name of a hook in a refusal; the opening of a refusal of the model check of a stop, which may name nothing. */
|
|
29
|
+
const BLOCKED_BY = /BLOCKED by ([\w-]+)/;
|
|
30
|
+
const MODEL_HOOK = /^Agent hook condition was not met:/;
|
|
31
|
+
/** The model check of a stop: its refusal with no name of a hook is still its own. */
|
|
32
|
+
const MODEL_CHECK = 'turn-judge';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The hook that refused a stop, read from the first line after the feedback header: the name of
|
|
36
|
+
* «BLOCKED by <name>» anywhere in the line, or null. After the opening of the model check only a
|
|
37
|
+
* name right after it counts, and with none the refusal is the model check's: its free text may
|
|
38
|
+
* quote another hook.
|
|
39
|
+
*/
|
|
40
|
+
export function refusalBy(text) {
|
|
41
|
+
const line = String(text ?? '').replace(STOP_FEEDBACK, '').replace(/^\s+/, '').split('\n')[0];
|
|
42
|
+
const rest = line.replace(MODEL_HOOK, '');
|
|
43
|
+
if (rest !== line) return rest.match(/^\s*BLOCKED by ([\w-]+)/)?.[1] ?? MODEL_CHECK;
|
|
44
|
+
return line.match(BLOCKED_BY)?.[1] ?? null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A hook refused a call: the result of the call names the guard that refused it. */
|
|
48
|
+
const CALL_REFUSAL = /hook error:[\s\S]*?BLOCKED by ([\w-]+):\s*([^\n]*)/;
|
|
49
|
+
|
|
50
|
+
/** The end of a background task in its notice. */
|
|
51
|
+
const TASK_OVER = /<status>(?:completed|failed|killed|stopped)<\/status>/;
|
|
52
|
+
/** A notice with a final status of an agent that goes on: it stopped with background work of its own and notifies again. */
|
|
53
|
+
const STILL_RUNNING = /<summary>[^<]*is waiting on its own background work<\/summary>/;
|
|
54
|
+
/** A refusal of a stop hook in the summary of the stop hooks. */
|
|
55
|
+
const STOP_BLOCK = /BLOCKED by |"decision"\s*:\s*"block"/;
|
|
56
|
+
/** The file a background task writes its output to, named in the result of its call. */
|
|
57
|
+
const OUTPUT_FILE = /(?:Output is being written to|output_file):?[ \t]*([^\n]+)/;
|
|
58
|
+
/** The path in the line of the output file: the line up to a sentence that follows it, with no closing stop. */
|
|
59
|
+
const outputOf = (text) => text.match(OUTPUT_FILE)?.[1].replace(/\.\s+[A-Z].*$/, '').replace(/[.,]$/, '').trim() || null;
|
|
60
|
+
/** The tools whose call ends a background task. */
|
|
61
|
+
const STOP_TOOLS = new Set(['TaskStop', 'KillShell', 'KillBash']);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The lines of a file, read by pieces of `piece` bytes: a record longer than one string of the
|
|
65
|
+
* runtime is never held whole. A line cut by the edge of a piece is put together from its parts.
|
|
66
|
+
*/
|
|
67
|
+
export function* linesOf(file, piece = 1 << 22) {
|
|
68
|
+
const fd = openSync(file, 'r');
|
|
69
|
+
const chunk = Buffer.alloc(piece);
|
|
70
|
+
let rest = [];
|
|
71
|
+
try {
|
|
72
|
+
for (let read; (read = readSync(fd, chunk, 0, chunk.length, null)) > 0; ) {
|
|
73
|
+
let start = 0;
|
|
74
|
+
for (let at = chunk.indexOf(10, 0); at !== -1 && at < read; at = chunk.indexOf(10, start)) {
|
|
75
|
+
if (rest.length === 0) yield chunk.toString('utf8', start, at);
|
|
76
|
+
else {
|
|
77
|
+
rest.push(Buffer.from(chunk.subarray(start, at)));
|
|
78
|
+
yield Buffer.concat(rest).toString('utf8');
|
|
79
|
+
rest = [];
|
|
80
|
+
}
|
|
81
|
+
start = at + 1;
|
|
82
|
+
}
|
|
83
|
+
if (start < read) rest.push(Buffer.from(chunk.subarray(start, read)));
|
|
84
|
+
}
|
|
85
|
+
} finally {
|
|
86
|
+
closeSync(fd);
|
|
87
|
+
}
|
|
88
|
+
if (rest.length > 0) yield Buffer.concat(rest).toString('utf8');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const parse = (file) => {
|
|
92
|
+
if (!file || !existsSync(file)) return [];
|
|
93
|
+
const entries = [];
|
|
94
|
+
for (const line of linesOf(file)) {
|
|
95
|
+
if (!line.trim()) continue;
|
|
96
|
+
try {
|
|
97
|
+
entries.push(JSON.parse(line));
|
|
98
|
+
} catch {
|
|
99
|
+
// A broken line is no entry.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return entries;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const parts = (entry) => (Array.isArray(entry?.message?.content) ? entry.message.content : []);
|
|
106
|
+
|
|
107
|
+
const feedbackText = (entry) => {
|
|
108
|
+
const content = entry?.message?.content;
|
|
109
|
+
const text = typeof content === 'string' ? content : parts(entry).map((part) => (part?.type === 'text' ? part.text : '')).join('\n');
|
|
110
|
+
return STOP_FEEDBACK.test(text) ? text : null;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const resultText = (part) =>
|
|
114
|
+
typeof part.content === 'string'
|
|
115
|
+
? part.content
|
|
116
|
+
: Array.isArray(part.content)
|
|
117
|
+
? part.content.map((piece) => (piece?.type === 'text' ? piece.text : '')).join('\n')
|
|
118
|
+
: '';
|
|
119
|
+
|
|
120
|
+
/** The notice of background tasks that are over: [{ id, task }], or null. */
|
|
121
|
+
const taskOver = (entry) => {
|
|
122
|
+
// A notice comes as a queue operation, as a message, or as a queued command attached to the record.
|
|
123
|
+
const content =
|
|
124
|
+
entry?.type === 'queue-operation'
|
|
125
|
+
? entry.content
|
|
126
|
+
: entry?.type === 'user'
|
|
127
|
+
? entry.message?.content
|
|
128
|
+
: entry?.type === 'attachment' && entry.attachment?.type === 'queued_command'
|
|
129
|
+
? entry.attachment.prompt
|
|
130
|
+
: null;
|
|
131
|
+
const text = typeof content === 'string' ? content : '';
|
|
132
|
+
if (!text.includes('<task-notification>') || !TASK_OVER.test(text) || STILL_RUNNING.test(text)) return null;
|
|
133
|
+
const id = text.match(/<tool-use-id>([^<]+)</)?.[1] ?? null;
|
|
134
|
+
const output = text.match(/<output-file>([^<]+)</)?.[1] ?? null;
|
|
135
|
+
const status = text.match(/<status>([^<]+)</)?.[1] ?? null;
|
|
136
|
+
// One notice may name several tasks: the commands a previous session left unfinished.
|
|
137
|
+
const tasks = [...text.matchAll(/<task-id>([^<]+)</g)].map((match) => match[1]);
|
|
138
|
+
return tasks.length > 1 ? tasks.map((task) => ({ id: null, task, output: null, status })) : [{ id, task: tasks[0] ?? null, output, status }];
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The start of a background task in the result of its call: a command sent to the background whose
|
|
143
|
+
* result names the task, an agent whose result is asynchronous, or an agent a message resumed — it
|
|
144
|
+
* runs in the background again and sends its notice again.
|
|
145
|
+
*/
|
|
146
|
+
const taskStarted = (entry) => {
|
|
147
|
+
const result = entry?.toolUseResult;
|
|
148
|
+
if (!result || typeof result !== 'object') return null;
|
|
149
|
+
if (result.backgroundTaskId) return String(result.backgroundTaskId);
|
|
150
|
+
if (result.resumedAgentId) return String(result.resumedAgentId);
|
|
151
|
+
return result.isAsync ? String(result.agentId ?? '') : null;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/** The refusals, the menus, the calls, the background tasks and the ended turns of a record, in their order. */
|
|
155
|
+
export function eventsOf(entries) {
|
|
156
|
+
const menus = new Map();
|
|
157
|
+
const calls = new Map();
|
|
158
|
+
const events = [];
|
|
159
|
+
// The agent closed its turn, and the record does not say yet whether the stop was released. A
|
|
160
|
+
// refusal of the stop comes as its feedback; a released stop is seen only by what follows it —
|
|
161
|
+
// the summary of the stop hooks with no refusal, a new message or a new turn of the agent. The
|
|
162
|
+
// last entry of a record is therefore never an ended turn. The service entries the harness
|
|
163
|
+
// flushes at any minute — the last prompt, the title, the mode — say nothing: in the records
|
|
164
|
+
// they stand between a closed turn and the feedback of its stop.
|
|
165
|
+
let closing = false;
|
|
166
|
+
const ended = () => {
|
|
167
|
+
if (closing) events.push({ kind: 'ended' });
|
|
168
|
+
closing = false;
|
|
169
|
+
};
|
|
170
|
+
for (const entry of entries) {
|
|
171
|
+
// A record of a subagent is no part of the session's own turn.
|
|
172
|
+
if (entry?.isSidechain) continue;
|
|
173
|
+
if (entry?.type === 'system' && entry.subtype === 'stop_hook_summary') {
|
|
174
|
+
if ((entry.hookErrors ?? []).some((error) => STOP_BLOCK.test(String(error)))) closing = false;
|
|
175
|
+
else {
|
|
176
|
+
closing = true;
|
|
177
|
+
ended();
|
|
178
|
+
}
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
// A meta entry is written by a hook, another hook of the stop among them: it ends no turn.
|
|
182
|
+
if (entry?.type === 'user' && !entry.isMeta && feedbackText(entry) === null) ended();
|
|
183
|
+
const over = taskOver(entry);
|
|
184
|
+
if (over) {
|
|
185
|
+
const at = Date.parse(entry.timestamp ?? '');
|
|
186
|
+
for (const task of over) events.push({ kind: 'backgroundEnd', ...task, ...(Number.isFinite(at) ? { at } : {}) });
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (entry?.type === 'assistant') {
|
|
190
|
+
if (entry.message?.stop_reason !== 'end_turn') ended();
|
|
191
|
+
closing = entry.message?.stop_reason === 'end_turn';
|
|
192
|
+
for (const part of parts(entry)) {
|
|
193
|
+
if (part?.type !== 'tool_use') continue;
|
|
194
|
+
if (part.name === 'AskUserQuestion') {
|
|
195
|
+
const event = { kind: 'menu', answered: false };
|
|
196
|
+
menus.set(part.id, event);
|
|
197
|
+
events.push(event);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const call = { kind: 'call', id: part.id, name: part.name, input: part.input ?? {}, blocked: false, at: Date.parse(entry.timestamp ?? ''), branch: entry.gitBranch ?? null };
|
|
201
|
+
calls.set(part.id, call);
|
|
202
|
+
events.push(call);
|
|
203
|
+
if (STOP_TOOLS.has(part.name)) {
|
|
204
|
+
const task = call.input.task_id ?? call.input.shell_id ?? call.input.bash_id;
|
|
205
|
+
events.push({ kind: 'backgroundEnd', id: null, task: task ? String(task) : null, output: null, stopped: true });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (entry?.type !== 'user') continue;
|
|
211
|
+
const refusal = feedbackText(entry);
|
|
212
|
+
if (refusal) {
|
|
213
|
+
closing = false;
|
|
214
|
+
events.push({ kind: 'refusal', text: refusal, by: refusalBy(refusal) });
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
for (const part of parts(entry)) {
|
|
218
|
+
if (part?.type !== 'tool_result') continue;
|
|
219
|
+
const menu = menus.get(part.tool_use_id);
|
|
220
|
+
if (menu) menu.answered = !part.is_error && Boolean(entry.toolUseResult?.answers);
|
|
221
|
+
// A monitor is no background task: a persistent one never ends.
|
|
222
|
+
const started = part.is_error || calls.get(part.tool_use_id)?.name === 'Monitor' ? null : taskStarted(entry);
|
|
223
|
+
if (started !== null) {
|
|
224
|
+
const output = outputOf(resultText(part));
|
|
225
|
+
const agent = !entry.toolUseResult.backgroundTaskId;
|
|
226
|
+
const command = calls.get(part.tool_use_id)?.input?.command ?? null;
|
|
227
|
+
events.push({ kind: 'background', id: part.tool_use_id, task: started || null, at: Date.parse(entry.timestamp ?? ''), output, agent, command });
|
|
228
|
+
}
|
|
229
|
+
const call = calls.get(part.tool_use_id);
|
|
230
|
+
if (call) {
|
|
231
|
+
// The result of a call: when it came, and whether the call failed.
|
|
232
|
+
call.doneAt = Date.parse(entry.timestamp ?? '');
|
|
233
|
+
call.failed = Boolean(part.is_error);
|
|
234
|
+
}
|
|
235
|
+
const refused = part.is_error ? resultText(part).match(CALL_REFUSAL) : null;
|
|
236
|
+
if (!refused) continue;
|
|
237
|
+
if (call) call.blocked = true;
|
|
238
|
+
events.push({ kind: 'blocked', by: refused[1], reason: refused[2].trim() });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return events;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function open() {
|
|
245
|
+
let cached = null;
|
|
246
|
+
const entries = () => (cached ??= parse(process.env.RT_FLOW_TRANSCRIPT));
|
|
247
|
+
return {
|
|
248
|
+
toolUses: () =>
|
|
249
|
+
entries()
|
|
250
|
+
.filter((entry) => entry?.type === 'assistant')
|
|
251
|
+
.flatMap((entry) => parts(entry).filter((part) => part?.type === 'tool_use'))
|
|
252
|
+
.map((part) => ({ name: part.name, input: part.input ?? {} })),
|
|
253
|
+
events: () => eventsOf(entries()),
|
|
254
|
+
now: () => Date.now(),
|
|
255
|
+
agent: () => process.env.RT_FLOW_AGENT || null,
|
|
256
|
+
roleTools: (role) => {
|
|
257
|
+
if (!role || /[/\\]|^\./.test(role)) return null;
|
|
258
|
+
const file = join(process.cwd(), '.claude', 'agents', `${role}.md`);
|
|
259
|
+
if (!existsSync(file)) return null;
|
|
260
|
+
const lines = readFileSync(file, 'utf8').split('\n');
|
|
261
|
+
if (lines[0] !== '---') return null;
|
|
262
|
+
for (const line of lines.slice(1)) {
|
|
263
|
+
if (line === '---') return null;
|
|
264
|
+
if (line.startsWith('tools:')) return line.slice('tools:'.length).trim();
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source «source.steps» of the task flow description: the parsing of the steps of a plan and of
|
|
3
|
+
* a progress, by the module every reader of both lists shares — `work-steps-lib.mjs`. A measurer
|
|
4
|
+
* imports nothing outside its directory, so the parsing reaches it through this port.
|
|
5
|
+
*
|
|
6
|
+
* ofPlan(text) [{ number, name }] — the steps of the plan in their order
|
|
7
|
+
* ofProgress(text) { steps: [{ mark, number, name }], declared } — the steps of the progress
|
|
8
|
+
* checks(text) [{ number, command, expected }] — the check line under each step of the plan;
|
|
9
|
+
* a step without one has `command` and `expected` null
|
|
10
|
+
*
|
|
11
|
+
* The parsing module lies next to the laid-out engine one level up, and in the package in the
|
|
12
|
+
* directory of the checks.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync } from 'node:fs';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const LIB = [join(HERE, '..', '..', 'work-steps-lib.mjs'), join(HERE, '..', '..', 'checks', 'work-steps-lib.mjs')].find((p) => existsSync(p));
|
|
20
|
+
const lib = LIB ? await import(pathToFileURL(LIB).href) : null;
|
|
21
|
+
|
|
22
|
+
/** The check line under each step, as the shared parsing reads it. */
|
|
23
|
+
const checks = (text) => lib.stepsOfPlan(text).map(({ number, command, expected }) => ({ number, command, expected }));
|
|
24
|
+
|
|
25
|
+
export function open() {
|
|
26
|
+
if (!lib) throw new Error('source.steps: work-steps-lib.mjs lies neither next to the engine nor in the package');
|
|
27
|
+
return { ofPlan: lib.stepsOfPlan, ofProgress: lib.stepsOfProgress, checks };
|
|
28
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source «source.tree» of the task flow description: the working copy as it lies on disk, from
|
|
3
|
+
* its root.
|
|
4
|
+
*
|
|
5
|
+
* read(path) the text of the file, null where it is absent
|
|
6
|
+
* exists(path) a file or a directory stands there
|
|
7
|
+
* list(dir) the names inside the directory, [] where it is absent
|
|
8
|
+
* copyEpic() the epic the assignment table gives this working copy, or null
|
|
9
|
+
*
|
|
10
|
+
* The assignment is read by the laid-out `tree-assignment.mjs` — next to the laid-out engine one
|
|
11
|
+
* level up, or in `tools/` of the tree root: the table has one reader, and a second one would drift
|
|
12
|
+
* from it.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const ASSIGNMENT = [join(HERE, '..', '..', 'tree-assignment.mjs'), join(process.cwd(), 'tools', 'tree-assignment.mjs')].find((p) => existsSync(p));
|
|
20
|
+
let assignment = null;
|
|
21
|
+
try {
|
|
22
|
+
assignment = ASSIGNMENT ? await import(pathToFileURL(ASSIGNMENT).href) : null;
|
|
23
|
+
} catch {
|
|
24
|
+
// A reader that does not load gives no assignment: the copy then has no epic of its own.
|
|
25
|
+
assignment = null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function open() {
|
|
29
|
+
const root = process.cwd();
|
|
30
|
+
return {
|
|
31
|
+
copyEpic: () => assignment?.assignmentOf(root)?.epic ?? null,
|
|
32
|
+
read(path) {
|
|
33
|
+
const file = join(root, path);
|
|
34
|
+
return existsSync(file) && statSync(file).isFile() ? readFileSync(file, 'utf8') : null;
|
|
35
|
+
},
|
|
36
|
+
exists: (path) => existsSync(join(root, path)),
|
|
37
|
+
list(dir) {
|
|
38
|
+
const at = join(root, dir);
|
|
39
|
+
return existsSync(at) && statSync(at).isDirectory() ? readdirSync(at).sort() : [];
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
package/bin/agent-kit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-kit.d.ts","sourceRoot":"","sources":["../../../projects/agent-kit/src/bin/agent-kit.ts"],"names":[],"mappings":";AAeA,OAAO,EAAqC,iBAAiB,EAAqB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-kit.d.ts","sourceRoot":"","sources":["../../../projects/agent-kit/src/bin/agent-kit.ts"],"names":[],"mappings":";AAeA,OAAO,EAAqC,iBAAiB,EAAqB,MAAM,oBAAoB,CAAC;AA6a7G,wBAAsB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAU9E"}
|