@tomflow/chatloop-tools 0.9.15 → 0.9.17

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 (148) hide show
  1. package/README.md +2 -1
  2. package/index.mjs +12 -1
  3. package/lib/gateway.mjs +15 -3
  4. package/lib/mcp-tool-router.mjs +50 -3
  5. package/lib/trace-observation.mjs +19 -0
  6. package/node_modules/@tomflow/chatloop-context/README.md +240 -0
  7. package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +48 -0
  8. package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +151 -0
  9. package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +376 -0
  10. package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +266 -0
  11. package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +134 -0
  12. package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +82 -0
  13. package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +349 -0
  14. package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +72 -0
  15. package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +73 -0
  16. package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +507 -0
  17. package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +11 -0
  18. package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +182 -0
  19. package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +277 -0
  20. package/node_modules/@tomflow/chatloop-context/index.mjs +233 -0
  21. package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +86 -0
  22. package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +24 -0
  23. package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +1989 -0
  24. package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +67 -0
  25. package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +280 -0
  26. package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +298 -0
  27. package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +280 -0
  28. package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +115 -0
  29. package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +51 -0
  30. package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +55 -0
  31. package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +262 -0
  32. package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +246 -0
  33. package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +147 -0
  34. package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +343 -0
  35. package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +391 -0
  36. package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +166 -0
  37. package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +13 -0
  38. package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +111 -0
  39. package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +107 -0
  40. package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +117 -0
  41. package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +20 -0
  42. package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +312 -0
  43. package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +153 -0
  44. package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +19 -0
  45. package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +115 -0
  46. package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +86 -0
  47. package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +169 -0
  48. package/node_modules/@tomflow/chatloop-context/package.json +40 -0
  49. package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +114 -0
  50. package/node_modules/@tomflow/chatloop-extension/README.md +94 -0
  51. package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +11 -0
  52. package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +141 -0
  53. package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +109 -0
  54. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +1 -0
  55. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +1 -0
  56. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +1 -0
  57. package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +1 -0
  58. package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +1 -0
  59. package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +1 -0
  60. package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +1 -0
  61. package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +1 -0
  62. package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +1 -0
  63. package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +120 -0
  64. package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +180 -0
  65. package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +322 -0
  66. package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +2 -0
  67. package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +378 -0
  68. package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +2 -0
  69. package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +54 -0
  70. package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +9 -0
  71. package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +20 -0
  72. package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +69 -0
  73. package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +287 -0
  74. package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +23 -0
  75. package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +2 -0
  76. package/node_modules/@tomflow/chatloop-extension/extension/background.js +16 -0
  77. package/node_modules/@tomflow/chatloop-extension/extension/clean.html +5 -0
  78. package/node_modules/@tomflow/chatloop-extension/extension/content.js +40 -0
  79. package/node_modules/@tomflow/chatloop-extension/extension/continue.html +9 -0
  80. package/node_modules/@tomflow/chatloop-extension/extension/dom.html +17 -0
  81. package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +9 -0
  82. package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +2 -0
  83. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +275 -0
  84. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +76 -0
  85. package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +107 -0
  86. package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +36 -0
  87. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +227 -0
  88. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +144 -0
  89. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +171 -0
  90. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +109 -0
  91. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +154 -0
  92. package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +254 -0
  93. package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +42 -0
  94. package/node_modules/@tomflow/chatloop-extension/extension/popup.html +25 -0
  95. package/node_modules/@tomflow/chatloop-extension/extension/popup.js +93 -0
  96. package/node_modules/@tomflow/chatloop-extension/extension/reload.html +17 -0
  97. package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +17 -0
  98. package/node_modules/@tomflow/chatloop-extension/extension/start.html +6 -0
  99. package/node_modules/@tomflow/chatloop-extension/extension/status.html +6 -0
  100. package/node_modules/@tomflow/chatloop-extension/extension/text.html +17 -0
  101. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +136 -0
  102. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +220 -0
  103. package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +122 -0
  104. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +155 -0
  105. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +185 -0
  106. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +120 -0
  107. package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +172 -0
  108. package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +165 -0
  109. package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +244 -0
  110. package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +181 -0
  111. package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +147 -0
  112. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +197 -0
  113. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +200 -0
  114. package/node_modules/@tomflow/chatloop-extension/index.mjs +71 -0
  115. package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +18 -0
  116. package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +74 -0
  117. package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +208 -0
  118. package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +40 -0
  119. package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +45 -0
  120. package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +111 -0
  121. package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +67 -0
  122. package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +120 -0
  123. package/node_modules/@tomflow/chatloop-extension/package.json +38 -0
  124. package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +133 -0
  125. package/node_modules/@tomflow/chatloop-trace/README.md +105 -0
  126. package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +23 -0
  127. package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +22 -0
  128. package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +4 -0
  129. package/node_modules/@tomflow/chatloop-trace/index.mjs +59 -0
  130. package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +273 -0
  131. package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +265 -0
  132. package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +205 -0
  133. package/node_modules/@tomflow/chatloop-trace/package.json +30 -0
  134. package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +68 -0
  135. package/node_modules/ps-list/index.d.ts +76 -0
  136. package/node_modules/ps-list/index.js +366 -0
  137. package/node_modules/ps-list/license +9 -0
  138. package/node_modules/ps-list/package.json +44 -0
  139. package/node_modules/ps-list/readme.md +56 -0
  140. package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
  141. package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
  142. package/package.json +23 -8
  143. package/providers/form.mjs +286 -0
  144. package/providers.generated.mjs +3 -2
  145. package/scripts/build-form-app.mjs +27 -0
  146. package/ui/form/review-app.js +128 -0
  147. package/ui/form/review.html +859 -0
  148. package/ui/form/review.template.html +45 -0
