scene-capability-engine 3.6.65 → 3.6.67

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 (121) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +17 -6
  3. package/README.zh.md +18 -6
  4. package/bin/scene-capability-engine.js +4 -0
  5. package/docs/README.md +2 -2
  6. package/docs/command-reference.md +382 -6
  7. package/docs/document-governance.md +3 -2
  8. package/docs/integration-modes.md +62 -478
  9. package/docs/integration-philosophy.md +56 -263
  10. package/docs/magicball-project-portfolio-contract.md +114 -2
  11. package/docs/project-management/README.md +14 -0
  12. package/docs/project-management/assurance/backup.md +3 -0
  13. package/docs/project-management/assurance/config.md +3 -0
  14. package/docs/project-management/assurance/evidence/README.md +3 -0
  15. package/docs/project-management/assurance/incidents/README.md +3 -0
  16. package/docs/project-management/assurance/logs.md +3 -0
  17. package/docs/project-management/assurance/overview.md +3 -0
  18. package/docs/project-management/assurance/recovery/README.md +3 -0
  19. package/docs/project-management/assurance/resource.md +3 -0
  20. package/docs/project-management/assurance/runbooks/README.md +3 -0
  21. package/docs/project-management/delivery/acceptance/README.md +3 -0
  22. package/docs/project-management/delivery/acceptance/evidence/README.md +3 -0
  23. package/docs/project-management/delivery/acceptance/exceptions/README.md +3 -0
  24. package/docs/project-management/delivery/acceptance/reports/README.md +3 -0
  25. package/docs/project-management/delivery/documents/changes.md +3 -0
  26. package/docs/project-management/delivery/documents/issues.md +3 -0
  27. package/docs/project-management/delivery/documents/overview.md +3 -0
  28. package/docs/project-management/delivery/documents/planning.md +3 -0
  29. package/docs/project-management/delivery/documents/requirements.md +3 -0
  30. package/docs/project-management/delivery/documents/tracking.md +3 -0
  31. package/docs/project-management/delivery/handoffs/README.md +3 -0
  32. package/docs/project-management/delivery/handoffs/evidence/README.md +3 -0
  33. package/docs/project-management/delivery/handoffs/records/README.md +3 -0
  34. package/docs/project-management/delivery/overview.md +10 -0
  35. package/docs/project-management/delivery/releases/README.md +3 -0
  36. package/docs/project-management/delivery/releases/baselines/README.md +3 -0
  37. package/docs/project-management/delivery/releases/evidence/README.md +3 -0
  38. package/docs/project-management/delivery/tables/changes.md +3 -0
  39. package/docs/project-management/delivery/tables/issues.md +3 -0
  40. package/docs/project-management/delivery/tables/planning.md +3 -0
  41. package/docs/project-management/delivery/tables/requirements.md +3 -0
  42. package/docs/project-management/delivery/tables/tracking.md +3 -0
  43. package/docs/project-management/environment/agent-discovery.md +3 -0
  44. package/docs/project-management/environment/development.md +3 -0
  45. package/docs/project-management/environment/overview.md +10 -0
  46. package/docs/project-management/environment/testing.md +3 -0
  47. package/docs/project-management/environment/version-alignment.md +3 -0
  48. package/docs/quick-start-with-ai-tools.md +68 -308
  49. package/docs/releases/README.md +2 -0
  50. package/docs/releases/v3.6.66.md +23 -0
  51. package/docs/releases/v3.6.67.md +23 -0
  52. package/docs/steering-governance.md +64 -2
  53. package/docs/zh/README.md +2 -2
  54. package/docs/zh/releases/README.md +2 -0
  55. package/docs/zh/releases/v3.6.66.md +23 -0
  56. package/docs/zh/releases/v3.6.67.md +23 -0
  57. package/lib/commands/adopt.js +24 -0
  58. package/lib/commands/native.js +158 -0
  59. package/lib/commands/project.js +95 -0
  60. package/lib/commands/semantic.js +1459 -0
  61. package/lib/commands/session.js +74 -3
  62. package/lib/commands/spec-bootstrap.js +10 -1
  63. package/lib/commands/spec-gate.js +10 -1
  64. package/lib/commands/spec-pipeline.js +10 -1
  65. package/lib/commands/studio.js +405 -30
  66. package/lib/commands/task.js +141 -7
  67. package/lib/governance/supreme-principles.js +530 -0
  68. package/lib/problem/problem-evaluator.js +4 -0
  69. package/lib/project/candidate-inspection-service.js +24 -1
  70. package/lib/project/portfolio-projection-service.js +315 -5
  71. package/lib/project/project-channel-output.js +94 -0
  72. package/lib/project/project-channel-projection.js +181 -0
  73. package/lib/project/root-onboarding-service.js +60 -8
  74. package/lib/project/semantic-shared-source-projection.js +150 -0
  75. package/lib/project/supervision-action-model.js +277 -0
  76. package/lib/project/supervision-projection-service.js +305 -5
  77. package/lib/project/target-resolution-service.js +70 -5
  78. package/lib/project/visibility-policy.js +93 -0
  79. package/lib/runtime/multi-spec-scene-session.js +8 -1
  80. package/lib/runtime/project-channel-context-store.js +387 -0
  81. package/lib/runtime/project-channel-context.js +406 -0
  82. package/lib/runtime/scene-session-binding.js +46 -0
  83. package/lib/runtime/session-store.js +186 -0
  84. package/lib/runtime/steering-contract.js +7 -1
  85. package/lib/semantic/archive-report.js +283 -0
  86. package/lib/semantic/archive-routing.js +67 -0
  87. package/lib/semantic/backflow-report.js +245 -0
  88. package/lib/semantic/capability-contract.js +30 -0
  89. package/lib/semantic/delta-export.js +145 -0
  90. package/lib/semantic/interaction-observer.js +254 -0
  91. package/lib/semantic/kernel-loader.js +881 -0
  92. package/lib/semantic/native-runtime.js +359 -0
  93. package/lib/semantic/progress-ledger.js +433 -0
  94. package/lib/semantic/replay-evaluator.js +382 -0
  95. package/lib/semantic/shared-publication.js +592 -0
  96. package/lib/semantic/shared-source-config.js +183 -0
  97. package/lib/semantic/shared-source-connect.js +139 -0
  98. package/lib/semantic/shared-source-discovery.js +98 -0
  99. package/lib/semantic/shared-sync-export.js +413 -0
  100. package/lib/semantic/shared-sync-intake.js +592 -0
  101. package/lib/semantic/shared-sync-merge.js +547 -0
  102. package/lib/semantic/shared-sync-release.js +463 -0
  103. package/lib/semantic/supreme-intent-report.js +300 -0
  104. package/lib/state/sce-state-store.js +1360 -0
  105. package/lib/steering/context-sync-manager.js +276 -25
  106. package/lib/studio/spec-intake-governor.js +39 -3
  107. package/lib/studio/task-envelope.js +35 -2
  108. package/lib/workspace/takeover-baseline.js +342 -83
  109. package/package.json +7 -2
  110. package/scripts/agent-governance-baseline-audit.js +395 -0
  111. package/scripts/clarification-first-audit.js +9 -9
  112. package/scripts/deprecated-entry-audit.js +240 -0
  113. package/scripts/release-posture-report.js +262 -0
  114. package/template/.sce/README.md +62 -228
  115. package/template/.sce/config/semantic-shared-sources.json +5 -0
  116. package/template/.sce/config/supreme-principles-policy.json +105 -0
  117. package/template/.sce/config/takeover-baseline.json +7 -0
  118. package/template/.sce/steering/CORE_PRINCIPLES.md +23 -63
  119. package/template/.sce/steering/CURRENT_CONTEXT.md +4 -0
  120. package/template/.sce/steering/RULES_GUIDE.md +17 -9
  121. package/template/README.md +32 -96
