create-principles-disciple 1.74.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.
Files changed (63) hide show
  1. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +3 -3
  2. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  3. package/core/dist/runtime-v2/activation/index.d.ts +0 -2
  4. package/core/dist/runtime-v2/activation/index.d.ts.map +1 -1
  5. package/core/dist/runtime-v2/activation/index.js +0 -1
  6. package/core/dist/runtime-v2/activation/index.js.map +1 -1
  7. package/core/dist/runtime-v2/index.d.ts +4 -4
  8. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  9. package/core/dist/runtime-v2/index.js +2 -2
  10. package/core/dist/runtime-v2/index.js.map +1 -1
  11. package/core/dist/runtime-v2/types/event-types.d.ts +3 -24
  12. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  13. package/core/dist/runtime-v2/types/event-types.js +0 -10
  14. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  15. package/dist/utils/env.d.ts.map +1 -1
  16. package/dist/utils/env.js +0 -1
  17. package/dist/utils/env.js.map +1 -1
  18. package/package.json +1 -1
  19. package/plugin/dist/core/event-log.d.ts +1 -3
  20. package/plugin/dist/core/event-log.js +0 -6
  21. package/plugin/dist/core/migration.js +0 -1
  22. package/plugin/dist/core/path-resolver.js +0 -1
  23. package/plugin/dist/core/paths.d.ts +0 -1
  24. package/plugin/dist/core/paths.js +0 -1
  25. package/plugin/dist/hooks/gate-block-helper.js +17 -20
  26. package/plugin/dist/hooks/gate.js +12 -58
  27. package/plugin/dist/hooks/prompt.d.ts +6 -0
  28. package/plugin/dist/hooks/prompt.js +1 -56
  29. package/plugin/dist/types/event-types.d.ts +1 -1
  30. package/plugin/dist/utils/io.d.ts +0 -1
  31. package/plugin/dist/utils/io.js +0 -23
  32. package/plugin/templates/langs/en/core/AGENTS.md +5 -5
  33. package/plugin/templates/langs/en/principles/THINKING_OS.md +3 -2
  34. package/plugin/templates/langs/en/skills/evolve-task/SKILL.md +2 -2
  35. package/plugin/templates/langs/en/skills/pd-mentor/SKILL.md +1 -2
  36. package/plugin/templates/langs/zh/core/AGENTS.md +5 -5
  37. package/plugin/templates/langs/zh/principles/THINKING_OS.md +3 -2
  38. package/plugin/templates/langs/zh/skills/evolve-task/SKILL.md +2 -2
  39. package/plugin/templates/langs/zh/skills/pd-mentor/SKILL.md +1 -2
  40. package/plugin/templates/workspace/.principles/THINKING_OS.md +3 -2
  41. package/templates/langs/en/core/AGENTS.md +7 -7
  42. package/templates/langs/en/principles/THINKING_OS.md +3 -2
  43. package/templates/langs/en/skills/evolve-task/SKILL.md +3 -3
  44. package/templates/langs/en/skills/pd-mentor/SKILL.md +1 -2
  45. package/templates/langs/zh/core/AGENTS.md +7 -7
  46. package/templates/langs/zh/principles/THINKING_OS.md +3 -2
  47. package/templates/langs/zh/skills/evolve-task/SKILL.md +4 -4
  48. package/templates/langs/zh/skills/pd-mentor/SKILL.md +1 -2
  49. package/templates/workspace/.principles/THINKING_OS.md +3 -2
  50. package/core/dist/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.d.ts +0 -2
  51. package/core/dist/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.d.ts.map +0 -1
  52. package/core/dist/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.js +0 -148
  53. package/core/dist/runtime-v2/__tests__/sqlite-confirm-first-state-store.test.js.map +0 -1
  54. package/core/dist/runtime-v2/activation/sqlite-confirm-first-state-store.d.ts +0 -22
  55. package/core/dist/runtime-v2/activation/sqlite-confirm-first-state-store.d.ts.map +0 -1
  56. package/core/dist/runtime-v2/activation/sqlite-confirm-first-state-store.js +0 -136
  57. package/core/dist/runtime-v2/activation/sqlite-confirm-first-state-store.js.map +0 -1
  58. package/plugin/dist/core/confirm-first-gate.d.ts +0 -59
  59. package/plugin/dist/core/confirm-first-gate.js +0 -215
  60. package/plugin/templates/langs/en/skills/plan-script/SKILL.md +0 -32
  61. package/plugin/templates/langs/zh/skills/plan-script/SKILL.md +0 -32
  62. package/templates/langs/en/skills/plan-script/SKILL.md +0 -32
  63. package/templates/langs/zh/skills/plan-script/SKILL.md +0 -32
