pi-harness-runtime 1.1.439 → 1.1.441

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 (359) hide show
  1. package/harness/e2e/auto-test-loop.ts +8 -2
  2. package/harness/e2e/browser-scrapers/base-browser-scraper.ts +2 -0
  3. package/harness/e2e/browser-scrapers/chrome-profile-manager.ts +2 -0
  4. package/harness/e2e/browser-scrapers/codex-browser-scraper.ts +2 -0
  5. package/harness/e2e/tools-detector.ts +2 -0
  6. package/harness/index.ts +2 -1
  7. package/harness/key-loader.ts +2 -0
  8. package/harness/langchain/checkpointer.ts +2 -0
  9. package/harness/langchain/cron-cli.ts +2 -0
  10. package/harness/langchain/graph.ts +2 -0
  11. package/harness/master-planner.ts +1 -1
  12. package/harness/notification-center.ts +2 -0
  13. package/harness/output-limit-handler.ts +1 -1
  14. package/harness/project-detector/detector.ts +2 -4
  15. package/harness/secret-provider.ts +2 -0
  16. package/harness/task-graph.ts +460 -113
  17. package/index.ts +16 -7
  18. package/package.json +7 -1
  19. package/packages/a2a-adapter/package.json +1 -1
  20. package/packages/agent-policy/dist/extension.d.ts.map +1 -1
  21. package/packages/agent-policy/dist/extension.js +2 -0
  22. package/packages/agent-policy/dist/extension.js.map +1 -1
  23. package/packages/agent-policy/package.json +1 -1
  24. package/packages/agent-policy/src/extension.ts +2 -0
  25. package/packages/architecture-generator/package.json +1 -1
  26. package/packages/auth/dist/minimax-browser-auth.d.ts.map +1 -1
  27. package/packages/auth/dist/minimax-browser-auth.js +23 -1
  28. package/packages/auth/dist/minimax-browser-auth.js.map +1 -1
  29. package/packages/auth/package.json +1 -1
  30. package/packages/auth/src/minimax-browser-auth.ts +30 -5
  31. package/packages/autonomous-refactor/package.json +1 -1
  32. package/packages/autonomous-runtime/dist/inbox.d.ts.map +1 -1
  33. package/packages/autonomous-runtime/dist/inbox.js +2 -0
  34. package/packages/autonomous-runtime/dist/inbox.js.map +1 -1
  35. package/packages/autonomous-runtime/package.json +1 -1
  36. package/packages/autonomous-runtime/src/inbox.ts +2 -0
  37. package/packages/cache-strategy/package.json +1 -1
  38. package/packages/capability-registry/package.json +1 -1
  39. package/packages/checkpoint/package.json +1 -1
  40. package/packages/cli-plugin-sdk/package.json +1 -1
  41. package/packages/clipboard/dist/src/clipboard.d.ts.map +1 -1
  42. package/packages/clipboard/dist/src/clipboard.js +2 -0
  43. package/packages/clipboard/dist/src/clipboard.js.map +1 -1
  44. package/packages/clipboard/dist/src/copy-sync.d.ts.map +1 -1
  45. package/packages/clipboard/dist/src/copy-sync.js +2 -0
  46. package/packages/clipboard/dist/src/copy-sync.js.map +1 -1
  47. package/packages/clipboard/dist/src/gist-relay.d.ts.map +1 -1
  48. package/packages/clipboard/dist/src/gist-relay.js +2 -0
  49. package/packages/clipboard/dist/src/gist-relay.js.map +1 -1
  50. package/packages/clipboard/package.json +1 -1
  51. package/packages/clipboard/src/clipboard.ts +2 -0
  52. package/packages/clipboard/src/copy-sync.ts +2 -0
  53. package/packages/clipboard/src/gist-relay.ts +2 -0
  54. package/packages/clipboard-plugin/dist/types.d.ts +9 -2
  55. package/packages/clipboard-plugin/dist/types.d.ts.map +1 -1
  56. package/packages/clipboard-plugin/package.json +1 -1
  57. package/packages/clipboard-plugin/src/types.ts +9 -2
  58. package/packages/code-generation/package.json +1 -1
  59. package/packages/code-review/package.json +1 -1
  60. package/packages/codex-adapter/package.json +1 -1
  61. package/packages/codex-watcher/package.json +1 -1
  62. package/packages/config-capture/package.json +1 -1
  63. package/packages/connection-runtime/package.json +1 -1
  64. package/packages/context-compiler/package.json +1 -1
  65. package/packages/context-discovery/package.json +1 -1
  66. package/packages/context-manager/package.json +1 -1
  67. package/packages/contracts/dist/delegation-store.js +1 -4
  68. package/packages/contracts/dist/workspace-env.js +28 -1
  69. package/packages/contracts/package.json +1 -1
  70. package/packages/contracts/src/delegation-store.ts +9 -4
  71. package/packages/contracts/src/workspace-env.ts +29 -4
  72. package/packages/cookie-sanitizer/package.json +1 -1
  73. package/packages/cost-optimizer/package.json +1 -1
  74. package/packages/dependency-analyzer/package.json +1 -1
  75. package/packages/django-plugin/package.json +1 -1
  76. package/packages/doc-generator/package.json +1 -1
  77. package/packages/durable-review/package.json +1 -1
  78. package/packages/e2e-tester/package.json +1 -1
  79. package/packages/evaluation-engine/package.json +1 -1
  80. package/packages/evaluation-runner/package.json +1 -1
  81. package/packages/event-bus/package.json +1 -1
  82. package/packages/event-sink/package.json +1 -1
  83. package/packages/event-store/dist/src/store.d.ts.map +1 -1
  84. package/packages/event-store/dist/src/store.js +2 -0
  85. package/packages/event-store/dist/src/store.js.map +1 -1
  86. package/packages/event-store/package.json +1 -1
  87. package/packages/event-store/src/store.ts +3 -0
  88. package/packages/experience-replay/package.json +1 -1
  89. package/packages/feedback-collector/package.json +1 -1
  90. package/packages/file-copy-helper/package.json +1 -1
  91. package/packages/framework-detector/package.json +1 -1
  92. package/packages/framework-plugin-sdk/package.json +1 -1
  93. package/packages/frappe-plugin/package.json +1 -1
  94. package/packages/generic-web-plugin/dist/analyzer.d.ts.map +1 -1
  95. package/packages/generic-web-plugin/dist/analyzer.js +2 -0
  96. package/packages/generic-web-plugin/dist/analyzer.js.map +1 -1
  97. package/packages/generic-web-plugin/package.json +1 -1
  98. package/packages/generic-web-plugin/src/analyzer.ts +3 -0
  99. package/packages/health-monitor/package.json +1 -1
  100. package/packages/intent-analyzer/package.json +1 -1
  101. package/packages/jev-judge/package.json +1 -1
  102. package/packages/knowledge-graph/package.json +1 -1
  103. package/packages/knowledge-retrieval/dist/mcp-client.d.ts.map +1 -1
  104. package/packages/knowledge-retrieval/dist/mcp-client.js +0 -1
  105. package/packages/knowledge-retrieval/dist/mcp-client.js.map +1 -1
  106. package/packages/knowledge-retrieval/package.json +1 -4
  107. package/packages/knowledge-retrieval/src/mcp-client.ts +0 -1
  108. package/packages/laravel-plugin/package.json +1 -1
  109. package/packages/learning-engine/package.json +1 -1
  110. package/packages/logging/package.json +1 -1
  111. package/packages/mcp-adapter/dist/server.d.ts.map +1 -1
  112. package/packages/mcp-adapter/dist/server.js +2 -0
  113. package/packages/mcp-adapter/dist/server.js.map +1 -1
  114. package/packages/mcp-adapter/package.json +1 -1
  115. package/packages/mcp-adapter/src/server.ts +3 -0
  116. package/packages/memory-engine/package.json +1 -1
  117. package/packages/milestone-manager/package.json +1 -1
  118. package/packages/model-registry/package.json +1 -1
  119. package/packages/nextjs-plugin/package.json +1 -1
  120. package/packages/notification/package.json +1 -1
  121. package/packages/observability/package.json +1 -1
  122. package/packages/okf-indexer/package.json +1 -1
  123. package/packages/paperclip-integration/dist/index.d.ts.map +1 -1
  124. package/packages/paperclip-integration/dist/index.js +2 -0
  125. package/packages/paperclip-integration/dist/index.js.map +1 -1
  126. package/packages/paperclip-integration/package.json +1 -1
  127. package/packages/paperclip-integration/src/index.ts +2 -0
  128. package/packages/performance-optimizer/package.json +1 -1
  129. package/packages/permission-mode/package.json +1 -1
  130. package/packages/privilege-broker/dist/audit.d.ts.map +1 -1
  131. package/packages/privilege-broker/dist/audit.js +2 -0
  132. package/packages/privilege-broker/dist/audit.js.map +1 -1
  133. package/packages/privilege-broker/package.json +1 -1
  134. package/packages/privilege-broker/src/audit.ts +2 -0
  135. package/packages/project-analyzer/package.json +1 -1
  136. package/packages/project-bootstrap/package.json +1 -1
  137. package/packages/projection-engine/package.json +1 -1
  138. package/packages/prompt-compiler/dist/compiler.d.ts.map +1 -1
  139. package/packages/prompt-compiler/dist/compiler.js +2 -0
  140. package/packages/prompt-compiler/dist/compiler.js.map +1 -1
  141. package/packages/prompt-compiler/package.json +1 -1
  142. package/packages/prompt-compiler/src/compiler.ts +2 -0
  143. package/packages/prompt-versioning/package.json +1 -1
  144. package/packages/provider-adapter-sdk/package.json +1 -1
  145. package/packages/provider-router/package.json +1 -1
  146. package/packages/provider-selector/package.json +1 -1
  147. package/packages/providers/package.json +1 -1
  148. package/packages/qdrant-skills/package.json +1 -1
  149. package/packages/quota-manager/package.json +1 -1
  150. package/packages/rate-limiter/package.json +1 -1
  151. package/packages/react-vite-plugin/package.json +1 -1
  152. package/packages/relay/package.json +1 -1
  153. package/packages/release-manager/package.json +1 -1
  154. package/packages/requirement-compiler/package.json +1 -1
  155. package/packages/runtime/package.json +1 -1
  156. package/packages/scheduler/package.json +1 -1
  157. package/packages/scheduler-adapter/package.json +1 -1
  158. package/packages/session/package.json +1 -1
  159. package/packages/session-api/package.json +1 -1
  160. package/packages/session-export/package.json +1 -1
  161. package/packages/shared-context/package.json +1 -1
  162. package/packages/skill-mcp-client/dist/client.d.ts.map +1 -1
  163. package/packages/skill-mcp-client/dist/client.js +0 -1
  164. package/packages/skill-mcp-client/dist/client.js.map +1 -1
  165. package/packages/skill-mcp-client/package.json +1 -4
  166. package/packages/skill-mcp-client/src/client.ts +0 -1
  167. package/packages/skill-registry/package.json +1 -1
  168. package/packages/skills/dist/parser.d.ts.map +1 -1
  169. package/packages/skills/dist/parser.js +2 -0
  170. package/packages/skills/dist/parser.js.map +1 -1
  171. package/packages/skills/dist/skill-versioning.d.ts.map +1 -1
  172. package/packages/skills/dist/skill-versioning.js +2 -0
  173. package/packages/skills/dist/skill-versioning.js.map +1 -1
  174. package/packages/skills/package.json +1 -1
  175. package/packages/skills/src/parser.ts +3 -0
  176. package/packages/skills/src/skill-versioning.ts +2 -0
  177. package/packages/sprint-planner/package.json +1 -1
  178. package/packages/subscription-engine/package.json +1 -1
  179. package/packages/task-compiler/package.json +1 -1
  180. package/packages/tencentdb-memory/package.json +1 -1
  181. package/packages/tencentdb-sync/package.json +1 -1
  182. package/packages/test-data-generator/package.json +1 -1
  183. package/packages/test-generator/package.json +1 -1
  184. package/packages/todo-bd-sync/package.json +1 -1
  185. package/packages/token-estimation/package.json +1 -1
  186. package/packages/token-optimizer/package.json +1 -1
  187. package/packages/tooling-preference/package.json +1 -1
  188. package/packages/trajectory/package.json +1 -1
  189. package/packages/tui/package.json +1 -1
  190. package/packages/two-phase-review/package.json +1 -1
  191. package/packages/types/package.json +1 -1
  192. package/packages/voice-api/package.json +1 -1
  193. package/packages/webmcp-tester/dist/index.js +0 -2
  194. package/packages/webmcp-tester/package.json +1 -1
  195. package/packages/webmcp-tester/src/index.ts +0 -3
  196. package/packages/wiki/package.json +1 -1
  197. package/packages/workflow-events/package.json +1 -1
  198. package/packages/workspace-scanner/package.json +1 -1
  199. package/packages/worktree/package.json +1 -1
  200. package/packages/write-review/dist/trigger.d.ts.map +1 -1
  201. package/packages/write-review/dist/trigger.js +1 -2
  202. package/packages/write-review/dist/trigger.js.map +1 -1
  203. package/packages/write-review/package.json +1 -1
  204. package/packages/write-review/src/trigger.ts +1 -2
  205. package/scripts/lib/runtime-imports.ts +189 -3
  206. package/scripts/release-all.ts +5 -3
  207. package/scripts/telegram-webhook-server.ts +2 -0
  208. package/scripts/typecheck-packages.mjs +7 -4
  209. package/scripts/verify-package-contents.ts +161 -2
  210. package/harness/e2e/tools-detector.test.ts +0 -156
  211. package/harness/glm-quota-countdown.test.ts +0 -323
  212. package/harness/langchain/agents.test.ts +0 -39
  213. package/harness/langchain/checkpointer.test.ts +0 -243
  214. package/harness/langchain/daemon.test.ts +0 -459
  215. package/harness/langchain/model-router.test.ts +0 -191
  216. package/harness/langchain/ping-pong-middleware.test.ts +0 -69
  217. package/harness/langchain/scoreboard.test.ts +0 -245
  218. package/harness/langchain/status-line.test.ts +0 -106
  219. package/harness/langchain/surge.test.ts +0 -467
  220. package/harness/langchain/widget.test.ts +0 -251
  221. package/harness/skill-sync.test.ts +0 -57
  222. package/harness/ssh-detach-interceptor.test.ts +0 -263
  223. package/harness/ssh-hang-recovery.test.ts +0 -86
  224. package/packages/a2a-adapter/test/a2a.test.ts +0 -151
  225. package/packages/agent-policy/test/interlock.test.ts +0 -101
  226. package/packages/agent-policy/test/policy-retention.test.ts +0 -380
  227. package/packages/agent-policy/test/policy.test.ts +0 -387
  228. package/packages/auth/test/auth.test.ts +0 -238
  229. package/packages/autonomous-refactor/test/refactor.test.ts +0 -202
  230. package/packages/autonomous-runtime/test/types.test.ts +0 -95
  231. package/packages/cache-strategy/test/cache.test.ts +0 -137
  232. package/packages/capability-registry/test/registry.test.ts +0 -204
  233. package/packages/checkpoint/test/engine.test.ts +0 -265
  234. package/packages/cli-plugin-sdk/test/cli.test.ts +0 -45
  235. package/packages/code-generation/test/generator.test.ts +0 -238
  236. package/packages/code-review/test/engine.test.ts +0 -302
  237. package/packages/codex-adapter/test/provider.test.ts +0 -142
  238. package/packages/codex-watcher/test/watch.test.ts +0 -453
  239. package/packages/context-compiler/test/context-compiler.test.ts +0 -746
  240. package/packages/context-manager/test/context.test.ts +0 -198
  241. package/packages/contracts/test/delegation.test.ts +0 -350
  242. package/packages/contracts/test/workspace-env.test.ts +0 -802
  243. package/packages/cookie-sanitizer/test/infer.test.ts +0 -110
  244. package/packages/cookie-sanitizer/test/normalize.test.ts +0 -113
  245. package/packages/cookie-sanitizer/test/parse.test.ts +0 -204
  246. package/packages/cookie-sanitizer/test/sync.test.ts +0 -237
  247. package/packages/cookie-sanitizer/test/watcher.test.ts +0 -27
  248. package/packages/cost-optimizer/test/cost-optimizer.test.ts +0 -438
  249. package/packages/dependency-analyzer/test/analyzer.test.ts +0 -49
  250. package/packages/django-plugin/test/analyzer.test.ts +0 -195
  251. package/packages/doc-generator/test/docs.test.ts +0 -168
  252. package/packages/durable-review/test/acceptance.test.ts +0 -357
  253. package/packages/durable-review/test/smoke.test.ts +0 -107
  254. package/packages/evaluation-engine/test/engine.test.ts +0 -277
  255. package/packages/evaluation-runner/test/runner.test.ts +0 -168
  256. package/packages/event-bus/test/bus.test.ts +0 -100
  257. package/packages/event-store/test/store.test.ts +0 -115
  258. package/packages/experience-replay/test/replay.test.ts +0 -267
  259. package/packages/feedback-collector/test/collector.test.ts +0 -142
  260. package/packages/framework-detector/test/detector.test.ts +0 -75
  261. package/packages/framework-plugin-sdk/test/manager.test.ts +0 -320
  262. package/packages/frappe-plugin/test/analyzer.test.ts +0 -250
  263. package/packages/generic-web-plugin/test/analyzer.test.ts +0 -134
  264. package/packages/health-monitor/test/health.test.ts +0 -231
  265. package/packages/intent-analyzer/test/analyzer.test.ts +0 -72
  266. package/packages/intent-analyzer/test/ping-pong.test.ts +0 -96
  267. package/packages/jev-judge/tests/auto-continue-context.test.ts +0 -280
  268. package/packages/jev-judge/tests/continuation-controller.test.ts +0 -1396
  269. package/packages/jev-judge/tests/jev-provider-chain.test.ts +0 -536
  270. package/packages/jev-judge/tests/outcome-application.test.ts +0 -132
  271. package/packages/jev-judge/tests/question-risk.test.ts +0 -129
  272. package/packages/jev-judge/tests/typesafe-provider.test.ts +0 -640
  273. package/packages/jev-judge/tests/validation-ledger.test.ts +0 -181
  274. package/packages/jev-judge/tests/validation-plan.test.ts +0 -170
  275. package/packages/jev-judge/tests/validation-tie-breaker.test.ts +0 -88
  276. package/packages/laravel-plugin/test/analyzer.test.ts +0 -220
  277. package/packages/learning-engine/test/engine.test.ts +0 -331
  278. package/packages/logging/test/buffer.test.ts +0 -44
  279. package/packages/logging/test/classification.test.ts +0 -137
  280. package/packages/logging/test/config.test.ts +0 -97
  281. package/packages/logging/test/fanout.test.ts +0 -186
  282. package/packages/logging/test/identity-transport.test.ts +0 -197
  283. package/packages/logging/test/incidents.test.ts +0 -404
  284. package/packages/logging/test/ingest-schema.test.ts +0 -184
  285. package/packages/logging/test/integration.test.ts +0 -140
  286. package/packages/logging/test/log-http.test.ts +0 -246
  287. package/packages/logging/test/redact.test.ts +0 -109
  288. package/packages/logging/test/sampler.test.ts +0 -57
  289. package/packages/logging/test/server.test.ts +0 -444
  290. package/packages/logging/test/shipper.test.ts +0 -152
  291. package/packages/logging/test/spool.test.ts +0 -96
  292. package/packages/mcp-adapter/test/server.test.ts +0 -91
  293. package/packages/memory-engine/test/engine.test.ts +0 -456
  294. package/packages/model-registry/test/registry.test.ts +0 -342
  295. package/packages/nextjs-plugin/test/analyzer.test.ts +0 -149
  296. package/packages/notification/test/approval-payload.test.ts +0 -269
  297. package/packages/notification/test/detail-format.test.ts +0 -106
  298. package/packages/notification/test/notification.test.ts +0 -375
  299. package/packages/notification/test/pending-question-lifecycle.test.ts +0 -195
  300. package/packages/notification/test/pending-question.test.ts +0 -331
  301. package/packages/notification/test/tooling-proposal-payload.test.ts +0 -212
  302. package/packages/observability/test/observability.test.ts +0 -1350
  303. package/packages/performance-optimizer/test/optimizer.test.ts +0 -267
  304. package/packages/project-analyzer/test/index.test.ts +0 -1719
  305. package/packages/prompt-compiler/test/prompt-compiler.test.ts +0 -813
  306. package/packages/prompt-versioning/test/versioning.test.ts +0 -112
  307. package/packages/provider-adapter-sdk/test/sdk.test.ts +0 -220
  308. package/packages/provider-router/test/provider-router.test.ts +0 -405
  309. package/packages/provider-selector/test/selector.test.ts +0 -192
  310. package/packages/providers/test/providers.test.ts +0 -225
  311. package/packages/qdrant-skills/test/collection-info.test.ts +0 -165
  312. package/packages/qdrant-skills/test/embedder-batch.test.ts +0 -184
  313. package/packages/qdrant-skills/test/embedder.test.ts +0 -97
  314. package/packages/quota-manager/test/quota.test.ts +0 -432
  315. package/packages/rate-limiter/test/limiter.test.ts +0 -128
  316. package/packages/react-vite-plugin/test/analyzer.test.ts +0 -139
  317. package/packages/relay/test/client.test.ts +0 -446
  318. package/packages/relay/test/relay-e2e.test.ts +0 -299
  319. package/packages/relay/test/relay-endpoint.test.ts +0 -278
  320. package/packages/release-manager/test/release.test.ts +0 -215
  321. package/packages/requirement-compiler/test/requirement-compiler.test.ts +0 -743
  322. package/packages/runtime/test/runtime-api.test.ts +0 -169
  323. package/packages/runtime/test/runtime.test.ts +0 -297
  324. package/packages/scheduler/test/scheduler.test.ts +0 -125
  325. package/packages/session/test/manager.test.ts +0 -233
  326. package/packages/shared-context/test/shared-context.test.ts +0 -114
  327. package/packages/skill-registry/test/registry.test.ts +0 -508
  328. package/packages/skills/test/init-skills.test.ts +0 -114
  329. package/packages/skills/test/remote-skills.test.ts +0 -360
  330. package/packages/skills/test/remote-source.test.ts +0 -248
  331. package/packages/skills/test/sanitize.test.ts +0 -250
  332. package/packages/skills/test/vector-indexing.test.ts +0 -205
  333. package/packages/skills/test/vector-schema.test.ts +0 -180
  334. package/packages/skills/test/vector-threshold.test.ts +0 -108
  335. package/packages/sprint-planner/test/planner.test.ts +0 -187
  336. package/packages/task-compiler/test/task-compiler.test.ts +0 -628
  337. package/packages/test-data-generator/test/generator.test.ts +0 -265
  338. package/packages/test-generator/test/generator.test.ts +0 -156
  339. package/packages/token-estimation/test/token-estimation.test.ts +0 -207
  340. package/packages/token-optimizer/test/optimizer.test.ts +0 -141
  341. package/packages/tooling-preference/tests/changed-files.test.ts +0 -124
  342. package/packages/tooling-preference/tests/detect.test.ts +0 -188
  343. package/packages/tooling-preference/tests/proposal.test.ts +0 -107
  344. package/packages/tooling-preference/tests/quality-check.test.ts +0 -272
  345. package/packages/tooling-preference/tests/registry.test.ts +0 -51
  346. package/packages/tooling-preference/tests/store.test.ts +0 -99
  347. package/packages/trajectory/test/store.test.ts +0 -250
  348. package/packages/tui/test/harness-footer.test.ts +0 -559
  349. package/packages/tui/test/harness-header.test.ts +0 -590
  350. package/packages/two-phase-review/test/classify.test.ts +0 -102
  351. package/packages/two-phase-review/test/helpers.ts +0 -72
  352. package/packages/two-phase-review/test/rules.test.ts +0 -150
  353. package/packages/two-phase-review/test/runtime.test.ts +0 -362
  354. package/packages/two-phase-review/test/scope.test.ts +0 -186
  355. package/packages/two-phase-review/test/signals.test.ts +0 -183
  356. package/packages/two-phase-review/test/state.test.ts +0 -201
  357. package/packages/wiki/test/basic.test.ts +0 -242
  358. package/packages/workspace-scanner/test/scanner.test.ts +0 -43
  359. package/packages/worktree/test/worktree.test.ts +0 -163
