kortext 2.2.3 → 3.0.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/AGENTS.md +0 -4
- package/CHANGELOG.md +81 -0
- package/LICENSE +21 -0
- package/README.md +145 -55
- package/USER-GUIDE.md +505 -0
- package/bin/kortext.js +23 -0
- package/bin/kortext.ts +377 -0
- package/dist/bin/kortext.js +346 -0
- package/dist/bin/kortext.js.map +1 -0
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.js +553 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/sse.js +38 -0
- package/dist/mcp/sse.js.map +1 -0
- package/dist/mcp/stdio.js +44 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/server/cli/cleanup.js +73 -0
- package/dist/server/cli/cleanup.js.map +1 -0
- package/dist/server/cli/commands.js +73 -0
- package/dist/server/cli/commands.js.map +1 -0
- package/dist/server/cli/doctor.js +118 -0
- package/dist/server/cli/doctor.js.map +1 -0
- package/dist/server/cli/executor-factory.js +39 -0
- package/dist/server/cli/executor-factory.js.map +1 -0
- package/dist/server/cli/init.js +121 -0
- package/dist/server/cli/init.js.map +1 -0
- package/dist/server/cli/logs.js +28 -0
- package/dist/server/cli/logs.js.map +1 -0
- package/dist/server/cli/serve.js +72 -0
- package/dist/server/cli/serve.js.map +1 -0
- package/dist/server/config/env.js +12 -0
- package/dist/server/config/env.js.map +1 -0
- package/dist/server/db/client.js +32 -0
- package/dist/server/db/client.js.map +1 -0
- package/dist/server/db/json.js +21 -0
- package/dist/server/db/json.js.map +1 -0
- package/dist/server/db/migrate.js +70 -0
- package/dist/server/db/migrate.js.map +1 -0
- package/dist/server/db/migrations/001_init.sql +243 -0
- package/dist/server/db/repositories/audit-log.js +58 -0
- package/dist/server/db/repositories/audit-log.js.map +1 -0
- package/dist/server/db/repositories/backlog.js +96 -0
- package/dist/server/db/repositories/backlog.js.map +1 -0
- package/dist/server/db/repositories/contexts.js +54 -0
- package/dist/server/db/repositories/contexts.js.map +1 -0
- package/dist/server/db/repositories/decisions.js +71 -0
- package/dist/server/db/repositories/decisions.js.map +1 -0
- package/dist/server/db/repositories/handovers.js +53 -0
- package/dist/server/db/repositories/handovers.js.map +1 -0
- package/dist/server/db/repositories/index.js +30 -0
- package/dist/server/db/repositories/index.js.map +1 -0
- package/dist/server/db/repositories/locks.js +59 -0
- package/dist/server/db/repositories/locks.js.map +1 -0
- package/dist/server/db/repositories/notifications.js +63 -0
- package/dist/server/db/repositories/notifications.js.map +1 -0
- package/dist/server/db/repositories/pending-questions.js +63 -0
- package/dist/server/db/repositories/pending-questions.js.map +1 -0
- package/dist/server/db/repositories/runs.js +138 -0
- package/dist/server/db/repositories/runs.js.map +1 -0
- package/dist/server/db/repositories/runtime-artifacts.js +39 -0
- package/dist/server/db/repositories/runtime-artifacts.js.map +1 -0
- package/dist/server/db/repositories/secrets.js +65 -0
- package/dist/server/db/repositories/secrets.js.map +1 -0
- package/dist/server/db/repositories/sessions.js +48 -0
- package/dist/server/db/repositories/sessions.js.map +1 -0
- package/dist/server/db/schemas.js +308 -0
- package/dist/server/db/schemas.js.map +1 -0
- package/dist/server/engine/consistency.js +25 -0
- package/dist/server/engine/consistency.js.map +1 -0
- package/dist/server/engine/dag.js +86 -0
- package/dist/server/engine/dag.js.map +1 -0
- package/dist/server/engine/executor.js +2 -0
- package/dist/server/engine/executor.js.map +1 -0
- package/dist/server/engine/executors/claude-cli-executor.js +83 -0
- package/dist/server/engine/executors/claude-cli-executor.js.map +1 -0
- package/dist/server/engine/executors/cli-spawn.js +127 -0
- package/dist/server/engine/executors/cli-spawn.js.map +1 -0
- package/dist/server/engine/executors/codex-cli-executor.js +69 -0
- package/dist/server/engine/executors/codex-cli-executor.js.map +1 -0
- package/dist/server/engine/executors/gemini-cli-executor.js +69 -0
- package/dist/server/engine/executors/gemini-cli-executor.js.map +1 -0
- package/dist/server/engine/executors/mock-executor.js +52 -0
- package/dist/server/engine/executors/mock-executor.js.map +1 -0
- package/dist/server/engine/executors/persona-routed-executor.js +17 -0
- package/dist/server/engine/executors/persona-routed-executor.js.map +1 -0
- package/dist/server/engine/gate-enforcer.js +75 -0
- package/dist/server/engine/gate-enforcer.js.map +1 -0
- package/dist/server/engine/git-commit.js +42 -0
- package/dist/server/engine/git-commit.js.map +1 -0
- package/dist/server/engine/handover.js +120 -0
- package/dist/server/engine/handover.js.map +1 -0
- package/dist/server/engine/item-lifecycle.js +74 -0
- package/dist/server/engine/item-lifecycle.js.map +1 -0
- package/dist/server/engine/persona-registry.js +108 -0
- package/dist/server/engine/persona-registry.js.map +1 -0
- package/dist/server/engine/worker-pool.js +324 -0
- package/dist/server/engine/worker-pool.js.map +1 -0
- package/dist/server/engine/workflow-loader.js +55 -0
- package/dist/server/engine/workflow-loader.js.map +1 -0
- package/dist/server/engine/workflow-parser.js +158 -0
- package/dist/server/engine/workflow-parser.js.map +1 -0
- package/dist/server/engine/worktree.js +176 -0
- package/dist/server/engine/worktree.js.map +1 -0
- package/dist/server/index.js +99 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/notifications/dispatcher.js +60 -0
- package/dist/server/notifications/dispatcher.js.map +1 -0
- package/dist/server/notifications/slack.js +37 -0
- package/dist/server/notifications/slack.js.map +1 -0
- package/dist/server/notifications/telegram.js +33 -0
- package/dist/server/notifications/telegram.js.map +1 -0
- package/dist/server/orchestrator/approval-queue.js +83 -0
- package/dist/server/orchestrator/approval-queue.js.map +1 -0
- package/dist/server/orchestrator/blueprint-watcher.js +94 -0
- package/dist/server/orchestrator/blueprint-watcher.js.map +1 -0
- package/dist/server/orchestrator/orchestrator.js +283 -0
- package/dist/server/orchestrator/orchestrator.js.map +1 -0
- package/dist/server/orchestrator/pipeline-chainer.js +96 -0
- package/dist/server/orchestrator/pipeline-chainer.js.map +1 -0
- package/dist/server/orchestrator/resume.js +36 -0
- package/dist/server/orchestrator/resume.js.map +1 -0
- package/dist/server/routes/approvals.js +52 -0
- package/dist/server/routes/approvals.js.map +1 -0
- package/dist/server/routes/backlog.js +44 -0
- package/dist/server/routes/backlog.js.map +1 -0
- package/dist/server/routes/db-info.js +21 -0
- package/dist/server/routes/db-info.js.map +1 -0
- package/dist/server/routes/docs.js +70 -0
- package/dist/server/routes/docs.js.map +1 -0
- package/dist/server/routes/doctor.js +19 -0
- package/dist/server/routes/doctor.js.map +1 -0
- package/dist/server/routes/handovers.js +25 -0
- package/dist/server/routes/handovers.js.map +1 -0
- package/dist/server/routes/health.js +11 -0
- package/dist/server/routes/health.js.map +1 -0
- package/dist/server/routes/personas.js +96 -0
- package/dist/server/routes/personas.js.map +1 -0
- package/dist/server/routes/runs.js +41 -0
- package/dist/server/routes/runs.js.map +1 -0
- package/dist/server/routes/workflows.js +38 -0
- package/dist/server/routes/workflows.js.map +1 -0
- package/dist/server/safety/harmful-output-filter.js +40 -0
- package/dist/server/safety/harmful-output-filter.js.map +1 -0
- package/dist/server/safety/secret-scanner.js +169 -0
- package/dist/server/safety/secret-scanner.js.map +1 -0
- package/dist/server/services/markdown-sync.js +101 -0
- package/dist/server/services/markdown-sync.js.map +1 -0
- package/dist/web/assets/index-B80d5ZPZ.js +75 -0
- package/dist/web/assets/index-B80d5ZPZ.js.map +1 -0
- package/dist/web/assets/index-Bge5Gzqv.css +1 -0
- package/dist/web/index.html +13 -0
- package/docs/architecture.md +413 -0
- package/package.json +83 -11
- package/scripts/copy-migrations.mjs +29 -0
- package/workspace/.locks/workspace_handover.md.lock +3 -0
- package/hooks/audit-logger.sh +0 -25
- package/hooks/auto-locker.sh +0 -74
- package/hooks/auto-unlocker.sh +0 -17
- package/hooks/backlog-sync-guard.sh +0 -12
- package/hooks/branch-guard.sh +0 -32
- package/hooks/commit-msg-guard.sh +0 -43
- package/hooks/git-pre-commit.sh +0 -76
- package/hooks/git-pre-push.sh +0 -17
- package/hooks/handover-guard.sh +0 -33
- package/hooks/kortext-init.sh +0 -194
- package/hooks/kortext-lib.sh +0 -151
- package/hooks/lint-guard.sh +0 -50
- package/hooks/secret-scanner.sh +0 -89
- package/hooks/size-guard.sh +0 -48
- package/hooks/snapshot-guard.sh +0 -39
- package/hooks/write-guard.sh +0 -77
- package/scripts/kortext-backlog-add.py +0 -123
- package/scripts/kortext-backlog-health.py +0 -112
- package/scripts/kortext-backlog-sync.py +0 -117
- package/scripts/kortext-bulk-plan.py +0 -63
- package/scripts/kortext-cli.py +0 -376
- package/scripts/kortext-consistency-check.py +0 -74
- package/scripts/kortext-context-check.py +0 -146
- package/scripts/kortext-handover.py +0 -107
- package/scripts/kortext-item-check.py +0 -61
- package/scripts/kortext-item-start.py +0 -70
- package/scripts/kortext-item-transition.py +0 -78
- package/scripts/kortext-lock.py +0 -174
- package/scripts/kortext-session-start.py +0 -127
- package/scripts/lock_kortext.sh +0 -34
- package/settings/.claude-settings.template.json +0 -48
- package/settings/CHANGELOG.md +0 -176
- package/settings/INTEGRATION-MAP.md +0 -276
- package/settings/README.md +0 -255
- package/settings/USER-GUIDE.md +0 -502
- package/settings/VERSION +0 -1
- package/settings/config.md +0 -8
- package/settings/runtime-adapters.md +0 -104
- package/skills/backend-developer/.gitkeep +0 -0
- package/skills/compliance-expert/.gitkeep +0 -0
- package/skills/copywriter/.gitkeep +0 -0
- package/skills/db-admin/.gitkeep +0 -0
- package/skills/delivery-manager/.gitkeep +0 -0
- package/skills/designer/.gitkeep +0 -0
- package/skills/devops-engineer/.gitkeep +0 -0
- package/skills/engineering-manager/.gitkeep +0 -0
- package/skills/frontend-developer/.gitkeep +0 -0
- package/skills/growth-expert/.gitkeep +0 -0
- package/skills/operation-manager/.gitkeep +0 -0
- package/skills/product-manager/.gitkeep +0 -0
- package/skills/qa-engineer/.gitkeep +0 -0
- package/skills/security-engineer/.gitkeep +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const TRANSITIONS = {
|
|
2
|
+
start: { from: ['to_do'], to: 'in_progress' },
|
|
3
|
+
review: { from: ['in_progress'], to: 'review' },
|
|
4
|
+
done: { from: ['review'], to: 'done' },
|
|
5
|
+
block: { from: ['in_progress', 'review'], to: 'blocked' },
|
|
6
|
+
unblock: { from: ['blocked'], to: 'in_progress' },
|
|
7
|
+
cancel: { from: ['to_do', 'in_progress', 'review', 'blocked'], to: 'cancelled' },
|
|
8
|
+
};
|
|
9
|
+
const TERMINAL_STATES = new Set(['done', 'cancelled']);
|
|
10
|
+
export class IllegalTransitionError extends Error {
|
|
11
|
+
itemId;
|
|
12
|
+
transition;
|
|
13
|
+
fromStatus;
|
|
14
|
+
constructor(itemId, transition, fromStatus) {
|
|
15
|
+
super(`illegal transition '${transition}' on item ${itemId} from status '${fromStatus}'`);
|
|
16
|
+
this.itemId = itemId;
|
|
17
|
+
this.transition = transition;
|
|
18
|
+
this.fromStatus = fromStatus;
|
|
19
|
+
this.name = 'IllegalTransitionError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class ItemLifecycle {
|
|
23
|
+
opts;
|
|
24
|
+
constructor(opts) {
|
|
25
|
+
this.opts = opts;
|
|
26
|
+
}
|
|
27
|
+
create(input) {
|
|
28
|
+
if (input.owner && this.opts.personas.get(input.owner) === null) {
|
|
29
|
+
throw new Error(`unknown persona for owner: ${input.owner}`);
|
|
30
|
+
}
|
|
31
|
+
return this.opts.repos.backlog.create({
|
|
32
|
+
id: input.id,
|
|
33
|
+
type: input.type,
|
|
34
|
+
title: input.title,
|
|
35
|
+
owner: input.owner ?? null,
|
|
36
|
+
parent_id: input.parent_id ?? null,
|
|
37
|
+
body_md: input.body_md ?? '',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
transition(itemId, action, by, reason) {
|
|
41
|
+
const current = this.opts.repos.backlog.get(itemId);
|
|
42
|
+
if (!current) {
|
|
43
|
+
throw new Error(`backlog item not found: ${itemId}`);
|
|
44
|
+
}
|
|
45
|
+
if (TERMINAL_STATES.has(current.status)) {
|
|
46
|
+
throw new IllegalTransitionError(itemId, action, current.status);
|
|
47
|
+
}
|
|
48
|
+
const rule = TRANSITIONS[action];
|
|
49
|
+
if (!rule.from.includes(current.status)) {
|
|
50
|
+
throw new IllegalTransitionError(itemId, action, current.status);
|
|
51
|
+
}
|
|
52
|
+
const updated = this.opts.repos.backlog.transitionStatus(itemId, rule.to);
|
|
53
|
+
this.opts.repos.auditLog.append({
|
|
54
|
+
actor: by,
|
|
55
|
+
action: 'item_transition',
|
|
56
|
+
resource_type: 'backlog_item',
|
|
57
|
+
resource_id: itemId,
|
|
58
|
+
payload: {
|
|
59
|
+
from: current.status,
|
|
60
|
+
to: rule.to,
|
|
61
|
+
transition: action,
|
|
62
|
+
reason: reason ?? null,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
return updated;
|
|
66
|
+
}
|
|
67
|
+
/** Items in any non-terminal state — useful for dashboard "active" view. */
|
|
68
|
+
listOpen() {
|
|
69
|
+
return this.opts.repos.backlog
|
|
70
|
+
.list({ limit: 1000 })
|
|
71
|
+
.filter((i) => !TERMINAL_STATES.has(i.status));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=item-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-lifecycle.js","sourceRoot":"","sources":["../../../server/engine/item-lifecycle.ts"],"names":[],"mappings":"AA+CA,MAAM,WAAW,GAAyE;IACxF,KAAK,EAAI,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE;IAC/C,MAAM,EAAG,EAAE,IAAI,EAAE,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE;IAChD,IAAI,EAAK,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE;IACzC,KAAK,EAAI,EAAE,IAAI,EAAE,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE;IAC3D,OAAO,EAAE,EAAE,IAAI,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,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,4EAA4E;IAC5E,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO;aAC3B,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;aACrB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACnD,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
const H1_RE = /^#\s+([\w-]+)\s*$/;
|
|
4
|
+
const DESCRIPTION_RE = /^-\s*description\s*:\s*(.+?)\s*$/i;
|
|
5
|
+
export function parsePersonaMarkdown(source, fileId) {
|
|
6
|
+
const lines = source.split('\n');
|
|
7
|
+
let handleId = null;
|
|
8
|
+
let description = null;
|
|
9
|
+
for (const raw of lines) {
|
|
10
|
+
const line = raw.replace(/\r$/, '');
|
|
11
|
+
if (handleId === null) {
|
|
12
|
+
const m = line.match(H1_RE);
|
|
13
|
+
if (m?.[1]) {
|
|
14
|
+
handleId = m[1];
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (description === null) {
|
|
19
|
+
const d = line.match(DESCRIPTION_RE);
|
|
20
|
+
if (d?.[1]) {
|
|
21
|
+
description = d[1];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (handleId !== null && description !== null)
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
if (!handleId) {
|
|
28
|
+
throw new Error(`missing H1 handle (expected '# <handle>') in ${fileId}`);
|
|
29
|
+
}
|
|
30
|
+
if (!description) {
|
|
31
|
+
throw new Error(`missing '- description:' bullet in ${fileId}`);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
handle: `+${handleId}`,
|
|
35
|
+
id: handleId,
|
|
36
|
+
description,
|
|
37
|
+
systemPrompt: source,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function loadPersonasFromDir(dir) {
|
|
41
|
+
const dirStat = statSync(dir);
|
|
42
|
+
if (!dirStat.isDirectory()) {
|
|
43
|
+
throw new Error(`persona registry: not a directory: ${dir}`);
|
|
44
|
+
}
|
|
45
|
+
const byHandle = new Map();
|
|
46
|
+
const errors = [];
|
|
47
|
+
const refresh = () => {
|
|
48
|
+
byHandle.clear();
|
|
49
|
+
errors.length = 0;
|
|
50
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
51
|
+
if (!entry.isFile())
|
|
52
|
+
continue;
|
|
53
|
+
if (!entry.name.endsWith('.md'))
|
|
54
|
+
continue;
|
|
55
|
+
const fullPath = join(dir, entry.name);
|
|
56
|
+
const fileId = basename(entry.name, '.md');
|
|
57
|
+
try {
|
|
58
|
+
const source = readFileSync(fullPath, 'utf8');
|
|
59
|
+
const def = parsePersonaMarkdown(source, fileId);
|
|
60
|
+
byHandle.set(def.handle, def);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
errors.push({
|
|
64
|
+
file: entry.name,
|
|
65
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
refresh();
|
|
71
|
+
return {
|
|
72
|
+
get(handle) {
|
|
73
|
+
const canonical = handle.startsWith('+') ? handle : `+${handle}`;
|
|
74
|
+
return byHandle.get(canonical) ?? null;
|
|
75
|
+
},
|
|
76
|
+
list() {
|
|
77
|
+
return [...byHandle.values()];
|
|
78
|
+
},
|
|
79
|
+
errors() {
|
|
80
|
+
return [...errors];
|
|
81
|
+
},
|
|
82
|
+
reload: refresh,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Shared prompt resolver for CLI executors.
|
|
87
|
+
*
|
|
88
|
+
* If `source` is a registry, look up the canonical systemPrompt. Otherwise
|
|
89
|
+
* fall back to a disk-direct read from `<agentsDir>/<handle>.md` — the
|
|
90
|
+
* pre-Faz-5 behavior, kept for tests and stand-alone use.
|
|
91
|
+
*
|
|
92
|
+
* Returns an empty string when the persona is unknown / file missing. The
|
|
93
|
+
* caller decides whether that's an error (CLI executors silently continue
|
|
94
|
+
* today; `kortext doctor` raises it as a consistency finding).
|
|
95
|
+
*/
|
|
96
|
+
export function readPersonaPrompt(handle, source) {
|
|
97
|
+
if (!handle)
|
|
98
|
+
return '';
|
|
99
|
+
if ('list' in source) {
|
|
100
|
+
return source.get(handle)?.systemPrompt ?? '';
|
|
101
|
+
}
|
|
102
|
+
const id = handle.replace(/^\+/, '');
|
|
103
|
+
const path = join(source.agentsDir, `${id}.md`);
|
|
104
|
+
if (!existsSync(path))
|
|
105
|
+
return '';
|
|
106
|
+
return readFileSync(path, 'utf8');
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=persona-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persona-registry.js","sourceRoot":"","sources":["../../../server/engine/persona-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAkD3C,MAAM,KAAK,GAAG,mBAAmB,CAAC;AAClC,MAAM,cAAc,GAAG,mCAAmC,CAAC;AAE3D,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,MAAc;IAEd,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,QAAQ,GAAkB,IAAI,CAAC;IACnC,IAAI,WAAW,GAAkB,IAAI,CAAC;IAEtC,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,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CAAC,IAAI,MAAM,EAAE,CAAC;YACjE,OAAO,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;QACzC,CAAC;QACD,IAAI;YACF,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QAChC,CAAC;QACD,MAAM;YACJ,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;QACrB,CAAC;QACD,MAAM,EAAE,OAAO;KAChB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAqB,EACrB,MAA+C;IAE/C,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,YAAY,IAAI,EAAE,CAAC;IAChD,CAAC;IACD,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAChD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { isAbsolute, join } from 'node:path';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
async function runSafetyGuards(step, logPath, safety, worktreePath, runId) {
|
|
4
|
+
if (!safety)
|
|
5
|
+
return null;
|
|
6
|
+
const outputFiles = step.outputs.map((rel) => isAbsolute(rel) ? rel : join(worktreePath, rel));
|
|
7
|
+
const filesToScan = logPath ? [...outputFiles, logPath] : outputFiles;
|
|
8
|
+
if (safety.secretScanner && filesToScan.length > 0) {
|
|
9
|
+
const report = await safety.secretScanner.scanForStep(runId, filesToScan);
|
|
10
|
+
if (report.shouldFailRun) {
|
|
11
|
+
const f = report.findings[0];
|
|
12
|
+
return `secret/token detected in step output: ${f?.finding_type} at ${f?.scanned_path}:${f?.line_number}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (safety.harmfulFilter && filesToScan.length > 0) {
|
|
16
|
+
for (const file of filesToScan) {
|
|
17
|
+
let body;
|
|
18
|
+
try {
|
|
19
|
+
body = readFileSync(file, 'utf8');
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const report = safety.harmfulFilter.scanText(body);
|
|
25
|
+
if (report.shouldFailRun) {
|
|
26
|
+
const f = report.findings[0];
|
|
27
|
+
return `banned/harmful phrase detected in ${file}:${f?.line_number} — ${f?.message}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
export async function runWorkflow(graph, executor, repos, options = {}) {
|
|
34
|
+
const concurrency = Math.max(1, options.concurrency ?? 3);
|
|
35
|
+
const triggeredBy = options.triggeredBy ?? 'system';
|
|
36
|
+
const run = repos.runs.createRun({
|
|
37
|
+
workflow_id: graph.workflowId,
|
|
38
|
+
item_id: options.itemId ?? null,
|
|
39
|
+
status: 'queued',
|
|
40
|
+
worktree_path: options.worktreePath ?? null,
|
|
41
|
+
triggered_by: triggeredBy,
|
|
42
|
+
});
|
|
43
|
+
repos.runs.transitionRun(run.id, 'running');
|
|
44
|
+
repos.auditLog.append({
|
|
45
|
+
actor: 'system',
|
|
46
|
+
action: 'pipeline.started',
|
|
47
|
+
resource_type: 'run',
|
|
48
|
+
resource_id: String(run.id),
|
|
49
|
+
payload: { workflow_id: graph.workflowId, concurrency },
|
|
50
|
+
});
|
|
51
|
+
// Pre-create step rows so the dashboard can render the full plan immediately.
|
|
52
|
+
const stepRowByKey = new Map();
|
|
53
|
+
const orderedNodes = [...graph.nodes.values()].sort((a, b) => a.step.index - b.step.index);
|
|
54
|
+
const preCompleted = options.preCompletedStepKeys ?? new Set();
|
|
55
|
+
for (const node of orderedNodes) {
|
|
56
|
+
const isResumed = preCompleted.has(node.step.key);
|
|
57
|
+
const row = repos.runs.addStep({
|
|
58
|
+
run_id: run.id,
|
|
59
|
+
step_index: node.step.index,
|
|
60
|
+
step_name: `${node.step.phase} — ${node.step.persona ?? '(no persona)'}: ${node.step.description.slice(0, 80)}`,
|
|
61
|
+
persona: node.step.persona,
|
|
62
|
+
status: 'pending',
|
|
63
|
+
});
|
|
64
|
+
stepRowByKey.set(node.step.key, row.id);
|
|
65
|
+
if (isResumed) {
|
|
66
|
+
repos.runs.transitionStep(row.id, 'skipped', {
|
|
67
|
+
output_summary: 'resumed-from-previous-run',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const gateByStepIndex = new Map();
|
|
72
|
+
for (const gate of options.gates ?? []) {
|
|
73
|
+
if (gate.afterStepIndex >= 0)
|
|
74
|
+
gateByStepIndex.set(gate.afterStepIndex, gate);
|
|
75
|
+
}
|
|
76
|
+
const firedGateIndices = new Set();
|
|
77
|
+
let pendingGate = null;
|
|
78
|
+
let rejectionReason = null;
|
|
79
|
+
// Resumed runs (Orchestrator.retryRun) replay the lowest gate that sat
|
|
80
|
+
// *after* one of the resumed steps. Without this, the scheduler's barrier
|
|
81
|
+
// would block forever — the gate would never fire because the step that
|
|
82
|
+
// would have fired it was pre-marked as skipped.
|
|
83
|
+
for (const node of orderedNodes) {
|
|
84
|
+
if (!preCompleted.has(node.step.key))
|
|
85
|
+
continue;
|
|
86
|
+
const gate = gateByStepIndex.get(node.step.index);
|
|
87
|
+
if (gate && !pendingGate) {
|
|
88
|
+
pendingGate = gate;
|
|
89
|
+
firedGateIndices.add(gate.afterStepIndex);
|
|
90
|
+
repos.auditLog.append({
|
|
91
|
+
actor: 'orchestrator',
|
|
92
|
+
action: 'gate.paused',
|
|
93
|
+
resource_type: 'run',
|
|
94
|
+
resource_id: String(run.id),
|
|
95
|
+
payload: {
|
|
96
|
+
phase: gate.phase,
|
|
97
|
+
after_step_index: gate.afterStepIndex,
|
|
98
|
+
reason: 'resumed',
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const done = new Set(preCompleted);
|
|
104
|
+
const running = new Map();
|
|
105
|
+
const aborter = new AbortController();
|
|
106
|
+
let failedStepKey = null;
|
|
107
|
+
let firstError = null;
|
|
108
|
+
const ctxFor = (runStepId) => ({
|
|
109
|
+
workflowId: graph.workflowId,
|
|
110
|
+
runId: run.id,
|
|
111
|
+
runStepId,
|
|
112
|
+
worktreePath: options.worktreePath ?? process.cwd(),
|
|
113
|
+
signal: aborter.signal,
|
|
114
|
+
});
|
|
115
|
+
const launch = (stepKey) => {
|
|
116
|
+
const node = graph.nodes.get(stepKey);
|
|
117
|
+
if (!node)
|
|
118
|
+
return;
|
|
119
|
+
const runStepId = stepRowByKey.get(stepKey);
|
|
120
|
+
repos.runs.transitionStep(runStepId, 'running');
|
|
121
|
+
repos.auditLog.append({
|
|
122
|
+
actor: executor.name,
|
|
123
|
+
action: 'pipeline.step.started',
|
|
124
|
+
resource_type: 'run_step',
|
|
125
|
+
resource_id: String(runStepId),
|
|
126
|
+
payload: { run_id: run.id, step_key: stepKey, persona: node.step.persona },
|
|
127
|
+
});
|
|
128
|
+
const promise = executor
|
|
129
|
+
.execute(node.step, ctxFor(runStepId))
|
|
130
|
+
.then(async (result) => {
|
|
131
|
+
if (result.ok) {
|
|
132
|
+
// Apply safety guards before we mark the step as succeeded.
|
|
133
|
+
const safetyError = await runSafetyGuards(node.step, result.logPath ?? null, options.safety, options.worktreePath ?? process.cwd(), run.id);
|
|
134
|
+
if (safetyError) {
|
|
135
|
+
repos.runs.transitionStep(runStepId, 'failed', {
|
|
136
|
+
output_summary: result.outputSummary ?? null,
|
|
137
|
+
error_message: safetyError,
|
|
138
|
+
log_path: result.logPath ?? null,
|
|
139
|
+
});
|
|
140
|
+
repos.auditLog.append({
|
|
141
|
+
actor: 'safety',
|
|
142
|
+
action: 'pipeline.step.failed',
|
|
143
|
+
resource_type: 'run_step',
|
|
144
|
+
resource_id: String(runStepId),
|
|
145
|
+
payload: { run_id: run.id, step_key: stepKey, error: safetyError },
|
|
146
|
+
});
|
|
147
|
+
if (!failedStepKey) {
|
|
148
|
+
failedStepKey = stepKey;
|
|
149
|
+
firstError = safetyError;
|
|
150
|
+
aborter.abort();
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
repos.runs.transitionStep(runStepId, 'succeeded', {
|
|
155
|
+
output_summary: result.outputSummary ?? null,
|
|
156
|
+
log_path: result.logPath ?? null,
|
|
157
|
+
});
|
|
158
|
+
repos.auditLog.append({
|
|
159
|
+
actor: executor.name,
|
|
160
|
+
action: 'pipeline.step.succeeded',
|
|
161
|
+
resource_type: 'run_step',
|
|
162
|
+
resource_id: String(runStepId),
|
|
163
|
+
payload: { run_id: run.id, step_key: stepKey },
|
|
164
|
+
});
|
|
165
|
+
done.add(stepKey);
|
|
166
|
+
// Gate trigger: a gate fires once after the step at its afterStepIndex completes.
|
|
167
|
+
const gate = gateByStepIndex.get(node.step.index);
|
|
168
|
+
if (gate && !firedGateIndices.has(gate.afterStepIndex)) {
|
|
169
|
+
firedGateIndices.add(gate.afterStepIndex);
|
|
170
|
+
pendingGate = gate;
|
|
171
|
+
repos.auditLog.append({
|
|
172
|
+
actor: 'orchestrator',
|
|
173
|
+
action: 'gate.paused',
|
|
174
|
+
resource_type: 'run',
|
|
175
|
+
resource_id: String(run.id),
|
|
176
|
+
payload: { phase: gate.phase, after_step_index: gate.afterStepIndex },
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
repos.runs.transitionStep(runStepId, 'failed', {
|
|
182
|
+
output_summary: result.outputSummary ?? null,
|
|
183
|
+
error_message: result.errorMessage ?? 'unknown failure',
|
|
184
|
+
log_path: result.logPath ?? null,
|
|
185
|
+
});
|
|
186
|
+
repos.auditLog.append({
|
|
187
|
+
actor: executor.name,
|
|
188
|
+
action: 'pipeline.step.failed',
|
|
189
|
+
resource_type: 'run_step',
|
|
190
|
+
resource_id: String(runStepId),
|
|
191
|
+
payload: { run_id: run.id, step_key: stepKey, error: result.errorMessage },
|
|
192
|
+
});
|
|
193
|
+
if (!failedStepKey) {
|
|
194
|
+
failedStepKey = stepKey;
|
|
195
|
+
firstError = result.errorMessage ?? null;
|
|
196
|
+
aborter.abort();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
.catch((err) => {
|
|
201
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
202
|
+
repos.runs.transitionStep(runStepId, 'failed', { error_message: msg });
|
|
203
|
+
if (!failedStepKey) {
|
|
204
|
+
failedStepKey = stepKey;
|
|
205
|
+
firstError = msg;
|
|
206
|
+
aborter.abort();
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
.finally(() => {
|
|
210
|
+
running.delete(stepKey);
|
|
211
|
+
});
|
|
212
|
+
running.set(stepKey, promise);
|
|
213
|
+
};
|
|
214
|
+
// Scheduler loop.
|
|
215
|
+
while (done.size + (failedStepKey ? 1 : 0) < graph.size ||
|
|
216
|
+
running.size > 0 ||
|
|
217
|
+
pendingGate !== null) {
|
|
218
|
+
// Gate barrier: when a gate is pending we drain in-flight work first,
|
|
219
|
+
// then ask the controller for approve/reject before scheduling more steps.
|
|
220
|
+
const gateToProcess = pendingGate;
|
|
221
|
+
if (gateToProcess && running.size === 0 && !failedStepKey && !rejectionReason) {
|
|
222
|
+
if (!options.gateController) {
|
|
223
|
+
throw new Error(`gate encountered but no gateController provided (phase: ${gateToProcess.phase})`);
|
|
224
|
+
}
|
|
225
|
+
pendingGate = null;
|
|
226
|
+
const decision = await options.gateController.pauseAtGate({
|
|
227
|
+
gate: gateToProcess,
|
|
228
|
+
runId: run.id,
|
|
229
|
+
workflowId: graph.workflowId,
|
|
230
|
+
});
|
|
231
|
+
if (decision.decision === 'approve') {
|
|
232
|
+
repos.auditLog.append({
|
|
233
|
+
actor: 'orchestrator',
|
|
234
|
+
action: 'gate.resumed',
|
|
235
|
+
resource_type: 'run',
|
|
236
|
+
resource_id: String(run.id),
|
|
237
|
+
payload: { phase: gateToProcess.phase, decision: 'approve' },
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
rejectionReason = decision.reason;
|
|
242
|
+
repos.auditLog.append({
|
|
243
|
+
actor: 'orchestrator',
|
|
244
|
+
action: 'gate.rejected',
|
|
245
|
+
resource_type: 'run',
|
|
246
|
+
resource_id: String(run.id),
|
|
247
|
+
payload: { phase: gateToProcess.phase, reason: decision.reason },
|
|
248
|
+
});
|
|
249
|
+
aborter.abort();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (!failedStepKey && !rejectionReason && !pendingGate) {
|
|
253
|
+
// Gate barrier: do not start any step whose index lies past an un-fired gate.
|
|
254
|
+
// This makes gates semantically equivalent to a phase boundary even when the
|
|
255
|
+
// pure data-flow DAG sees later steps as already runnable in parallel.
|
|
256
|
+
let barrier = Number.POSITIVE_INFINITY;
|
|
257
|
+
for (const idx of gateByStepIndex.keys()) {
|
|
258
|
+
if (!firedGateIndices.has(idx) && idx < barrier)
|
|
259
|
+
barrier = idx;
|
|
260
|
+
}
|
|
261
|
+
const ready = graph.readyKeys(done).filter((k) => {
|
|
262
|
+
if (running.has(k))
|
|
263
|
+
return false;
|
|
264
|
+
const node = graph.nodes.get(k);
|
|
265
|
+
if (node && node.step.index > barrier)
|
|
266
|
+
return false;
|
|
267
|
+
return true;
|
|
268
|
+
});
|
|
269
|
+
while (ready.length > 0 && running.size < concurrency) {
|
|
270
|
+
const next = ready.shift();
|
|
271
|
+
launch(next);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (running.size === 0 && !pendingGate)
|
|
275
|
+
break;
|
|
276
|
+
if (running.size > 0) {
|
|
277
|
+
await Promise.race(running.values());
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// Mark any un-started steps as skipped (only happens after failure or rejection).
|
|
281
|
+
if (failedStepKey || rejectionReason) {
|
|
282
|
+
for (const [key, rowId] of stepRowByKey) {
|
|
283
|
+
if (done.has(key))
|
|
284
|
+
continue;
|
|
285
|
+
if (key === failedStepKey)
|
|
286
|
+
continue;
|
|
287
|
+
const row = repos.runs.getStep(rowId);
|
|
288
|
+
if (row && row.status === 'pending') {
|
|
289
|
+
repos.runs.transitionStep(rowId, 'skipped');
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
let finalStatus;
|
|
294
|
+
let finalError;
|
|
295
|
+
if (rejectionReason) {
|
|
296
|
+
finalStatus = 'cancelled';
|
|
297
|
+
finalError = `rejected: ${rejectionReason}`;
|
|
298
|
+
}
|
|
299
|
+
else if (failedStepKey) {
|
|
300
|
+
finalStatus = 'failed';
|
|
301
|
+
finalError = firstError;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
finalStatus = 'succeeded';
|
|
305
|
+
finalError = null;
|
|
306
|
+
}
|
|
307
|
+
const finalRun = repos.runs.transitionRun(run.id, finalStatus, {
|
|
308
|
+
error_message: finalError,
|
|
309
|
+
});
|
|
310
|
+
repos.auditLog.append({
|
|
311
|
+
actor: 'system',
|
|
312
|
+
action: `pipeline.${finalStatus}`,
|
|
313
|
+
resource_type: 'run',
|
|
314
|
+
resource_id: String(run.id),
|
|
315
|
+
payload: {
|
|
316
|
+
workflow_id: graph.workflowId,
|
|
317
|
+
failed_step: failedStepKey,
|
|
318
|
+
step_count: graph.size,
|
|
319
|
+
rejection_reason: rejectionReason,
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
return { run: finalRun, failedStepKey };
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=worker-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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B,OAAO,EAAE;YACP,WAAW,EAAE,KAAK,CAAC,UAAU;YAC7B,WAAW,EAAE,aAAa;YAC1B,UAAU,EAAE,KAAK,CAAC,IAAI;YACtB,gBAAgB,EAAE,eAAe;SAClC;KACF,CAAC,CAAC;IAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { loadWorkflowFromFile, } from "./workflow-parser.js";
|
|
4
|
+
/**
|
|
5
|
+
* Scan `dir` and build a registry of workflows.
|
|
6
|
+
*
|
|
7
|
+
* - Only `*.md` files at the top level are considered (no recursion).
|
|
8
|
+
* - Files that parse to zero steps are treated as malformed: they go to
|
|
9
|
+
* `errors()` and are NOT included in `list()`/`get()`.
|
|
10
|
+
* - A non-existent directory throws — this is a config bug, not an
|
|
11
|
+
* operational error.
|
|
12
|
+
*/
|
|
13
|
+
export function loadWorkflowsFromDir(dir) {
|
|
14
|
+
// statSync throws ENOENT for missing dirs — that's the contract.
|
|
15
|
+
const dirStat = statSync(dir);
|
|
16
|
+
if (!dirStat.isDirectory()) {
|
|
17
|
+
throw new Error(`workflow loader: not a directory: ${dir}`);
|
|
18
|
+
}
|
|
19
|
+
const definitions = new Map();
|
|
20
|
+
const errors = [];
|
|
21
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
if (!entry.isFile())
|
|
24
|
+
continue;
|
|
25
|
+
if (!entry.name.endsWith('.md'))
|
|
26
|
+
continue;
|
|
27
|
+
const fullPath = join(dir, entry.name);
|
|
28
|
+
try {
|
|
29
|
+
const def = loadWorkflowFromFile(fullPath);
|
|
30
|
+
if (def.steps.length === 0) {
|
|
31
|
+
errors.push({ file: entry.name, reason: 'no steps parsed (empty workflow)' });
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
definitions.set(def.id, def);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
errors.push({
|
|
38
|
+
file: entry.name,
|
|
39
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
get(id) {
|
|
45
|
+
return definitions.get(id) ?? null;
|
|
46
|
+
},
|
|
47
|
+
list() {
|
|
48
|
+
return [...definitions.values()];
|
|
49
|
+
},
|
|
50
|
+
errors() {
|
|
51
|
+
return [...errors];
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=workflow-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-loader.js","sourceRoot":"","sources":["../../../server/engine/workflow-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,oBAAoB,GAErB,MAAM,sBAAsB,CAAC;AA4B9B;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,iEAAiE;IACjE,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAC;IAC1D,MAAM,MAAM,GAAwB,EAAE,CAAC;IAEvC,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,KAAK,C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