create-principles-disciple 1.75.0 → 1.76.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/core/dist/runtime-v2/__tests__/architecture-regression.test.js +3 -3
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/index.d.ts +0 -2
- package/core/dist/runtime-v2/activation/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/index.js +0 -1
- package/core/dist/runtime-v2/activation/index.js.map +1 -1
- package/core/dist/runtime-v2/index.d.ts +4 -4
- package/core/dist/runtime-v2/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/index.js +2 -2
- package/core/dist/runtime-v2/index.js.map +1 -1
- package/core/dist/runtime-v2/types/event-types.d.ts +3 -24
- package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/types/event-types.js +0 -10
- package/core/dist/runtime-v2/types/event-types.js.map +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +0 -1
- package/dist/utils/env.js.map +1 -1
- package/package.json +1 -1
- package/plugin/dist/core/event-log.d.ts +1 -3
- package/plugin/dist/core/event-log.js +0 -6
- package/plugin/dist/core/migration.js +0 -1
- package/plugin/dist/core/path-resolver.js +0 -1
- package/plugin/dist/core/paths.d.ts +0 -1
- package/plugin/dist/core/paths.js +0 -1
- package/plugin/dist/hooks/gate-block-helper.js +17 -20
- package/plugin/dist/hooks/gate.js +12 -58
- package/plugin/dist/hooks/prompt.d.ts +6 -0
- package/plugin/dist/hooks/prompt.js +1 -56
- package/plugin/dist/types/event-types.d.ts +1 -1
- package/plugin/dist/utils/io.d.ts +0 -1
- package/plugin/dist/utils/io.js +0 -23
- package/plugin/templates/langs/en/core/AGENTS.md +5 -5
- package/plugin/templates/langs/en/principles/THINKING_OS.md +3 -2
- package/plugin/templates/langs/en/skills/evolve-task/SKILL.md +2 -2
- package/plugin/templates/langs/en/skills/pd-mentor/SKILL.md +1 -2
- package/plugin/templates/langs/zh/core/AGENTS.md +5 -5
- package/plugin/templates/langs/zh/principles/THINKING_OS.md +3 -2
- package/plugin/templates/langs/zh/skills/evolve-task/SKILL.md +2 -2
- package/plugin/templates/langs/zh/skills/pd-mentor/SKILL.md +1 -2
- package/plugin/templates/workspace/.principles/THINKING_OS.md +3 -2
- package/templates/langs/en/core/AGENTS.md +7 -7
- package/templates/langs/en/principles/THINKING_OS.md +3 -2
- package/templates/langs/en/skills/evolve-task/SKILL.md +3 -3
- package/templates/langs/en/skills/pd-mentor/SKILL.md +1 -2
- package/templates/langs/zh/core/AGENTS.md +7 -7
- package/templates/langs/zh/principles/THINKING_OS.md +3 -2
- package/templates/langs/zh/skills/evolve-task/SKILL.md +4 -4
- package/templates/langs/zh/skills/pd-mentor/SKILL.md +1 -2
- package/templates/workspace/.principles/THINKING_OS.md +3 -2
- package/core/dist/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.d.ts +0 -2
- package/core/dist/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.d.ts.map +0 -1
- package/core/dist/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.js +0 -148
- package/core/dist/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.js.map +0 -1
- package/core/dist/runtime-v2/activation/sqlite-confirm-first-state-store.d.ts +0 -22
- package/core/dist/runtime-v2/activation/sqlite-confirm-first-state-store.d.ts.map +0 -1
- package/core/dist/runtime-v2/activation/sqlite-confirm-first-state-store.js +0 -136
- package/core/dist/runtime-v2/activation/sqlite-confirm-first-state-store.js.map +0 -1
- package/plugin/dist/core/confirm-first-gate.d.ts +0 -59
- package/plugin/dist/core/confirm-first-gate.js +0 -215
- package/plugin/templates/langs/en/skills/plan-script/SKILL.md +0 -32
- package/plugin/templates/langs/zh/skills/plan-script/SKILL.md +0 -32
- package/templates/langs/en/skills/plan-script/SKILL.md +0 -32
- package/templates/langs/zh/skills/plan-script/SKILL.md +0 -32
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
基于**项目战场**中的相对路径进行决策:
|
|
18
18
|
|
|
19
19
|
- **项目最高战略**: `./memory/STRATEGY.md`
|
|
20
|
-
-
|
|
21
|
-
- **痛觉反射信号**: `./.state/.pain_flag`
|
|
20
|
+
- **痛觉反射信号**: Runtime V2 `PainSignalBridge`(手动触发使用 `pd pain record`;`.state/.pain_flag` 仅为 legacy compatibility)
|
|
22
21
|
- **系统能力快照**: `./.state/SYSTEM_CAPABILITIES.json`
|
|
23
22
|
|
|
24
23
|
---
|
|
@@ -63,7 +62,7 @@
|
|
|
63
62
|
|
|
64
63
|
### 心跳时应该检查(轮流执行):
|
|
65
64
|
|
|
66
|
-
- **痛觉与进化**: 检查
|
|
65
|
+
- **痛觉与进化**: 检查 Runtime V2 诊断(`pd pain record`、candidate、ledger)和 `EVOLUTION_QUEUE.json`;`.pain_flag` 仅为 legacy compatibility
|
|
67
66
|
- **战略对齐**: 对比 `CURRENT_FOCUS.md`,确保未偏离重点
|
|
68
67
|
- **环境健康**: 检查工具链状态、项目根目录整洁度
|
|
69
68
|
|
|
@@ -158,12 +157,13 @@
|
|
|
158
157
|
你默认处于架构师模式。
|
|
159
158
|
|
|
160
159
|
- **L1 (直接执行)**:单文件微调、文档维护 → 直接操作
|
|
161
|
-
- **L2 (委派协议)**:重大变更 →
|
|
160
|
+
- **L2 (委派协议)**:重大变更 → 建议先描述计划并获得 owner 确认后再执行
|
|
162
161
|
|
|
163
|
-
###
|
|
162
|
+
### 计划引导 (Planning Guidance)
|
|
164
163
|
|
|
165
|
-
-
|
|
166
|
-
-
|
|
164
|
+
- 对复杂任务,建议先起草计划文档并获得 owner 批准后再做大幅修改
|
|
165
|
+
- 这是行为建议,不是内置门禁 — PD 默认不强制"先计划后执行"
|
|
166
|
+
- 若 owner 批准的 RuleHost 规则强制了计划行为,该规则会自动生效
|
|
167
167
|
- **防止污染**:禁止将执行层细节写回战略文档
|
|
168
168
|
|
|
169
169
|
---
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
<!-- 执行与物理限制 (Execution & Physical Constraints) -->
|
|
40
40
|
<directive id="T-05" name="PHYSICAL_DEFENSE_AND_ORCHESTRATION">
|
|
41
41
|
<trigger>当被要求执行大型重构、多文件修改(>2 个文件)或架构变更时。</trigger>
|
|
42
|
-
<
|
|
43
|
-
<
|
|
42
|
+
<should>对复杂变更,先描述计划并获得 owner 确认后再执行。</should>
|
|
43
|
+
<must>限制爆炸半径。在修改任何代码后,必须运行金丝雀测试(例如 `npm test`、linters)以验证完整性。</must>
|
|
44
|
+
<forbidden>直接执行大规模非结构化变更,或跳过修改后的验证环节。</forbidden>
|
|
44
45
|
</directive>
|
|
45
46
|
|
|
46
47
|
<directive id="T-06" name="OCCAMS_RAZOR_MVC">
|
|
@@ -10,7 +10,7 @@ disable-model-invocation: true
|
|
|
10
10
|
- 读取 memory/CHECKPOINT.md 的最后一条
|
|
11
11
|
- 读取 memory/ISSUE_LOG.md 的最近 3 条
|
|
12
12
|
- 读取 memory/DECISIONS.md 的最近决策
|
|
13
|
-
-
|
|
13
|
+
- Runtime V2 痛苦诊断使用 task input/context,不使用 `.state/.pain_flag`
|
|
14
14
|
|
|
15
15
|
## Step 1: 读取运行参数与能力自检
|
|
16
16
|
- 读取 .principles/PROFILE.json,理解 risk_paths、gate、tests.commands。
|
|
@@ -51,7 +51,7 @@ disable-model-invocation: true
|
|
|
51
51
|
|
|
52
52
|
## Step 6: 委派 Planner(电影剧本计划)
|
|
53
53
|
- Planner 输出 Plan(步骤/命令/指标/回滚)。
|
|
54
|
-
-
|
|
54
|
+
- 将计划写入计划文档供 owner 审阅。
|
|
55
55
|
- **任务同步 (Task Sync)**:
|
|
56
56
|
- 如果 `CLAUDE_CODE_TASK_LIST_ID` 已设置,你必须将上述 Plan 的核心步骤直接转化为 Native Tasks(通过自然语言指令"Add task..."或相关工具)。
|
|
57
57
|
- 如果未设置且为交互模式,提示用户:"建议运行 `export CLAUDE_CODE_TASK_LIST_ID=task-$(date +%s)` 以启用持久化任务追踪。"
|
|
@@ -59,7 +59,7 @@ disable-model-invocation: true
|
|
|
59
59
|
- **绩效评估**: 任务完成后,写入 `.state/.verdict.json`。格式遵循 `@.principles/schemas/agent_verdict_schema.json`。
|
|
60
60
|
|
|
61
61
|
## Step 7: 委派 Implementer(执行)
|
|
62
|
-
- Implementer
|
|
62
|
+
- Implementer 按照 Step 6 的计划执行。任何偏离必须先更新计划并获得确认。
|
|
63
63
|
- **绩效评估**: 任务完成后,根据验证结果写入 `.state/.verdict.json`。格式遵循 `@.principles/schemas/agent_verdict_schema.json`。
|
|
64
64
|
|
|
65
65
|
## Step 8: 委派 Reviewer(审查)
|
|
@@ -80,4 +80,4 @@ disable-model-invocation: true
|
|
|
80
80
|
## Step 10: 最终汇报 (Final Briefing)
|
|
81
81
|
- **动作**: 委派 ``pd_spawn_agent(reporter)`` 进行结项陈述。
|
|
82
82
|
- **要求**: 将 Implementer 和 Reviewer 的最终产出作为输入传给它。让它根据 `USER_CONTEXT.md` 决定汇报的深度和风格。
|
|
83
|
-
- **目标**: 确保老板(用户)在不产生认知负荷的前提下,清楚了解任务成果与潜在风险。
|
|
83
|
+
- **目标**: 确保老板(用户)在不产生认知负荷的前提下,清楚了解任务成果与潜在风险。
|
|
@@ -185,7 +185,7 @@ disable-model-invocation: true
|
|
|
185
185
|
|
|
186
186
|
| 场景 | 组合流程 |
|
|
187
187
|
|------|----------|
|
|
188
|
-
| 大型重构 | `/pd-evolve` → `
|
|
188
|
+
| 大型重构 | `/pd-evolve` → `deductive-audit` → 执行 |
|
|
189
189
|
| 系统优化 | `/pd-status` → `evolve-system` → `root-cause` |
|
|
190
190
|
| 项目复盘 | `/pd-daily` → `/pd-okr` → `reflection-log` |
|
|
191
191
|
|
|
@@ -196,7 +196,6 @@ disable-model-invocation: true
|
|
|
196
196
|
- `triage` - 问题分诊
|
|
197
197
|
- `root-cause` - 根因分析
|
|
198
198
|
- `deductive-audit` - 演绎审计
|
|
199
|
-
- `plan-script` - 计划编排
|
|
200
199
|
- `reflection` - 元认知反思
|
|
201
200
|
- `reflection-log` - 反思落盘
|
|
202
201
|
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
<!-- 执行与物理限制 (Execution & Physical Constraints) -->
|
|
40
40
|
<directive id="T-05" name="PHYSICAL_DEFENSE_AND_ORCHESTRATION">
|
|
41
41
|
<trigger>当被要求执行大型重构、多文件修改(>2 个文件)或架构变更时。</trigger>
|
|
42
|
-
<
|
|
43
|
-
<
|
|
42
|
+
<should>对复杂变更,先描述计划并获得 owner 确认后再执行。</should>
|
|
43
|
+
<must>限制爆炸半径。在修改任何代码后,必须运行金丝雀测试(例如 `npm test`、linters)以验证完整性。</must>
|
|
44
|
+
<forbidden>直接执行大规模非结构化变更,或跳过修改后的验证环节。</forbidden>
|
|
44
45
|
</directive>
|
|
45
46
|
|
|
46
47
|
<directive id="T-06" name="OCCAMS_RAZOR_MVC">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-confirm-first-state-store.test.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import * as os from 'os';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import * as fs from 'fs';
|
|
5
|
-
import { SqliteConfirmFirstStateStore } from '../activation/sqlite-confirm-first-state-store.js';
|
|
6
|
-
import { SqliteConnection } from '../store/sqlite-connection.js';
|
|
7
|
-
describe('SqliteConfirmFirstStateStore', () => {
|
|
8
|
-
let tmpDir = '';
|
|
9
|
-
let connection = null;
|
|
10
|
-
let store = null;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-cf-test-'));
|
|
13
|
-
connection = new SqliteConnection(tmpDir);
|
|
14
|
-
store = new SqliteConfirmFirstStateStore(connection);
|
|
15
|
-
});
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
connection.close();
|
|
18
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
19
|
-
});
|
|
20
|
-
it('upsertDirective insert: inserts a new directive and getState returns correct record', () => {
|
|
21
|
-
store.upsertDirective('sess-1', true, 'principle-abc');
|
|
22
|
-
const record = store.getState('sess-1');
|
|
23
|
-
expect(record).not.toBeNull();
|
|
24
|
-
if (record) {
|
|
25
|
-
expect(record.sessionId).toBe('sess-1');
|
|
26
|
-
expect(record.directiveActive).toBe(true);
|
|
27
|
-
expect(record.directivePrincipleId).toBe('principle-abc');
|
|
28
|
-
expect(record.directiveSetAt).toBeTruthy();
|
|
29
|
-
expect(record.lastSeenAt).toBeTruthy();
|
|
30
|
-
expect(record.approvalActive).toBe(false);
|
|
31
|
-
expect(record.approvalSetAt).toBeNull();
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
it('upsertDirective update: updates directive while preserving approval fields', () => {
|
|
35
|
-
store.upsertDirective('sess-2', true, 'p-old');
|
|
36
|
-
store.upsertApproval('sess-2');
|
|
37
|
-
store.upsertDirective('sess-2', false, 'p-new');
|
|
38
|
-
const record = store.getState('sess-2');
|
|
39
|
-
expect(record).not.toBeNull();
|
|
40
|
-
if (record) {
|
|
41
|
-
expect(record.directiveActive).toBe(false);
|
|
42
|
-
expect(record.directivePrincipleId).toBe('p-new');
|
|
43
|
-
expect(record.approvalActive).toBe(true);
|
|
44
|
-
expect(record.approvalSetAt).not.toBeNull();
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
it('upsertApproval on existing row: sets approval fields on a row with prior directive', () => {
|
|
48
|
-
store.upsertDirective('sess-3', true, 'p-1');
|
|
49
|
-
store.upsertApproval('sess-3');
|
|
50
|
-
const record = store.getState('sess-3');
|
|
51
|
-
expect(record).not.toBeNull();
|
|
52
|
-
if (record) {
|
|
53
|
-
expect(record.directiveActive).toBe(true);
|
|
54
|
-
expect(record.directivePrincipleId).toBe('p-1');
|
|
55
|
-
expect(record.approvalActive).toBe(true);
|
|
56
|
-
expect(record.approvalSetAt).not.toBeNull();
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
it('upsertApproval on non-existent row: creates row with directive_active=0', () => {
|
|
60
|
-
store.upsertApproval('sess-4');
|
|
61
|
-
const db = connection.getDb();
|
|
62
|
-
const row = db.prepare('SELECT session_id, directive_active, approval_active FROM confirm_first_state WHERE session_id = ?').get('sess-4');
|
|
63
|
-
expect(row).toBeDefined();
|
|
64
|
-
if (row) {
|
|
65
|
-
expect(row.session_id).toBe('sess-4');
|
|
66
|
-
expect(row.directive_active).toBe(0);
|
|
67
|
-
expect(row.approval_active).toBe(1);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
it('getState returns null for missing session', () => {
|
|
71
|
-
const result = store.getState('nonexistent');
|
|
72
|
-
expect(result).toBeNull();
|
|
73
|
-
});
|
|
74
|
-
it('deleteState: removes a specific session record', () => {
|
|
75
|
-
store.upsertDirective('sess-5', true, 'p-del');
|
|
76
|
-
store.deleteState('sess-5');
|
|
77
|
-
expect(store.getState('sess-5')).toBeNull();
|
|
78
|
-
});
|
|
79
|
-
it('deleteAllState: removes all session records', () => {
|
|
80
|
-
store.upsertDirective('sess-a', true, 'p-a');
|
|
81
|
-
store.upsertDirective('sess-b', true, 'p-b');
|
|
82
|
-
store.upsertDirective('sess-c', true, 'p-c');
|
|
83
|
-
store.deleteAllState();
|
|
84
|
-
expect(store.getAllState()).toEqual([]);
|
|
85
|
-
});
|
|
86
|
-
it('pruneStaleRows with old rows: deletes rows older than 30 days', () => {
|
|
87
|
-
const db = connection.getDb();
|
|
88
|
-
const oldDate = '2020-01-01T00:00:00Z';
|
|
89
|
-
db.prepare(`INSERT INTO confirm_first_state (session_id, directive_active, directive_set_at, last_seen_at) VALUES (?, 1, ?, ?)`).run('old-sess-1', oldDate, oldDate);
|
|
90
|
-
db.prepare(`INSERT INTO confirm_first_state (session_id, directive_active, directive_set_at, last_seen_at) VALUES (?, 1, ?, ?)`).run('old-sess-2', oldDate, oldDate);
|
|
91
|
-
store.upsertDirective('fresh-sess', true, 'p-fresh');
|
|
92
|
-
const pruned = store.pruneStaleRows();
|
|
93
|
-
expect(pruned).toBe(2);
|
|
94
|
-
expect(store.getState('old-sess-1')).toBeNull();
|
|
95
|
-
expect(store.getState('old-sess-2')).toBeNull();
|
|
96
|
-
expect(store.getState('fresh-sess')).not.toBeNull();
|
|
97
|
-
});
|
|
98
|
-
it('pruneStaleRows with > 500 rows: evicts oldest rows keeping only 500', () => {
|
|
99
|
-
const db = connection.getDb();
|
|
100
|
-
for (let i = 0; i < 502; i++) {
|
|
101
|
-
const id = `sess-${String(i).padStart(4, '0')}`;
|
|
102
|
-
db.prepare(`INSERT INTO confirm_first_state (session_id, directive_active, directive_set_at, last_seen_at) VALUES (?, 1, ?, ?)`).run(id, '2026-05-30T00:00:00Z', '2026-05-30T00:00:00Z');
|
|
103
|
-
}
|
|
104
|
-
const pruned = store.pruneStaleRows();
|
|
105
|
-
expect(pruned).toBe(2);
|
|
106
|
-
const all = store.getAllState();
|
|
107
|
-
expect(all).toHaveLength(500);
|
|
108
|
-
expect(store.getState('sess-0000')).toBeNull();
|
|
109
|
-
expect(store.getState('sess-0001')).toBeNull();
|
|
110
|
-
expect(store.getState('sess-0002')).not.toBeNull();
|
|
111
|
-
});
|
|
112
|
-
it('concurrent upsertApproval: calling upsertApproval twice for same session yields single coherent row', () => {
|
|
113
|
-
store.upsertApproval('sess-dup');
|
|
114
|
-
store.upsertApproval('sess-dup');
|
|
115
|
-
const db = connection.getDb();
|
|
116
|
-
const rows = db.prepare('SELECT session_id, approval_active, approval_set_at FROM confirm_first_state WHERE session_id = ?').all('sess-dup');
|
|
117
|
-
expect(rows).toHaveLength(1);
|
|
118
|
-
const [firstRow] = rows;
|
|
119
|
-
if (firstRow) {
|
|
120
|
-
expect(firstRow.session_id).toBe('sess-dup');
|
|
121
|
-
expect(firstRow.approval_active).toBe(1);
|
|
122
|
-
expect(firstRow.approval_set_at).toBeTruthy();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
it('fresh workspace: getState returns null without error on a new connection', () => {
|
|
126
|
-
const freshTmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-cf-fresh-'));
|
|
127
|
-
try {
|
|
128
|
-
const freshConn = new SqliteConnection(freshTmpDir);
|
|
129
|
-
const freshStore = new SqliteConfirmFirstStateStore(freshConn);
|
|
130
|
-
const result = freshStore.getState('no-such-session');
|
|
131
|
-
expect(result).toBeNull();
|
|
132
|
-
freshConn.close();
|
|
133
|
-
}
|
|
134
|
-
finally {
|
|
135
|
-
fs.rmSync(freshTmpDir, { recursive: true, force: true });
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
it('getAllState: returns all inserted records', () => {
|
|
139
|
-
store.upsertDirective('sess-g1', true, 'p-g1');
|
|
140
|
-
store.upsertDirective('sess-g2', false, 'p-g2');
|
|
141
|
-
store.upsertDirective('sess-g3', true, 'p-g3');
|
|
142
|
-
const all = store.getAllState();
|
|
143
|
-
expect(all).toHaveLength(3);
|
|
144
|
-
const ids = all.map(r => r.sessionId).sort();
|
|
145
|
-
expect(ids).toEqual(['sess-g1', 'sess-g2', 'sess-g3']);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
//# sourceMappingURL=sqlite-confirm-first-state-store.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-confirm-first-state-store.test.js","sourceRoot":"","sources":["../../../src/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAA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AAS,CAAC,CAAC;YAE/D,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;YAEtD,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC1B,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;gBAAS,CAAC;YACT,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,KAAK,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/C,KAAK,CAAC,eAAe,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAChD,KAAK,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAE/C,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QAEhC,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC5B,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7C,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { SqliteConnection } from '../store/sqlite-connection.js';
|
|
2
|
-
export interface ConfirmFirstStateRecord {
|
|
3
|
-
sessionId: string;
|
|
4
|
-
directiveActive: boolean;
|
|
5
|
-
directivePrincipleId: string | null;
|
|
6
|
-
directiveSetAt: string;
|
|
7
|
-
approvalActive: boolean;
|
|
8
|
-
approvalSetAt: string | null;
|
|
9
|
-
lastSeenAt: string;
|
|
10
|
-
}
|
|
11
|
-
export declare class SqliteConfirmFirstStateStore {
|
|
12
|
-
private readonly connection;
|
|
13
|
-
constructor(connection: SqliteConnection);
|
|
14
|
-
upsertDirective(sessionId: string, active: boolean, principleId?: string | null): void;
|
|
15
|
-
upsertApproval(sessionId: string): void;
|
|
16
|
-
getState(sessionId: string): ConfirmFirstStateRecord | null;
|
|
17
|
-
deleteState(sessionId: string): void;
|
|
18
|
-
deleteAllState(): void;
|
|
19
|
-
pruneStaleRows(): number;
|
|
20
|
-
getAllState(): ConfirmFirstStateRecord[];
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=sqlite-confirm-first-state-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-confirm-first-state-store.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/activation/sqlite-confirm-first-state-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB;AAwCD,qBAAa,4BAA4B;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,gBAAgB;IAEzD,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IActF,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAavC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,uBAAuB,GAAG,IAAI;IAgB3D,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAKpC,cAAc,IAAI,IAAI;IAKtB,cAAc,IAAI,MAAM;IA2BxB,WAAW,IAAI,uBAAuB,EAAE;CAsBzC"}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
const MAX_SESSION_ENTRIES = 500;
|
|
2
|
-
const STALE_ROW_DAYS = 30;
|
|
3
|
-
function isRecord(value) {
|
|
4
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
|
-
}
|
|
6
|
-
function readStringField(row, key) {
|
|
7
|
-
if (!Object.hasOwn(row, key))
|
|
8
|
-
return null;
|
|
9
|
-
const val = row[key];
|
|
10
|
-
return typeof val === 'string' && val.length > 0 ? val : null;
|
|
11
|
-
}
|
|
12
|
-
function mapRowToRecord(row) {
|
|
13
|
-
if (!isRecord(row))
|
|
14
|
-
return null;
|
|
15
|
-
const sessionId = readStringField(row, 'session_id');
|
|
16
|
-
const directiveSetAt = readStringField(row, 'directive_set_at');
|
|
17
|
-
const lastSeenAt = readStringField(row, 'last_seen_at');
|
|
18
|
-
if (!sessionId || !directiveSetAt || !lastSeenAt)
|
|
19
|
-
return null;
|
|
20
|
-
const directiveActive = row.directive_active === 1;
|
|
21
|
-
const directivePrincipleId = readStringField(row, 'directive_principle_id');
|
|
22
|
-
const approvalActive = row.approval_active === 1;
|
|
23
|
-
const approvalSetAt = readStringField(row, 'approval_set_at');
|
|
24
|
-
return {
|
|
25
|
-
sessionId,
|
|
26
|
-
directiveActive,
|
|
27
|
-
directivePrincipleId,
|
|
28
|
-
directiveSetAt,
|
|
29
|
-
approvalActive,
|
|
30
|
-
approvalSetAt,
|
|
31
|
-
lastSeenAt,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export class SqliteConfirmFirstStateStore {
|
|
35
|
-
connection;
|
|
36
|
-
constructor(connection) {
|
|
37
|
-
this.connection = connection;
|
|
38
|
-
}
|
|
39
|
-
upsertDirective(sessionId, active, principleId) {
|
|
40
|
-
const db = this.connection.getDb();
|
|
41
|
-
const now = new Date().toISOString();
|
|
42
|
-
db.prepare(`
|
|
43
|
-
INSERT INTO confirm_first_state (session_id, directive_active, directive_principle_id, directive_set_at, last_seen_at)
|
|
44
|
-
VALUES (?, ?, ?, ?, ?)
|
|
45
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
46
|
-
directive_active=excluded.directive_active,
|
|
47
|
-
directive_principle_id=excluded.directive_principle_id,
|
|
48
|
-
directive_set_at=excluded.directive_set_at,
|
|
49
|
-
last_seen_at=excluded.last_seen_at
|
|
50
|
-
`).run(sessionId, active ? 1 : 0, principleId ?? null, now, now);
|
|
51
|
-
}
|
|
52
|
-
upsertApproval(sessionId) {
|
|
53
|
-
const db = this.connection.getDb();
|
|
54
|
-
const now = new Date().toISOString();
|
|
55
|
-
db.prepare(`
|
|
56
|
-
INSERT INTO confirm_first_state (session_id, approval_active, approval_set_at, last_seen_at, directive_active, directive_set_at)
|
|
57
|
-
VALUES (?, 1, ?, ?, 0, '')
|
|
58
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
59
|
-
approval_active=1,
|
|
60
|
-
approval_set_at=excluded.approval_set_at,
|
|
61
|
-
last_seen_at=excluded.last_seen_at
|
|
62
|
-
`).run(sessionId, now, now);
|
|
63
|
-
}
|
|
64
|
-
getState(sessionId) {
|
|
65
|
-
try {
|
|
66
|
-
const db = this.connection.getDb();
|
|
67
|
-
const row = db.prepare(`
|
|
68
|
-
SELECT session_id, directive_active, directive_principle_id, directive_set_at,
|
|
69
|
-
approval_active, approval_set_at, last_seen_at
|
|
70
|
-
FROM confirm_first_state
|
|
71
|
-
WHERE session_id = ?
|
|
72
|
-
`).get(sessionId);
|
|
73
|
-
return mapRowToRecord(row);
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
if (err instanceof Error && err.message.includes('no such table'))
|
|
77
|
-
return null;
|
|
78
|
-
throw err;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
deleteState(sessionId) {
|
|
82
|
-
const db = this.connection.getDb();
|
|
83
|
-
db.prepare('DELETE FROM confirm_first_state WHERE session_id = ?').run(sessionId);
|
|
84
|
-
}
|
|
85
|
-
deleteAllState() {
|
|
86
|
-
const db = this.connection.getDb();
|
|
87
|
-
db.prepare('DELETE FROM confirm_first_state').run();
|
|
88
|
-
}
|
|
89
|
-
pruneStaleRows() {
|
|
90
|
-
const db = this.connection.getDb();
|
|
91
|
-
const staleResult = db.prepare(`DELETE FROM confirm_first_state WHERE datetime(last_seen_at) < datetime('now', '-${STALE_ROW_DAYS} days')`).run();
|
|
92
|
-
let pruned = staleResult.changes;
|
|
93
|
-
const countRow = db.prepare('SELECT COUNT(*) as cnt FROM confirm_first_state').get();
|
|
94
|
-
if (isRecord(countRow) && Object.hasOwn(countRow, 'cnt')) {
|
|
95
|
-
const total = Number(countRow.cnt);
|
|
96
|
-
if (total > MAX_SESSION_ENTRIES) {
|
|
97
|
-
const excess = total - MAX_SESSION_ENTRIES;
|
|
98
|
-
const excessResult = db.prepare(`
|
|
99
|
-
DELETE FROM confirm_first_state
|
|
100
|
-
WHERE session_id IN (
|
|
101
|
-
SELECT session_id FROM confirm_first_state
|
|
102
|
-
ORDER BY last_seen_at ASC
|
|
103
|
-
LIMIT ?
|
|
104
|
-
)
|
|
105
|
-
`).run(excess);
|
|
106
|
-
pruned += excessResult.changes;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return pruned;
|
|
110
|
-
}
|
|
111
|
-
getAllState() {
|
|
112
|
-
try {
|
|
113
|
-
const db = this.connection.getDb();
|
|
114
|
-
const rows = db.prepare(`
|
|
115
|
-
SELECT session_id, directive_active, directive_principle_id, directive_set_at,
|
|
116
|
-
approval_active, approval_set_at, last_seen_at
|
|
117
|
-
FROM confirm_first_state
|
|
118
|
-
`).all();
|
|
119
|
-
if (!Array.isArray(rows))
|
|
120
|
-
return [];
|
|
121
|
-
const result = [];
|
|
122
|
-
for (const row of rows) {
|
|
123
|
-
const record = mapRowToRecord(row);
|
|
124
|
-
if (record)
|
|
125
|
-
result.push(record);
|
|
126
|
-
}
|
|
127
|
-
return result;
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
if (err instanceof Error && err.message.includes('no such table'))
|
|
131
|
-
return [];
|
|
132
|
-
throw err;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=sqlite-confirm-first-state-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-confirm-first-state-store.js","sourceRoot":"","sources":["../../../src/runtime-v2/activation/sqlite-confirm-first-state-store.ts"],"names":[],"mappings":"AAYA,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,eAAe,CAAC,GAA4B,EAAE,GAAW;IAChE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACrB,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC;AAED,SAAS,cAAc,CAAC,GAAY;IAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAEhC,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACrD,MAAM,cAAc,GA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|
-
* Confirm-First Gate
|
|
3
|
-
*
|
|
4
|
-
* Hard enforcement for confirm-first Runtime V2 prompt activations.
|
|
5
|
-
* When an owner-approved activation requires confirmation before coding,
|
|
6
|
-
* this gate blocks mutating tools until the session has explicit owner approval.
|
|
7
|
-
*
|
|
8
|
-
* This is NOT a replacement for prompt injection — it's a hard fallback
|
|
9
|
-
* for models that don't follow system prompt behavioral directives.
|
|
10
|
-
*
|
|
11
|
-
* Flow:
|
|
12
|
-
* 1. Prompt hook (before_prompt_build) detects confirm-first directive and caches state
|
|
13
|
-
* 2. Prompt hook detects user approval language and marks session approved
|
|
14
|
-
* 3. Gate hook (before_tool_call) checks cached state synchronously
|
|
15
|
-
*/
|
|
16
|
-
import { SqliteConfirmFirstStateStore } from '@principles/core/runtime-v2';
|
|
17
|
-
export declare function setConfirmFirstStore(store: SqliteConfirmFirstStateStore | null): void;
|
|
18
|
-
export interface ConfirmFirstGateResult {
|
|
19
|
-
action: 'allow' | 'block' | 'skip';
|
|
20
|
-
reason?: string;
|
|
21
|
-
nextAction?: string;
|
|
22
|
-
principleId?: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Detect if user message contains clear approval language.
|
|
26
|
-
* Rejects negated forms (e.g., "don't proceed", "不同意", "确认一下").
|
|
27
|
-
*/
|
|
28
|
-
export declare function detectApprovalMarker(message: string): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Set confirm-first directive state for a session (called from prompt hook).
|
|
31
|
-
*/
|
|
32
|
-
export declare function setConfirmFirstDirective(sessionId: string, active: boolean, principleId?: string): void;
|
|
33
|
-
/**
|
|
34
|
-
* Mark a session as approved (called from prompt hook when approval detected).
|
|
35
|
-
*/
|
|
36
|
-
export declare function setConfirmFirstApproval(sessionId: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Synchronous gate evaluation — checks cached state only.
|
|
39
|
-
* Called from before_tool_call hook (must be synchronous).
|
|
40
|
-
*/
|
|
41
|
-
export declare function evaluateConfirmFirstGateSync(sessionId: string | undefined, toolName: string, params: Record<string, unknown> | undefined): ConfirmFirstGateResult;
|
|
42
|
-
/**
|
|
43
|
-
* Reset state for a session (e.g., on /reset).
|
|
44
|
-
*/
|
|
45
|
-
export declare function resetConfirmFirst(sessionId: string): void;
|
|
46
|
-
/**
|
|
47
|
-
* Check if a session has been approved (for testing).
|
|
48
|
-
*/
|
|
49
|
-
export declare function isSessionApproved(sessionId: string): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Check if a session has an active directive (for testing).
|
|
52
|
-
*/
|
|
53
|
-
export declare function hasActiveDirective(sessionId: string): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Clear all state (for testing).
|
|
56
|
-
*/
|
|
57
|
-
export declare function clearAllConfirmFirstState(): void;
|
|
58
|
-
export declare function hydrateFromStore(sessionId: string): void;
|
|
59
|
-
export declare function pruneStoreStaleRows(): number;
|