@@ -1,387 +0,0 @@
1
- /**
2
- * Tests for the agent-policy package
3
- */
4
-
5
- import { describe, it, beforeEach, afterEach, expect } from "bun:test";
6
- import { existsSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
7
- import { join } from "node:path";
8
- import { PolicyLoader } from "../src/policy-loader.js";
9
- import { PolicyStore, resetPolicyStore, getPolicyStore } from "../src/policy-store.js";
10
- import { renderSystemContract, parseSections, createCleanEnvelope, createDegradedEnvelope } from "../src/policy-renderer.js";
11
- import { classifyToolCall } from "../src/types.js";
12
-
13
- // ---------------------------------------------------------------------------
14
- // Test Fixtures
15
- // ---------------------------------------------------------------------------
16
-
17
- const TEST_DIR = "/tmp/agent-policy-test";
18
-
19
- function setupTestDir() {
20
- rmSync(TEST_DIR, { force: true, recursive: true });
21
- mkdirSync(TEST_DIR, { recursive: true });
22
- mkdirSync(join(TEST_DIR, "src"), { recursive: true });
23
- mkdirSync(join(TEST_DIR, "packages/test"), { recursive: true });
24
- }
25
-
26
- function teardownTestDir() {
27
- rmSync(TEST_DIR, { force: true, recursive: true });
28
- }
29
-
30
- function createTestFile(relativePath: string, content: string) {
31
- const fullPath = join(TEST_DIR, relativePath);
32
- writeFileSync(fullPath, content, "utf8");
33
- return fullPath;
34
- }
35
-
36
- // ---------------------------------------------------------------------------
37
- // PolicyLoader Tests
38
- // ---------------------------------------------------------------------------
39
-
40
- describe("PolicyLoader", () => {
41
- let loader: PolicyLoader;
42
- let harnessPath: string;
43
-
44
- beforeEach(() => {
45
- setupTestDir();
46
- harnessPath = createTestFile("AGENTS.md", `# Test Harness Rules
47
-
48
- ## Mandatory Rules
49
-
50
- - Follow these rules
51
- - Always do X
52
-
53
- ## Advisory
54
-
55
- - Consider doing Y
56
- `);
57
- loader = new PolicyLoader({
58
- harnessRulesPath: new URL(`file://${harnessPath}`),
59
- });
60
- });
61
-
62
- afterEach(() => {
63
- teardownTestDir();
64
- loader = undefined as any;
65
- });
66
-
67
- it("should load harness rules", async () => {
68
- const manifest = await loader.load(TEST_DIR);
69
-
70
- expect(manifest.revision).toBeTruthy();
71
- expect(manifest.projectRoot).toBe(TEST_DIR);
72
- expect(manifest.sources.length).toBeGreaterThan(0);
73
- expect(manifest.coverage).toBe("complete");
74
-
75
- // Check mandatory sources
76
- const mandatory = manifest.sources.filter(s => s.priority === "mandatory");
77
- expect(mandatory.length).toBeGreaterThan(0);
78
- });
79
-
80
- it("should compute deterministic revision", async () => {
81
- const manifest1 = await loader.load(TEST_DIR);
82
- const manifest2 = await loader.load(TEST_DIR);
83
-
84
- expect(manifest1.revision).toBe(manifest2.revision);
85
- });
86
-
87
- it("should detect rule changes", async () => {
88
- const manifest1 = await loader.load(TEST_DIR);
89
-
90
- // Modify the harness rules
91
- createTestFile("AGENTS.md", `# Modified Rules
92
-
93
- ## Changed
94
-
95
- - Different content
96
- `);
97
-
98
- // Invalidate cache
99
- loader.invalidateCache(TEST_DIR);
100
-
101
- const manifest2 = await loader.load(TEST_DIR);
102
-
103
- expect(manifest1.revision).not.toBe(manifest2.revision);
104
- });
105
-
106
- it("should load project rules when present", async () => {
107
- createTestFile("RULES.md", `# Project Rules
108
-
109
- This is a project rule file.
110
- `);
111
-
112
- const manifest = await loader.load(TEST_DIR);
113
-
114
- expect(manifest.sources.length).toBeGreaterThanOrEqual(2);
115
- expect(manifest.trust).toBeTruthy();
116
- });
117
-
118
- it("should handle missing harness rules when outside harness repo", async () => {
119
- // When working outside the harness repository, missing harness rules are OK
120
- // because the rules don't apply to user projects
121
- const emptyLoader = new PolicyLoader({
122
- harnessRulesPath: new URL("file:///nonexistent/path/AGENTS.md"),
123
- });
124
-
125
- // Should succeed with empty manifest (no harness rules apply)
126
- const manifest = await emptyLoader.load(TEST_DIR);
127
- expect(manifest.sources.length).toBeGreaterThanOrEqual(0);
128
- });
129
-
130
- it("should infer scope from target path", async () => {
131
- const manifest = await loader.loadForTarget(TEST_DIR, join(TEST_DIR, "src/file.ts"));
132
-
133
- expect(manifest).toBeTruthy();
134
- });
135
- });
136
-
137
- // ---------------------------------------------------------------------------
138
- // PolicyStore Tests
139
- // ---------------------------------------------------------------------------
140
-
141
- describe("PolicyStore", () => {
142
- let store: PolicyStore;
143
-
144
- beforeEach(() => {
145
- resetPolicyStore();
146
- store = getPolicyStore();
147
- });
148
-
149
- afterEach(() => {
150
- store.invalidateAll();
151
- });
152
-
153
- function createTestManifest(revision = "test-rev-1") {
154
- return {
155
- revision,
156
- projectRoot: TEST_DIR,
157
- trust: "trusted" as const,
158
- coverage: "complete" as const,
159
- sources: [{
160
- path: "/test/AGENTS.md",
161
- scope: "",
162
- priority: "mandatory" as const,
163
- sha256: "abc123",
164
- bytes: 100,
165
- harnessOwned: true,
166
- }],
167
- loadedAt: Date.now(),
168
- };
169
- }
170
-
171
- it("should record and retrieve receipt", () => {
172
- const manifest = createTestManifest();
173
- const sessionId = "test-session-1";
174
-
175
- const receipt = store.noteDelivered(sessionId, manifest, "system_prompt");
176
-
177
- expect(receipt.sessionId).toBe(sessionId);
178
- expect(receipt.revision).toBe(manifest.revision);
179
- expect(receipt.deliveryMethod).toBe("system_prompt");
180
-
181
- const retrieved = store.getReceipt(sessionId, TEST_DIR);
182
- expect(retrieved).not.toBeNull();
183
- expect(retrieved?.revision).toBe(manifest.revision);
184
- });
185
-
186
- it("should validate receipt against manifest", () => {
187
- const manifest = createTestManifest();
188
- const sessionId = "test-session-2";
189
-
190
- store.noteDelivered(sessionId, manifest, "system_prompt");
191
-
192
- const valid = store.validateReceipt(sessionId, manifest);
193
- expect(valid.valid).toBe(true);
194
-
195
- const wrongManifest = createTestManifest("different-revision");
196
- const invalid = store.validateReceipt(sessionId, wrongManifest);
197
- expect(invalid.valid).toBe(false);
198
- expect(invalid.reason).toContain("does not match");
199
- });
200
-
201
- it("should check receipt validity", () => {
202
- const manifest = createTestManifest();
203
- const sessionId = "test-session-3";
204
-
205
- // No receipt yet
206
- expect(store.hasValidReceipt(sessionId, manifest)).toBe(false);
207
-
208
- // Add receipt
209
- store.noteDelivered(sessionId, manifest, "system_prompt");
210
- expect(store.hasValidReceipt(sessionId, manifest)).toBe(true);
211
-
212
- // Different revision
213
- const wrongManifest = createTestManifest("other-rev");
214
- expect(store.hasValidReceipt(sessionId, wrongManifest)).toBe(false);
215
- });
216
-
217
- it("should invalidate on revision change", () => {
218
- const manifest1 = createTestManifest("rev-1");
219
- const manifest2 = createTestManifest("rev-2");
220
- const sessionId = "test-session-4";
221
-
222
- store.noteDelivered(sessionId, manifest1, "system_prompt");
223
- expect(store.hasValidReceipt(sessionId, manifest1)).toBe(true);
224
-
225
- // New revision - old receipt should not cover it
226
- expect(store.hasValidReceipt(sessionId, manifest2)).toBe(false);
227
- });
228
-
229
- it("should clear session receipts", () => {
230
- const manifest = createTestManifest();
231
- const sessionId = "test-session-5";
232
-
233
- store.noteDelivered(sessionId, manifest, "system_prompt");
234
- expect(store.getReceipt(sessionId, TEST_DIR)).not.toBeNull();
235
-
236
- store.clearSession(sessionId);
237
- expect(store.getReceipt(sessionId, TEST_DIR)).toBeNull();
238
- });
239
-
240
- it("should track statistics", () => {
241
- const manifest = createTestManifest();
242
-
243
- store.noteDelivered("session-1", manifest, "system_prompt");
244
- store.noteDelivered("session-2", manifest, "tool");
245
-
246
- const stats = store.getStats();
247
- expect(stats.totalReceipts).toBe(2);
248
- expect(stats.sessionsTracked).toBe(2);
249
- });
250
- });
251
-
252
- // ---------------------------------------------------------------------------
253
- // PolicyRenderer Tests
254
- // ---------------------------------------------------------------------------
255
-
256
- describe("PolicyRenderer", () => {
257
- function createTestManifest() {
258
- return {
259
- revision: "abc123",
260
- projectRoot: TEST_DIR,
261
- trust: "trusted" as const,
262
- coverage: "complete" as const,
263
- sources: [{
264
- path: "/test/AGENTS.md",
265
- scope: "",
266
- priority: "mandatory" as const,
267
- sha256: "abc123",
268
- bytes: 100,
269
- harnessOwned: true,
270
- }],
271
- loadedAt: Date.now(),
272
- };
273
- }
274
-
275
- it("should render system contract", () => {
276
- const manifest = createTestManifest();
277
- const contract = renderSystemContract(manifest);
278
-
279
- expect(contract).toContain("PI-HARNESS POLICY");
280
- expect(contract).toContain(manifest.revision);
281
- expect(contract).toContain("Mandatory:");
282
- expect(contract).toContain("harness_rules");
283
- });
284
-
285
- it("should include coverage in contract", () => {
286
- const manifest = {
287
- ...createTestManifest(),
288
- coverage: "partial" as const,
289
- };
290
-
291
- const contract = renderSystemContract(manifest);
292
- expect(contract).toContain("coverage=partial");
293
- expect(contract).toContain("WARNING");
294
- });
295
-
296
- it("should include trust warning for untrusted projects", () => {
297
- const manifest = {
298
- ...createTestManifest(),
299
- trust: "untrusted" as const,
300
- };
301
-
302
- const contract = renderSystemContract(manifest);
303
- expect(contract).toContain("not trusted");
304
- });
305
-
306
- it("should parse markdown sections", () => {
307
- const content = `# Header 1
308
-
309
- Some content here.
310
-
311
- ## Header 2
312
-
313
- More content.
314
- `;
315
-
316
- const sections = parseSections(content, "/test/AGENTS.md", "", "mandatory");
317
-
318
- expect(sections.length).toBe(2);
319
- expect(sections[0].title).toBe("Header 1");
320
- expect(sections[0].content).toContain("Some content here");
321
- expect(sections[1].title).toBe("Header 2");
322
- });
323
-
324
- it("should create clean envelope", () => {
325
- const envelope = createCleanEnvelope();
326
-
327
- expect(envelope.verdict).toBe("clean");
328
- expect(envelope.findings).toHaveLength(0);
329
- expect(envelope.nextAction).toBe("continue");
330
- });
331
-
332
- it("should create degraded envelope", () => {
333
- const envelope = createDegradedEnvelope("LSP timeout");
334
-
335
- expect(envelope.verdict).toBe("degraded");
336
- expect(envelope.summary).toContain("LSP timeout");
337
- expect(envelope.nextAction).toBe("run_full");
338
- });
339
- });
340
-
341
- // ---------------------------------------------------------------------------
342
- // Tool Classification Tests
343
- // ---------------------------------------------------------------------------
344
-
345
- describe("Tool Classifier", () => {
346
- it("should classify write as mutating", () => {
347
- const cap = classifyToolCall("write", { path: "/test/file.ts", content: "" });
348
- expect(cap.mutatesProject).toBe(true);
349
- expect(cap.releasesProject).toBe(false);
350
- expect(cap.confidence).toBe("high");
351
- });
352
-
353
- it("should classify edit as mutating", () => {
354
- const cap = classifyToolCall("edit", { path: "/test/file.ts" });
355
- expect(cap.mutatesProject).toBe(true);
356
- });
357
-
358
- it("should classify read as non-mutating", () => {
359
- const cap = classifyToolCall("read", { path: "/test/file.ts" });
360
- expect(cap.mutatesProject).toBe(false);
361
- expect(cap.releasesProject).toBe(false);
362
- });
363
-
364
- it("should classify bash git commands as releasing", () => {
365
- const cap = classifyToolCall("bash", { command: "git commit -m 'test'" });
366
- expect(cap.mutatesProject).toBe(true);
367
- expect(cap.releasesProject).toBe(true);
368
- });
369
-
370
- it("should classify subagent as child delegation", () => {
371
- const cap = classifyToolCall("subagent", { agent: "test", task: "do something" });
372
- expect(cap.isChildDelegation).toBe(true);
373
- expect(cap.mutatesProject).toBe(true);
374
- });
375
-
376
- it("should classify harness_rules as non-mutating", () => {
377
- const cap = classifyToolCall("harness_rules", { action: "manifest" });
378
- expect(cap.mutatesProject).toBe(false);
379
- expect(cap.releasesProject).toBe(false);
380
- });
381
-
382
- it("should conservatively classify unknown tools", () => {
383
- const cap = classifyToolCall("unknown_tool", {});
384
- expect(cap.mutatesProject).toBe(true); // Conservative
385
- expect(cap.confidence).toBe("low");
386
- });
387
- });
@@ -1,238 +0,0 @@
1
- /**
2
- * Auth Tests — Filesystem helpers and pure functions (no browser required)
3
- */
4
-
5
- import { describe, it, expect, beforeEach } from "bun:test";
6
- import {
7
- detectUsagePage,
8
- extractUsageLines,
9
- getRuntimeDir,
10
- getProfileDir,
11
- getStatusPath,
12
- getLiveSessionPath,
13
- saveAuthStatus,
14
- loadLiveBrowserSession,
15
- } from "../src/minimax-browser-auth";
16
- import {
17
- existsSync,
18
- mkdirSync,
19
- rmSync,
20
- writeFileSync,
21
- readFileSync,
22
- } from "node:fs";
23
- import { join } from "node:path";
24
-
25
- const TMP = join(process.cwd(), ".test-auth-tmp");
26
-
27
- function tmpStatus() {
28
- return join(TMP, "auth-status.json");
29
- }
30
- function tmpLiveSession() {
31
- return join(TMP, "live-session.json");
32
- }
33
-
34
- beforeEach(() => {
35
- rmSync(TMP, { force: true, recursive: true });
36
- mkdirSync(TMP, { recursive: true });
37
- });
38
-
39
- describe("path helpers", () => {
40
- it("getRuntimeDir returns a path with pi-harness-runtime", () => {
41
- expect(getRuntimeDir()).toContain(".pi-harness-runtime");
42
- });
43
-
44
- it("getProfileDir is under runtime dir", () => {
45
- expect(getProfileDir()).toStartWith(getRuntimeDir());
46
- expect(getProfileDir()).toContain("minimax");
47
- });
48
-
49
- it("getStatusPath is under runtime dir", () => {
50
- expect(getStatusPath()).toStartWith(getRuntimeDir());
51
- expect(getStatusPath()).toContain("auth");
52
- });
53
-
54
- it("getLiveSessionPath contains session file name", () => {
55
- expect(getLiveSessionPath()).toContain("minimax-live-browser");
56
- });
57
- });
58
-
59
- describe("saveAuthStatus", () => {
60
- beforeEach(() => {
61
- rmSync(TMP, { force: true, recursive: true });
62
- mkdirSync(TMP, { recursive: true });
63
- });
64
-
65
- it("writes a status file", () => {
66
- const status = {
67
- provider: "minimax" as const,
68
- authenticated: true,
69
- checked_at: "2025-01-15T10:00:00Z",
70
- page_url: "https://platform.minimax.io/console/usage",
71
- detected_text_sample: "Usage details",
72
- profile_path: "/fake/profile",
73
- usage_lines: ["Token Plan", "Monthly Plus", "Used 71%"],
74
- };
75
- saveAuthStatus(status, { statusPath: tmpStatus() });
76
- expect(existsSync(tmpStatus())).toBe(true);
77
- let loaded: any;
78
- try {
79
- loaded = JSON.parse(readFileSync(tmpStatus(), "utf-8"));
80
- } catch {
81
- throw new Error("saveAuthStatus did not write valid JSON");
82
- }
83
- expect(loaded.authenticated).toBe(true);
84
- expect(loaded.provider).toBe("minimax");
85
- expect(loaded.usage_lines).toHaveLength(3);
86
- });
87
-
88
- it("round-trips an unauthenticated status", () => {
89
- const status = {
90
- provider: "minimax" as const,
91
- authenticated: false,
92
- checked_at: "2025-01-15T10:00:00Z",
93
- page_url: "",
94
- detected_text_sample: null,
95
- profile_path: "/fake/profile",
96
- error_message: "Session expired",
97
- };
98
- saveAuthStatus(status, { statusPath: tmpStatus() });
99
- let loaded: any;
100
- try {
101
- loaded = JSON.parse(readFileSync(tmpStatus(), "utf-8"));
102
- } catch {
103
- throw new Error("saveAuthStatus did not write valid JSON");
104
- }
105
- expect(loaded.authenticated).toBe(false);
106
- expect(loaded.error_message).toBe("Session expired");
107
- });
108
-
109
- it("creates parent directories", () => {
110
- const nestedPath = join(TMP, "deeply", "nested", "status.json");
111
- saveAuthStatus(
112
- {
113
- provider: "minimax" as const,
114
- authenticated: false,
115
- checked_at: "",
116
- page_url: "",
117
- detected_text_sample: null,
118
- profile_path: "/",
119
- } as any,
120
- { statusPath: nestedPath },
121
- );
122
- expect(existsSync(nestedPath)).toBe(true);
123
- });
124
- });
125
-
126
- describe("loadLiveBrowserSession", () => {
127
- beforeEach(() => {
128
- rmSync(TMP, { force: true, recursive: true });
129
- mkdirSync(TMP, { recursive: true });
130
- });
131
-
132
- it("loads a saved session", () => {
133
- const session = {
134
- profile_path: "/tmp/chrome-profile",
135
- target_url: "https://platform.minimax.io/console/usage",
136
- chrome_path: "/usr/bin/google-chrome",
137
- debugging_port: 9222,
138
- pid: 12345,
139
- started_at: "2025-01-15T10:00:00Z",
140
- };
141
- writeFileSync(tmpLiveSession(), JSON.stringify(session));
142
- const loaded = loadLiveBrowserSession(tmpLiveSession());
143
- expect(loaded?.debugging_port).toBe(9222);
144
- expect(loaded?.pid).toBe(12345);
145
- expect(loaded?.profile_path).toBe("/tmp/chrome-profile");
146
- });
147
-
148
- it("returns null for missing file", () => {
149
- const loaded = loadLiveBrowserSession(join(TMP, "not-found.json"));
150
- expect(loaded).toBeNull();
151
- });
152
-
153
- it("returns null for corrupted JSON", () => {
154
- writeFileSync(tmpLiveSession(), "not json {");
155
- const loaded = loadLiveBrowserSession(tmpLiveSession());
156
- expect(loaded).toBeNull();
157
- });
158
- });
159
-
160
- describe("detectUsagePage", () => {
161
- it("detects page with usage keywords", () => {
162
- const body =
163
- "Your Usage: 5h limit, resets in 1 hour. Weekly limit used 71%. Token Plan · Monthly Plus";
164
- const result = detectUsagePage(body);
165
- expect(result.detected).toBe(true);
166
- expect(result.sample).not.toBeNull();
167
- expect(result.sample!.length).toBeGreaterThan(0);
168
- });
169
-
170
- it("does not detect page with few keywords", () => {
171
- const body =
172
- "Welcome to our website. This is a generic page with no usage information.";
173
- const result = detectUsagePage(body);
174
- expect(result.detected).toBe(false);
175
- expect(result.sample).toBeNull();
176
- });
177
-
178
- it("triggers on 2+ matching keywords", () => {
179
- const body = "Usage Quota limit exceeded";
180
- const result = detectUsagePage(body);
181
- expect(result.detected).toBe(true);
182
- });
183
-
184
- it("sample is truncated to 200 chars", () => {
185
- const body =
186
- "A".repeat(300) + " special_usage_keyword_here and another_token";
187
- const result = detectUsagePage(body);
188
- expect(result.detected).toBe(true);
189
- expect(result.sample!.length).toBeLessThanOrEqual(200);
190
- });
191
-
192
- it("case insensitive matching", () => {
193
- const body = "USAGE QUOTA TOKEN PLAN CREDITS";
194
- const result = detectUsagePage(body);
195
- expect(result.detected).toBe(true);
196
- });
197
-
198
- it("empty body returns not detected", () => {
199
- const result = detectUsagePage("");
200
- expect(result.detected).toBe(false);
201
- });
202
- });
203
-
204
- describe("extractUsageLines", () => {
205
- it("extracts lines with usage keywords", () => {
206
- const body =
207
- "<div>Your Token Plan</div><span>Monthly Plus</span><p>Used 71%</p>";
208
- const lines = extractUsageLines(body);
209
- expect(lines.length).toBeGreaterThan(0);
210
- });
211
-
212
- it("strips script and style tags", () => {
213
- const body =
214
- '<script>{"secret": true}</script><style>body{}</style>Visible content usage quota 71%';
215
- const lines = extractUsageLines(body);
216
- expect(lines.some((l) => l.includes("secret"))).toBe(false);
217
- });
218
-
219
- it("filters out overly short parts", () => {
220
- const body = "ab cd ef gh ij usage token";
221
- const lines = extractUsageLines(body);
222
- for (const l of lines) {
223
- expect(l.length).toBeGreaterThanOrEqual(3);
224
- }
225
- });
226
-
227
- it("returns array for content-free input", () => {
228
- const lines = extractUsageLines("<html><body></body></html>");
229
- expect(Array.isArray(lines)).toBe(true);
230
- });
231
-
232
- it("deduplicates results", () => {
233
- const body = "usage token 71% usage token 71%";
234
- const lines = extractUsageLines(body);
235
- const unique = [...new Set(lines)];
236
- expect(lines.length).toBe(unique.length);
237
- });
238
- });