devworkspace 0.5.0 → 0.5.2

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 (384) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +57 -509
  3. package/dist/agents/claude/adapter.js +0 -1
  4. package/dist/agents/claude/content.js +0 -1
  5. package/dist/agents/codex/adapter.js +0 -1
  6. package/dist/agents/copilot/adapter.js +0 -1
  7. package/dist/agents/cursor/adapter.js +0 -1
  8. package/dist/agents/index.js +0 -1
  9. package/dist/agents/shared.js +0 -1
  10. package/dist/agents/types.js +0 -1
  11. package/dist/cli/args.d.ts +16 -0
  12. package/dist/cli/args.js +5 -1
  13. package/dist/cli/help.js +59 -17
  14. package/dist/cli/main.js +0 -1
  15. package/dist/cli/prompt.d.ts +15 -0
  16. package/dist/cli/prompt.js +113 -0
  17. package/dist/cli/render.d.ts +10 -0
  18. package/dist/cli/render.js +174 -4
  19. package/dist/cli/run.d.ts +3 -0
  20. package/dist/cli/run.js +366 -17
  21. package/dist/config/feature-gate.d.ts +15 -0
  22. package/dist/config/feature-gate.js +77 -0
  23. package/dist/config/feature-registry.d.ts +49 -0
  24. package/dist/config/feature-registry.js +451 -0
  25. package/dist/config/schemas.js +0 -1
  26. package/dist/config/settings.d.ts +54 -0
  27. package/dist/config/settings.js +293 -0
  28. package/dist/config/validate.js +0 -1
  29. package/dist/core/artifacts.js +0 -1
  30. package/dist/core/contracts.js +0 -1
  31. package/dist/core/migrations.js +0 -1
  32. package/dist/core/version.js +0 -1
  33. package/dist/core/versioned.js +0 -1
  34. package/dist/core/workspace.d.ts +1 -0
  35. package/dist/core/workspace.js +1 -1
  36. package/dist/decisions/decision.js +0 -1
  37. package/dist/discovery/cache.js +0 -1
  38. package/dist/discovery/commands.js +0 -1
  39. package/dist/discovery/detect.js +0 -1
  40. package/dist/discovery/docs.js +0 -1
  41. package/dist/discovery/entrypoints.js +0 -1
  42. package/dist/discovery/ignore.js +0 -1
  43. package/dist/discovery/scan.js +0 -1
  44. package/dist/discovery/types.js +0 -1
  45. package/dist/dx/dashboard.js +2 -1
  46. package/dist/dx/guidance.js +0 -1
  47. package/dist/dx/guided-setup.d.ts +102 -0
  48. package/dist/dx/guided-setup.js +508 -0
  49. package/dist/dx/index.js +0 -1
  50. package/dist/dx/onboarding.js +0 -1
  51. package/dist/dx/types.js +0 -1
  52. package/dist/errors/index.js +0 -1
  53. package/dist/features/schema.js +0 -1
  54. package/dist/features/types.js +0 -1
  55. package/dist/features/validate.js +0 -1
  56. package/dist/git/git.js +0 -1
  57. package/dist/index.d.ts +15 -5
  58. package/dist/index.js +10 -2
  59. package/dist/integrations/adapters/agent-skills.js +0 -1
  60. package/dist/integrations/adapters/claudePlugin.js +0 -1
  61. package/dist/integrations/adapters/graphify.js +0 -1
  62. package/dist/integrations/adapters/omniroute.js +0 -1
  63. package/dist/integrations/adapters/pluginSkill.js +0 -1
  64. package/dist/integrations/adapters/ponytail.js +0 -1
  65. package/dist/integrations/exec.js +0 -1
  66. package/dist/integrations/index.js +0 -1
  67. package/dist/integrations/manager.d.ts +2 -1
  68. package/dist/integrations/manager.js +22 -3
  69. package/dist/integrations/notices.js +0 -1
  70. package/dist/integrations/persistentPath.js +0 -1
  71. package/dist/integrations/protect.js +0 -1
  72. package/dist/integrations/state.js +0 -1
  73. package/dist/integrations/types.d.ts +1 -1
  74. package/dist/integrations/types.js +1 -1
  75. package/dist/intelligence/agents/profiles.js +0 -1
  76. package/dist/intelligence/agents/registry.js +0 -1
  77. package/dist/intelligence/agents/types.js +0 -1
  78. package/dist/intelligence/observability/tracer.js +0 -1
  79. package/dist/intelligence/observability/types.js +0 -1
  80. package/dist/intelligence/orchestration/engine.d.ts +21 -3
  81. package/dist/intelligence/orchestration/engine.js +486 -48
  82. package/dist/intelligence/orchestration/lock-manager.js +0 -1
  83. package/dist/intelligence/orchestration/store.js +0 -1
  84. package/dist/intelligence/orchestration/types.d.ts +40 -2
  85. package/dist/intelligence/orchestration/types.js +2 -3
  86. package/dist/intelligence/routing/matcher.js +0 -1
  87. package/dist/intelligence/routing/router.js +0 -1
  88. package/dist/intelligence/routing/types.js +0 -1
  89. package/dist/intelligence/runtime/adk/adapter.js +21 -33
  90. package/dist/intelligence/runtime/adk/detector.js +0 -1
  91. package/dist/intelligence/runtime/auth-provider.d.ts +63 -0
  92. package/dist/intelligence/runtime/auth-provider.js +201 -0
  93. package/dist/intelligence/runtime/boundary.d.ts +142 -0
  94. package/dist/intelligence/runtime/boundary.js +845 -0
  95. package/dist/intelligence/runtime/changes.d.ts +59 -0
  96. package/dist/intelligence/runtime/changes.js +362 -0
  97. package/dist/intelligence/runtime/external.d.ts +1 -0
  98. package/dist/intelligence/runtime/external.js +38 -61
  99. package/dist/intelligence/runtime/native.js +23 -56
  100. package/dist/intelligence/runtime/types.d.ts +91 -1
  101. package/dist/intelligence/runtime/types.js +11 -2
  102. package/dist/intelligence/security/audit.js +8 -2
  103. package/dist/intelligence/security/policy.js +0 -1
  104. package/dist/intelligence/security/types.d.ts +8 -0
  105. package/dist/intelligence/security/types.js +0 -1
  106. package/dist/intelligence/skills/builtins.js +0 -1
  107. package/dist/intelligence/skills/loader.js +0 -1
  108. package/dist/intelligence/skills/registry.js +0 -1
  109. package/dist/intelligence/skills/types.js +0 -1
  110. package/dist/intelligence/verification/engine.d.ts +30 -8
  111. package/dist/intelligence/verification/engine.js +126 -21
  112. package/dist/intelligence/verification/reviewer.d.ts +18 -2
  113. package/dist/intelligence/verification/reviewer.js +356 -4
  114. package/dist/intelligence/verification/types.d.ts +71 -0
  115. package/dist/intelligence/verification/types.js +0 -1
  116. package/dist/knowledge/facts.js +0 -1
  117. package/dist/mcp/protocol.js +0 -1
  118. package/dist/mcp/server.js +38 -2
  119. package/dist/mcp/setup.js +5 -2
  120. package/dist/mcp/tools.js +0 -1
  121. package/dist/mcp/types.js +0 -1
  122. package/dist/mcp/verify.js +0 -1
  123. package/dist/portability/bundle.js +0 -1
  124. package/dist/prompts/onboarding.js +0 -1
  125. package/dist/prompts/refresh.js +0 -1
  126. package/dist/prompts/requirements.js +0 -1
  127. package/dist/security/files.js +0 -1
  128. package/dist/security/redact.js +0 -1
  129. package/dist/services/agent.js +2 -1
  130. package/dist/services/analysis.js +0 -1
  131. package/dist/services/common.js +0 -1
  132. package/dist/services/doctor.js +13 -2
  133. package/dist/services/drift.js +0 -1
  134. package/dist/services/features.js +5 -1
  135. package/dist/services/graph.js +4 -1
  136. package/dist/services/init.js +0 -1
  137. package/dist/services/integrations.d.ts +2 -1
  138. package/dist/services/integrations.js +29 -6
  139. package/dist/services/intelligence.d.ts +2 -2
  140. package/dist/services/intelligence.js +38 -36
  141. package/dist/services/knowledge.js +0 -1
  142. package/dist/services/migrate.js +0 -1
  143. package/dist/services/modules.d.ts +85 -0
  144. package/dist/services/modules.js +313 -0
  145. package/dist/services/portability.js +0 -1
  146. package/dist/services/records.js +5 -1
  147. package/dist/services/refresh.js +0 -1
  148. package/dist/services/reset.js +0 -1
  149. package/dist/services/settings.d.ts +36 -0
  150. package/dist/services/settings.js +102 -0
  151. package/dist/services/setup.d.ts +4 -5
  152. package/dist/services/setup.js +40 -28
  153. package/dist/services/standards.js +10 -1
  154. package/dist/services/status.js +0 -1
  155. package/dist/services/taskContext.js +0 -1
  156. package/dist/services/tasks.js +9 -1
  157. package/dist/services/verify.js +7 -2
  158. package/dist/sessions/session.js +0 -1
  159. package/dist/standards/acquisition/ingest.js +0 -1
  160. package/dist/standards/applicability/engine.js +0 -1
  161. package/dist/standards/builtin/code-quality.js +0 -1
  162. package/dist/standards/builtin/database-safety.js +0 -1
  163. package/dist/standards/builtin/index.js +0 -1
  164. package/dist/standards/builtin/security-baseline.js +0 -1
  165. package/dist/standards/builtin/testing-contracts.js +0 -1
  166. package/dist/standards/builtin/undo-kit.js +0 -1
  167. package/dist/standards/config/config.js +0 -1
  168. package/dist/standards/distribution/cache.d.ts +1 -0
  169. package/dist/standards/distribution/cache.js +199 -186
  170. package/dist/standards/distribution/index.js +0 -1
  171. package/dist/standards/distribution/keys.js +0 -1
  172. package/dist/standards/distribution/package.js +6 -1
  173. package/dist/standards/distribution/server.js +0 -1
  174. package/dist/standards/distribution/sync.d.ts +7 -2
  175. package/dist/standards/distribution/sync.js +41 -9
  176. package/dist/standards/distribution/types.js +0 -1
  177. package/dist/standards/engine/compliance.js +0 -1
  178. package/dist/standards/engine/engine.js +0 -1
  179. package/dist/standards/engine/reporter.js +0 -1
  180. package/dist/standards/index.js +0 -1
  181. package/dist/standards/registry/registry.js +0 -1
  182. package/dist/standards/schema/types.js +0 -1
  183. package/dist/standards/schema/validate.js +0 -1
  184. package/dist/standards/templates/index.js +0 -1
  185. package/dist/standards/validators/database.js +0 -1
  186. package/dist/standards/validators/quality.js +0 -1
  187. package/dist/standards/validators/registry.js +0 -1
  188. package/dist/standards/validators/security.js +0 -1
  189. package/dist/standards/validators/testing.js +0 -1
  190. package/dist/standards/validators/types.js +0 -1
  191. package/dist/standards/validators/undo-kit.js +0 -1
  192. package/dist/tasks/routing.js +0 -1
  193. package/dist/tasks/task.js +0 -1
  194. package/dist/utils/cleanup.js +0 -1
  195. package/dist/utils/fs.js +0 -1
  196. package/dist/utils/lock.js +92 -49
  197. package/dist/utils/logger.js +0 -1
  198. package/dist/utils/paths.js +0 -1
  199. package/dist/utils/proc.d.ts +12 -0
  200. package/dist/utils/proc.js +106 -44
  201. package/dist/verification/safety.js +0 -1
  202. package/dist/verification/scope.js +0 -1
  203. package/docs/agents.md +15 -0
  204. package/docs/architecture/global-standards-architecture.md +287 -0
  205. package/docs/archive/global-standards/GLOBAL_STANDARDS_AUDIT.md +99 -0
  206. package/docs/archive/global-standards/GLOBAL_STANDARDS_FINAL_STATUS.md +138 -0
  207. package/docs/archive/global-standards/GLOBAL_STANDARDS_IMPLEMENTATION_PLAN.md +100 -0
  208. package/docs/archive/global-standards/GLOBAL_STANDARDS_INDEPENDENT_AUDIT.md +219 -0
  209. package/docs/archive/global-standards/GLOBAL_STANDARDS_SECURITY_REPORT.md +184 -0
  210. package/docs/configuration.md +67 -0
  211. package/docs/contributing.md +15 -5
  212. package/docs/development/EXECUTION_STATE.md +50 -0
  213. package/docs/features.md +80 -0
  214. package/docs/getting-started.md +69 -111
  215. package/docs/guides/global-standards-migration.md +100 -0
  216. package/docs/integrations.md +7 -0
  217. package/docs/mcp.md +13 -0
  218. package/docs/security/THIRD_PARTY_LICENSES.md +41 -0
  219. package/docs/security.md +8 -2
  220. package/docs/testing/FINAL_CORRECTION_AND_CLEANUP_REPORT.md +92 -0
  221. package/docs/testing/global-standards-real-project-tests.md +218 -0
  222. package/docs/testing/global-standards-test-report.md +89 -0
  223. package/docs/testing/global-standards-verification-matrix.md +174 -0
  224. package/docs/troubleshooting.md +3 -0
  225. package/package.json +1 -1
  226. package/dist/agents/claude/adapter.js.map +0 -1
  227. package/dist/agents/claude/content.js.map +0 -1
  228. package/dist/agents/codex/adapter.js.map +0 -1
  229. package/dist/agents/copilot/adapter.js.map +0 -1
  230. package/dist/agents/cursor/adapter.js.map +0 -1
  231. package/dist/agents/index.js.map +0 -1
  232. package/dist/agents/shared.js.map +0 -1
  233. package/dist/agents/types.js.map +0 -1
  234. package/dist/cli/args.js.map +0 -1
  235. package/dist/cli/help.js.map +0 -1
  236. package/dist/cli/main.js.map +0 -1
  237. package/dist/cli/render.js.map +0 -1
  238. package/dist/cli/run.js.map +0 -1
  239. package/dist/config/schemas.js.map +0 -1
  240. package/dist/config/validate.js.map +0 -1
  241. package/dist/core/artifacts.js.map +0 -1
  242. package/dist/core/contracts.js.map +0 -1
  243. package/dist/core/migrations.js.map +0 -1
  244. package/dist/core/version.js.map +0 -1
  245. package/dist/core/versioned.js.map +0 -1
  246. package/dist/core/workspace.js.map +0 -1
  247. package/dist/decisions/decision.js.map +0 -1
  248. package/dist/discovery/cache.js.map +0 -1
  249. package/dist/discovery/commands.js.map +0 -1
  250. package/dist/discovery/detect.js.map +0 -1
  251. package/dist/discovery/docs.js.map +0 -1
  252. package/dist/discovery/entrypoints.js.map +0 -1
  253. package/dist/discovery/ignore.js.map +0 -1
  254. package/dist/discovery/scan.js.map +0 -1
  255. package/dist/discovery/types.js.map +0 -1
  256. package/dist/dx/dashboard.js.map +0 -1
  257. package/dist/dx/guidance.js.map +0 -1
  258. package/dist/dx/index.js.map +0 -1
  259. package/dist/dx/onboarding.js.map +0 -1
  260. package/dist/dx/types.js.map +0 -1
  261. package/dist/errors/index.js.map +0 -1
  262. package/dist/features/schema.js.map +0 -1
  263. package/dist/features/types.js.map +0 -1
  264. package/dist/features/validate.js.map +0 -1
  265. package/dist/git/git.js.map +0 -1
  266. package/dist/index.js.map +0 -1
  267. package/dist/integrations/adapters/agent-skills.js.map +0 -1
  268. package/dist/integrations/adapters/claudePlugin.js.map +0 -1
  269. package/dist/integrations/adapters/graphify.js.map +0 -1
  270. package/dist/integrations/adapters/omniroute.js.map +0 -1
  271. package/dist/integrations/adapters/pluginSkill.js.map +0 -1
  272. package/dist/integrations/adapters/ponytail.js.map +0 -1
  273. package/dist/integrations/exec.js.map +0 -1
  274. package/dist/integrations/index.js.map +0 -1
  275. package/dist/integrations/manager.js.map +0 -1
  276. package/dist/integrations/notices.js.map +0 -1
  277. package/dist/integrations/persistentPath.js.map +0 -1
  278. package/dist/integrations/protect.js.map +0 -1
  279. package/dist/integrations/state.js.map +0 -1
  280. package/dist/integrations/types.js.map +0 -1
  281. package/dist/intelligence/agents/profiles.js.map +0 -1
  282. package/dist/intelligence/agents/registry.js.map +0 -1
  283. package/dist/intelligence/agents/types.js.map +0 -1
  284. package/dist/intelligence/observability/tracer.js.map +0 -1
  285. package/dist/intelligence/observability/types.js.map +0 -1
  286. package/dist/intelligence/orchestration/engine.js.map +0 -1
  287. package/dist/intelligence/orchestration/lock-manager.js.map +0 -1
  288. package/dist/intelligence/orchestration/store.js.map +0 -1
  289. package/dist/intelligence/orchestration/types.js.map +0 -1
  290. package/dist/intelligence/routing/matcher.js.map +0 -1
  291. package/dist/intelligence/routing/router.js.map +0 -1
  292. package/dist/intelligence/routing/types.js.map +0 -1
  293. package/dist/intelligence/runtime/adk/adapter.js.map +0 -1
  294. package/dist/intelligence/runtime/adk/detector.js.map +0 -1
  295. package/dist/intelligence/runtime/external.js.map +0 -1
  296. package/dist/intelligence/runtime/native.js.map +0 -1
  297. package/dist/intelligence/runtime/types.js.map +0 -1
  298. package/dist/intelligence/security/audit.js.map +0 -1
  299. package/dist/intelligence/security/policy.js.map +0 -1
  300. package/dist/intelligence/security/types.js.map +0 -1
  301. package/dist/intelligence/skills/builtins.js.map +0 -1
  302. package/dist/intelligence/skills/loader.js.map +0 -1
  303. package/dist/intelligence/skills/registry.js.map +0 -1
  304. package/dist/intelligence/skills/types.js.map +0 -1
  305. package/dist/intelligence/verification/engine.js.map +0 -1
  306. package/dist/intelligence/verification/reviewer.js.map +0 -1
  307. package/dist/intelligence/verification/types.js.map +0 -1
  308. package/dist/knowledge/facts.js.map +0 -1
  309. package/dist/mcp/protocol.js.map +0 -1
  310. package/dist/mcp/server.js.map +0 -1
  311. package/dist/mcp/setup.js.map +0 -1
  312. package/dist/mcp/tools.js.map +0 -1
  313. package/dist/mcp/types.js.map +0 -1
  314. package/dist/mcp/verify.js.map +0 -1
  315. package/dist/portability/bundle.js.map +0 -1
  316. package/dist/prompts/onboarding.js.map +0 -1
  317. package/dist/prompts/refresh.js.map +0 -1
  318. package/dist/prompts/requirements.js.map +0 -1
  319. package/dist/security/files.js.map +0 -1
  320. package/dist/security/redact.js.map +0 -1
  321. package/dist/services/agent.js.map +0 -1
  322. package/dist/services/analysis.js.map +0 -1
  323. package/dist/services/common.js.map +0 -1
  324. package/dist/services/doctor.js.map +0 -1
  325. package/dist/services/drift.js.map +0 -1
  326. package/dist/services/features.js.map +0 -1
  327. package/dist/services/graph.js.map +0 -1
  328. package/dist/services/init.js.map +0 -1
  329. package/dist/services/integrations.js.map +0 -1
  330. package/dist/services/intelligence.js.map +0 -1
  331. package/dist/services/knowledge.js.map +0 -1
  332. package/dist/services/migrate.js.map +0 -1
  333. package/dist/services/portability.js.map +0 -1
  334. package/dist/services/records.js.map +0 -1
  335. package/dist/services/refresh.js.map +0 -1
  336. package/dist/services/reset.js.map +0 -1
  337. package/dist/services/setup.js.map +0 -1
  338. package/dist/services/standards.js.map +0 -1
  339. package/dist/services/status.js.map +0 -1
  340. package/dist/services/taskContext.js.map +0 -1
  341. package/dist/services/tasks.js.map +0 -1
  342. package/dist/services/verify.js.map +0 -1
  343. package/dist/sessions/session.js.map +0 -1
  344. package/dist/standards/acquisition/ingest.js.map +0 -1
  345. package/dist/standards/applicability/engine.js.map +0 -1
  346. package/dist/standards/builtin/code-quality.js.map +0 -1
  347. package/dist/standards/builtin/database-safety.js.map +0 -1
  348. package/dist/standards/builtin/index.js.map +0 -1
  349. package/dist/standards/builtin/security-baseline.js.map +0 -1
  350. package/dist/standards/builtin/testing-contracts.js.map +0 -1
  351. package/dist/standards/builtin/undo-kit.js.map +0 -1
  352. package/dist/standards/config/config.js.map +0 -1
  353. package/dist/standards/distribution/cache.js.map +0 -1
  354. package/dist/standards/distribution/index.js.map +0 -1
  355. package/dist/standards/distribution/keys.js.map +0 -1
  356. package/dist/standards/distribution/package.js.map +0 -1
  357. package/dist/standards/distribution/server.js.map +0 -1
  358. package/dist/standards/distribution/sync.js.map +0 -1
  359. package/dist/standards/distribution/types.js.map +0 -1
  360. package/dist/standards/engine/compliance.js.map +0 -1
  361. package/dist/standards/engine/engine.js.map +0 -1
  362. package/dist/standards/engine/reporter.js.map +0 -1
  363. package/dist/standards/index.js.map +0 -1
  364. package/dist/standards/registry/registry.js.map +0 -1
  365. package/dist/standards/schema/types.js.map +0 -1
  366. package/dist/standards/schema/validate.js.map +0 -1
  367. package/dist/standards/templates/index.js.map +0 -1
  368. package/dist/standards/validators/database.js.map +0 -1
  369. package/dist/standards/validators/quality.js.map +0 -1
  370. package/dist/standards/validators/registry.js.map +0 -1
  371. package/dist/standards/validators/security.js.map +0 -1
  372. package/dist/standards/validators/testing.js.map +0 -1
  373. package/dist/standards/validators/types.js.map +0 -1
  374. package/dist/standards/validators/undo-kit.js.map +0 -1
  375. package/dist/tasks/routing.js.map +0 -1
  376. package/dist/tasks/task.js.map +0 -1
  377. package/dist/utils/cleanup.js.map +0 -1
  378. package/dist/utils/fs.js.map +0 -1
  379. package/dist/utils/lock.js.map +0 -1
  380. package/dist/utils/logger.js.map +0 -1
  381. package/dist/utils/paths.js.map +0 -1
  382. package/dist/utils/proc.js.map +0 -1
  383. package/dist/verification/safety.js.map +0 -1
  384. package/dist/verification/scope.js.map +0 -1