@@ -0,0 +1,300 @@
1
+ const { getSceStateStore } = require('../state/sce-state-store');
2
+
3
+ function normalizeString(value) {
4
+ if (typeof value !== 'string') {
5
+ return '';
6
+ }
7
+ return value.trim();
8
+ }
9
+
10
+ function normalizeInteger(value, fallback = 0) {
11
+ const parsed = Number.parseInt(`${value}`, 10);
12
+ if (!Number.isFinite(parsed) || parsed <= 0) {
13
+ return fallback;
14
+ }
15
+ return parsed;
16
+ }
17
+
18
+ function percent(part, total) {
19
+ if (!Number.isFinite(part) || !Number.isFinite(total) || total <= 0) {
20
+ return 0;
21
+ }
22
+ return Number(((part / total) * 100).toFixed(2));
23
+ }
24
+
25
+ function incrementCounter(map, key, amount = 1) {
26
+ if (!key) {
27
+ return;
28
+ }
29
+ map[key] = (map[key] || 0) + amount;
30
+ }
31
+
32
+ function countBy(items = [], getKey) {
33
+ const totals = {};
34
+ for (const item of items) {
35
+ const key = normalizeString(getKey(item));
36
+ incrementCounter(totals, key || 'unknown');
37
+ }
38
+ return Object.entries(totals)
39
+ .map(([key, count]) => ({ key, count }))
40
+ .sort((left, right) => {
41
+ if (right.count !== left.count) {
42
+ return right.count - left.count;
43
+ }
44
+ return left.key.localeCompare(right.key);
45
+ });
46
+ }
47
+
48
+ function listMatchedRuleIds(matchedRules = {}) {
49
+ const ids = new Set();
50
+ if (!matchedRules || typeof matchedRules !== 'object') {
51
+ return [];
52
+ }
53
+ for (const value of Object.values(matchedRules)) {
54
+ if (Array.isArray(value)) {
55
+ for (const item of value) {
56
+ if (item && typeof item === 'object') {
57
+ const id = normalizeString(item.id || item.rule_id || item.ruleId);
58
+ if (id) {
59
+ ids.add(id);
60
+ }
61
+ }
62
+ }
63
+ continue;
64
+ }
65
+ if (value && typeof value === 'object') {
66
+ const id = normalizeString(value.id || value.rule_id || value.ruleId);
67
+ if (id) {
68
+ ids.add(id);
69
+ }
70
+ }
71
+ }
72
+ return [...ids].sort((left, right) => left.localeCompare(right));
73
+ }
74
+
75
+ function rankGroupedItems(items = [], hotspotLimit = 5) {
76
+ return items
77
+ .sort((left, right) => {
78
+ if (right.governed_count !== left.governed_count) {
79
+ return right.governed_count - left.governed_count;
80
+ }
81
+ if (right.total !== left.total) {
82
+ return right.total - left.total;
83
+ }
84
+ return `${right.latest_at || ''}`.localeCompare(`${left.latest_at || ''}`);
85
+ })
86
+ .slice(0, hotspotLimit);
87
+ }
88
+
89
+ function buildScopeHotspots(items = [], hotspotLimit = 5) {
90
+ const scopes = new Map();
91
+ for (const item of items) {
92
+ const key = [
93
+ normalizeString(item.project_id) || 'project:none',
94
+ normalizeString(item.channel_id) || 'channel:none',
95
+ normalizeString(item.scene_id) || 'scene:none',
96
+ normalizeString(item.spec_id) || 'spec:none'
97
+ ].join('::');
98
+ if (!scopes.has(key)) {
99
+ scopes.set(key, {
100
+ project_id: normalizeString(item.project_id) || null,
101
+ channel_id: normalizeString(item.channel_id) || null,
102
+ scene_id: normalizeString(item.scene_id) || null,
103
+ spec_id: normalizeString(item.spec_id) || null,
104
+ total: 0,
105
+ allow: 0,
106
+ clarify: 0,
107
+ rewrite: 0,
108
+ narrow: 0,
109
+ refuse: 0,
110
+ governed_count: 0,
111
+ latest_at: null
112
+ });
113
+ }
114
+ const scope = scopes.get(key);
115
+ const action = normalizeString(item.action) || 'unknown';
116
+ scope.total += 1;
117
+ if (Object.prototype.hasOwnProperty.call(scope, action)) {
118
+ scope[action] += 1;
119
+ }
120
+ if (action !== 'allow') {
121
+ scope.governed_count += 1;
122
+ }
123
+ const updatedAt = normalizeString(item.updated_at) || null;
124
+ if (!scope.latest_at || `${updatedAt || ''}` > `${scope.latest_at || ''}`) {
125
+ scope.latest_at = updatedAt;
126
+ }
127
+ }
128
+ return rankGroupedItems([...scopes.values()], hotspotLimit);
129
+ }
130
+
131
+ function buildMatchedRuleHotspots(items = [], hotspotLimit = 5) {
132
+ const rules = new Map();
133
+ for (const item of items) {
134
+ const ruleIds = listMatchedRuleIds(item.matched_rules);
135
+ for (const ruleId of ruleIds) {
136
+ if (!rules.has(ruleId)) {
137
+ rules.set(ruleId, {
138
+ rule_id: ruleId,
139
+ count: 0,
140
+ actions: {},
141
+ sources: {},
142
+ latest_at: null
143
+ });
144
+ }
145
+ const record = rules.get(ruleId);
146
+ const action = normalizeString(item.action) || 'unknown';
147
+ const sourceKind = normalizeString(item.source_kind) || 'unknown';
148
+ record.count += 1;
149
+ incrementCounter(record.actions, action);
150
+ incrementCounter(record.sources, sourceKind);
151
+ const updatedAt = normalizeString(item.updated_at) || null;
152
+ if (!record.latest_at || `${updatedAt || ''}` > `${record.latest_at || ''}`) {
153
+ record.latest_at = updatedAt;
154
+ }
155
+ }
156
+ }
157
+ return [...rules.values()]
158
+ .sort((left, right) => {
159
+ if (right.count !== left.count) {
160
+ return right.count - left.count;
161
+ }
162
+ return `${right.latest_at || ''}`.localeCompare(`${left.latest_at || ''}`);
163
+ })
164
+ .slice(0, hotspotLimit)
165
+ .map((item) => ({
166
+ ...item,
167
+ actions: countBy(
168
+ Object.entries(item.actions).map(([key, count]) => ({ key, count })),
169
+ (entry) => entry.key
170
+ ).map((entry) => ({ action: entry.key, count: item.actions[entry.key] || entry.count })),
171
+ sources: countBy(
172
+ Object.entries(item.sources).map(([key, count]) => ({ key, count })),
173
+ (entry) => entry.key
174
+ ).map((entry) => ({ source_kind: entry.key, count: item.sources[entry.key] || entry.count }))
175
+ }));
176
+ }
177
+
178
+ function summarizeRecentItems(items = [], recentLimit = 10, actionFilter = '') {
179
+ const normalizedAction = normalizeString(actionFilter);
180
+ return items
181
+ .filter((item) => !normalizedAction || normalizeString(item.action) === normalizedAction)
182
+ .sort((left, right) => `${right.updated_at || ''}`.localeCompare(`${left.updated_at || ''}`))
183
+ .slice(0, recentLimit)
184
+ .map((item) => ({
185
+ assessment_id: item.assessment_id,
186
+ project_id: item.project_id,
187
+ channel_id: item.channel_id,
188
+ session_id: item.session_id,
189
+ scene_id: item.scene_id,
190
+ spec_id: item.spec_id,
191
+ job_id: item.job_id,
192
+ source_kind: item.source_kind,
193
+ action: item.action,
194
+ planning_allowed: item.planning_allowed,
195
+ execution_allowed: item.execution_allowed,
196
+ message: item.message,
197
+ matched_rule_ids: listMatchedRuleIds(item.matched_rules),
198
+ updated_at: item.updated_at
199
+ }));
200
+ }
201
+
202
+ async function buildSupremeIntentGovernanceReport(options = {}, dependencies = {}) {
203
+ const projectPath = dependencies.projectPath || process.cwd();
204
+ const store = dependencies.stateStore || getSceStateStore(projectPath, {
205
+ fileSystem: dependencies.fileSystem,
206
+ env: dependencies.env,
207
+ sqliteModule: dependencies.sqliteModule,
208
+ noCache: dependencies.noCache === true
209
+ });
210
+ const scanLimit = normalizeInteger(options.limit, 200);
211
+ const hotspotLimit = normalizeInteger(options.hotspot_limit || options.hotspotLimit, 5);
212
+ const recentLimit = normalizeInteger(options.recent_limit || options.recentLimit, 10);
213
+
214
+ let items = await store.listSupremeIntentAssessments({
215
+ project_id: options.project_id || options.projectId,
216
+ channel_id: options.channel_id || options.channelId,
217
+ session_id: options.session_id || options.sessionId,
218
+ scene_id: options.scene_id || options.sceneId,
219
+ spec_id: options.spec_id || options.specId,
220
+ job_id: options.job_id || options.jobId,
221
+ source_kind: options.source_kind || options.sourceKind,
222
+ action: options.action,
223
+ limit: scanLimit
224
+ });
225
+ items = Array.isArray(items) ? items : [];
226
+
227
+ const governedItems = items.filter((item) => normalizeString(item.action) && normalizeString(item.action) !== 'allow');
228
+ const planningBlocked = items.filter((item) => item.planning_allowed !== true);
229
+ const executionBlocked = items.filter((item) => item.execution_allowed !== true);
230
+
231
+ return {
232
+ mode: 'semantic-governance-report',
233
+ success: true,
234
+ generated_at: new Date().toISOString(),
235
+ filters: {
236
+ project_id: normalizeString(options.project_id || options.projectId) || null,
237
+ channel_id: normalizeString(options.channel_id || options.channelId) || null,
238
+ session_id: normalizeString(options.session_id || options.sessionId) || null,
239
+ scene_id: normalizeString(options.scene_id || options.sceneId) || null,
240
+ spec_id: normalizeString(options.spec_id || options.specId) || null,
241
+ job_id: normalizeString(options.job_id || options.jobId) || null,
242
+ source_kind: normalizeString(options.source_kind || options.sourceKind) || null,
243
+ action: normalizeString(options.action) || null,
244
+ limit: scanLimit,
245
+ hotspot_limit: hotspotLimit,
246
+ recent_limit: recentLimit
247
+ },
248
+ totals: {
249
+ total: items.length,
250
+ governed: governedItems.length,
251
+ allow: items.filter((item) => normalizeString(item.action) === 'allow').length,
252
+ clarify: items.filter((item) => normalizeString(item.action) === 'clarify').length,
253
+ rewrite: items.filter((item) => normalizeString(item.action) === 'rewrite').length,
254
+ narrow: items.filter((item) => normalizeString(item.action) === 'narrow').length,
255
+ refuse: items.filter((item) => normalizeString(item.action) === 'refuse').length,
256
+ planning_blocked: planningBlocked.length,
257
+ execution_blocked: executionBlocked.length,
258
+ governed_action_rate_percent: percent(governedItems.length, items.length)
259
+ },
260
+ top_actions: countBy(items, (item) => item.action)
261
+ .slice(0, hotspotLimit)
262
+ .map((item) => ({ action: item.key, count: item.count })),
263
+ top_sources: countBy(items, (item) => item.source_kind)
264
+ .slice(0, hotspotLimit)
265
+ .map((item) => ({ source_kind: item.key, count: item.count })),
266
+ top_projects: countBy(governedItems, (item) => item.project_id)
267
+ .slice(0, hotspotLimit)
268
+ .map((item) => ({ project_id: item.key === 'unknown' ? null : item.key, count: item.count })),
269
+ top_channels: countBy(governedItems, (item) => `${normalizeString(item.project_id) || 'unknown'}::${normalizeString(item.channel_id) || 'none'}`)
270
+ .slice(0, hotspotLimit)
271
+ .map((item) => {
272
+ const [projectId, channelId] = item.key.split('::');
273
+ return {
274
+ project_id: projectId === 'unknown' ? null : projectId,
275
+ channel_id: channelId === 'none' ? null : channelId,
276
+ count: item.count
277
+ };
278
+ }),
279
+ top_specs: countBy(governedItems, (item) => `${normalizeString(item.project_id) || 'unknown'}::${normalizeString(item.spec_id) || 'none'}`)
280
+ .slice(0, hotspotLimit)
281
+ .map((item) => {
282
+ const [projectId, specId] = item.key.split('::');
283
+ return {
284
+ project_id: projectId === 'unknown' ? null : projectId,
285
+ spec_id: specId === 'none' ? null : specId,
286
+ count: item.count
287
+ };
288
+ }),
289
+ top_scope_hotspots: buildScopeHotspots(governedItems, hotspotLimit),
290
+ top_matched_rules: buildMatchedRuleHotspots(governedItems, hotspotLimit),
291
+ recent_governed_items: summarizeRecentItems(governedItems, recentLimit),
292
+ recent_refusals: summarizeRecentItems(governedItems, recentLimit, 'refuse'),
293
+ recent_rewrites: summarizeRecentItems(governedItems, recentLimit, 'rewrite')
294
+ };
295
+ }
296
+
297
+ module.exports = {
298
+ buildSupremeIntentGovernanceReport,
299
+ listMatchedRuleIds
300
+ };