cladogram 0.6.0-beta.3 → 0.6.0-beta.5
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 +42 -44
- package/docs/agent-context.md +62 -0
- package/docs/agent-reference.md +126 -0
- package/docs/release.md +18 -0
- package/package.json +3 -1
- package/plugins/agent/index.js +266 -134
- package/plugins/agent/style.css +54 -45
- package/plugins/view-controls/index.js +0 -11
- package/plugins/view-controls/style.css +0 -7
- package/skills/clado/SKILL.md +1 -1
- package/src/agent/pi-bridge.js +92 -8
- package/src/agent/pi-config.js +97 -57
- package/src/html/app-css.js +69 -1
- package/src/html/canvas-chain.js +6 -4
- package/src/html/canvas-live-diff.js +329 -0
- package/src/html/canvas-ui.css +146 -2
- package/src/html/page.js +4 -2
- package/src/html/runtime-api.js +6 -0
- package/src/html/runtime.js +453 -11
- package/src/server/agent.js +15 -0
- package/src/server/assets/library-canvas.js +12 -4
- package/src/server/assets/library.css +139 -0
- package/src/server/assets/library.js +90 -18
- package/src/server/workspace.js +6 -1
package/plugins/agent/style.css
CHANGED
|
@@ -605,16 +605,6 @@ body.clado-dock-resizing iframe {
|
|
|
605
605
|
padding: 3px 10px;
|
|
606
606
|
}
|
|
607
607
|
|
|
608
|
-
.clado-dock-handoff {
|
|
609
|
-
padding: 8px 14px;
|
|
610
|
-
border-top: 1px solid var(--clado-ui-edge);
|
|
611
|
-
display: flex;
|
|
612
|
-
align-items: center;
|
|
613
|
-
justify-content: space-between;
|
|
614
|
-
gap: 8px;
|
|
615
|
-
font-size: 11.5px;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
608
|
/* Role Strip */
|
|
619
609
|
.clado-role-strip {
|
|
620
610
|
display: flex;
|
|
@@ -622,12 +612,15 @@ body.clado-dock-resizing iframe {
|
|
|
622
612
|
gap: 6px;
|
|
623
613
|
overflow-x: auto;
|
|
624
614
|
scrollbar-width: none;
|
|
625
|
-
padding: 2px
|
|
615
|
+
padding: 4px 2px 10px;
|
|
626
616
|
}
|
|
627
617
|
.clado-role-strip::-webkit-scrollbar { display: none; }
|
|
628
618
|
.clado-role-pill {
|
|
619
|
+
--pill-c1: rgba(56, 189, 248, 0.85);
|
|
620
|
+
--pill-c2: rgba(129, 140, 248, 0.85);
|
|
621
|
+
--pill-glow: rgba(56, 189, 248, 0.34);
|
|
629
622
|
position: relative;
|
|
630
|
-
overflow:
|
|
623
|
+
overflow: visible;
|
|
631
624
|
flex: none;
|
|
632
625
|
appearance: none;
|
|
633
626
|
border-radius: 999px;
|
|
@@ -647,28 +640,64 @@ body.clado-dock-resizing iframe {
|
|
|
647
640
|
gap: 6px;
|
|
648
641
|
transition: all 150ms ease;
|
|
649
642
|
}
|
|
643
|
+
.clado-role-pill[data-tone="sky"] {
|
|
644
|
+
--pill-c1: rgba(56, 189, 248, 0.85);
|
|
645
|
+
--pill-c2: rgba(129, 140, 248, 0.85);
|
|
646
|
+
--pill-glow: rgba(56, 189, 248, 0.36);
|
|
647
|
+
}
|
|
648
|
+
.clado-role-pill[data-tone="emerald"] {
|
|
649
|
+
--pill-c1: rgba(16, 185, 129, 0.85);
|
|
650
|
+
--pill-c2: rgba(45, 212, 191, 0.85);
|
|
651
|
+
--pill-glow: rgba(16, 185, 129, 0.36);
|
|
652
|
+
}
|
|
653
|
+
.clado-role-pill[data-tone="violet"] {
|
|
654
|
+
--pill-c1: rgba(139, 92, 246, 0.85);
|
|
655
|
+
--pill-c2: rgba(244, 114, 182, 0.85);
|
|
656
|
+
--pill-glow: rgba(139, 92, 246, 0.36);
|
|
657
|
+
}
|
|
658
|
+
.clado-role-pill[data-tone="amber"] {
|
|
659
|
+
--pill-c1: rgba(245, 158, 11, 0.85);
|
|
660
|
+
--pill-c2: rgba(251, 146, 60, 0.85);
|
|
661
|
+
--pill-glow: rgba(245, 158, 11, 0.36);
|
|
662
|
+
}
|
|
663
|
+
.clado-role-pill::before {
|
|
664
|
+
content: "";
|
|
665
|
+
position: absolute;
|
|
666
|
+
left: 14px;
|
|
667
|
+
right: 14px;
|
|
668
|
+
top: calc(100% - 1px);
|
|
669
|
+
height: 9px;
|
|
670
|
+
border-radius: 50%;
|
|
671
|
+
background: radial-gradient(ellipse 62% 100% at 50% 0%, var(--pill-glow), transparent 78%);
|
|
672
|
+
filter: blur(4px);
|
|
673
|
+
opacity: 0;
|
|
674
|
+
pointer-events: none;
|
|
675
|
+
transition: opacity 180ms ease;
|
|
676
|
+
}
|
|
650
677
|
.clado-role-pill::after {
|
|
651
678
|
content: "";
|
|
652
679
|
position: absolute;
|
|
653
680
|
left: 16px;
|
|
654
681
|
right: 16px;
|
|
655
|
-
bottom: 0;
|
|
656
|
-
height:
|
|
657
|
-
border-radius:
|
|
658
|
-
|
|
682
|
+
bottom: -0.5px;
|
|
683
|
+
height: 1px;
|
|
684
|
+
border-radius: 1px;
|
|
685
|
+
background: linear-gradient(90deg, transparent 0%, var(--pill-c1) 28%, var(--pill-c2) 72%, transparent 100%);
|
|
686
|
+
opacity: 0.42;
|
|
687
|
+
pointer-events: none;
|
|
659
688
|
transition: all 150ms ease;
|
|
660
689
|
}
|
|
661
|
-
.clado-role-pill
|
|
662
|
-
.clado-role-pill
|
|
663
|
-
.clado-role-pill[data-tone="violet"]::after { background: linear-gradient(90deg, #a78bfa, #f472b6); }
|
|
664
|
-
.clado-role-pill[data-tone="amber"]::after { background: linear-gradient(90deg, #fbbf24, #fb923c); }
|
|
665
|
-
.clado-role-pill.active {
|
|
690
|
+
.clado-role-pill.active,
|
|
691
|
+
.clado-role-pill.running {
|
|
666
692
|
color: var(--clado-ui-text);
|
|
667
693
|
background: var(--clado-ui-active);
|
|
668
|
-
border-color: rgba(147, 197, 253, 0.
|
|
669
|
-
box-shadow: 0
|
|
694
|
+
border-color: rgba(147, 197, 253, 0.52);
|
|
695
|
+
box-shadow: 0 3px 12px -6px var(--pill-glow), inset 0 1px 0 var(--clado-ui-highlight);
|
|
670
696
|
}
|
|
671
|
-
.clado-role-pill.active::
|
|
697
|
+
.clado-role-pill.active::before,
|
|
698
|
+
.clado-role-pill.running::before { opacity: 0.92; }
|
|
699
|
+
.clado-role-pill.active::after,
|
|
700
|
+
.clado-role-pill.running::after { left: 11px; right: 11px; opacity: 0.88; }
|
|
672
701
|
|
|
673
702
|
.clado-role-add {
|
|
674
703
|
width: 30px;
|
|
@@ -676,6 +705,7 @@ body.clado-dock-resizing iframe {
|
|
|
676
705
|
padding: 0;
|
|
677
706
|
justify-content: center;
|
|
678
707
|
}
|
|
708
|
+
.clado-role-add::before,
|
|
679
709
|
.clado-role-add::after { display: none; }
|
|
680
710
|
|
|
681
711
|
/* Multiline Auto-Grow Composer */
|
|
@@ -982,27 +1012,6 @@ body.clado-dock-resizing iframe {
|
|
|
982
1012
|
flex: none;
|
|
983
1013
|
}
|
|
984
1014
|
|
|
985
|
-
.clado-handoff-card {
|
|
986
|
-
width: min(468px, calc(100% - 32px));
|
|
987
|
-
border-radius: 24px;
|
|
988
|
-
padding: 24px;
|
|
989
|
-
background: var(--clado-ui-popover);
|
|
990
|
-
backdrop-filter: blur(28px) saturate(200%);
|
|
991
|
-
-webkit-backdrop-filter: blur(28px) saturate(200%);
|
|
992
|
-
border: 1px solid var(--clado-ui-glass-outline);
|
|
993
|
-
box-shadow: var(--clado-ui-glass-shadow);
|
|
994
|
-
position: relative;
|
|
995
|
-
color: var(--clado-ui-text);
|
|
996
|
-
}
|
|
997
|
-
.clado-handoff-opt {
|
|
998
|
-
cursor: pointer;
|
|
999
|
-
transition: all 150ms ease;
|
|
1000
|
-
}
|
|
1001
|
-
.clado-handoff-opt:hover {
|
|
1002
|
-
background: var(--clado-ui-hover);
|
|
1003
|
-
border-color: var(--clado-ui-hover-border);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
1015
|
/* Composer Context Chips Bar */
|
|
1007
1016
|
.clado-ctx-bar {
|
|
1008
1017
|
display: flex;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const modes = [['cards', '卡片'], ['mindmap', '脑图'], ['doc', '文档']];
|
|
3
|
-
const icoArrow = '<svg class="clado-svg-ico" aria-hidden="true" viewBox="0 0 24 24"><path d="M5 12h14M13 5l7 7-7 7"/></svg>';
|
|
4
3
|
const button = (className, text) => {
|
|
5
4
|
const element = document.createElement('button');
|
|
6
5
|
element.type = 'button';
|
|
@@ -36,16 +35,6 @@
|
|
|
36
35
|
bar.append(group);
|
|
37
36
|
topRow.append(bar);
|
|
38
37
|
|
|
39
|
-
if (actions.openHandoff) {
|
|
40
|
-
const deliverBtn = document.createElement('button');
|
|
41
|
-
deliverBtn.type = 'button';
|
|
42
|
-
deliverBtn.className = 'clado-ui-button clado-ui-button-primary clado-deliver-btn';
|
|
43
|
-
deliverBtn.innerHTML = icoArrow + '<span>交付产物</span>';
|
|
44
|
-
deliverBtn.title = '将画布设计交付给角色落地开发、测试或归档';
|
|
45
|
-
deliverBtn.onclick = () => actions.openHandoff();
|
|
46
|
-
topRow.append(deliverBtn);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
38
|
const statuses = document.createElement('div');
|
|
50
39
|
statuses.className = 'clado-view-status';
|
|
51
40
|
const issues = button('clado-ui-glass clado-ui-button clado-issue-count', '');
|
|
@@ -65,13 +65,6 @@
|
|
|
65
65
|
transition: transform 220ms cubic-bezier(.22,.75,.24,1);
|
|
66
66
|
pointer-events: none;
|
|
67
67
|
}
|
|
68
|
-
.clado-deliver-btn {
|
|
69
|
-
min-height: 38px;
|
|
70
|
-
padding: 7px 15px;
|
|
71
|
-
font-size: 12px;
|
|
72
|
-
border-radius: 999px;
|
|
73
|
-
pointer-events: auto;
|
|
74
|
-
}
|
|
75
68
|
.clado-view-status { display: flex; gap: 6px; }
|
|
76
69
|
.clado-view-bar, .clado-view-status > * { pointer-events: auto; }
|
|
77
70
|
.clado-view-status .clado-ui-button { border-radius: 999px; font-size: 12px; }
|
package/skills/clado/SKILL.md
CHANGED
|
@@ -207,6 +207,6 @@ YAML中的版本写成带引号的文字,例如 `version: "1.0"`;组织方
|
|
|
207
207
|
|
|
208
208
|
删除有孩子的节点需要 `recursive:true`。被引用目标默认拒绝删除;确实要断开入链才给 `unlink:true`,工具保留链接显示文字。改名、移动用专用操作,让工具维护可解析引用;未解析目标由全量诊断持续报告。
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
交付前重新读取关键节点、检查引用并实际看网页;多卡画布应保持从左到右的单向无环流(DAG),严禁尾连头反向回环或双向互连,克制单卡跨卡连线数量(建议 1–3 条)且不留孤立卡片(单卡豁免)。按语义展开层级,不跳级、不凑L6;代码、表格、Mermaid、` ```svg ` 矢量图/轻动效、` ```ui ` 隔离沙盒 UI 原型及本地音视频(``)解释所属逻辑,不用巨型Mermaid代替节点。方法卡按当前模板说明职责、输入输出、内部步骤和失败出口。
|
|
211
211
|
|
|
212
212
|
事实需核对材料,新设计标提案,未知项保留待确认。工具不执行业务代码、SQL、迁移或发布任务,未执行的验证不能写成通过。最后说明修改文档、未决项、实际检查和打开方式;离线交付使用 `clado build`,默认输出可携带目录导航的只读 `clado.html`。
|
package/src/agent/pi-bridge.js
CHANGED
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
SettingsManager,
|
|
16
16
|
} from '@earendil-works/pi-coding-agent';
|
|
17
17
|
import {
|
|
18
|
-
CLADO_CANVAS_MASTERY_GUIDE,
|
|
19
18
|
createCladoModelRuntime,
|
|
19
|
+
readCladoPlatformContext,
|
|
20
20
|
readRuntimeSettings,
|
|
21
21
|
resolvePiAgentDir,
|
|
22
22
|
resolveRole,
|
|
@@ -442,6 +442,7 @@ export function createPiBridge({
|
|
|
442
442
|
|
|
443
443
|
const turnAbort = new AbortController();
|
|
444
444
|
let draftActive = false;
|
|
445
|
+
let customSteerHandler = null;
|
|
445
446
|
|
|
446
447
|
const runState = {
|
|
447
448
|
sessionId: cleanId,
|
|
@@ -452,11 +453,23 @@ export function createPiBridge({
|
|
|
452
453
|
return true;
|
|
453
454
|
},
|
|
454
455
|
async steer(steerText) {
|
|
455
|
-
|
|
456
|
-
|
|
456
|
+
const clean = String(steerText || '').trim();
|
|
457
|
+
if (!clean) return false;
|
|
458
|
+
const handler = session?.steer
|
|
459
|
+
? (t) => session.steer(t)
|
|
460
|
+
: (typeof customSteerHandler === 'function' ? customSteerHandler : null);
|
|
461
|
+
if (!handler) return false;
|
|
462
|
+
const steerBlock = { type: 'steer', text: clean };
|
|
463
|
+
blocks.push(steerBlock);
|
|
464
|
+
emitWrapped({ type: 'steer', text: clean });
|
|
465
|
+
try {
|
|
466
|
+
await handler(clean);
|
|
457
467
|
return true;
|
|
468
|
+
} catch (err) {
|
|
469
|
+
const idx = blocks.lastIndexOf(steerBlock);
|
|
470
|
+
if (idx >= 0) blocks.splice(idx, 1);
|
|
471
|
+
throw err;
|
|
458
472
|
}
|
|
459
|
-
return false;
|
|
460
473
|
},
|
|
461
474
|
async abort() {
|
|
462
475
|
abortedByUser = true;
|
|
@@ -510,6 +523,30 @@ export function createPiBridge({
|
|
|
510
523
|
};
|
|
511
524
|
|
|
512
525
|
let latestContextUsage = meta.contextUsage || null;
|
|
526
|
+
let presenceTouched = false;
|
|
527
|
+
const selectedCardTitles = [...new Set(
|
|
528
|
+
(Array.isArray(canvas?.selection) ? canvas.selection : [])
|
|
529
|
+
.map(item => (Array.isArray(item) ? item[0] : (Array.isArray(item?.nodePath) ? item.nodePath[0] : (typeof item === 'string' ? item : ''))))
|
|
530
|
+
.map(s => String(s || '').trim())
|
|
531
|
+
.filter(Boolean)
|
|
532
|
+
)];
|
|
533
|
+
const emitPresence = (payload = {}) => {
|
|
534
|
+
if (!events) return;
|
|
535
|
+
const phase = payload.phase || 'active';
|
|
536
|
+
if (phase === 'active') presenceTouched = true;
|
|
537
|
+
events.emit(workspace, 'agent.presence', {
|
|
538
|
+
sessionId: cleanId,
|
|
539
|
+
roleId: role.id,
|
|
540
|
+
roleName: role.name,
|
|
541
|
+
tone: role.tone || 'sky',
|
|
542
|
+
file: payload.file || canvas?.file || '',
|
|
543
|
+
cards: Array.isArray(payload.cards) ? payload.cards : [],
|
|
544
|
+
label: payload.label || '',
|
|
545
|
+
codePath: payload.codePath || '',
|
|
546
|
+
phase,
|
|
547
|
+
ts: Date.now(),
|
|
548
|
+
});
|
|
549
|
+
};
|
|
513
550
|
|
|
514
551
|
try {
|
|
515
552
|
emitWrapped({ type: 'session', sessionId: cleanId, roleId: role.id, roleName: role.name, snapshotId: snap?.id || '' });
|
|
@@ -522,6 +559,16 @@ export function createPiBridge({
|
|
|
522
559
|
handoffFrom: handoffFrom || '',
|
|
523
560
|
file: canvas?.file || '',
|
|
524
561
|
});
|
|
562
|
+
if (selectedCardTitles.length) {
|
|
563
|
+
const phaseVerb = role.phase ? role.phase.replace(/阶段$/, '') : '处理';
|
|
564
|
+
emitPresence({
|
|
565
|
+
phase: 'active',
|
|
566
|
+
cards: selectedCardTitles,
|
|
567
|
+
label: `${phaseVerb}中…`,
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const platformContext = readCladoPlatformContext(agentDir);
|
|
525
572
|
|
|
526
573
|
if (sessionFactory) {
|
|
527
574
|
const factoryEmit = ev => {
|
|
@@ -529,6 +576,10 @@ export function createPiBridge({
|
|
|
529
576
|
if (ev?.type === 'text' && ev.text) appendTextDelta(ev.text);
|
|
530
577
|
if (ev?.type === 'tool') upsertToolEntry(ev);
|
|
531
578
|
if (ev?.type === 'usage' && ev.usage) latestContextUsage = ev.usage;
|
|
579
|
+
if (ev?.type === 'presence') {
|
|
580
|
+
emitPresence(ev);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
532
583
|
emitWrapped(ev);
|
|
533
584
|
};
|
|
534
585
|
const result = await sessionFactory({
|
|
@@ -537,12 +588,14 @@ export function createPiBridge({
|
|
|
537
588
|
documentRoot,
|
|
538
589
|
sessionId: cleanId,
|
|
539
590
|
role,
|
|
591
|
+
platformContext,
|
|
540
592
|
text,
|
|
541
593
|
canvas,
|
|
542
594
|
cladoTools,
|
|
543
595
|
events,
|
|
544
596
|
emit: factoryEmit,
|
|
545
597
|
waitForUserAnswer,
|
|
598
|
+
onSteer: fn => { customSteerHandler = fn; },
|
|
546
599
|
signal: turnAbort.signal,
|
|
547
600
|
});
|
|
548
601
|
if (!assistantText && result?.text) appendTextDelta(String(result.text));
|
|
@@ -581,10 +634,8 @@ export function createPiBridge({
|
|
|
581
634
|
packageCommandOutput: 'capture',
|
|
582
635
|
appendSystemPrompt: [
|
|
583
636
|
role.systemPrompt,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
'提问规范:如果你需要向用户确认方案或提问,请先完整阐述你的分析与建议,再在最后一步调用 ask_user 工具,避免在回答中途插入问题。',
|
|
587
|
-
],
|
|
637
|
+
platformContext,
|
|
638
|
+
].filter(Boolean),
|
|
588
639
|
});
|
|
589
640
|
await loader.reload();
|
|
590
641
|
|
|
@@ -856,6 +907,23 @@ export function createPiBridge({
|
|
|
856
907
|
nodes: canvasAct.nodes,
|
|
857
908
|
label: canvasAct.label,
|
|
858
909
|
});
|
|
910
|
+
let pCards = canvasAct.nodes
|
|
911
|
+
.map(n => (Array.isArray(n) ? n[0] : String(n || '')))
|
|
912
|
+
.map(s => String(s || '').trim())
|
|
913
|
+
.filter(Boolean);
|
|
914
|
+
if (!pCards.length && typeof ev.args?.content === 'string') {
|
|
915
|
+
const h1s = (ev.args.content.match(/^#\s+(.+)$/gm) || []).map(l => l.replace(/^#\s+/, '').trim()).filter(Boolean);
|
|
916
|
+
if (h1s.length) pCards = h1s.slice(0, 6);
|
|
917
|
+
}
|
|
918
|
+
if (!pCards.length) pCards = selectedCardTitles;
|
|
919
|
+
if (pCards.length) {
|
|
920
|
+
emitPresence({
|
|
921
|
+
phase: 'active',
|
|
922
|
+
file: canvasAct.file,
|
|
923
|
+
cards: [...new Set(pCards)],
|
|
924
|
+
label: canvasAct.label.replace(/^AI\s*/, ''),
|
|
925
|
+
});
|
|
926
|
+
}
|
|
859
927
|
} else if (['edit', 'write', 'read'].includes(ev.toolName)) {
|
|
860
928
|
const codeTarget = resolveWorkspaceCodeRel(ev.args?.path || ev.args?.file_path || ev.args?.file);
|
|
861
929
|
if (codeTarget) {
|
|
@@ -875,6 +943,19 @@ export function createPiBridge({
|
|
|
875
943
|
roleId: role.id,
|
|
876
944
|
roleName: role.name,
|
|
877
945
|
});
|
|
946
|
+
const codeCards = matchedCards
|
|
947
|
+
.map(n => (Array.isArray(n) ? n[0] : String(n || '')))
|
|
948
|
+
.map(s => String(s || '').trim())
|
|
949
|
+
.filter(Boolean);
|
|
950
|
+
const presenceCards = codeCards.length ? codeCards : selectedCardTitles;
|
|
951
|
+
if (presenceCards.length) {
|
|
952
|
+
emitPresence({
|
|
953
|
+
phase: 'active',
|
|
954
|
+
cards: [...new Set(presenceCards)],
|
|
955
|
+
codePath: codeTarget.rel,
|
|
956
|
+
label: `${ev.toolName === 'read' ? '查看' : '修改'} ${codeTarget.rel}`,
|
|
957
|
+
});
|
|
958
|
+
}
|
|
878
959
|
}
|
|
879
960
|
}
|
|
880
961
|
upsertToolEntry({
|
|
@@ -1002,6 +1083,9 @@ export function createPiBridge({
|
|
|
1002
1083
|
draftActive = false;
|
|
1003
1084
|
events?.emit(workspace, 'canvas.draft', { active: false });
|
|
1004
1085
|
}
|
|
1086
|
+
if (presenceTouched) {
|
|
1087
|
+
emitPresence({ phase: 'afterglow', label: '刚刚完成' });
|
|
1088
|
+
}
|
|
1005
1089
|
liveRuns.delete(`${workspace}::${cleanId}`);
|
|
1006
1090
|
try { unsub?.(); } catch {}
|
|
1007
1091
|
try { session?.dispose?.(); } catch {}
|
package/src/agent/pi-config.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
16
|
-
import { join, resolve } from 'node:path';
|
|
16
|
+
import { dirname, join, resolve } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
17
18
|
import {
|
|
18
19
|
DefaultPackageManager,
|
|
19
20
|
DefaultResourceLoader,
|
|
@@ -22,39 +23,19 @@ import {
|
|
|
22
23
|
SettingsManager,
|
|
23
24
|
} from '@earendil-works/pi-coding-agent';
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
' - **控制单卡出度**:每张卡片发出的跨卡连线建议 **1–3 条**(严格不超过 **4 条**),整张图平均每张卡约 **1.0–1.8 条**跨卡连线;该分叉处分叉、该汇聚处汇聚,整体一眼顺畅通透,绝不画成密密麻麻的蜘蛛网。',
|
|
39
|
-
' - **无孤立卡片**:多卡画布中每张核心卡都必须处于主干流的合理位置,不留下脱离流程的游离卡片。',
|
|
40
|
-
'',
|
|
41
|
-
'### 3. 跨卡连线语法与六色语义 Tag(二元连线模型)',
|
|
42
|
-
'- **连卡片**:`[说明文字](目标卡片标题)`(目标须与某张 `# 标题` 一字不差)。',
|
|
43
|
-
'- **连小节**:`[说明文字](目标卡片标题#小节标题)`。',
|
|
44
|
-
'- **语义 Tag 锚点(文档内 `#id` 必须唯一)**:',
|
|
45
|
-
' - 正文/列表/表格:`[新增]{#id .green}`、`[修改]{#id .amber}`、`[风险]{#id .red}`、`[契约]{#id .blue}`、`[说明]{#id .purple}`,或无字圆点 `[]{#id .green}`。',
|
|
46
|
-
' - 代码块行尾注释(保持代码可直接编译):`verifySign(req); // {#verify-sign .blue}`。',
|
|
47
|
-
' - Mermaid 注释:`%% {#NODE_ID .green}`。',
|
|
48
|
-
' - 精准连到 Tag:`[触发验签](#verify-sign)` 或 `[触发验签](目标卡片标题#verify-sign)`。',
|
|
49
|
-
'- **连线落在真实位置**:把连线直接写在调用/流转发生的具体 `##` 步骤、代码行或表格行内,避免在卡片末尾堆裸链接;自连、外链网址(`https://`)和跨文档链接不计入本画布卡片连线。单块正文保持精炼(建议 ≤ 400 字),善用 `##`/`###` 拆层。',
|
|
50
|
-
'',
|
|
51
|
-
'### 4. 像读 DOM 树一样自检画布(`clado_graph` 闭环)',
|
|
52
|
-
'- 新建或修改画布前,先用 `clado_list` / `clado_graph` / `clado_templates` 了解现有画布和模板约束(如 `call-chain`、`business-flow`、`requirement-overview`、`data-design`、`test-cases`、`system-state`)。',
|
|
53
|
-
'- 每次调用 `clado_create` / `clado_update` / `clado_nodes` / `clado_links` 都会附带渲染后的 `graphCheck`,且画布会自动原生呈现红删绿增的实时变更并展开新连线;**交付前必须调用 `clado_graph`** 复核实际连出来的列布局、端到端链路、Tag 与体检结果,确认:**0 反向回环、0 孤立卡、0 未解析断链、0 语法错误、无单卡出度过载或连线过密警告**。',
|
|
54
|
-
'',
|
|
55
|
-
'### 5. 工具失败强感知铁律',
|
|
56
|
-
'- 只要任何工具返回错误(`isError: true` 或包含 `[TOOL_ERROR]`),或者 `graphCheck` / `clado_graph` 提示 `actionRequired`(存在反向回环、孤立卡、断链或语法错误),**严禁忽略或向用户宣称已完成**!必须立即阅读错误信息、回环边清单与行号,修正画布后重试,直到 `clado_graph` 显示 `healthy: true` 且流向顺畅克制后再总结汇报。',
|
|
57
|
-
].join('\n');
|
|
26
|
+
const PKG_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
27
|
+
const PACKAGE_CONTEXT_DOC_PATH = join(PKG_ROOT, 'docs', 'agent-context.md');
|
|
28
|
+
const PACKAGE_REFERENCE_DOC_PATH = join(PKG_ROOT, 'docs', 'agent-reference.md');
|
|
29
|
+
|
|
30
|
+
function readPackageDoc(filePath, fallback = '') {
|
|
31
|
+
try {
|
|
32
|
+
return existsSync(filePath) ? readFileSync(filePath, 'utf8') : fallback;
|
|
33
|
+
} catch {
|
|
34
|
+
return fallback;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const CLADO_CANVAS_MASTERY_GUIDE = readPackageDoc(PACKAGE_CONTEXT_DOC_PATH);
|
|
58
39
|
|
|
59
40
|
export const BUILTIN_ROLES = [
|
|
60
41
|
{
|
|
@@ -63,15 +44,14 @@ export const BUILTIN_ROLES = [
|
|
|
63
44
|
phase: '设计阶段',
|
|
64
45
|
tone: 'sky',
|
|
65
46
|
builtin: true,
|
|
66
|
-
description: '
|
|
47
|
+
description: '分析现状代码、梳理模块边界与核心契约、设计清晰可扩展的端到端技术方案并推动定稿。',
|
|
67
48
|
systemPrompt: [
|
|
68
|
-
'
|
|
49
|
+
'你是「主架构师」,专注于系统架构设计、模块边界梳理与技术方案评审。',
|
|
69
50
|
'你的核心工作流程:',
|
|
70
|
-
'1.
|
|
71
|
-
'2.
|
|
72
|
-
'3.
|
|
73
|
-
'4.
|
|
74
|
-
'5. **关键决策确认**:遇到多个合理架构方案或核心边界需要拍板时,先完整阐述分析与权衡,再在最后调用 `ask_user` 给出 2–4 个清晰选项卡片让用户确认。',
|
|
51
|
+
'1. **摸清现状**:动手设计前先核查真实源码、入口边界、数据模型与上下游依赖,避免凭空猜测。',
|
|
52
|
+
'2. **端到端方案设计**:从入口触发、核心编排与并行分支、领域处理到持久化与外部依赖,梳理清晰的职责划分、数据流向、异常边界与演进权衡;明确标出新增、变更与潜在风险点。',
|
|
53
|
+
'3. **保持设计简洁克制**:优先选择低耦合、易验证的方案,避免过度抽象与循环依赖。',
|
|
54
|
+
'4. **关键决策拍板**:存在多个合理方案或重大边界取舍时,先完整阐述利弊与推荐理由,再请用户确认方向。',
|
|
75
55
|
].join('\n'),
|
|
76
56
|
},
|
|
77
57
|
{
|
|
@@ -80,14 +60,14 @@ export const BUILTIN_ROLES = [
|
|
|
80
60
|
phase: '交付阶段',
|
|
81
61
|
tone: 'emerald',
|
|
82
62
|
builtin: true,
|
|
83
|
-
description: '
|
|
63
|
+
description: '对照设计契约精准落地代码、补齐边界处理、运行构建与测试校验并同步交付事实。',
|
|
84
64
|
systemPrompt: [
|
|
85
|
-
'
|
|
65
|
+
'你是「开发落地」工程师,专注于高质量代码实现、边界处理与工程验证。',
|
|
86
66
|
'你的核心工作流程:',
|
|
87
|
-
'1.
|
|
88
|
-
'2.
|
|
89
|
-
'3.
|
|
90
|
-
'4.
|
|
67
|
+
'1. **先读设计契约与上下文**:开工前先理解目标方案的入口契约、核心数据流、修改范围与风险点。',
|
|
68
|
+
'2. **精准实现**:改动克制聚焦,遵循项目既有风格与约束,妥善处理空值、并发、超时与错误恢复,不引入无关重构。',
|
|
69
|
+
'3. **真实验证**:实现完成后务必实际运行构建、静态检查与相关测试,核对真实输出;遇到失败立即定位修复。',
|
|
70
|
+
'4. **同步与交付**:若落地细节较原设计有调整,及时同步更新文档事实,并清晰汇报改动文件与验证结果。',
|
|
91
71
|
].join('\n'),
|
|
92
72
|
},
|
|
93
73
|
{
|
|
@@ -96,13 +76,14 @@ export const BUILTIN_ROLES = [
|
|
|
96
76
|
phase: '验收阶段',
|
|
97
77
|
tone: 'violet',
|
|
98
78
|
builtin: true,
|
|
99
|
-
description: '
|
|
79
|
+
description: '梳理关键路径与异常边界、编写高信噪比自动化测试、真实执行验证并沉淀验收结论。',
|
|
100
80
|
systemPrompt: [
|
|
101
|
-
'
|
|
81
|
+
'你是「测试验证」工程师,专注于质量保障、边界挖掘与自动化回归测试。',
|
|
102
82
|
'你的核心工作流程:',
|
|
103
|
-
'1.
|
|
104
|
-
'2.
|
|
105
|
-
'3.
|
|
83
|
+
'1. **全路径查漏**:沿核心主流程、分支条件、并发竞争、权限与异常出口梳理测试矩阵,识别高风险薄弱点。',
|
|
84
|
+
'2. **编写高价值测试**:优先覆盖行为契约与真实回归场景,断言清晰独立、不依赖脆弱实现细节。',
|
|
85
|
+
'3. **真实执行验收**:实际运行测试套件并核对真实通过/失败结果;未执行的验证绝不可宣称为通过。',
|
|
86
|
+
'4. **沉淀验收结论**:清晰记录已覆盖路径、失败复现步骤与遗留风险,辅助团队决策发布。',
|
|
106
87
|
].join('\n'),
|
|
107
88
|
},
|
|
108
89
|
{
|
|
@@ -111,13 +92,13 @@ export const BUILTIN_ROLES = [
|
|
|
111
92
|
phase: '文档阶段',
|
|
112
93
|
tone: 'amber',
|
|
113
94
|
builtin: true,
|
|
114
|
-
description: '
|
|
95
|
+
description: '核对已落地事实与设计文档、清理过时信息、沉淀高质量系统现状文档、ADR 与变更记录。',
|
|
115
96
|
systemPrompt: [
|
|
116
|
-
'
|
|
97
|
+
'你是「归档整理」专家,专注于技术文档沉淀、事实核对与知识结构化归档。',
|
|
117
98
|
'你的核心工作流程:',
|
|
118
|
-
'1.
|
|
119
|
-
'2.
|
|
120
|
-
'3.
|
|
99
|
+
'1. **事实核对**:以真实代码与已验证行为为准,严格区分「已落地现状」与「未实现提案」,绝不把提案写成事实。',
|
|
100
|
+
'2. **去冗提纯**:清理过时描述与矛盾表述,确保模块职责、关键契约、配置项与排障入口准确可查。',
|
|
101
|
+
'3. **结构化沉淀**:输出条理清晰的现状文档、架构决策记录(ADR)或版本变更说明,方便团队长期维护。',
|
|
121
102
|
].join('\n'),
|
|
122
103
|
},
|
|
123
104
|
];
|
|
@@ -964,3 +945,62 @@ export function toggleCanvasComponent(id, enabled, agentDir = resolvePiAgentDir(
|
|
|
964
945
|
writeJsonSafe(file, saved);
|
|
965
946
|
return readCanvasComponentsConfig(agentDir);
|
|
966
947
|
}
|
|
948
|
+
|
|
949
|
+
// ============================================================================
|
|
950
|
+
// 6. Clado Platform Context & Reference Manual (~/.pi/agent/clado-*.md)
|
|
951
|
+
// Automatically injected into EVERY persona (builtin, custom, or external).
|
|
952
|
+
// ============================================================================
|
|
953
|
+
|
|
954
|
+
export function ensureCladoPlatformDocs(agentDir = resolvePiAgentDir()) {
|
|
955
|
+
mkdirSync(agentDir, { recursive: true });
|
|
956
|
+
const contextPath = join(agentDir, 'clado-context.md');
|
|
957
|
+
const referencePath = join(agentDir, 'clado-reference.md');
|
|
958
|
+
const defaultContext = readPackageDoc(PACKAGE_CONTEXT_DOC_PATH);
|
|
959
|
+
const defaultReference = readPackageDoc(PACKAGE_REFERENCE_DOC_PATH);
|
|
960
|
+
|
|
961
|
+
if (!existsSync(contextPath) && defaultContext) {
|
|
962
|
+
writeFileSync(contextPath, defaultContext, 'utf8');
|
|
963
|
+
}
|
|
964
|
+
if (!existsSync(referencePath) && defaultReference) {
|
|
965
|
+
writeFileSync(referencePath, defaultReference, 'utf8');
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
const contextContent = existsSync(contextPath) ? readFileSync(contextPath, 'utf8') : defaultContext;
|
|
969
|
+
const referenceContent = existsSync(referencePath) ? readFileSync(referencePath, 'utf8') : defaultReference;
|
|
970
|
+
const customized = contextContent.trim() !== defaultContext.trim();
|
|
971
|
+
|
|
972
|
+
return {
|
|
973
|
+
contextPath,
|
|
974
|
+
referencePath,
|
|
975
|
+
packageContextPath: PACKAGE_CONTEXT_DOC_PATH,
|
|
976
|
+
packageReferencePath: PACKAGE_REFERENCE_DOC_PATH,
|
|
977
|
+
contextContent,
|
|
978
|
+
referenceContent,
|
|
979
|
+
customized,
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
export function readCladoPlatformContext(agentDir = resolvePiAgentDir()) {
|
|
984
|
+
const docs = ensureCladoPlatformDocs(agentDir);
|
|
985
|
+
return String(docs.contextContent || '')
|
|
986
|
+
.replace(/\{\{CLADO_CONTEXT_PATH\}\}/g, docs.contextPath)
|
|
987
|
+
.replace(/\{\{CLADO_REFERENCE_PATH\}\}/g, docs.referencePath);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
export function saveCladoPlatformContext(content, agentDir = resolvePiAgentDir()) {
|
|
991
|
+
mkdirSync(agentDir, { recursive: true });
|
|
992
|
+
const contextPath = join(agentDir, 'clado-context.md');
|
|
993
|
+
writeFileSync(contextPath, String(content || ''), 'utf8');
|
|
994
|
+
return { ok: true, ...ensureCladoPlatformDocs(agentDir) };
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
export function resetCladoPlatformDocs(agentDir = resolvePiAgentDir()) {
|
|
998
|
+
mkdirSync(agentDir, { recursive: true });
|
|
999
|
+
const contextPath = join(agentDir, 'clado-context.md');
|
|
1000
|
+
const referencePath = join(agentDir, 'clado-reference.md');
|
|
1001
|
+
const defaultContext = readPackageDoc(PACKAGE_CONTEXT_DOC_PATH);
|
|
1002
|
+
const defaultReference = readPackageDoc(PACKAGE_REFERENCE_DOC_PATH);
|
|
1003
|
+
if (defaultContext) writeFileSync(contextPath, defaultContext, 'utf8');
|
|
1004
|
+
if (defaultReference) writeFileSync(referencePath, defaultReference, 'utf8');
|
|
1005
|
+
return { ok: true, ...ensureCladoPlatformDocs(agentDir) };
|
|
1006
|
+
}
|