@@ -1,215 +0,0 @@
1
- /**
2
- * 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 { BASH_TOOLS_SET, WRITE_TOOLS } from '../constants/tools.js';
17
- /** Size cap to prevent memory leaks from abandoned sessions */
18
- const MAX_SESSION_ENTRIES = 500;
19
- // TODO(PRI-268): stale directive cleanup
20
- const sessionDirectiveState = new Map();
21
- // TODO(PRI-267): per-task approval scope
22
- const sessionApprovalState = new Map();
23
- let confirmFirstStore = null;
24
- export function setConfirmFirstStore(store) {
25
- confirmFirstStore = store;
26
- }
27
- function evictOldestIfFull(map) {
28
- if (map.size >= MAX_SESSION_ENTRIES) {
29
- const firstKey = map.keys().next().value;
30
- if (firstKey !== undefined)
31
- map.delete(firstKey);
32
- }
33
- }
34
- /**
35
- * Check if a tool is mutating (write, edit, delete, or mutating exec).
36
- */
37
- function isMutatingTool(toolName, params) {
38
- // Direct write/edit/delete tools are always mutating
39
- if (WRITE_TOOLS.has(toolName))
40
- return true;
41
- // For exec/bash, only mutating if the command content is mutating
42
- if (BASH_TOOLS_SET.has(toolName)) {
43
- const command = String(params?.command || params?.args || '');
44
- if (!command)
45
- return false;
46
- return />\s*|>>\s*|\brm\b|\bmv\b|\bmkdir\b|\btouch\b|\bcp\s|\bsed\s+-i|\bchmod\b|\bchown\b|\bdel\s|\bRemove-Item\b|\bSet-Content\b|\bOut-File\b|\bNew-Item\b/.test(command);
47
- }
48
- return false;
49
- }
50
- /**
51
- * Detect if user message contains clear approval language.
52
- * Rejects negated forms (e.g., "don't proceed", "不同意", "确认一下").
53
- */
54
- export function detectApprovalMarker(message) {
55
- const trimmed = message.trim();
56
- // Negation prefixes — reject if present before approval keywords
57
- const zhNegation = /不|别|暂不|先不|无法|不能|没准备好|还没|尚未/;
58
- const enNegation = /don'?t|not\s+ready|can'?t|won'?t|stop|hold|cannot|isn'?t|aren'?t|haven'?t|shouldn'?t/i;
59
- // Single-word Chinese markers require exact match (the word alone, not embedded in a sentence)
60
- const zhExactMarkers = /^(?:确认|批准|同意|执行吧|开始执行)$/;
61
- // Multi-word Chinese markers
62
- const zhPhraseMarkers = /按计划执行|可以执行|就这么做|去执行|照.*做|没问题.*执行/;
63
- // English markers — unambiguous single-word approvals only
64
- const enMarkers = /\bapproved\b|\bgo\s*ahead\b|\blgtm\b/i;
65
- // English phrase markers — require explicit approval context
66
- const enPhraseMarkers = /\byes,?\s*(do\s+it|proceed|execute)\b|\bdo\s+it\b|\bproceed\s+with\s+the\s+plan\b|\bexecute\s+the\s+plan\b|\bplease\s+proceed\s+with\s+the\s+plan\b/i;
67
- // Check Chinese
68
- if (zhExactMarkers.test(trimmed) || zhPhraseMarkers.test(trimmed)) {
69
- // Reject if negation prefix present
70
- if (zhNegation.test(trimmed))
71
- return false;
72
- return true;
73
- }
74
- // Check English
75
- if (enMarkers.test(trimmed) || enPhraseMarkers.test(trimmed)) {
76
- if (enNegation.test(trimmed))
77
- return false;
78
- return true;
79
- }
80
- return false;
81
- }
82
- /**
83
- * Set confirm-first directive state for a session (called from prompt hook).
84
- */
85
- export function setConfirmFirstDirective(sessionId, active, principleId) {
86
- evictOldestIfFull(sessionDirectiveState);
87
- sessionDirectiveState.set(sessionId, { active, principleId });
88
- if (confirmFirstStore) {
89
- try {
90
- confirmFirstStore.upsertDirective(sessionId, active, principleId ?? null);
91
- }
92
- catch (storeErr) {
93
- console.warn(`[PD:ConfirmFirst] Store write failed for directive (session=${sessionId}), degraded to cache-only: ${String(storeErr)}`);
94
- }
95
- }
96
- }
97
- /**
98
- * Mark a session as approved (called from prompt hook when approval detected).
99
- */
100
- export function setConfirmFirstApproval(sessionId) {
101
- evictOldestIfFull(sessionApprovalState);
102
- sessionApprovalState.set(sessionId, true);
103
- if (confirmFirstStore) {
104
- try {
105
- confirmFirstStore.upsertApproval(sessionId);
106
- }
107
- catch (storeErr) {
108
- console.warn(`[PD:ConfirmFirst] Store write failed for approval (session=${sessionId}), degraded to cache-only: ${String(storeErr)}`);
109
- }
110
- }
111
- }
112
- /**
113
- * Synchronous gate evaluation — checks cached state only.
114
- * Called from before_tool_call hook (must be synchronous).
115
- */
116
- export function evaluateConfirmFirstGateSync(sessionId, toolName, params) {
117
- if (!sessionId)
118
- return { action: 'skip' };
119
- // 1. Check if session is already approved
120
- if (sessionApprovalState.get(sessionId)) {
121
- return { action: 'allow' };
122
- }
123
- // 2. Check if confirm-first directive is active for this session
124
- const directive = sessionDirectiveState.get(sessionId);
125
- if (!directive?.active) {
126
- return { action: 'skip' };
127
- }
128
- // 3. Check if tool is mutating
129
- if (!isMutatingTool(toolName, params)) {
130
- return { action: 'allow' };
131
- }
132
- // 4. Block: mutating tool with active confirm-first and no approval
133
- return {
134
- action: 'block',
135
- reason: 'confirm_first_required',
136
- nextAction: 'Summarize requirements, list ambiguities, propose a plan, and wait for explicit owner approval before mutating files.',
137
- principleId: directive.principleId,
138
- };
139
- }
140
- /**
141
- * Reset state for a session (e.g., on /reset).
142
- */
143
- export function resetConfirmFirst(sessionId) {
144
- sessionDirectiveState.delete(sessionId);
145
- sessionApprovalState.delete(sessionId);
146
- if (confirmFirstStore) {
147
- try {
148
- confirmFirstStore.deleteState(sessionId);
149
- }
150
- catch (storeErr) {
151
- console.warn(`[PD:ConfirmFirst] Store delete failed for session=${sessionId}: ${String(storeErr)}`);
152
- }
153
- }
154
- }
155
- /**
156
- * Check if a session has been approved (for testing).
157
- */
158
- export function isSessionApproved(sessionId) {
159
- return sessionApprovalState.get(sessionId) === true;
160
- }
161
- /**
162
- * Check if a session has an active directive (for testing).
163
- */
164
- export function hasActiveDirective(sessionId) {
165
- return sessionDirectiveState.get(sessionId)?.active === true;
166
- }
167
- /**
168
- * Clear all state (for testing).
169
- */
170
- export function clearAllConfirmFirstState() {
171
- sessionDirectiveState.clear();
172
- sessionApprovalState.clear();
173
- if (confirmFirstStore) {
174
- try {
175
- confirmFirstStore.deleteAllState();
176
- }
177
- catch (storeErr) {
178
- console.warn(`[PD:ConfirmFirst] Store clearAll failed: ${String(storeErr)}`);
179
- }
180
- }
181
- }
182
- export function hydrateFromStore(sessionId) {
183
- if (!confirmFirstStore)
184
- return;
185
- if (sessionDirectiveState.has(sessionId))
186
- return;
187
- try {
188
- const record = confirmFirstStore.getState(sessionId);
189
- if (!record)
190
- return;
191
- evictOldestIfFull(sessionDirectiveState);
192
- sessionDirectiveState.set(sessionId, {
193
- active: record.directiveActive,
194
- principleId: record.directivePrincipleId ?? undefined,
195
- });
196
- if (record.approvalActive) {
197
- evictOldestIfFull(sessionApprovalState);
198
- sessionApprovalState.set(sessionId, true);
199
- }
200
- }
201
- catch (storeErr) {
202
- console.warn(`[PD:ConfirmFirst] Store hydration failed for session=${sessionId}: ${String(storeErr)}`);
203
- }
204
- }
205
- export function pruneStoreStaleRows() {
206
- if (!confirmFirstStore)
207
- return 0;
208
- try {
209
- return confirmFirstStore.pruneStaleRows();
210
- }
211
- catch (storeErr) {
212
- console.warn(`[PD:ConfirmFirst] Store pruning failed: ${String(storeErr)}`);
213
- return 0;
214
- }
215
- }
@@ -1,32 +0,0 @@
1
- ---
2
- name: plan-script
3
- description: Create a step-by-step movie-script style execution plan. Includes target files, verification metrics, and rollback strategy.
4
- disable-model-invocation: true
5
- ---
6
-
7
- # Plan Script
8
-
9
- **Goal**: Produce a "foolproof" executable plan to ensure controlled execution.
10
-
11
- Please generate plan in the following structure:
12
-
13
- ## 1. Target Files (Authorization List)
14
- - List file paths **uniquely authorized** for modification in this plan.
15
- - Format: `- path/to/file`
16
-
17
- ## 2. Steps (Execution Steps)
18
- 1. Operations specific to filenames and tool calls.
19
- 2. Each step includes expected intermediate state.
20
-
21
- ## 3. Metrics (Verification Metrics)
22
- - How to quantitatively prove this plan succeeded? (e.g., tests pass, command returns 0, specific string appears in logs).
23
-
24
- ## 4. Active Mental Models
25
- - Select exactly **2** meta-cognitive models from `.principles/THINKING_OS.md` that are most relevant to the current task.
26
- - Format: `- [T-0X] Model Name: Why is it needed for this specific task?`
27
-
28
- ## 5. Rollback (Rollback Strategy)
29
- - If step 2 fails, how to one-click restore to safe state?
30
-
31
- ---
32
- **Action**: Update above content to `PLAN.md` and set `STATUS: READY`.
@@ -1,32 +0,0 @@
1
- ---
2
- name: plan-script
3
- description: Create a step-by-step movie-script style execution plan. Includes target files, verification metrics, and rollback strategy.
4
- disable-model-invocation: true
5
- ---
6
-
7
- # Plan Script (计划编排)
8
-
9
- **目标**: 产生一份“傻瓜式”可执行计划,确保执行过程受控。
10
-
11
- 请按以下结构生成计划:
12
-
13
- ## 1. Target Files (授权清单)
14
- - 列出本次计划**唯一授权**修改的文件路径。
15
- - 格式:`- path/to/file`
16
-
17
- ## 2. Steps (执行步骤)
18
- 1. 具体到文件名和工具调用的操作。
19
- 2. 每个步骤包含预期的中间状态。
20
-
21
- ## 3. Metrics (验证指标)
22
- - 如何量化证明本计划成功了?(如:测试通过、命令返回 0、日志出现特定字符串)。
23
-
24
- ## 4. Active Mental Models (激活的思维模型)
25
- - 从 `.principles/THINKING_OS.md` 中挑选 **2 个** 最适合当前任务的元认知模型。
26
- - 格式:`- [T-0X] 模型名称:为什么在这个任务中需要它?`
27
-
28
- ## 5. Rollback (回滚方案)
29
- - 如果步骤 2 失败,如何一键恢复到安全状态?
30
-
31
- ---
32
- **动作**: 请将以上内容更新至 `PLAN.md`,并设置 `STATUS: READY`。
@@ -1,32 +0,0 @@
1
- ---
2
- name: plan-script
3
- description: Create a step-by-step movie-script style execution plan. Includes target files, verification metrics, and rollback strategy.
4
- disable-model-invocation: true
5
- ---
6
-
7
- # Plan Script
8
-
9
- **Goal**: Produce a "foolproof" executable plan to ensure controlled execution.
10
-
11
- Please generate plan in the following structure:
12
-
13
- ## 1. Target Files (Authorization List)
14
- - List file paths **uniquely authorized** for modification in this plan.
15
- - Format: `- path/to/file`
16
-
17
- ## 2. Steps (Execution Steps)
18
- 1. Operations specific to filenames and tool calls.
19
- 2. Each step includes expected intermediate state.
20
-
21
- ## 3. Metrics (Verification Metrics)
22
- - How to quantitatively prove this plan succeeded? (e.g., tests pass, command returns 0, specific string appears in logs).
23
-
24
- ## 4. Active Mental Models
25
- - Select exactly **2** meta-cognitive models from `.principles/THINKING_OS.md` that are most relevant to the current task.
26
- - Format: `- [T-0X] Model Name: Why is it needed for this specific task?`
27
-
28
- ## 5. Rollback (Rollback Strategy)
29
- - If step 2 fails, how to one-click restore to safe state?
30
-
31
- ---
32
- **Action**: Update above content to `PLAN.md` and set `STATUS: READY`.
@@ -1,32 +0,0 @@
1
- ---
2
- name: plan-script
3
- description: Create a step-by-step movie-script style execution plan. Includes target files, verification metrics, and rollback strategy.
4
- disable-model-invocation: true
5
- ---
6
-
7
- # Plan Script (计划编排)
8
-
9
- **目标**: 产生一份“傻瓜式”可执行计划,确保执行过程受控。
10
-
11
- 请按以下结构生成计划:
12
-
13
- ## 1. Target Files (授权清单)
14
- - 列出本次计划**唯一授权**修改的文件路径。
15
- - 格式:`- path/to/file`
16
-
17
- ## 2. Steps (执行步骤)
18
- 1. 具体到文件名和工具调用的操作。
19
- 2. 每个步骤包含预期的中间状态。
20
-
21
- ## 3. Metrics (验证指标)
22
- - 如何量化证明本计划成功了?(如:测试通过、命令返回 0、日志出现特定字符串)。
23
-
24
- ## 4. Active Mental Models (激活的思维模型)
25
- - 从 `.principles/THINKING_OS.md` 中挑选 **2 个** 最适合当前任务的元认知模型。
26
- - 格式:`- [T-0X] 模型名称:为什么在这个任务中需要它?`
27
-
28
- ## 5. Rollback (回滚方案)
29
- - 如果步骤 2 失败,如何一键恢复到安全状态?
30
-
31
- ---
32
- **动作**: 请将以上内容更新至 `PLAN.md`,并设置 `STATUS: READY`。