@@ -3,6 +3,7 @@ import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { DevWorkspaceError } from '../../errors/index.js';
5
5
  import { atomicWriteJson, ensureDir, pathExists, readJsonFile } from '../../utils/fs.js';
6
+ import { withLock } from '../../utils/lock.js';
6
7
  import { computePackageDigest, verifyPackageIntegrityAndSignature } from './keys.js';
7
8
  import { checkCompatibility, parseAndValidateKnowledgePackage } from './package.js';
8
9
  import { KNOWLEDGE_PACKAGE_SCHEMA_VERSION, } from './types.js';
@@ -140,19 +141,26 @@ export class LocalPackageCache {
140
141
  const state = await this.loadState();
141
142
  return Object.values(state.active).sort((a, b) => a.packageId.localeCompare(b.packageId));
142
143
  }
144
+ async withCacheLock(fn) {
145
+ return withLock(this.cacheDir, fn, { name: 'cache.lock', timeoutMs: 10_000 });
146
+ }
143
147
  async pin(packageId, version) {
144
- const state = await this.loadState();
145
- const pkgExists = await pathExists(this.packageFilePath(packageId, version));
146
- if (!pkgExists) {
147
- throw new DevWorkspaceError('NOT_FOUND', `Cannot pin "${packageId}@${version}": version is not in local cache.`);
148
- }
149
- state.pinned[packageId] = version;
150
- await this.saveState(state);
148
+ return this.withCacheLock(async () => {
149
+ const state = await this.loadState();
150
+ const pkgExists = await pathExists(this.packageFilePath(packageId, version));
151
+ if (!pkgExists) {
152
+ throw new DevWorkspaceError('NOT_FOUND', `Cannot pin "${packageId}@${version}": version is not in local cache.`);
153
+ }
154
+ state.pinned[packageId] = version;
155
+ await this.saveState(state);
156
+ });
151
157
  }