@@ -0,0 +1,233 @@
1
+ // The ONLY JavaScript package entry. Roles are explicit; importing it does
2
+ // not open a Store, authorize a Principal, or grant an execution capability.
3
+ import {fileURLToPath} from 'node:url';
4
+ import {capabilities} from './capabilities.generated.mjs';
5
+ import {createCapabilityRouter} from './lib/capability-router.mjs';
6
+ import {auditFunction,auditMethods,subscribeContextApiLog} from './lib/api-log.mjs';
7
+ export {subscribeContextApiLog};
8
+ import {CONTEXT_CONTRACT,CONTEXT_PACKAGE_VERSION,methodById,methodDefinitions,
9
+ contextGatewayTools,validateContextCall,parseContextAllowedProjects,
10
+ listMethods,describeMethod} from './lib/methods.mjs';
11
+
12
+ export {CONTEXT_CONTRACT,CONTEXT_PACKAGE_VERSION};
13
+
14
+ // Public MCP adapter contract: metadata, validation, and the npm-installed
15
+ // CLI command. The adapter cannot select a private module path itself.
16
+ export const contextGateway=auditMethods(Object.freeze({
17
+ tools:contextGatewayTools,
18
+ validate:validateContextCall,
19
+ allowedProjects:parseContextAllowedProjects,
20
+ cliPath:fileURLToPath(new URL('./bin/cli.mjs',import.meta.url))
21
+ }),{
22
+ validate:([name,args])=>({api:'gateway.validate',surface:'gateway',mode:'read',
23
+ projectRef:args?.projectId,taskRef:args?.taskId}),
24
+ allowedProjects:()=>({api:'gateway.allowed_projects',surface:'gateway',mode:'read'})
25
+ });
26
+ const fail=code=>Object.assign(new Error(code),{code});
27
+ const runtimeRequired=()=>{
28
+ if(Number(process.versions.node.split('.')[0])<24)
29
+ throw fail('CONTEXT_RUNTIME_UNSUPPORTED');
30
+ };
31
+
32
+ // Two public package entrypoints, one SDK composition root here.
33
+ // Private modules only declare typed named capabilities; they never import one
34
+ // another, nor reverse-import this facade (which would create ESM cycles).
35
+ // Lazy tiers keep privileged operator code out of ordinary business requests.
36
+ let sdkPromise,operatorPromise,trustedPromise;
37
+ function sdkRuntime(){
38
+ if(!sdkPromise)sdkPromise=(async()=>{
39
+ const [
40
+ core,health,migrationCore,projectCore,taskCore,reviewCore,
41
+ evidenceCore,contextCore,runCore,migration,policy,methods,
42
+ projectStore,operations,lineReview
43
+ ]=await Promise.all([
44
+ import('./lib/core/store.mjs'),import('./lib/core/health.mjs'),
45
+ import('./lib/core/migration.mjs'),import('./lib/core/project.mjs'),
46
+ import('./lib/core/task.mjs'),import('./lib/core/review.mjs'),
47
+ import('./lib/core/evidence.mjs'),import('./lib/core/context.mjs'),
48
+ import('./lib/core/run.mjs'),import('./lib/context-migration.mjs'),
49
+ import('./lib/approval-policy.mjs'),import('./lib/methods.mjs'),
50
+ import('./lib/project-store.mjs'),import('./lib/operations.mjs'),
51
+ import('./lib/line-review.mjs')
52
+ ]);
53
+ migration.configureMigrationSource({
54
+ reviewPreservedLines:lineReview.reviewPreservedLines
55
+ });
56
+ core.configureCore({
57
+ createHealthMethods:health.createHealthMethods,
58
+ createMigrationMethods:migrationCore.createMigrationMethods,
59
+ createProjectMethods:projectCore.createProjectMethods,
60
+ createTaskMethods:taskCore.createTaskMethods,
61
+ createReviewMethods:reviewCore.createReviewMethods,
62
+ createEvidenceMethods:evidenceCore.createEvidenceMethods,
63
+ createContextMethods:contextCore.createContextMethods,
64
+ createRunMethods:runCore.createRunMethods,
65
+ verifySourceUnit:migration.verifySourceUnit,
66
+ inspectRegistryReferenceForReview:migration.inspectRegistryReferenceForReview,
67
+ hasApprovedPlan:policy.hasApprovedPlan,
68
+ hasRequirementApproval:policy.hasRequirementApproval
69
+ });
70
+ projectStore.configureProjectStore({
71
+ parseContextAllowedProjects:methods.parseContextAllowedProjects
72
+ });
73
+ operations.configureOperations({
74
+ capabilityRouter:createCapabilityRouter(methodDefinitions,capabilities),
75
+ openContextProtocol:core.openContextProtocol,
76
+ CONTEXT_CONTRACT:methods.CONTEXT_CONTRACT,
77
+ validateContextCall:methods.validateContextCall,
78
+ listMethods:methods.listMethods,describeMethod:methods.describeMethod,
79
+ projectDatabase:projectStore.projectDatabase,
80
+ projectMeta:projectStore.projectMeta,
81
+ verifiedStoreFile:projectStore.verifiedStoreFile,
82
+ resolveProjects:projectStore.resolveProjects,
83
+ allowedProjects:projectStore.allowedProjects
84
+ });
85
+ return Object.freeze({core,migration,methods,operations,projectStore,lineReview});
86
+ })();
87
+ return sdkPromise;
88
+ }
89
+
90
+ function operatorRuntime(){
91
+ if(!operatorPromise)operatorPromise=(async()=>{
92
+ const sdk=await sdkRuntime();
93
+ const {core,migration,methods,operations,projectStore,lineReview}=sdk;
94
+ const [inventory,workspace,branch,diagnostic,orphan,admin,guards,commands]=
95
+ await Promise.all([
96
+ import('./lib/process-inventory.mjs'),
97
+ import('./lib/workspace-operator.mjs'),
98
+ import('./lib/project-branch.mjs'),
99
+ import('./lib/project-diagnostic.mjs'),
100
+ import('./lib/orphan-operator.mjs'),
101
+ import('./lib/context-cli.mjs'),
102
+ import('./lib/project-guards.mjs'),
103
+ import('./lib/cli-commands.mjs')
104
+ ]);
105
+ admin.configureContextAdmin({
106
+ activeLegacyWriters:inventory.activeLegacyWriters,
107
+ openContextProtocol:core.openContextProtocol,
108
+ parseContextAllowedProjects:methods.parseContextAllowedProjects,
109
+ scanSourceUnit:migration.scanSourceUnit,
110
+ saveShadowManifest:migration.saveShadowManifest,
111
+ readShadowManifest:migration.readShadowManifest,
112
+ verifyShadowManifest:migration.verifyShadowManifest,
113
+ backupContextDb:migration.backupContextDb,
114
+ createRecoveryManifest:migration.createRecoveryManifest,
115
+ restoreBackupToDiagnosticBranch:migration.restoreBackupToDiagnosticBranch
116
+ });
117
+ workspace.configureWorkspaceOperator({
118
+ openContextProtocol:core.openContextProtocol,
119
+ contextRoot:projectStore.contextRoot,
120
+ allowedProjects:projectStore.allowedProjects,
121
+ dispatchContextCall:operations.dispatchContextCall
122
+ });
123
+ branch.configureProjectBranch({
124
+ knownWriterInventory:inventory.knownWriterInventory,
125
+ openContextProtocol:core.openContextProtocol,
126
+ backupContextDb:migration.backupContextDb,
127
+ verifySourceUnit:migration.verifySourceUnit,
128
+ scanSourceUnit:migration.scanSourceUnit,
129
+ ID:guards.ID,ensure:guards.ensure,
130
+ privateFile:guards.privateFile,privateRoot:guards.privateRoot
131
+ });
132
+ diagnostic.configureProjectDiagnostic({
133
+ projectBranch:branch,
134
+ openContextProtocol:core.openContextProtocol,
135
+ verifySourceUnit:migration.verifySourceUnit,
136
+ scanSourceUnit:migration.scanSourceUnit,
137
+ reviewPreservedLines:lineReview.reviewPreservedLines,
138
+ ID:guards.ID,ensure:guards.ensure,privateFile:guards.privateFile
139
+ });
140
+ orphan.configureOrphanOperator({
141
+ openContextProtocol:core.openContextProtocol,
142
+ contextRoot:projectStore.contextRoot,
143
+ allowedProjects:projectStore.allowedProjects,
144
+ confirmWorkspaceOperator:workspace.confirmWorkspaceOperator
145
+ });
146
+ commands.configureCliCommands({
147
+ openContextProtocol:core.openContextProtocol,
148
+ contextRoot:projectStore.contextRoot,
149
+ allowedProjects:projectStore.allowedProjects,
150
+ verifySourceUnit:migration.verifySourceUnit,
151
+ createProjectDiagnosticBranch:diagnostic.createProjectDiagnosticBranch,
152
+ createManagedProjectBranch:diagnostic.createManagedProjectBranch,
153
+ fenceLegacyProjectStore:diagnostic.fenceLegacyProjectStore,
154
+ auditLegacyProjectSources:diagnostic.auditLegacyProjectSources,
155
+ inspectLegacyRegistryReference:diagnostic.inspectLegacyRegistryReference,
156
+ activeLegacyWriters:inventory.activeLegacyWriters,
157
+ fenceOrphanRunOperator:orphan.fenceOrphanRunOperator,
158
+ canonicalWorkspaceRefs:workspace.canonicalWorkspaceRefs,
159
+ confirmWorkspaceOperator:workspace.confirmWorkspaceOperator,
160
+ assertWorkspaceUnclaimed:workspace.assertWorkspaceUnclaimed,
161
+ withWorkspaceRegistryLock:workspace.withWorkspaceRegistryLock,
162
+ rebindProjectWorkspaces:workspace.rebindProjectWorkspaces,
163
+ readOperatorWorkspaceReceipt:workspace.readOperatorWorkspaceReceipt,
164
+ runContextCli:admin.runContextCli,
165
+ requestContext,listMethods,describeMethod,CONTEXT_PACKAGE_VERSION
166
+ });
167
+ return Object.freeze({...sdk,inventory,workspace,branch,diagnostic,
168
+ orphan,admin,guards,commands});
169
+ })();
170
+ return operatorPromise;
171
+ }
172
+
173
+ function trustedRuntime(){
174
+ if(!trustedPromise)trustedPromise=(async()=>{
175
+ const {core,projectStore}=await sdkRuntime();
176
+ const trusted=await import('./lib/trusted-run.mjs');
177
+ trusted.configureTrustedRun({
178
+ openContextProtocol:core.openContextProtocol,
179
+ allowedProjects:projectStore.allowedProjects,
180
+ resolveVerifiedProjectDatabase:projectStore.resolveVerifiedProjectDatabase
181
+ });
182
+ return Object.freeze({execute:trusted.executeTrustedRun});
183
+ })();
184
+ return trustedPromise;
185
+ }
186
+
187
+ // Implementation stays free of observability; the exported callable is a Proxy.
188
+ async function requestContextCore(args){
189
+ const method=methodById.get(args?.operation);
190
+ const tool=method?.mode==='write'?'chat_loop_context_mutate':'chat_loop_context_get';
191
+ validateContextCall(tool,args);
192
+ if(method.id==='sdk.methods.list')return listMethods(args.group,args.view);
193
+ if(method.id==='sdk.methods.describe')return describeMethod(args.methodId);
194
+ runtimeRequired();
195
+ const {operations}=await sdkRuntime();
196
+ return operations.dispatchContextCall(tool,args);
197
+ }
198
+ export const requestContext=auditFunction(requestContextCore,([args])=>{
199
+ const method=methodById.get(args?.operation);
200
+ return {api:method?.id??'request.invalid',surface:'sdk',
201
+ mode:method?.mode??'unknown',projectRef:args?.projectId,taskRef:args?.taskId};
202
+ });
203
+
204
+ // Each nested operation is intercepted without modifying the trusted runtime.
205
+ async function loadTrustedRuntimeCore(){
206
+ runtimeRequired();
207
+ const instance=await trustedRuntime();
208
+ return auditMethods(instance,{
209
+ execute:([command,args])=>({
210
+ api:typeof command==='string'&&/^[a-z][a-z0-9.-]{1,69}$/.test(command)
211
+ ?'trusted.'+command:'trusted.invalid',
212
+ surface:'trusted',mode:'internal',projectRef:args?.projectId,taskRef:args?.taskId
213
+ })
214
+ });
215
+ }
216
+ export const loadTrustedRuntime=auditFunction(loadTrustedRuntimeCore,
217
+ ()=>({api:'sdk.load_trusted',surface:'sdk',mode:'internal'}));
218
+
219
+ // Only the single public CLI callable is exposed; the internals stay private.
220
+ async function loadLocalOperatorCore(){
221
+ runtimeRequired();
222
+ const {commands}=await operatorRuntime();
223
+ return auditMethods(Object.freeze({
224
+ runLocalCliCommand:commands.runLocalCliCommand
225
+ }),{
226
+ runLocalCliCommand:()=>({
227
+ // Only the public callable name, not CLI tokens, may enter logs.
228
+ api:'operator.runLocalCliCommand',surface:'operator',mode:'operator'
229
+ })
230
+ });
231
+ }
232
+ export const loadLocalOperator=auditFunction(loadLocalOperatorCore,
233
+ ()=>({api:'sdk.load_operator',surface:'sdk',mode:'operator'}));
@@ -0,0 +1,86 @@
1
+ // Context-specific evidence adapter for the one canonical API AOP runtime.
2
+ // Public functions, promise/throw semantics, correlation and queue handling
3
+ // belong to the public @tomflow/chatloop-trace API, not a copied runtime.
4
+ import {createApiAspect} from '@tomflow/chatloop-trace';
5
+
6
+ export const API_LOG_CONTRACT='chat-loop.context-api-log.v1';
7
+ const API=/^[a-z][A-Za-z0-9._-]{1,89}$/;
8
+ const REF=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
9
+ const CODE=/^[A-Z][A-Z0-9_]{1,95}$/;
10
+ const listeners=new Set(),metadata=new Map();
11
+ const safe=(value,re)=>typeof value==='string'&&re.test(value)?value:null;
12
+ const adapter=createApiAspect('@tomflow/chatloop-context',{sink:deliver});
13
+
14
+ // At the public boundary capture only safe, bounded identifiers. Never log
15
+ // method arguments, bodies, workspace paths or tool return values.
16
+ function capture(detail,ids){
17
+ // If a Promise never settles, evict its oldest soft span rather than
18
+ // permanently disabling observation of all future business calls.
19
+ // Evicted spans report a transport failure if/when delivery is attempted.
20
+ if(metadata.size>=4096)metadata.delete(metadata.keys().next().value);
21
+ metadata.set(ids.spanId,{
22
+ api:safe(detail.api,API)||'api.invalid',
23
+ surface:safe(detail.surface,API)||'sdk',
24
+ mode:safe(detail.mode,API)||'read',
25
+ projectRef:safe(detail.projectRef,REF),
26
+ taskRef:safe(detail.taskRef,REF),
27
+ targets:[...listeners]
28
+ });
29
+ }
30
+ function deliver(raw){
31
+ const meta=metadata.get(raw.callId);
32
+ if(!meta)return false;
33
+ if(raw.phase!=='BEGIN')metadata.delete(raw.callId);
34
+ const event=Object.freeze({
35
+ contract:API_LOG_CONTRACT,callId:raw.callId,traceId:raw.traceId,
36
+ spanId:raw.spanId,parentSpanId:raw.parentSpanId,
37
+ api:meta.api,surface:meta.surface,mode:meta.mode,
38
+ projectRef:meta.projectRef,taskRef:meta.taskRef,phase:raw.phase,
39
+ time:raw.time,durationMs:raw.durationMs,
40
+ errorCode:raw.phase==='FAILED'
41
+ ?safe(raw.errorCode,CODE)==='API_FAILED'?'CONTEXT_FAILED':
42
+ safe(raw.errorCode,CODE)||'CONTEXT_FAILED'
43
+ :null
44
+ });
45
+ let attempted=false,failed=false;
46
+ if(process.env.CHAT_LOOP_CONTEXT_API_LOG_STDERR==='1'){
47
+ attempted=true;
48
+ try{process.stderr.write('CHAT_LOOP_CONTEXT_API_LOG '+JSON.stringify(event)+'\n')}
49
+ catch{failed=true}
50
+ }
51
+ const pending=[];
52
+ for(const listener of meta.targets){
53
+ attempted=true;
54
+ try{
55
+ const result=listener(event);
56
+ if(result&&typeof result.then==='function')
57
+ pending.push(Promise.resolve(result).then(value=>value!==false,()=>false));
58
+ else if(result===false)failed=true;
59
+ }catch{failed=true}
60
+ }
61
+ // A different successful observer cannot conceal a failed writer.
62
+ // All registered sinks must acknowledge; none may affect the API result.
63
+ return pending.length?Promise.all(pending).then(values=>
64
+ attempted&&!failed&&values.every(Boolean)):attempted&&!failed;
65
+ }
66
+
67
+ // Context's public SDK retains the established descriptor contracts, but
68
+ // uses the shared AOP for every intercepted callable and its child spans.
69
+ export const auditFunction=(target,describe)=>adapter.described(target,describe,capture);
70
+ export const auditMethods=(target,descriptors)=>
71
+ adapter.describedMethods(target,descriptors,capture);
72
+
73
+ function subscribe(listener){
74
+ if(typeof listener!=='function')throw TypeError('API_LOG_LISTENER_REQUIRED');
75
+ listeners.add(listener);
76
+ // Own subscription begins before registration; attach this subscriber to
77
+ // exactly its own span without inventing a second bootstrap event.
78
+ const spanId=adapter.current()?.spanId;
79
+ const current=spanId?metadata.get(spanId):null;
80
+ if(current&&current.api==='sdk.subscribe_log'&&!current.targets.includes(listener))
81
+ current.targets.push(listener);
82
+ return auditFunction(()=>listeners.delete(listener),
83
+ ()=>({api:'sdk.unsubscribe_log',mode:'internal'}));
84
+ }
85
+ export const subscribeContextApiLog=auditFunction(subscribe,
86
+ ()=>({api:'sdk.subscribe_log',mode:'internal'}));
@@ -0,0 +1,24 @@
1
+ // Context owns business approval policy. No SQLite, browser, MCP or Session state.
2
+ // V1 is intentionally the two genuine R->P soft user Turns already in production.
3
+ // A new strong approval requires an explicitly versioned policy and migrations,
4
+ // not changing a count scattered through Run/Permit transactions.
5
+ export const APPROVAL_POLICY_V1=Object.freeze({
6
+ id:'chat-loop.approval.r-p.v1',
7
+ requiredKinds:Object.freeze(['R','P'])
8
+ });
9
+
10
+ const fromUser=a=>Boolean(a&&typeof a==='object'
11
+ &&(a.sourceRole===undefined||a.sourceRole==='user')
12
+ &&typeof a.userTurn==='string'&&a.userTurn.length>0);
13
+
14
+ export function hasRequirementApproval(records){
15
+ return Array.isArray(records)&&records.length===1
16
+ &&records[0]?.kind==='R'&&fromUser(records[0]);
17
+ }
18
+
19
+ export function hasApprovedPlan(records){
20
+ return Array.isArray(records)&&records.length===2
21
+ &&records[0]?.kind==='R'&&records[1]?.kind==='P'
22
+ &&fromUser(records[0])&&fromUser(records[1])
23
+ &&records[0].userTurn!==records[1].userTurn;
24
+ }