@tomflow/chatloop-tools 0.9.17 → 0.9.18

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 (140) hide show
  1. package/package.json +3 -11
  2. package/providers/form.mjs +4 -2
  3. package/ui/form/review-app.js +122 -71
  4. package/ui/form/review.html +1 -814
  5. package/node_modules/@tomflow/chatloop-context/README.md +0 -240
  6. package/node_modules/@tomflow/chatloop-context/bin/cli.mjs +0 -48
  7. package/node_modules/@tomflow/chatloop-context/capabilities/approval.mjs +0 -151
  8. package/node_modules/@tomflow/chatloop-context/capabilities/context.mjs +0 -376
  9. package/node_modules/@tomflow/chatloop-context/capabilities/document.mjs +0 -266
  10. package/node_modules/@tomflow/chatloop-context/capabilities/evidence.mjs +0 -134
  11. package/node_modules/@tomflow/chatloop-context/capabilities/presentation.mjs +0 -82
  12. package/node_modules/@tomflow/chatloop-context/capabilities/project.mjs +0 -349
  13. package/node_modules/@tomflow/chatloop-context/capabilities/sdk.mjs +0 -72
  14. package/node_modules/@tomflow/chatloop-context/capabilities/start.mjs +0 -73
  15. package/node_modules/@tomflow/chatloop-context/capabilities/task.mjs +0 -507
  16. package/node_modules/@tomflow/chatloop-context/capabilities.generated.mjs +0 -11
  17. package/node_modules/@tomflow/chatloop-context/docs/interfaces.md +0 -182
  18. package/node_modules/@tomflow/chatloop-context/docs/operator-and-migration.md +0 -277
  19. package/node_modules/@tomflow/chatloop-context/index.mjs +0 -233
  20. package/node_modules/@tomflow/chatloop-context/lib/api-log.mjs +0 -86
  21. package/node_modules/@tomflow/chatloop-context/lib/approval-policy.mjs +0 -24
  22. package/node_modules/@tomflow/chatloop-context/lib/capability-catalog.generated.json +0 -1989
  23. package/node_modules/@tomflow/chatloop-context/lib/capability-router.mjs +0 -67
  24. package/node_modules/@tomflow/chatloop-context/lib/cli-commands.mjs +0 -280
  25. package/node_modules/@tomflow/chatloop-context/lib/context-cli.mjs +0 -298
  26. package/node_modules/@tomflow/chatloop-context/lib/context-migration.mjs +0 -280
  27. package/node_modules/@tomflow/chatloop-context/lib/core/context.mjs +0 -115
  28. package/node_modules/@tomflow/chatloop-context/lib/core/evidence.mjs +0 -51
  29. package/node_modules/@tomflow/chatloop-context/lib/core/health.mjs +0 -55
  30. package/node_modules/@tomflow/chatloop-context/lib/core/migration.mjs +0 -262
  31. package/node_modules/@tomflow/chatloop-context/lib/core/project.mjs +0 -246
  32. package/node_modules/@tomflow/chatloop-context/lib/core/review.mjs +0 -147
  33. package/node_modules/@tomflow/chatloop-context/lib/core/run.mjs +0 -343
  34. package/node_modules/@tomflow/chatloop-context/lib/core/store.mjs +0 -391
  35. package/node_modules/@tomflow/chatloop-context/lib/core/task.mjs +0 -166
  36. package/node_modules/@tomflow/chatloop-context/lib/line-review.mjs +0 -13
  37. package/node_modules/@tomflow/chatloop-context/lib/methods.mjs +0 -111
  38. package/node_modules/@tomflow/chatloop-context/lib/operations.mjs +0 -107
  39. package/node_modules/@tomflow/chatloop-context/lib/orphan-operator.mjs +0 -117
  40. package/node_modules/@tomflow/chatloop-context/lib/process-inventory.mjs +0 -20
  41. package/node_modules/@tomflow/chatloop-context/lib/project-branch.mjs +0 -312
  42. package/node_modules/@tomflow/chatloop-context/lib/project-diagnostic.mjs +0 -153
  43. package/node_modules/@tomflow/chatloop-context/lib/project-guards.mjs +0 -19
  44. package/node_modules/@tomflow/chatloop-context/lib/project-store.mjs +0 -115
  45. package/node_modules/@tomflow/chatloop-context/lib/trusted-run.mjs +0 -86
  46. package/node_modules/@tomflow/chatloop-context/lib/workspace-operator.mjs +0 -169
  47. package/node_modules/@tomflow/chatloop-context/package.json +0 -40
  48. package/node_modules/@tomflow/chatloop-context/scripts/build-capabilities.mjs +0 -114
  49. package/node_modules/@tomflow/chatloop-extension/README.md +0 -94
  50. package/node_modules/@tomflow/chatloop-extension/actions.generated.mjs +0 -11
  51. package/node_modules/@tomflow/chatloop-extension/bin/cli.mjs +0 -141
  52. package/node_modules/@tomflow/chatloop-extension/bin/native-host.mjs +0 -109
  53. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_dom.mjs +0 -1
  54. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_screenshot.mjs +0 -1
  55. package/node_modules/@tomflow/chatloop-extension/capabilities/chat_text.mjs +0 -1
  56. package/node_modules/@tomflow/chatloop-extension/capabilities/clean.mjs +0 -1
  57. package/node_modules/@tomflow/chatloop-extension/capabilities/continue.mjs +0 -1
  58. package/node_modules/@tomflow/chatloop-extension/capabilities/handoff.mjs +0 -1
  59. package/node_modules/@tomflow/chatloop-extension/capabilities/reload.mjs +0 -1
  60. package/node_modules/@tomflow/chatloop-extension/capabilities/start.mjs +0 -1
  61. package/node_modules/@tomflow/chatloop-extension/capabilities/status.mjs +0 -1
  62. package/node_modules/@tomflow/chatloop-extension/extension/actions/clean.js +0 -120
  63. package/node_modules/@tomflow/chatloop-extension/extension/actions/common.js +0 -180
  64. package/node_modules/@tomflow/chatloop-extension/extension/actions/continue.js +0 -322
  65. package/node_modules/@tomflow/chatloop-extension/extension/actions/dom.js +0 -2
  66. package/node_modules/@tomflow/chatloop-extension/extension/actions/handoff.js +0 -378
  67. package/node_modules/@tomflow/chatloop-extension/extension/actions/index.js +0 -2
  68. package/node_modules/@tomflow/chatloop-extension/extension/actions/model-intent.js +0 -54
  69. package/node_modules/@tomflow/chatloop-extension/extension/actions/read-mode.js +0 -9
  70. package/node_modules/@tomflow/chatloop-extension/extension/actions/reload.js +0 -20
  71. package/node_modules/@tomflow/chatloop-extension/extension/actions/screenshot.js +0 -69
  72. package/node_modules/@tomflow/chatloop-extension/extension/actions/start.js +0 -287
  73. package/node_modules/@tomflow/chatloop-extension/extension/actions/status.js +0 -23
  74. package/node_modules/@tomflow/chatloop-extension/extension/actions/text.js +0 -2
  75. package/node_modules/@tomflow/chatloop-extension/extension/background.js +0 -16
  76. package/node_modules/@tomflow/chatloop-extension/extension/clean.html +0 -5
  77. package/node_modules/@tomflow/chatloop-extension/extension/content.js +0 -40
  78. package/node_modules/@tomflow/chatloop-extension/extension/continue.html +0 -9
  79. package/node_modules/@tomflow/chatloop-extension/extension/dom.html +0 -17
  80. package/node_modules/@tomflow/chatloop-extension/extension/handoff.html +0 -9
  81. package/node_modules/@tomflow/chatloop-extension/extension/loop/action-catalog.generated.js +0 -2
  82. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-aspect.generated.js +0 -275
  83. package/node_modules/@tomflow/chatloop-extension/extension/loop/api-observation-queue.generated.js +0 -76
  84. package/node_modules/@tomflow/chatloop-extension/extension/loop/core.js +0 -107
  85. package/node_modules/@tomflow/chatloop-extension/extension/loop/index.js +0 -36
  86. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-approval.js +0 -227
  87. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-inspect.js +0 -144
  88. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-poll.js +0 -171
  89. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer-recovery.js +0 -109
  90. package/node_modules/@tomflow/chatloop-extension/extension/loop/observer.js +0 -154
  91. package/node_modules/@tomflow/chatloop-extension/extension/loop/resources.js +0 -254
  92. package/node_modules/@tomflow/chatloop-extension/extension/manifest.json +0 -42
  93. package/node_modules/@tomflow/chatloop-extension/extension/popup.html +0 -25
  94. package/node_modules/@tomflow/chatloop-extension/extension/popup.js +0 -93
  95. package/node_modules/@tomflow/chatloop-extension/extension/reload.html +0 -17
  96. package/node_modules/@tomflow/chatloop-extension/extension/screenshot.html +0 -17
  97. package/node_modules/@tomflow/chatloop-extension/extension/start.html +0 -6
  98. package/node_modules/@tomflow/chatloop-extension/extension/status.html +0 -6
  99. package/node_modules/@tomflow/chatloop-extension/extension/text.html +0 -17
  100. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-result.js +0 -136
  101. package/node_modules/@tomflow/chatloop-extension/extension/worker/action-take.js +0 -220
  102. package/node_modules/@tomflow/chatloop-extension/extension/worker/admission.js +0 -122
  103. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-prepare.js +0 -155
  104. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-recovery.js +0 -185
  105. package/node_modules/@tomflow/chatloop-extension/extension/worker/adopt-result.js +0 -120
  106. package/node_modules/@tomflow/chatloop-extension/extension/worker/bootstrap.js +0 -172
  107. package/node_modules/@tomflow/chatloop-extension/extension/worker/manual.js +0 -165
  108. package/node_modules/@tomflow/chatloop-extension/extension/worker/readiness.js +0 -244
  109. package/node_modules/@tomflow/chatloop-extension/extension/worker/router.js +0 -181
  110. package/node_modules/@tomflow/chatloop-extension/extension/worker/scheduler.js +0 -147
  111. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-failure.js +0 -197
  112. package/node_modules/@tomflow/chatloop-extension/extension/worker/turn-finished.js +0 -200
  113. package/node_modules/@tomflow/chatloop-extension/index.mjs +0 -71
  114. package/node_modules/@tomflow/chatloop-extension/lib/action-routing.mjs +0 -18
  115. package/node_modules/@tomflow/chatloop-extension/lib/api-observation-queue.mjs +0 -74
  116. package/node_modules/@tomflow/chatloop-extension/lib/bridge.mjs +0 -208
  117. package/node_modules/@tomflow/chatloop-extension/lib/browser-launch.mjs +0 -40
  118. package/node_modules/@tomflow/chatloop-extension/lib/context-binding.mjs +0 -45
  119. package/node_modules/@tomflow/chatloop-extension/lib/context-ipc.mjs +0 -111
  120. package/node_modules/@tomflow/chatloop-extension/lib/owner-evidence.mjs +0 -67
  121. package/node_modules/@tomflow/chatloop-extension/lib/session-file.mjs +0 -120
  122. package/node_modules/@tomflow/chatloop-extension/package.json +0 -38
  123. package/node_modules/@tomflow/chatloop-extension/scripts/build-actions.mjs +0 -133
  124. package/node_modules/@tomflow/chatloop-trace/README.md +0 -105
  125. package/node_modules/@tomflow/chatloop-trace/events/context.api.mjs +0 -23
  126. package/node_modules/@tomflow/chatloop-trace/events/typed.api.call.mjs +0 -22
  127. package/node_modules/@tomflow/chatloop-trace/events.generated.mjs +0 -4
  128. package/node_modules/@tomflow/chatloop-trace/index.mjs +0 -59
  129. package/node_modules/@tomflow/chatloop-trace/lib/api-aspect.mjs +0 -273
  130. package/node_modules/@tomflow/chatloop-trace/lib/trace-reader.mjs +0 -265
  131. package/node_modules/@tomflow/chatloop-trace/lib/trace.mjs +0 -205
  132. package/node_modules/@tomflow/chatloop-trace/package.json +0 -30
  133. package/node_modules/@tomflow/chatloop-trace/scripts/build-events.mjs +0 -68
  134. package/node_modules/ps-list/index.d.ts +0 -76
  135. package/node_modules/ps-list/index.js +0 -366
  136. package/node_modules/ps-list/license +0 -9
  137. package/node_modules/ps-list/package.json +0 -44
  138. package/node_modules/ps-list/readme.md +0 -56
  139. package/node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe +0 -0
  140. package/node_modules/ps-list/vendor/fastlist-0.3.0-x86.exe +0 -0
@@ -1,233 +0,0 @@
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'}));
@@ -1,86 +0,0 @@
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'}));
@@ -1,24 +0,0 @@
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
- }