152
158
  async unpin(packageId) {
153
- const state = await this.loadState();
154
- delete state.pinned[packageId];
155
- await this.saveState(state);
159
+ return this.withCacheLock(async () => {
160
+ const state = await this.loadState();
161
+ delete state.pinned[packageId];
162
+ await this.saveState(state);
163
+ });
156
164
  }
157
165
  async getPinnedVersion(packageId) {
158
166
  const state = await this.loadState();
@@ -208,204 +216,209 @@ export class LocalPackageCache {
208
216
  * Guarantee: Any validation, trust, signature, pin, or review failure leaves prior active package untouched.
209
217
  */
210
218
  async stageAndInstall(rawOrPkg, trustStore, options = {}) {
211
- // 1. Parse and enforce size, file count, path, archive, schema, and compatibility limits
212
- const pkg = parseAndValidateKnowledgePackage(rawOrPkg);
213
- const m = pkg.manifest;
214
- // 2. Cryptographic signature, digest, expiry, and key trust/revocation check
215
- const verification = verifyPackageIntegrityAndSignature(pkg, trustStore, options.now);
216
- if (!verification.valid) {
217
- throw new DevWorkspaceError('SECURITY', `Package verification failed for "${m.packageId}@${m.version}": ${verification.reason}`);
218
- }
219
- // 3. Stage payload atomically into temporary staging location first
220
- const pkgStageDir = path.join(this.stagingDir, m.packageId, m.version);
221
- await ensureDir(pkgStageDir);
222
- const stagedPkgFile = path.join(pkgStageDir, 'package.json');
223
- const stagedManifestFile = path.join(pkgStageDir, 'manifest.json');
224
- try {
225
- await atomicWriteJson(stagedManifestFile, pkg.manifest);
226
- await atomicWriteJson(stagedPkgFile, pkg);
227
- const state = await this.loadState();
228
- const pinnedVer = state.pinned[m.packageId];
229
- if (pinnedVer && pinnedVer !== m.version && !options.force) {
230
- throw new DevWorkspaceError('CONFLICT', `Package "${m.packageId}" is pinned to version "${pinnedVer}". Unpin or pass force to install "${m.version}".`);
219
+ return this.withCacheLock(async () => {
220
+ // 1. Parse and enforce size, file count, path, archive, schema, and compatibility limits
221
+ const pkg = parseAndValidateKnowledgePackage(rawOrPkg);
222
+ const m = pkg.manifest;
223
+ // 2. Cryptographic signature, digest, expiry, and key trust/revocation check
224
+ const verification = verifyPackageIntegrityAndSignature(pkg, trustStore, options.now);
225
+ if (!verification.valid) {
226
+ throw new DevWorkspaceError('SECURITY', `Package verification failed for "${m.packageId}@${m.version}": ${verification.reason}`);
231
227
  }
232
- // 4. Knowledge review/approval check
233
- const reviewKey = `${m.packageId}@${m.version}`;
234
- const locallyApproved = state.localReviews?.[reviewKey]?.status === 'APPROVED';
235
- if (m.provenance.reviewStatus !== 'APPROVED' && !locallyApproved && !options.allowUnreviewed) {
236
- // Keep staged copy for review, do NOT activate!
237
- const prior = state.active[m.packageId]?.version ?? null;
228
+ // 3. Stage payload atomically into temporary staging location first
229
+ const pkgStageDir = path.join(this.stagingDir, m.packageId, m.version);
230
+ await ensureDir(pkgStageDir);
231
+ const stagedPkgFile = path.join(pkgStageDir, 'package.json');
232
+ const stagedManifestFile = path.join(pkgStageDir, 'manifest.json');
233
+ try {
234
+ await atomicWriteJson(stagedManifestFile, pkg.manifest);
235
+ await atomicWriteJson(stagedPkgFile, pkg);
236
+ const state = await this.loadState();
237
+ const pinnedVer = state.pinned[m.packageId];
238
+ if (pinnedVer && pinnedVer !== m.version && !options.force) {
239
+ throw new DevWorkspaceError('CONFLICT', `Package "${m.packageId}" is pinned to version "${pinnedVer}". Unpin or pass force to install "${m.version}".`);
240
+ }
241
+ // 4. Knowledge review/approval check
242
+ const reviewKey = `${m.packageId}@${m.version}`;
243
+ const locallyApproved = state.localReviews?.[reviewKey]?.status === 'APPROVED';
244
+ if (m.provenance.reviewStatus !== 'APPROVED' && !locallyApproved && !options.allowUnreviewed) {
245
+ // Keep staged copy for review, do NOT activate!
246
+ const prior = state.active[m.packageId]?.version ?? null;
247
+ return {
248
+ installed: {
249
+ packageId: m.packageId,
250
+ version: m.version,
251
+ digest: m.digest,
252
+ keyId: m.keyId,
253
+ installedAt: new Date().toISOString(),
254
+ license: m.license,
255
+ provenance: m.provenance,
256
+ },
257
+ previousVersion: prior,
258
+ stagedOnly: true,
259
+ };
260
+ }
261
+ // 5. Commit package into immutable cached version directory
262
+ const targetDir = path.join(this.packagesDir, m.packageId, m.version);
263
+ await ensureDir(targetDir);
264
+ await atomicWriteJson(path.join(targetDir, 'manifest.json'), pkg.manifest);
265
+ await atomicWriteJson(path.join(targetDir, 'package.json'), pkg);
266
+ const priorActive = state.active[m.packageId] ?? null;
267
+ const now = new Date().toISOString();
268
+ if (priorActive) {
269
+ state.history.push({
270
+ packageId: priorActive.packageId,
271
+ version: priorActive.version,
272
+ digest: priorActive.digest,
273
+ replacedAt: now,
274
+ reason: 'update',
275
+ });
276
+ }
277
+ const record = {
278
+ packageId: m.packageId,
279
+ version: m.version,
280
+ digest: m.digest,
281
+ keyId: m.keyId,
282
+ installedAt: now,
283
+ license: m.license,
284
+ provenance: m.provenance,
285
+ };
286
+ state.active[m.packageId] = record;
287
+ await this.saveState(state);
288
+ // Clean up staging copy upon successful activation
289
+ await fs.rm(pkgStageDir, { recursive: true, force: true });
238
290
  return {
239
- installed: {
240
- packageId: m.packageId,
241
- version: m.version,
242
- digest: m.digest,
243
- keyId: m.keyId,
244
- installedAt: new Date().toISOString(),
245
- license: m.license,
246
- provenance: m.provenance,
247
- },
248
- previousVersion: prior,
249
- stagedOnly: true,
291
+ installed: record,
292
+ previousVersion: priorActive?.version ?? null,
293
+ stagedOnly: false,
250
294
  };
251
295
  }
252
- // 5. Commit package into immutable cached version directory
253
- const targetDir = path.join(this.packagesDir, m.packageId, m.version);
254
- await ensureDir(targetDir);
255
- await atomicWriteJson(path.join(targetDir, 'manifest.json'), pkg.manifest);
256
- await atomicWriteJson(path.join(targetDir, 'package.json'), pkg);
257
- const priorActive = state.active[m.packageId] ?? null;
258
- const now = new Date().toISOString();
259
- if (priorActive) {
260
- state.history.push({
261
- packageId: priorActive.packageId,
262
- version: priorActive.version,
263
- digest: priorActive.digest,
264
- replacedAt: now,
265
- reason: 'update',
266
- });
296
+ catch (err) {
297
+ // Ensure failed staging artifacts are cleaned up and prior active state remains intact
298
+ try {
299
+ await fs.rm(pkgStageDir, { recursive: true, force: true });
300
+ }
301
+ catch {
302
+ // ignore cleanup failure
303
+ }
304
+ throw err;
267
305
  }
268
- const record = {
269
- packageId: m.packageId,
270
- version: m.version,
271
- digest: m.digest,
272
- keyId: m.keyId,
273
- installedAt: now,
274
- license: m.license,
275
- provenance: m.provenance,
306
+ });
307
+ }
308
+ /** Records a local review/approval decision without mutating the signed package digest, optionally activating if APPROVED. */
309
+ async reviewStagedPackage(packageId, version, decision) {
310
+ return this.withCacheLock(async () => {
311
+ const stagedFile = path.join(this.stagingDir, packageId, version, 'package.json');
312
+ const cachedFile = this.packageFilePath(packageId, version);
313
+ const sourceFile = (await pathExists(stagedFile)) ? stagedFile : cachedFile;
314
+ if (!(await pathExists(sourceFile))) {
315
+ throw new DevWorkspaceError('NOT_FOUND', `No staged or cached package found for "${packageId}@${version}".`);
316
+ }
317
+ const pkg = await readJsonFile(sourceFile);
318
+ const now = new Date().toISOString();
319
+ const state = await this.loadState();
320
+ state.localReviews = state.localReviews ?? {};
321
+ state.localReviews[`${packageId}@${version}`] = {
322
+ packageId,
323
+ version,
324
+ status: decision.status,
325
+ reviewer: decision.reviewer,
326
+ reviewedAt: now,
327
+ reason: decision.reason,
276
328
  };
277
- state.active[m.packageId] = record;
329
+ if (decision.status === 'APPROVED' && decision.activate) {
330
+ if (decision.trustStore) {
331
+ const ver = verifyPackageIntegrityAndSignature(pkg, decision.trustStore);
332
+ if (!ver.valid) {
333
+ throw new DevWorkspaceError('SECURITY', `Cannot activate "${packageId}@${version}": ${ver.reason}`);
334
+ }
335
+ }
336
+ const targetDir = path.join(this.packagesDir, packageId, version);
337
+ await ensureDir(targetDir);
338
+ await atomicWriteJson(path.join(targetDir, 'manifest.json'), pkg.manifest);
339
+ await atomicWriteJson(path.join(targetDir, 'package.json'), pkg);
340
+ const priorActive = state.active[packageId];
341
+ if (priorActive) {
342
+ state.history.push({
343
+ packageId: priorActive.packageId,
344
+ version: priorActive.version,
345
+ digest: priorActive.digest,
346
+ replacedAt: now,
347
+ reason: 'install',
348
+ });
349
+ }
350
+ state.active[packageId] = {
351
+ packageId,
352
+ version,
353
+ digest: pkg.manifest.digest,
354
+ keyId: pkg.manifest.keyId,
355
+ installedAt: now,
356
+ license: pkg.manifest.license,
357
+ provenance: pkg.manifest.provenance,
358
+ };
359
+ if (await pathExists(stagedFile)) {
360
+ await fs.rm(path.join(this.stagingDir, packageId, version), { recursive: true, force: true });
361
+ }
362
+ }
278
363
  await this.saveState(state);
279
- // Clean up staging copy upon successful activation
280
- await fs.rm(pkgStageDir, { recursive: true, force: true });
281
- return {
282
- installed: record,
283
- previousVersion: priorActive?.version ?? null,
284
- stagedOnly: false,
285
- };
286
- }
287
- catch (err) {
288
- // Ensure failed staging artifacts are cleaned up and prior active state remains intact
289
- try {
290
- await fs.rm(pkgStageDir, { recursive: true, force: true });
364
+ return pkg;
365
+ });
366
+ }
367
+ /**
368
+ * Rolls back a cached package to a previous version in history (or explicit `targetVersion`).
369
+ * Re-verifies digest and optionally signature against `trustStore` before reactivating.
370
+ */
371
+ async rollback(packageId, targetVersion, trustStore) {
372
+ return this.withCacheLock(async () => {
373
+ const state = await this.loadState();
374
+ const current = state.active[packageId];
375
+ let chosenVersion = targetVersion;
376
+ if (!chosenVersion) {
377
+ // Pick most recent distinct version from history
378
+ const candidates = state.history
379
+ .filter((h) => h.packageId === packageId && h.version !== current?.version)
380
+ .reverse();
381
+ chosenVersion = candidates[0]?.version;
291
382
  }
292
- catch {
293
- // ignore cleanup failure
383
+ if (!chosenVersion) {
384
+ throw new DevWorkspaceError('NOT_FOUND', `No previous version found in rollback history for "${packageId}".`);
294
385
  }
295
- throw err;
296
- }
297
- }
298
- /** Records a local review/approval decision without mutating the signed package digest, optionally activating if APPROVED. */
299
- async reviewStagedPackage(packageId, version, decision) {
300
- const stagedFile = path.join(this.stagingDir, packageId, version, 'package.json');
301
- const cachedFile = this.packageFilePath(packageId, version);
302
- const sourceFile = (await pathExists(stagedFile)) ? stagedFile : cachedFile;
303
- if (!(await pathExists(sourceFile))) {
304
- throw new DevWorkspaceError('NOT_FOUND', `No staged or cached package found for "${packageId}@${version}".`);
305
- }
306
- const pkg = await readJsonFile(sourceFile);
307
- const now = new Date().toISOString();
308
- const state = await this.loadState();
309
- state.localReviews = state.localReviews ?? {};
310
- state.localReviews[`${packageId}@${version}`] = {
311
- packageId,
312
- version,
313
- status: decision.status,
314
- reviewer: decision.reviewer,
315
- reviewedAt: now,
316
- reason: decision.reason,
317
- };
318
- if (decision.status === 'APPROVED' && decision.activate) {
319
- if (decision.trustStore) {
320
- const ver = verifyPackageIntegrityAndSignature(pkg, decision.trustStore);
386
+ const pkg = await this.getInstalledPackage(packageId, chosenVersion);
387
+ if (!pkg) {
388
+ throw new DevWorkspaceError('NOT_FOUND', `Rollback target "${packageId}@${chosenVersion}" is missing from local cache.`);
389
+ }
390
+ const computedDigest = computePackageDigest(pkg);
391
+ if (computedDigest !== pkg.manifest.digest) {
392
+ throw new DevWorkspaceError('SECURITY', `Cached rollback package "${packageId}@${chosenVersion}" failed integrity digest check.`);
393
+ }
394
+ if (trustStore) {
395
+ const ver = verifyPackageIntegrityAndSignature(pkg, trustStore);
321
396
  if (!ver.valid) {
322
- throw new DevWorkspaceError('SECURITY', `Cannot activate "${packageId}@${version}": ${ver.reason}`);
397
+ throw new DevWorkspaceError('SECURITY', `Cannot rollback to "${packageId}@${chosenVersion}": ${ver.reason}`);
323
398
  }
324
399
  }
325
- const targetDir = path.join(this.packagesDir, packageId, version);
326
- await ensureDir(targetDir);
327
- await atomicWriteJson(path.join(targetDir, 'manifest.json'), pkg.manifest);
328
- await atomicWriteJson(path.join(targetDir, 'package.json'), pkg);
329
- const priorActive = state.active[packageId];
330
- if (priorActive) {
400
+ const now = new Date().toISOString();
401
+ if (current) {
331
402
  state.history.push({
332
- packageId: priorActive.packageId,
333
- version: priorActive.version,
334
- digest: priorActive.digest,
403
+ packageId: current.packageId,
404
+ version: current.version,
405
+ digest: current.digest,
335
406
  replacedAt: now,
336
- reason: 'install',
407
+ reason: 'rollback',
337
408
  });
338
409
  }
339
- state.active[packageId] = {
410
+ const record = {
340
411
  packageId,
341
- version,
412
+ version: chosenVersion,
342
413
  digest: pkg.manifest.digest,
343
414
  keyId: pkg.manifest.keyId,
344
415
  installedAt: now,
345
416
  license: pkg.manifest.license,
346
417
  provenance: pkg.manifest.provenance,
347
418
  };
348
- if (await pathExists(stagedFile)) {
349
- await fs.rm(path.join(this.stagingDir, packageId, version), { recursive: true, force: true });
350
- }
351
- }
352
- await this.saveState(state);
353
- return pkg;
354
- }
355
- /**
356
- * Rolls back a cached package to a previous version in history (or explicit `targetVersion`).
357
- * Re-verifies digest and optionally signature against `trustStore` before reactivating.
358
- */
359
- async rollback(packageId, targetVersion, trustStore) {
360
- const state = await this.loadState();
361
- const current = state.active[packageId];
362
- let chosenVersion = targetVersion;
363
- if (!chosenVersion) {
364
- // Pick most recent distinct version from history
365
- const candidates = state.history
366
- .filter((h) => h.packageId === packageId && h.version !== current?.version)
367
- .reverse();
368
- chosenVersion = candidates[0]?.version;
369
- }
370
- if (!chosenVersion) {
371
- throw new DevWorkspaceError('NOT_FOUND', `No previous version found in rollback history for "${packageId}".`);
372
- }
373
- const pkg = await this.getInstalledPackage(packageId, chosenVersion);
374
- if (!pkg) {
375
- throw new DevWorkspaceError('NOT_FOUND', `Rollback target "${packageId}@${chosenVersion}" is missing from local cache.`);
376
- }
377
- const computedDigest = computePackageDigest(pkg);
378
- if (computedDigest !== pkg.manifest.digest) {
379
- throw new DevWorkspaceError('SECURITY', `Cached rollback package "${packageId}@${chosenVersion}" failed integrity digest check.`);
380
- }
381
- if (trustStore) {
382
- const ver = verifyPackageIntegrityAndSignature(pkg, trustStore);
383
- if (!ver.valid) {
384
- throw new DevWorkspaceError('SECURITY', `Cannot rollback to "${packageId}@${chosenVersion}": ${ver.reason}`);
385
- }
386
- }
387
- const now = new Date().toISOString();
388
- if (current) {
389
- state.history.push({
390
- packageId: current.packageId,
391
- version: current.version,
392
- digest: current.digest,
393
- replacedAt: now,
394
- reason: 'rollback',
395
- });
396
- }
397
- const record = {
398
- packageId,
399
- version: chosenVersion,
400
- digest: pkg.manifest.digest,
401
- keyId: pkg.manifest.keyId,
402
- installedAt: now,
403
- license: pkg.manifest.license,
404
- provenance: pkg.manifest.provenance,
405
- };
406
- state.active[packageId] = record;
407
- await this.saveState(state);
408
- return record;
419
+ state.active[packageId] = record;
420
+ await this.saveState(state);
421
+ return record;
422
+ });
409
423
  }
410
424
  }
411
- //# sourceMappingURL=cache.js.map
@@ -4,4 +4,3 @@ export * from './package.js';
4
4
  export * from './cache.js';
5
5
  export * from './server.js';
6
6
  export * from './sync.js';
7
- //# sourceMappingURL=index.js.map
@@ -266,4 +266,3 @@ export class KeyTrustStore {
266
266
  };
267
267
  }
268
268
  }
269
- //# sourceMappingURL=keys.js.map
@@ -178,6 +178,7 @@ export function parseAndValidateKnowledgePackage(rawOrObj, currentDevWorkspaceVe
178
178
  if (manifest.files.length > MAX_PACKAGE_FILES) {
179
179
  throw new DevWorkspaceError('SECURITY', `Knowledge package file count (${manifest.files.length}) exceeds limit (${MAX_PACKAGE_FILES}).`);
180
180
  }
181
+ const seenPaths = new Set();
181
182
  for (const entry of manifest.files) {
182
183
  if (!entry || typeof entry !== 'object') {
183
184
  throw new DevWorkspaceError('SCHEMA', 'Invalid entry in manifest.files.');
@@ -186,6 +187,11 @@ export function parseAndValidateKnowledgePackage(rawOrObj, currentDevWorkspaceVe
186
187
  if (typeof f.path !== 'string' || typeof f.sha256 !== 'string' || typeof f.sizeBytes !== 'number') {
187
188
  throw new DevWorkspaceError('SCHEMA', 'Manifest file entry missing path, sha256, or sizeBytes.');
188
189
  }
190
+ const normKey = f.path.toLowerCase();
191
+ if (seenPaths.has(normKey)) {
192
+ throw new DevWorkspaceError('SECURITY', `Duplicate or conflicting package file path "${f.path}".`);
193
+ }
194
+ seenPaths.add(normKey);
189
195
  // Path traversal / archive zip-slip / sensitive file checks
190
196
  if (f.path.includes('..') || f.path.startsWith('/') || f.path.startsWith('\\') || /^[A-Za-z]:/.test(f.path)) {
191
197
  throw new DevWorkspaceError('SECURITY', `Unsafe archive/file path detected: "${f.path}".`);
@@ -245,4 +251,3 @@ export function parseAndValidateKnowledgePackage(rawOrObj, currentDevWorkspaceVe
245
251
  }
246
252
  return data;
247
253
  }
248
- //# sourceMappingURL=package.js.map
@@ -201,4 +201,3 @@ export class StaticKnowledgeDistributor {
201
201
  });
202
202
  }
203
203
  }
204
- //# sourceMappingURL=server.js.map
@@ -12,8 +12,13 @@ export interface SyncTransport {
12
12
  export declare function validateSyncRequest(input: Record<string, unknown>): GenericPackageSyncRequest;
13
13
  /** Creates an in-process transport backed by a StaticKnowledgeDistributor (home server handler). */
14
14
  export declare function createDistributorTransport(distributor: StaticKnowledgeDistributor): SyncTransport;
15
- /** Creates an explicit HTTP(S) transport using Web Fetch API for user-configured home server URLs. */
16
- export declare function createHttpSyncTransport(baseUrl: string, timeoutMs?: number): SyncTransport;
15
+ export interface HttpSyncTransportOptions {
16
+ timeoutMs?: number;
17
+ /** Allow plain HTTP for non-loopback hosts (default: false; HTTPS required for remote hosts). */
18
+ allowInsecureHttp?: boolean;
19
+ }
20
+ /** Creates an explicit HTTPS transport using Web Fetch API, blocking untrusted redirects and oversized payloads. */
21
+ export declare function createHttpSyncTransport(baseUrl: string, timeoutMsOrOpts?: number | HttpSyncTransportOptions): SyncTransport;
17
22
  export interface SyncPackageResult {
18
23
  package: KnowledgePackage;
19
24
  installed?: InstalledPackageRecord;
@@ -1,6 +1,6 @@
1
1
  import { DevWorkspaceError } from '../../errors/index.js';
2
2
  import { parseAndValidateKnowledgePackage } from './package.js';
3
- import { FORBIDDEN_SYNC_FIELDS, KNOWLEDGE_PACKAGE_SCHEMA_VERSION, } from './types.js';
3
+ import { FORBIDDEN_SYNC_FIELDS, KNOWLEDGE_PACKAGE_SCHEMA_VERSION, MAX_PACKAGE_BYTES, } from './types.js';
4
4
  const ALLOWED_SYNC_KEYS = new Set(['packageId', 'version', 'schemaVersion', 'targetPlatform']);
5
5
  const FORBIDDEN_SET = new Set(FORBIDDEN_SYNC_FIELDS.map((f) => f.toLowerCase()));
6
6
  /**
@@ -48,24 +48,57 @@ export function createDistributorTransport(distributor) {
48
48
  },
49
49
  };
50
50
  }
51
- /** Creates an explicit HTTP(S) transport using Web Fetch API for user-configured home server URLs. */
52
- export function createHttpSyncTransport(baseUrl, timeoutMs = 15_000) {
51
+ const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
52
+ /** Creates an explicit HTTPS transport using Web Fetch API, blocking untrusted redirects and oversized payloads. */
53
+ export function createHttpSyncTransport(baseUrl, timeoutMsOrOpts = 15_000) {
54
+ const opts = typeof timeoutMsOrOpts === 'number' ? { timeoutMs: timeoutMsOrOpts } : timeoutMsOrOpts;
55
+ const timeoutMs = opts.timeoutMs ?? 15_000;
56
+ const parsedBase = new URL(baseUrl);
57
+ const isLoopback = LOOPBACK_HOSTS.has(parsedBase.hostname.toLowerCase());
58
+ if (parsedBase.protocol !== 'https:' && !(parsedBase.protocol === 'http:' && (isLoopback || opts.allowInsecureHttp))) {
59
+ throw new DevWorkspaceError('SECURITY', `Refusing insecure home server URL protocol "${parsedBase.protocol}"; HTTPS is required for remote hosts.`);
60
+ }
53
61
  const normalizedBase = baseUrl.replace(/\/+$/, '');
54
62
  return {
55
63
  async get(reqPath, query) {
56
64
  const url = new URL(`${normalizedBase}${reqPath}`);
65
+ if (url.origin !== parsedBase.origin) {
66
+ throw new DevWorkspaceError('SECURITY', `Rejected cross-origin request target "${url.origin}".`);
67
+ }
57
68
  if (query) {
58
69
  for (const [k, v] of Object.entries(query)) {
59
70
  if (v !== undefined)
60
71
  url.searchParams.set(k, v);
61
72
  }
62
73
  }
63
- const res = await fetch(url.toString(), {
64
- method: 'GET',
65
- headers: { accept: 'application/json' },
66
- signal: AbortSignal.timeout(timeoutMs),
67
- });
74
+ let res;
75
+ try {
76
+ res = await fetch(url.toString(), {
77
+ method: 'GET',
78
+ headers: { accept: 'application/json' },
79
+ redirect: 'manual',
80
+ signal: AbortSignal.timeout(timeoutMs),
81
+ });
82
+ }
83
+ catch (err) {
84
+ const msg = err.message || String(err);
85
+ if (/cert|tls|ssl|self[- ]signed|unable to verify/i.test(msg)) {
86
+ throw new DevWorkspaceError('SECURITY', `TLS/certificate validation failed for "${parsedBase.origin}": ${msg}`);
87
+ }
88
+ throw err;
89
+ }
90
+ if (res.status >= 300 && res.status < 400) {
91
+ const location = res.headers.get('location') ?? 'unknown';
92
+ throw new DevWorkspaceError('SECURITY', `Rejected HTTP redirect (${res.status}) to "${location}"; redirects to untrusted hosts are disallowed.`);
93
+ }
94
+ const contentLen = Number(res.headers.get('content-length') ?? '0');
95
+ if (Number.isFinite(contentLen) && contentLen > MAX_PACKAGE_BYTES) {
96
+ throw new DevWorkspaceError('SECURITY', `Remote response (${contentLen} bytes) exceeds max limit (${MAX_PACKAGE_BYTES}).`);
97
+ }
68
98
  const body = await res.text();
99
+ if (Buffer.byteLength(body, 'utf8') > MAX_PACKAGE_BYTES) {
100
+ throw new DevWorkspaceError('SECURITY', `Remote payload exceeds max limit (${MAX_PACKAGE_BYTES} bytes).`);
101
+ }
69
102
  const headers = {};
70
103
  res.headers.forEach((value, key) => {
71
104
  headers[key.toLowerCase()] = value;
@@ -209,4 +242,3 @@ export class KnowledgeSyncClient {
209
242
  }
210
243
  }
211
244
  }
212
- //# sourceMappingURL=sync.js.map
@@ -23,4 +23,3 @@ export const FORBIDDEN_SYNC_FIELDS = [
23
23
  'facts',
24
24
  'context',
25
25
  ];
26
- //# sourceMappingURL=types.js.map
@@ -42,4 +42,3 @@ export function calculateComplianceSummary(results, totalApplicableStandards) {
42
42
  complianceLevel,
43
43
  };
44
44
  }
45
- //# sourceMappingURL=compliance.js.map
@@ -111,4 +111,3 @@ export class StandardsEngine {
111
111
  }
112
112
  }
113
113
  import path from 'node:path';
114
- //# sourceMappingURL=engine.js.map
@@ -39,4 +39,3 @@ export function renderStandardsAuditMarkdown(report) {
39
39
  }
40
40
  return lines.join('\n');
41
41
  }
42
- //# sourceMappingURL=reporter.js.map
@@ -16,4 +16,3 @@ export * from './config/config.js';
16
16
  export * from './templates/index.js';
17
17
  export * from './acquisition/ingest.js';
18
18
  export * from './distribution/index.js';
19
- //# sourceMappingURL=index.js.map
@@ -207,4 +207,3 @@ export class StandardsRegistry {
207
207
  };
208
208
  }
209
209
  }
210
- //# sourceMappingURL=registry.js.map
@@ -30,4 +30,3 @@ export const ENFORCEMENT_LEVELS = [
30
30
  'recommended',
31
31
  'optional',
32
32
  ];
33
- //# sourceMappingURL=types.js.map
@@ -128,4 +128,3 @@ export function validateStandardSchema(data) {
128
128
  return { valid: false, errors: [msg] };
129
129
  }
130
130
  }
131
- //# sourceMappingURL=validate.js.map
@@ -173,4 +173,3 @@ export const TEMPLATES = {
173
173
  'ADR.md': ADR_TEMPLATE,
174
174
  'TESTING.md': TESTING_TEMPLATE,
175
175
  };
176
- //# sourceMappingURL=index.js.map
@@ -119,4 +119,3 @@ export async function validateMigrationRollback(ctx) {
119
119
  };
120
120
  }
121
121
  export const validateExpandContractCheck = validateExpandAndContract;
122
- //# sourceMappingURL=database.js.map
@@ -88,4 +88,3 @@ export async function validateLint(ctx) {
88
88
  };
89
89
  }
90
90
  export const validateStrictModeCheck = validateStrictTypeScript;
91
- //# sourceMappingURL=quality.js.map