@xenosystem/agent-sdk 0.10.37 → 0.10.39

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 (57) hide show
  1. package/dist/artifacts/index.cjs +9 -9
  2. package/dist/artifacts/index.js +9 -9
  3. package/dist/artifacts/metafile-cjs.json +1 -1
  4. package/dist/artifacts/metafile-esm.json +1 -1
  5. package/dist/automation/index.cjs +8 -8
  6. package/dist/automation/index.d.cts +10 -0
  7. package/dist/automation/index.d.ts +10 -0
  8. package/dist/automation/index.js +9 -9
  9. package/dist/automation/metafile-cjs.json +1 -1
  10. package/dist/automation/metafile-esm.json +1 -1
  11. package/dist/control-plane/index.cjs +1 -1
  12. package/dist/control-plane/index.js +1 -1
  13. package/dist/electron/index.cjs +221 -200
  14. package/dist/electron/index.d.cts +91 -1
  15. package/dist/electron/index.d.ts +91 -1
  16. package/dist/electron/index.js +221 -200
  17. package/dist/electron/metafile-cjs.json +1 -1
  18. package/dist/electron/metafile-esm.json +1 -1
  19. package/dist/index.cjs +397 -372
  20. package/dist/index.d.cts +136 -4
  21. package/dist/index.d.ts +136 -4
  22. package/dist/index.js +397 -372
  23. package/dist/intelligence/index.cjs +9 -9
  24. package/dist/intelligence/index.js +9 -9
  25. package/dist/intelligence/metafile-cjs.json +1 -1
  26. package/dist/intelligence/metafile-esm.json +1 -1
  27. package/dist/mcp/index.d.cts +10 -0
  28. package/dist/mcp/index.d.ts +10 -0
  29. package/dist/metafile-cjs.json +1 -1
  30. package/dist/metafile-esm.json +1 -1
  31. package/dist/providers/index.cjs +9 -9
  32. package/dist/providers/index.js +9 -9
  33. package/dist/providers/metafile-cjs.json +1 -1
  34. package/dist/providers/metafile-esm.json +1 -1
  35. package/dist/recipes/index.cjs +2 -2
  36. package/dist/recipes/index.js +2 -2
  37. package/dist/recipes/metafile-cjs.json +1 -1
  38. package/dist/recipes/metafile-esm.json +1 -1
  39. package/dist/research/index.cjs +3 -3
  40. package/dist/research/index.js +3 -3
  41. package/dist/research/metafile-cjs.json +1 -1
  42. package/dist/research/metafile-esm.json +1 -1
  43. package/dist/session/index.cjs +25 -25
  44. package/dist/session/index.js +25 -25
  45. package/dist/session/metafile-cjs.json +1 -1
  46. package/dist/session/metafile-esm.json +1 -1
  47. package/dist/sharing/index.cjs +4 -4
  48. package/dist/sharing/index.js +4 -4
  49. package/dist/sharing/metafile-cjs.json +1 -1
  50. package/dist/sharing/metafile-esm.json +1 -1
  51. package/dist/utils/index.cjs +23 -23
  52. package/dist/utils/index.d.cts +15 -1
  53. package/dist/utils/index.d.ts +15 -1
  54. package/dist/utils/index.js +23 -23
  55. package/dist/utils/metafile-cjs.json +1 -1
  56. package/dist/utils/metafile-esm.json +1 -1
  57. package/package.json +3 -3
@@ -1 +1 @@
1
- {"inputs":{"src/session/id-generator.ts":{"bytes":870,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/fs.ts":{"bytes":13746,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/utils/json.ts":{"bytes":804,"imports":[],"format":"esm"},"src/utils/logger.ts":{"bytes":3719,"imports":[],"format":"esm"},"src/session/direct-shell.ts":{"bytes":2317,"imports":[],"format":"esm"},"src/session/transcript-pages.ts":{"bytes":9566,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/session/transcript.ts":{"bytes":18791,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"crypto","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/utils/logger.ts","kind":"import-statement","original":"../utils/logger.js"},{"path":"src/session/direct-shell.ts","kind":"import-statement","original":"./direct-shell.js"},{"path":"src/session/transcript-pages.ts","kind":"import-statement","original":"./transcript-pages.js"}],"format":"esm"},"src/tools/tool-names.ts":{"bytes":3779,"imports":[],"format":"esm"},"src/session/checkpoint.ts":{"bytes":5786,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"crypto","kind":"import-statement","external":true},{"path":"fs/promises","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/tools/tool-names.ts","kind":"import-statement","original":"../tools/tool-names.js"}],"format":"esm"},"src/runtime/shutdown.ts":{"bytes":7260,"imports":[],"format":"esm"},"src/version.ts":{"bytes":195,"imports":[],"format":"esm"},"src/session/lock.ts":{"bytes":10975,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"os","kind":"import-statement","external":true},{"path":"fs","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/utils/logger.ts","kind":"import-statement","original":"../utils/logger.js"},{"path":"src/runtime/shutdown.ts","kind":"import-statement","original":"../runtime/shutdown.js"},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"}],"format":"esm"},"src/types.ts":{"bytes":35885,"imports":[],"format":"esm"},"src/utils/path-security.ts":{"bytes":1762,"imports":[{"path":"path","kind":"import-statement","external":true}],"format":"esm"},"src/session/execution-mode.ts":{"bytes":313,"imports":[],"format":"esm"},"src/runtime/process-tree-kill.ts":{"bytes":9124,"imports":[{"path":"node:child_process","kind":"import-statement","external":true}],"format":"esm"},"src/utils/platform.ts":{"bytes":9633,"imports":[{"path":"node:os","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/runtime/process-tree-kill.ts","kind":"import-statement","original":"../runtime/process-tree-kill.js"}],"format":"esm"},"src/session/recent-sessions.ts":{"bytes":15374,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"os","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"}],"format":"esm"},"src/session/registry.ts":{"bytes":16366,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/utils/path-security.ts","kind":"import-statement","original":"../utils/path-security.js"},{"path":"src/session/execution-mode.ts","kind":"import-statement","original":"./execution-mode.js"},{"path":"src/session/recent-sessions.ts","kind":"import-statement","original":"./recent-sessions.js"},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"},{"path":"src/session/id-generator.ts","kind":"import-statement","original":"./id-generator.js"},{"path":"src/session/transcript.ts","kind":"import-statement","original":"./transcript.js"},{"path":"src/session/checkpoint.ts","kind":"import-statement","original":"./checkpoint.js"}],"format":"esm"},"src/utils/validation.ts":{"bytes":5336,"imports":[],"format":"esm"},"src/tools/runtime-context.ts":{"bytes":6152,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/path-security.ts","kind":"import-statement","original":"../utils/path-security.js"}],"format":"esm"},"src/tools/ask-user.ts":{"bytes":9295,"imports":[{"path":"src/utils/validation.ts","kind":"import-statement","original":"../utils/validation.js"},{"path":"src/tools/runtime-context.ts","kind":"import-statement","original":"./runtime-context.js"}],"format":"esm"},"src/session/recovery.ts":{"bytes":12359,"imports":[{"path":"src/session/checkpoint.ts","kind":"import-statement","original":"./checkpoint.js"},{"path":"src/session/transcript.ts","kind":"import-statement","original":"./transcript.js"},{"path":"src/tools/ask-user.ts","kind":"import-statement","original":"../tools/ask-user.js"}],"format":"esm"},"src/session/manager.ts":{"bytes":16015,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/session/transcript.ts","kind":"import-statement","original":"./transcript.js"},{"path":"src/session/checkpoint.ts","kind":"import-statement","original":"./checkpoint.js"},{"path":"src/session/lock.ts","kind":"import-statement","original":"./lock.js"},{"path":"src/session/registry.ts","kind":"import-statement","original":"./registry.js"},{"path":"src/session/id-generator.ts","kind":"import-statement","original":"./id-generator.js"},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/session/direct-shell.ts","kind":"import-statement","original":"./direct-shell.js"},{"path":"src/utils/logger.ts","kind":"import-statement","original":"../utils/logger.js"},{"path":"src/session/recovery.ts","kind":"import-statement","original":"./recovery.js"},{"path":"src/session/execution-mode.ts","kind":"import-statement","original":"./execution-mode.js"}],"format":"esm"},"src/session/turn-restore.ts":{"bytes":30751,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/tools/tool-names.ts","kind":"import-statement","original":"../tools/tool-names.js"},{"path":"src/utils/path-security.ts","kind":"import-statement","original":"../utils/path-security.js"}],"format":"esm"},"src/session/index.ts":{"bytes":1570,"imports":[{"path":"src/session/id-generator.ts","kind":"import-statement","original":"./id-generator.js"},{"path":"src/session/transcript.ts","kind":"import-statement","original":"./transcript.js"},{"path":"src/session/checkpoint.ts","kind":"import-statement","original":"./checkpoint.js"},{"path":"src/session/lock.ts","kind":"import-statement","original":"./lock.js"},{"path":"src/session/registry.ts","kind":"import-statement","original":"./registry.js"},{"path":"src/session/manager.ts","kind":"import-statement","original":"./manager.js"},{"path":"src/session/recovery.ts","kind":"import-statement","original":"./recovery.js"},{"path":"src/session/direct-shell.ts","kind":"import-statement","original":"./direct-shell.js"},{"path":"src/session/recent-sessions.ts","kind":"import-statement","original":"./recent-sessions.js"},{"path":"src/session/turn-restore.ts","kind":"import-statement","original":"./turn-restore.js"}],"format":"esm"}},"outputs":{"dist/session/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"crypto","kind":"import-statement","external":true},{"path":"fs/promises","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"os","kind":"import-statement","external":true},{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"os","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"exports":["CheckpointManager","DIRECT_SHELL_CONTEXT_WARNING","MAX_DIRECT_SHELL_OUTPUT_CHARS","SessionLock","SessionManager","SessionRegistry","TranscriptWriter","TurnRestoreManager","createDirectShellMessage","forgetRecentSession","forgetRecentSessionById","formatDirectShellContext","generateSessionId","getRecentSessionsIndexPath","isDirectShellMessage","isValidSessionId","loadRecentSessionsIndex","lookupRecentSession","normalizeDirectShellResultRecord","normalizeWorkingDirectory","parseSessionId","readSessionFormatVersion","recordRecentSession","recoverSessionMessages","repairInterruptedToolCalls"],"entryPoint":"src/session/index.ts","inputs":{"src/session/id-generator.ts":{"bytesInOutput":337},"src/session/index.ts":{"bytesInOutput":0},"src/session/transcript.ts":{"bytesInOutput":7903},"src/utils/fs.ts":{"bytesInOutput":1617},"src/utils/json.ts":{"bytesInOutput":170},"src/utils/logger.ts":{"bytesInOutput":489},"src/session/direct-shell.ts":{"bytesInOutput":1071},"src/session/transcript-pages.ts":{"bytesInOutput":3828},"src/session/checkpoint.ts":{"bytesInOutput":2301},"src/tools/tool-names.ts":{"bytesInOutput":242},"src/session/lock.ts":{"bytesInOutput":3729},"src/runtime/shutdown.ts":{"bytesInOutput":400},"src/version.ts":{"bytesInOutput":17},"src/session/registry.ts":{"bytesInOutput":5241},"src/types.ts":{"bytesInOutput":8},"src/utils/path-security.ts":{"bytesInOutput":400},"src/session/execution-mode.ts":{"bytesInOutput":136},"src/session/recent-sessions.ts":{"bytesInOutput":4301},"src/utils/platform.ts":{"bytesInOutput":254},"src/session/manager.ts":{"bytesInOutput":6018},"src/utils/validation.ts":{"bytesInOutput":216},"src/tools/runtime-context.ts":{"bytesInOutput":1351},"src/tools/ask-user.ts":{"bytesInOutput":2359},"src/session/recovery.ts":{"bytesInOutput":4340},"src/session/turn-restore.ts":{"bytesInOutput":13280}},"bytes":60706}}}
1
+ {"inputs":{"src/session/id-generator.ts":{"bytes":870,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/file-cache.ts":{"bytes":6195,"imports":[{"path":"node:fs","kind":"import-statement","external":true}],"format":"esm"},"src/utils/fs.ts":{"bytes":13885,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/file-cache.ts","kind":"import-statement","original":"./file-cache.js"}],"format":"esm"},"src/utils/json.ts":{"bytes":804,"imports":[],"format":"esm"},"src/utils/logger.ts":{"bytes":3719,"imports":[],"format":"esm"},"src/session/direct-shell.ts":{"bytes":2317,"imports":[],"format":"esm"},"src/session/transcript-pages.ts":{"bytes":9566,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/session/transcript.ts":{"bytes":18791,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"crypto","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/utils/logger.ts","kind":"import-statement","original":"../utils/logger.js"},{"path":"src/session/direct-shell.ts","kind":"import-statement","original":"./direct-shell.js"},{"path":"src/session/transcript-pages.ts","kind":"import-statement","original":"./transcript-pages.js"}],"format":"esm"},"src/tools/tool-names.ts":{"bytes":3779,"imports":[],"format":"esm"},"src/session/checkpoint.ts":{"bytes":5786,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"crypto","kind":"import-statement","external":true},{"path":"fs/promises","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/tools/tool-names.ts","kind":"import-statement","original":"../tools/tool-names.js"}],"format":"esm"},"src/runtime/shutdown.ts":{"bytes":7260,"imports":[],"format":"esm"},"src/version.ts":{"bytes":195,"imports":[],"format":"esm"},"src/session/lock.ts":{"bytes":10975,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"os","kind":"import-statement","external":true},{"path":"fs","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/utils/logger.ts","kind":"import-statement","original":"../utils/logger.js"},{"path":"src/runtime/shutdown.ts","kind":"import-statement","original":"../runtime/shutdown.js"},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"}],"format":"esm"},"src/types.ts":{"bytes":35885,"imports":[],"format":"esm"},"src/utils/path-security.ts":{"bytes":1762,"imports":[{"path":"path","kind":"import-statement","external":true}],"format":"esm"},"src/session/execution-mode.ts":{"bytes":313,"imports":[],"format":"esm"},"src/runtime/process-tree-kill.ts":{"bytes":9124,"imports":[{"path":"node:child_process","kind":"import-statement","external":true}],"format":"esm"},"src/utils/platform.ts":{"bytes":9633,"imports":[{"path":"node:os","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/runtime/process-tree-kill.ts","kind":"import-statement","original":"../runtime/process-tree-kill.js"}],"format":"esm"},"src/session/recent-sessions.ts":{"bytes":15374,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"os","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"}],"format":"esm"},"src/session/registry.ts":{"bytes":17155,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/file-cache.ts","kind":"import-statement","original":"../utils/file-cache.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/utils/path-security.ts","kind":"import-statement","original":"../utils/path-security.js"},{"path":"src/session/execution-mode.ts","kind":"import-statement","original":"./execution-mode.js"},{"path":"src/session/recent-sessions.ts","kind":"import-statement","original":"./recent-sessions.js"},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"},{"path":"src/session/id-generator.ts","kind":"import-statement","original":"./id-generator.js"},{"path":"src/session/transcript.ts","kind":"import-statement","original":"./transcript.js"},{"path":"src/session/checkpoint.ts","kind":"import-statement","original":"./checkpoint.js"}],"format":"esm"},"src/utils/validation.ts":{"bytes":5336,"imports":[],"format":"esm"},"src/tools/runtime-context.ts":{"bytes":6152,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/path-security.ts","kind":"import-statement","original":"../utils/path-security.js"}],"format":"esm"},"src/tools/ask-user.ts":{"bytes":9295,"imports":[{"path":"src/utils/validation.ts","kind":"import-statement","original":"../utils/validation.js"},{"path":"src/tools/runtime-context.ts","kind":"import-statement","original":"./runtime-context.js"}],"format":"esm"},"src/session/recovery.ts":{"bytes":12359,"imports":[{"path":"src/session/checkpoint.ts","kind":"import-statement","original":"./checkpoint.js"},{"path":"src/session/transcript.ts","kind":"import-statement","original":"./transcript.js"},{"path":"src/tools/ask-user.ts","kind":"import-statement","original":"../tools/ask-user.js"}],"format":"esm"},"src/session/manager.ts":{"bytes":16015,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/utils/json.ts","kind":"import-statement","original":"../utils/json.js"},{"path":"src/session/transcript.ts","kind":"import-statement","original":"./transcript.js"},{"path":"src/session/checkpoint.ts","kind":"import-statement","original":"./checkpoint.js"},{"path":"src/session/lock.ts","kind":"import-statement","original":"./lock.js"},{"path":"src/session/registry.ts","kind":"import-statement","original":"./registry.js"},{"path":"src/session/id-generator.ts","kind":"import-statement","original":"./id-generator.js"},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/session/direct-shell.ts","kind":"import-statement","original":"./direct-shell.js"},{"path":"src/utils/logger.ts","kind":"import-statement","original":"../utils/logger.js"},{"path":"src/session/recovery.ts","kind":"import-statement","original":"./recovery.js"},{"path":"src/session/execution-mode.ts","kind":"import-statement","original":"./execution-mode.js"}],"format":"esm"},"src/session/turn-restore.ts":{"bytes":30751,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/tools/tool-names.ts","kind":"import-statement","original":"../tools/tool-names.js"},{"path":"src/utils/path-security.ts","kind":"import-statement","original":"../utils/path-security.js"}],"format":"esm"},"src/session/index.ts":{"bytes":1570,"imports":[{"path":"src/session/id-generator.ts","kind":"import-statement","original":"./id-generator.js"},{"path":"src/session/transcript.ts","kind":"import-statement","original":"./transcript.js"},{"path":"src/session/checkpoint.ts","kind":"import-statement","original":"./checkpoint.js"},{"path":"src/session/lock.ts","kind":"import-statement","original":"./lock.js"},{"path":"src/session/registry.ts","kind":"import-statement","original":"./registry.js"},{"path":"src/session/manager.ts","kind":"import-statement","original":"./manager.js"},{"path":"src/session/recovery.ts","kind":"import-statement","original":"./recovery.js"},{"path":"src/session/direct-shell.ts","kind":"import-statement","original":"./direct-shell.js"},{"path":"src/session/recent-sessions.ts","kind":"import-statement","original":"./recent-sessions.js"},{"path":"src/session/turn-restore.ts","kind":"import-statement","original":"./turn-restore.js"}],"format":"esm"}},"outputs":{"dist/session/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"crypto","kind":"import-statement","external":true},{"path":"fs/promises","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"os","kind":"import-statement","external":true},{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"os","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"exports":["CheckpointManager","DIRECT_SHELL_CONTEXT_WARNING","MAX_DIRECT_SHELL_OUTPUT_CHARS","SessionLock","SessionManager","SessionRegistry","TranscriptWriter","TurnRestoreManager","createDirectShellMessage","forgetRecentSession","forgetRecentSessionById","formatDirectShellContext","generateSessionId","getRecentSessionsIndexPath","isDirectShellMessage","isValidSessionId","loadRecentSessionsIndex","lookupRecentSession","normalizeDirectShellResultRecord","normalizeWorkingDirectory","parseSessionId","readSessionFormatVersion","recordRecentSession","recoverSessionMessages","repairInterruptedToolCalls"],"entryPoint":"src/session/index.ts","inputs":{"src/session/id-generator.ts":{"bytesInOutput":337},"src/session/index.ts":{"bytesInOutput":0},"src/session/transcript.ts":{"bytesInOutput":7903},"src/utils/fs.ts":{"bytesInOutput":1637},"src/utils/file-cache.ts":{"bytesInOutput":1225},"src/utils/json.ts":{"bytesInOutput":170},"src/utils/logger.ts":{"bytesInOutput":489},"src/session/direct-shell.ts":{"bytesInOutput":1071},"src/session/transcript-pages.ts":{"bytesInOutput":3828},"src/session/checkpoint.ts":{"bytesInOutput":2301},"src/tools/tool-names.ts":{"bytesInOutput":242},"src/session/lock.ts":{"bytesInOutput":3729},"src/runtime/shutdown.ts":{"bytesInOutput":400},"src/version.ts":{"bytesInOutput":17},"src/session/registry.ts":{"bytesInOutput":5362},"src/types.ts":{"bytesInOutput":9},"src/utils/path-security.ts":{"bytesInOutput":400},"src/session/execution-mode.ts":{"bytesInOutput":136},"src/session/recent-sessions.ts":{"bytesInOutput":4301},"src/utils/platform.ts":{"bytesInOutput":254},"src/session/manager.ts":{"bytesInOutput":6020},"src/utils/validation.ts":{"bytesInOutput":216},"src/tools/runtime-context.ts":{"bytesInOutput":1351},"src/tools/ask-user.ts":{"bytesInOutput":2359},"src/session/recovery.ts":{"bytesInOutput":4340},"src/session/turn-restore.ts":{"bytesInOutput":13280}},"bytes":62075}}}
@@ -1,4 +1,4 @@
1
- "use strict";var oe=Object.create;var I=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var ue=(e,t)=>{for(var r in t)I(e,r,{get:t[r],enumerable:!0})},$=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ae(t))!de.call(e,i)&&i!==r&&I(e,i,{get:()=>t[i],enumerable:!(n=se(t,i))||n.enumerable});return e};var le=(e,t,r)=>(r=e!=null?oe(ce(e)):{},$(t||!e||!e.__esModule?I(r,"default",{value:e,enumerable:!0}):r,e)),fe=e=>$(I({},"__esModule",{value:!0}),e);var Ue={};ue(Ue,{FileXenoShareRegistry:()=>V,XENO_HANDOFF_SCHEMA_VERSION:()=>v,XENO_SHARE_REGISTRY_SCHEMA_VERSION:()=>x,XENO_SHARE_SCHEMA_VERSION:()=>A,createXenoSecureShare:()=>ke,createXenoSessionHandoff:()=>ve,createXenoShareSigningIdentity:()=>Re,publicKeyFingerprint:()=>_,redactXenoShareValue:()=>T,signSharePayload:()=>J,verifyXenoSecureShare:()=>Ae,verifyXenoSessionHandoff:()=>Pe});module.exports=fe(Ue);var A=2,v=1,x=1;var ge=/(?:^|[_-])(api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|auth(?:orization)?|bearer|secret|password|passwd|credential|cookie|private[_-]?key|client[_-]?secret)(?:$|[_-])/i,pe=/\b([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|PRIVATE_KEY|CLIENT_SECRET)[A-Z0-9_]*)\s*=\s*([^\s"']+)/g,he=/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,me=/\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[0-9A-Z]{16})\b/g,ye=/-----BEGIN (?:RSA |EC |OPENSSH |)PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH |)PRIVATE KEY-----/g,Se=/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi,we=/([?&#](?:access_token|refresh_token|token|key|secret|password|api[_-]?key|signature)=)[^&#\s]+/gi;function T(e,t={}){let r={options:{...t,redactEmails:t.redactEmails??!0,maxDepth:t.maxDepth??48,maxStringLength:t.maxStringLength??2e5,maxEvents:t.maxEvents??256},seen:new Set,events:[],byCategory:{},total:0};return{value:P(e,"$","",0,r),report:{schemaVersion:1,total:r.total,byCategory:r.byCategory,events:r.events,eventsTruncated:r.total>r.events.length}}}function h(e,t,r){e.total+=1,e.byCategory[r]=(e.byCategory[r]??0)+1,e.events.length<e.options.maxEvents&&e.events.push({path:t,category:r})}function P(e,t,r,n,i){if(ge.test(r))return e!=null&&e!==""&&h(i,t,"secret-field"),e==null||e===""?null:"[redacted]";if(n>i.options.maxDepth)return h(i,t,"truncated"),"[redacted:depth-limit]";if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="string")return Ie(e,t,i);if(e instanceof Date)return e.toISOString();if(e instanceof Uint8Array)return h(i,t,"binary"),`[redacted:binary:${e.byteLength}-bytes]`;if(Array.isArray(e)){if(i.seen.has(e))return h(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o=e.map((s,a)=>P(s,`${t}[${a}]`,"",n+1,i));return i.seen.delete(e),o}if(e&&typeof e=="object"){if(i.seen.has(e))return h(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o={};for(let[s,a]of Object.entries(e))o[s]=P(a,`${t}.${Ee(s)}`,s,n+1,i);return i.seen.delete(e),o}return null}function Ie(e,t,r){let n=e;return n=p(n,ye,"[redacted:private-key]",t,"private-key",r),n=p(n,he,"$1[redacted]",t,"authorization",r),n=p(n,me,"[redacted:credential]",t,"credential-pattern",r),n=p(n,pe,"$1=[redacted]",t,"environment-secret",r),n=p(n,we,"$1[redacted]",t,"url-secret",r),r.options.redactEmails&&(n=p(n,Se,"[redacted:email]",t,"email",r)),n=F(n,r.options.workspaceRoot,"<workspace>",t,"workspace-path",r),n=F(n,r.options.homeDirectory,"<home>",t,"home-path",r),n.length>r.options.maxStringLength&&(h(r,t,"truncated"),n=`${n.slice(0,r.options.maxStringLength)}
2
- [truncated]`),n}function p(e,t,r,n,i,o){t.lastIndex=0;let s=0,a=e.replace(t,(...d)=>(s+=1,r.includes("$1")?r.replace("$1",String(d[1]??"")):r));for(let d=0;d<s;d+=1)h(o,n,i);return t.lastIndex=0,a}function F(e,t,r,n,i,o){let s=t?.trim().replace(/[\\/]+$/,"");if(!s)return e;let a=new RegExp(xe(s).replace(/[\\/]+/g,"[\\\\/]"),process.platform==="win32"?"gi":"g");return p(e,a,r,n,i,o)}function xe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ee(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}var c=require("node:crypto");function S(e){return JSON.stringify(C(e,new Set))}function C(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(i=>C(i,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((i,o)=>i.localeCompare(o))){let i=e[n];if(i===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=C(i,t)}return t.delete(e),r}function w(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}var Xe=10080*60*1e3,be=365*24*60*60*1e3;function Re(){let{publicKey:e,privateKey:t}=(0,c.generateKeyPairSync)("ed25519"),r=e.export({type:"spki",format:"pem"}).toString(),n=t.export({type:"pkcs8",format:"pem"}).toString();return{keyId:_(r),publicKeyPem:r,privateKeyPem:n}}function _(e){let t=(0,c.createPublicKey)(e).export({type:"spki",format:"der"});return`ed25519:${(0,c.createHash)("sha256").update(t).digest("hex").slice(0,32)}`}function ke(e){let t=e.now??new Date,r=t.toISOString(),n=M(t,e.expiresAt,e.ttlMs),i=(0,c.randomBytes)(32).toString("base64url"),o=T(e.content,e.redaction),s=e.visibility??"private";Le(s,e.workspaceId,e.teamId,e.allowedPrincipalIds);let a={schemaVersion:2,kind:"xeno-secure-share",shareId:u(e.shareId??`share_${(0,c.randomUUID)()}`,"shareId"),createdAt:r,expiresAt:n,issuer:j(e.issuer),session:q({...e.session,name:e.session.name??e.name}),access:{mode:"read-only",visibility:s,...e.workspaceId?{workspaceId:u(e.workspaceId,"workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"teamId")}:{},...e.allowedPrincipalIds?.length?{allowedPrincipalIds:X(e.allowedPrincipalIds,"allowedPrincipalIds")}:{},capabilityToken:{algorithm:"sha256",hash:W(i)}},content:o.value,references:z(e.references??[]),redaction:o.report};return{envelope:J(a,e.signingIdentity),capabilityToken:i,url:Oe(e.baseUrl,a.shareId,i)}}function J(e,t){if(t.keyId!==_(t.publicKeyPem))throw new Error("Signing identity keyId does not match public key");let r=B(e,t);return{payload:e,signature:r}}function Ae(e,t={}){let r=[],n=!1,i=!1;if(e?.payload?.kind!=="xeno-secure-share"||e.payload.schemaVersion!==2)r.push("Unsupported secure-share envelope");else{let H=U(t.trustedPublicKeys,e.signature.keyId),D=H??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki);if(i=!!H,!D)r.push("No trusted or embedded issuer public key is available");else try{n=K(e.payload,e.signature,D),n||r.push("Share signature is invalid")}catch(k){r.push(k instanceof Error?k.message:String(k))}}let o=(t.now??new Date).getTime(),s=Date.parse(e?.payload?.expiresAt??""),d=t.revokedShareIds?.has(e?.payload?.shareId??"")??!1?"revoked":Number.isFinite(s)&&s<=o?"expired":"active";d==="revoked"&&r.push("Share has been revoked"),d==="expired"&&r.push("Share has expired");let y=Te(e?.payload,t.capabilityToken);y||r.push("Capability token is missing or invalid");let R=Ce(e?.payload,t.principal);return R||r.push("Principal is outside the share audience"),{valid:n&&y&&R&&d==="active",integrityValid:n,issuerTrusted:i,capabilityValid:y,audienceAllowed:R,status:d,errors:r}}function ve(e){let t=e.now??new Date,r={schemaVersion:1,kind:"xeno-session-handoff",handoffId:u(e.handoffId??`handoff_${(0,c.randomUUID)()}`,"handoffId"),createdAt:t.toISOString(),expiresAt:M(t,e.expiresAt,e.ttlMs??1440*60*1e3),issuer:j(e.issuer),source:q(e.source),target:_e(e.target),resume:Ne(e.resume),authority:Ve(e.authority),references:z(e.references??[]),...e.shareId?{shareId:u(e.shareId,"shareId")}:{}};return{payload:r,signature:B(r,e.signingIdentity)}}function Pe(e,t={}){let r=[];if(e?.payload?.kind!=="xeno-session-handoff"||e.payload.schemaVersion!==1)return{valid:!1,integrityValid:!1,issuerTrusted:!1,expired:!1,errors:["Unsupported handoff envelope"]};let n=U(t.trustedPublicKeys,e.signature.keyId),i=n??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki),o=!!n,s=!1;if(!i)r.push("No trusted or embedded issuer public key is available");else try{s=K(e.payload,e.signature,i),s||r.push("Handoff signature is invalid")}catch(d){r.push(d instanceof Error?d.message:String(d))}let a=Date.parse(e.payload.expiresAt)<=(t.now??new Date).getTime();return a&&r.push("Handoff has expired"),{valid:s&&!a,integrityValid:s,issuerTrusted:o,expired:a,errors:r}}function B(e,t){let r=S(e),n=(0,c.sign)(null,Buffer.from(r),(0,c.createPrivateKey)(t.privateKeyPem)).toString("base64");return{algorithm:"ed25519",keyId:t.keyId,value:n,publicKeySpki:t.publicKeyPem}}function K(e,t,r){if(t.algorithm!=="ed25519")return!1;let n=Buffer.from(t.value,"base64");if(n.toString("base64")!==t.value)throw new Error("Signature is not canonical base64");return(0,c.verify)(null,Buffer.from(S(e)),(0,c.createPublicKey)(r),n)}function Te(e,t){if(!e||!t)return!1;let r=Buffer.from(e.access.capabilityToken.hash,"hex"),n=Buffer.from(W(t),"hex");return r.length===n.length&&(0,c.timingSafeEqual)(r,n)}function Ce(e,t){if(!e)return!1;let r=e.access;return r.allowedPrincipalIds?.length&&(!t?.id||!r.allowedPrincipalIds.includes(t.id))?!1:r.visibility==="workspace"?!!(t?.workspaceId&&t.workspaceId===r.workspaceId):r.visibility==="team"?!!(r.teamId&&t?.teamIds?.includes(r.teamId)):r.visibility==="private"?!!(t?.id&&t.id===e.issuer.id):r.visibility==="link"}function Oe(e,t,r){let n=new URL(e??"xeno://share/");if(n.username||n.password)throw new Error("Share base URL cannot contain credentials");if(n.protocol!=="https:"&&n.protocol!=="xeno:")throw new Error("Share base URL must use https: or xeno:");return n.pathname=`${n.pathname.replace(/\/$/,"")}/${encodeURIComponent(t)}`,n.search="",n.hash=new URLSearchParams({access_token:r}).toString(),n.toString()}function M(e,t,r=Xe){let n=t?new Date(t):new Date(e.getTime()+r);if(!Number.isFinite(n.getTime()))throw new Error("expiresAt must be a valid timestamp");let i=n.getTime()-e.getTime();if(i<=0)throw new Error("expiresAt must be in the future");if(i>be)throw new Error("Share and handoff expiry cannot exceed 365 days");return n.toISOString()}function j(e){return{id:u(e.id,"issuer.id"),...e.displayName?.trim()?{displayName:e.displayName.trim().slice(0,160)}:{},...e.workspaceId?{workspaceId:u(e.workspaceId,"issuer.workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"issuer.teamId")}:{}}}function q(e){let t={name:E(e.name,"session.name",200),surface:e.surface};for(let r of["sessionId","runId","hostedRunId","conversationId","parentSessionId","forkedFromSessionId","forkedAtEventId"])e[r]&&(t[r]=u(e[r],`session.${r}`));if(!t.sessionId&&!t.runId&&!t.hostedRunId&&!t.conversationId)throw new Error("Session identity requires sessionId, runId, hostedRunId, or conversationId");return e.git&&(t.git={...e.git.repositoryId?{repositoryId:u(e.git.repositoryId,"git.repositoryId")}:{},...e.git.remoteUrl?{remoteUrl:O(e.git.remoteUrl,"git.remoteUrl")}:{},...e.git.branch?{branch:E(e.git.branch,"git.branch",300)}:{},...e.git.commit?{commit:Z(e.git.commit,"git.commit")}:{},...e.git.pullRequest?{pullRequest:{provider:e.git.pullRequest.provider,repository:E(e.git.pullRequest.repository,"git.pullRequest.repository",300),number:He(e.git.pullRequest.number,"git.pullRequest.number"),...e.git.pullRequest.url?{url:O(e.git.pullRequest.url,"git.pullRequest.url")}:{}}}:{}}),t}function z(e){let t=new Set;return e.map(r=>{let n=`${r.kind}:${r.id}`;if(t.has(n))throw new Error(`Duplicate share reference: ${n}`);return t.add(n),{kind:r.kind,id:u(r.id,"reference.id"),...r.title?.trim()?{title:r.title.trim().slice(0,300)}:{},...r.uri?{uri:O(r.uri,"reference.uri")}:{},...r.hash?{hash:Z(r.hash,"reference.hash")}:{}}})}function _e(e){return{surface:e.surface,...e.workspaceId?{workspaceId:u(e.workspaceId,"target.workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"target.teamId")}:{},...e.environmentId?{environmentId:u(e.environmentId,"target.environmentId")}:{},...e.repositoryId?{repositoryId:u(e.repositoryId,"target.repositoryId")}:{}}}function Ne(e){let t={};for(let r of["sessionId","runId","hostedRunId","checkpointId","transcriptEventId"])e[r]&&(t[r]=u(e[r],`resume.${r}`));if(e.artifactIds?.length&&(t.artifactIds=X(e.artifactIds,"resume.artifactIds")),e.taskIds?.length&&(t.taskIds=X(e.taskIds,"resume.taskIds")),!Object.keys(t).length)throw new Error("Handoff resume point cannot be empty");return t}function Ve(e){return{filesystem:e.filesystem,network:e.network,externalActions:e.externalActions,secretRefs:X(e.secretRefs,"authority.secretRefs")}}function Le(e,t,r,n){if(e==="workspace"&&!t)throw new Error("workspace visibility requires workspaceId");if(e==="team"&&!r)throw new Error("team visibility requires teamId");if(e==="private"&&n?.length)throw new Error("private shares cannot add allowed principals; use link/workspace/team visibility")}function U(e,t){if(!e)return;let r=e;return typeof r.get=="function"?r.get(t):e[t]}function W(e){return(0,c.createHash)("sha256").update(e).digest("hex")}function X(e,t){return[...new Set(e.map(r=>u(r,t)))].sort()}function u(e,t){let r=e.trim();if(!r||r.length>500||w(r))throw new Error(`${t} is invalid`);return r}function Z(e,t){let r=e.trim();if(!/^[A-Za-z0-9:+._-]{7,256}$/.test(r))throw new Error(`${t} is invalid`);return r}function E(e,t,r){let n=e.trim();if(!n||n.length>r||w(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function He(e,t){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${t} must be a positive integer`);return e}function O(e,t){let r=E(e,t,2e3),n=new URL(r);if(n.username||n.password)throw new Error(`${t} cannot contain credentials`);if(!["https:","xeno:","artifact:","urn:"].includes(n.protocol))throw new Error(`${t} uses an unsupported scheme`);return n.toString()}var L=require("node:crypto"),l=require("node:fs/promises"),m=require("node:path");var f=le(require("node:fs/promises"),1);var De=new Set(["EACCES","EBUSY","EPERM"]),$e=[10,20,40,80,160,320,640];async function Y(e,t){for(let r=0;;r+=1)try{await f.rename(e,t);return}catch(n){let i=n.code,o=$e[r];if(process.platform!=="win32"||!i||!De.has(i)||o===void 0)throw n;await new Promise(s=>setTimeout(s,o))}}var g=require("node:fs"),N=require("node:os"),Q=require("node:path");function Fe(){return new Date().toISOString()}function Je(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function ee(e){try{return JSON.parse((0,g.readFileSync)(e,"utf8"))}catch{return null}}function Be(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function Ke(e){return e.hostname!==(0,N.hostname)()?!0:Be(e.pid)}function G(e,t){(0,g.mkdirSync)((0,Q.dirname)(e),{recursive:!0}),(0,g.writeFileSync)(e,JSON.stringify(t,null,2)+`
3
- `,{encoding:"utf8",flag:"wx"})}function Me(e,t){let r=ee(e);r?.pid!==t.pid||r.hostname!==t.hostname||(0,g.rmSync)(e,{force:!0})}function te(e,t,r){let n=Fe(),i={schemaVersion:1,name:t,pid:process.pid,hostname:(0,N.hostname)(),processStartedAt:Je(),version:r,acquiredAt:n,updatedAt:n};try{G(e,i)}catch(o){if(o.code!=="EEXIST")throw o;let a=ee(e);if(a&&Ke(a))throw new Error(`${t} is already locked by PID ${a.pid} on ${a.hostname}.`);(0,g.rmSync)(e,{force:!0}),G(e,i)}return{record:i,release:()=>{Me(e,i)}}}var V=class{directory;snapshotPath;lockPath;now;constructor(t){this.directory=(0,m.resolve)(t.directory),this.snapshotPath=(0,m.join)(this.directory,"registry.json"),this.lockPath=(0,m.join)(this.directory,"registry.lock"),this.now=t.now??(()=>new Date)}async register(t,r="created"){return this.mutate(n=>{let i=n.records.find(s=>s.shareId===t.payload.shareId);if(i){if(b(i.envelope)!==b(t))throw new Error(`Share ${t.payload.shareId} already exists with different content`);return{snapshot:n,result:i}}let o={shareId:t.payload.shareId,envelope:t,status:Date.parse(t.payload.expiresAt)<=this.now().getTime()?"expired":"active",registeredAt:this.now().toISOString(),origin:r};return{snapshot:re(n,[...n.records,o],this.now()),result:o}})}async revoke(t,r,n){return this.mutate(i=>{let o=i.records.findIndex(y=>y.shareId===t);if(o<0)throw new Error(`Share not found: ${t}`);let s=i.records[o];if(s.status==="revoked")return{snapshot:i,result:s};let a={...s,status:"revoked",revokedAt:this.now().toISOString(),revokedBy:ne(r,"actor"),revocationReason:ne(n,"reason")},d=[...i.records];return d[o]=a,{snapshot:re(i,d,this.now()),result:a}})}async get(t){return(await this.load()).records.find(r=>r.shareId===t)??null}async list(){let t=this.now().getTime();return(await this.load()).records.map(r=>r.status==="active"&&Date.parse(r.envelope.payload.expiresAt)<=t?{...r,status:"expired"}:r).sort((r,n)=>n.registeredAt.localeCompare(r.registeredAt))}async revokedIds(){return new Set((await this.list()).filter(t=>t.status==="revoked").map(t=>t.shareId))}async load(){try{let t=await(0,l.readFile)(this.snapshotPath,"utf8"),r=JSON.parse(t);return qe(r),r}catch(t){if(t.code==="ENOENT")return je(this.now());throw t}}async mutate(t){await(0,l.mkdir)(this.directory,{recursive:!0,mode:448});let r=te(this.lockPath,"xeno secure-share registry","1");try{let n=await this.load(),{snapshot:i,result:o}=t(n);return i!==n&&await ze(this.snapshotPath,`${JSON.stringify(i,null,2)}
4
- `),o}finally{r.release()}}};function je(e){return ie({schemaVersion:1,generation:0,updatedAt:e.toISOString(),records:[]})}function re(e,t,r){return ie({schemaVersion:1,generation:e.generation+1,updatedAt:r.toISOString(),records:[...t].sort((n,i)=>n.shareId.localeCompare(i.shareId))})}function ie(e){return{...e,checksum:{algorithm:"sha256",value:(0,L.createHash)("sha256").update(b(e)).digest("hex")}}}function qe(e){if(e.schemaVersion!==1||!Array.isArray(e.records))throw new Error("Invalid secure-share registry snapshot");let{checksum:t,...r}=e,n=(0,L.createHash)("sha256").update(b(r)).digest("hex");if(t?.algorithm!=="sha256"||t.value!==n)throw new Error("Secure-share registry checksum mismatch");let i=new Set;for(let o of e.records){if(o.shareId!==o.envelope?.payload?.shareId)throw new Error("Secure-share registry identity mismatch");if(i.has(o.shareId))throw new Error(`Duplicate secure-share registry record: ${o.shareId}`);i.add(o.shareId)}}async function ze(e,t){await(0,l.mkdir)((0,m.dirname)(e),{recursive:!0,mode:448});let r=`${e}.${process.pid}.${Date.now()}.tmp`,n;try{n=await(0,l.open)(r,"wx",384),await n.writeFile(t,"utf8"),await n.sync(),await n.close(),n=void 0,await Y(r,e),await(0,l.chmod)(e,384).catch(()=>{})}finally{n&&await n.close().catch(()=>{}),await(0,l.unlink)(r).catch(()=>{})}}function b(e){return S(e)}function ne(e,t){let r=e.trim();if(!r||r.length>500||w(r))throw new Error(`${t} is invalid`);return r}0&&(module.exports={FileXenoShareRegistry,XENO_HANDOFF_SCHEMA_VERSION,XENO_SHARE_REGISTRY_SCHEMA_VERSION,XENO_SHARE_SCHEMA_VERSION,createXenoSecureShare,createXenoSessionHandoff,createXenoShareSigningIdentity,publicKeyFingerprint,redactXenoShareValue,signSharePayload,verifyXenoSecureShare,verifyXenoSessionHandoff});
1
+ "use strict";var ce=Object.create;var x=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty;var ge=(e,t)=>{for(var r in t)x(e,r,{get:t[r],enumerable:!0})},$=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ue(t))!fe.call(e,i)&&i!==r&&x(e,i,{get:()=>t[i],enumerable:!(n=de(t,i))||n.enumerable});return e};var he=(e,t,r)=>(r=e!=null?ce(le(e)):{},$(t||!e||!e.__esModule?x(r,"default",{value:e,enumerable:!0}):r,e)),pe=e=>$(x({},"__esModule",{value:!0}),e);var Ye={};ge(Ye,{FileXenoShareRegistry:()=>L,XENO_HANDOFF_SCHEMA_VERSION:()=>v,XENO_SHARE_REGISTRY_SCHEMA_VERSION:()=>E,XENO_SHARE_SCHEMA_VERSION:()=>A,createXenoSecureShare:()=>Te,createXenoSessionHandoff:()=>Pe,createXenoShareSigningIdentity:()=>ve,publicKeyFingerprint:()=>N,redactXenoShareValue:()=>C,signSharePayload:()=>J,verifyXenoSecureShare:()=>Ce,verifyXenoSessionHandoff:()=>Oe});module.exports=pe(Ye);var A=2,v=1,E=1;var me=/(?:^|[_-])(api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|auth(?:orization)?|bearer|secret|password|passwd|credential|cookie|private[_-]?key|client[_-]?secret)(?:$|[_-])/i,ye=/\b([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|PRIVATE_KEY|CLIENT_SECRET)[A-Z0-9_]*)\s*=\s*([^\s"']+)/g,Se=/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,we=/\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[0-9A-Z]{16})\b/g,xe=/-----BEGIN (?:RSA |EC |OPENSSH |)PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH |)PRIVATE KEY-----/g,Ee=/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi,Ie=/([?&#](?:access_token|refresh_token|token|key|secret|password|api[_-]?key|signature)=)[^&#\s]+/gi;function C(e,t={}){let r={options:{...t,redactEmails:t.redactEmails??!0,maxDepth:t.maxDepth??48,maxStringLength:t.maxStringLength??2e5,maxEvents:t.maxEvents??256},seen:new Set,events:[],byCategory:{},total:0};return{value:T(e,"$","",0,r),report:{schemaVersion:1,total:r.total,byCategory:r.byCategory,events:r.events,eventsTruncated:r.total>r.events.length}}}function p(e,t,r){e.total+=1,e.byCategory[r]=(e.byCategory[r]??0)+1,e.events.length<e.options.maxEvents&&e.events.push({path:t,category:r})}function T(e,t,r,n,i){if(me.test(r))return e!=null&&e!==""&&p(i,t,"secret-field"),e==null||e===""?null:"[redacted]";if(n>i.options.maxDepth)return p(i,t,"truncated"),"[redacted:depth-limit]";if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="string")return be(e,t,i);if(e instanceof Date)return e.toISOString();if(e instanceof Uint8Array)return p(i,t,"binary"),`[redacted:binary:${e.byteLength}-bytes]`;if(Array.isArray(e)){if(i.seen.has(e))return p(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o=e.map((s,a)=>T(s,`${t}[${a}]`,"",n+1,i));return i.seen.delete(e),o}if(e&&typeof e=="object"){if(i.seen.has(e))return p(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o={};for(let[s,a]of Object.entries(e))o[s]=T(a,`${t}.${Re(s)}`,s,n+1,i);return i.seen.delete(e),o}return null}function be(e,t,r){let n=e;return n=h(n,xe,"[redacted:private-key]",t,"private-key",r),n=h(n,Se,"$1[redacted]",t,"authorization",r),n=h(n,we,"[redacted:credential]",t,"credential-pattern",r),n=h(n,ye,"$1=[redacted]",t,"environment-secret",r),n=h(n,Ie,"$1[redacted]",t,"url-secret",r),r.options.redactEmails&&(n=h(n,Ee,"[redacted:email]",t,"email",r)),n=B(n,r.options.workspaceRoot,"<workspace>",t,"workspace-path",r),n=B(n,r.options.homeDirectory,"<home>",t,"home-path",r),n.length>r.options.maxStringLength&&(p(r,t,"truncated"),n=`${n.slice(0,r.options.maxStringLength)}
2
+ [truncated]`),n}function h(e,t,r,n,i,o){t.lastIndex=0;let s=0,a=e.replace(t,(...d)=>(s+=1,r.includes("$1")?r.replace("$1",String(d[1]??"")):r));for(let d=0;d<s;d+=1)p(o,n,i);return t.lastIndex=0,a}function B(e,t,r,n,i,o){let s=t?.trim().replace(/[\\/]+$/,"");if(!s)return e;let a=new RegExp(Xe(s).replace(/[\\/]+/g,"[\\\\/]"),process.platform==="win32"?"gi":"g");return h(e,a,r,n,i,o)}function Xe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Re(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}var c=require("node:crypto");function S(e){return JSON.stringify(P(e,new Set))}function P(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(i=>P(i,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((i,o)=>i.localeCompare(o))){let i=e[n];if(i===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=P(i,t)}return t.delete(e),r}function w(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}var ke=10080*60*1e3,Ae=365*24*60*60*1e3;function ve(){let{publicKey:e,privateKey:t}=(0,c.generateKeyPairSync)("ed25519"),r=e.export({type:"spki",format:"pem"}).toString(),n=t.export({type:"pkcs8",format:"pem"}).toString();return{keyId:N(r),publicKeyPem:r,privateKeyPem:n}}function N(e){let t=(0,c.createPublicKey)(e).export({type:"spki",format:"der"});return`ed25519:${(0,c.createHash)("sha256").update(t).digest("hex").slice(0,32)}`}function Te(e){let t=e.now??new Date,r=t.toISOString(),n=z(t,e.expiresAt,e.ttlMs),i=(0,c.randomBytes)(32).toString("base64url"),o=C(e.content,e.redaction),s=e.visibility??"private";De(s,e.workspaceId,e.teamId,e.allowedPrincipalIds);let a={schemaVersion:2,kind:"xeno-secure-share",shareId:u(e.shareId??`share_${(0,c.randomUUID)()}`,"shareId"),createdAt:r,expiresAt:n,issuer:j(e.issuer),session:q({...e.session,name:e.session.name??e.name}),access:{mode:"read-only",visibility:s,...e.workspaceId?{workspaceId:u(e.workspaceId,"workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"teamId")}:{},...e.allowedPrincipalIds?.length?{allowedPrincipalIds:b(e.allowedPrincipalIds,"allowedPrincipalIds")}:{},capabilityToken:{algorithm:"sha256",hash:Z(i)}},content:o.value,references:U(e.references??[]),redaction:o.report};return{envelope:J(a,e.signingIdentity),capabilityToken:i,url:Ve(e.baseUrl,a.shareId,i)}}function J(e,t){if(t.keyId!==N(t.publicKeyPem))throw new Error("Signing identity keyId does not match public key");let r=M(e,t);return{payload:e,signature:r}}function Ce(e,t={}){let r=[],n=!1,i=!1;if(e?.payload?.kind!=="xeno-secure-share"||e.payload.schemaVersion!==2)r.push("Unsupported secure-share envelope");else{let F=W(t.trustedPublicKeys,e.signature.keyId),D=F??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki);if(i=!!F,!D)r.push("No trusted or embedded issuer public key is available");else try{n=K(e.payload,e.signature,D),n||r.push("Share signature is invalid")}catch(k){r.push(k instanceof Error?k.message:String(k))}}let o=(t.now??new Date).getTime(),s=Date.parse(e?.payload?.expiresAt??""),d=t.revokedShareIds?.has(e?.payload?.shareId??"")??!1?"revoked":Number.isFinite(s)&&s<=o?"expired":"active";d==="revoked"&&r.push("Share has been revoked"),d==="expired"&&r.push("Share has expired");let y=Ne(e?.payload,t.capabilityToken);y||r.push("Capability token is missing or invalid");let R=_e(e?.payload,t.principal);return R||r.push("Principal is outside the share audience"),{valid:n&&y&&R&&d==="active",integrityValid:n,issuerTrusted:i,capabilityValid:y,audienceAllowed:R,status:d,errors:r}}function Pe(e){let t=e.now??new Date,r={schemaVersion:1,kind:"xeno-session-handoff",handoffId:u(e.handoffId??`handoff_${(0,c.randomUUID)()}`,"handoffId"),createdAt:t.toISOString(),expiresAt:z(t,e.expiresAt,e.ttlMs??1440*60*1e3),issuer:j(e.issuer),source:q(e.source),target:Le(e.target),resume:He(e.resume),authority:Fe(e.authority),references:U(e.references??[]),...e.shareId?{shareId:u(e.shareId,"shareId")}:{}};return{payload:r,signature:M(r,e.signingIdentity)}}function Oe(e,t={}){let r=[];if(e?.payload?.kind!=="xeno-session-handoff"||e.payload.schemaVersion!==1)return{valid:!1,integrityValid:!1,issuerTrusted:!1,expired:!1,errors:["Unsupported handoff envelope"]};let n=W(t.trustedPublicKeys,e.signature.keyId),i=n??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki),o=!!n,s=!1;if(!i)r.push("No trusted or embedded issuer public key is available");else try{s=K(e.payload,e.signature,i),s||r.push("Handoff signature is invalid")}catch(d){r.push(d instanceof Error?d.message:String(d))}let a=Date.parse(e.payload.expiresAt)<=(t.now??new Date).getTime();return a&&r.push("Handoff has expired"),{valid:s&&!a,integrityValid:s,issuerTrusted:o,expired:a,errors:r}}function M(e,t){let r=S(e),n=(0,c.sign)(null,Buffer.from(r),(0,c.createPrivateKey)(t.privateKeyPem)).toString("base64");return{algorithm:"ed25519",keyId:t.keyId,value:n,publicKeySpki:t.publicKeyPem}}function K(e,t,r){if(t.algorithm!=="ed25519")return!1;let n=Buffer.from(t.value,"base64");if(n.toString("base64")!==t.value)throw new Error("Signature is not canonical base64");return(0,c.verify)(null,Buffer.from(S(e)),(0,c.createPublicKey)(r),n)}function Ne(e,t){if(!e||!t)return!1;let r=Buffer.from(e.access.capabilityToken.hash,"hex"),n=Buffer.from(Z(t),"hex");return r.length===n.length&&(0,c.timingSafeEqual)(r,n)}function _e(e,t){if(!e)return!1;let r=e.access;return r.allowedPrincipalIds?.length&&(!t?.id||!r.allowedPrincipalIds.includes(t.id))?!1:r.visibility==="workspace"?!!(t?.workspaceId&&t.workspaceId===r.workspaceId):r.visibility==="team"?!!(r.teamId&&t?.teamIds?.includes(r.teamId)):r.visibility==="private"?!!(t?.id&&t.id===e.issuer.id):r.visibility==="link"}function Ve(e,t,r){let n=new URL(e??"xeno://share/");if(n.username||n.password)throw new Error("Share base URL cannot contain credentials");if(n.protocol!=="https:"&&n.protocol!=="xeno:")throw new Error("Share base URL must use https: or xeno:");return n.pathname=`${n.pathname.replace(/\/$/,"")}/${encodeURIComponent(t)}`,n.search="",n.hash=new URLSearchParams({access_token:r}).toString(),n.toString()}function z(e,t,r=ke){let n=t?new Date(t):new Date(e.getTime()+r);if(!Number.isFinite(n.getTime()))throw new Error("expiresAt must be a valid timestamp");let i=n.getTime()-e.getTime();if(i<=0)throw new Error("expiresAt must be in the future");if(i>Ae)throw new Error("Share and handoff expiry cannot exceed 365 days");return n.toISOString()}function j(e){return{id:u(e.id,"issuer.id"),...e.displayName?.trim()?{displayName:e.displayName.trim().slice(0,160)}:{},...e.workspaceId?{workspaceId:u(e.workspaceId,"issuer.workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"issuer.teamId")}:{}}}function q(e){let t={name:I(e.name,"session.name",200),surface:e.surface};for(let r of["sessionId","runId","hostedRunId","conversationId","parentSessionId","forkedFromSessionId","forkedAtEventId"])e[r]&&(t[r]=u(e[r],`session.${r}`));if(!t.sessionId&&!t.runId&&!t.hostedRunId&&!t.conversationId)throw new Error("Session identity requires sessionId, runId, hostedRunId, or conversationId");return e.git&&(t.git={...e.git.repositoryId?{repositoryId:u(e.git.repositoryId,"git.repositoryId")}:{},...e.git.remoteUrl?{remoteUrl:O(e.git.remoteUrl,"git.remoteUrl")}:{},...e.git.branch?{branch:I(e.git.branch,"git.branch",300)}:{},...e.git.commit?{commit:Y(e.git.commit,"git.commit")}:{},...e.git.pullRequest?{pullRequest:{provider:e.git.pullRequest.provider,repository:I(e.git.pullRequest.repository,"git.pullRequest.repository",300),number:$e(e.git.pullRequest.number,"git.pullRequest.number"),...e.git.pullRequest.url?{url:O(e.git.pullRequest.url,"git.pullRequest.url")}:{}}}:{}}),t}function U(e){let t=new Set;return e.map(r=>{let n=`${r.kind}:${r.id}`;if(t.has(n))throw new Error(`Duplicate share reference: ${n}`);return t.add(n),{kind:r.kind,id:u(r.id,"reference.id"),...r.title?.trim()?{title:r.title.trim().slice(0,300)}:{},...r.uri?{uri:O(r.uri,"reference.uri")}:{},...r.hash?{hash:Y(r.hash,"reference.hash")}:{}}})}function Le(e){return{surface:e.surface,...e.workspaceId?{workspaceId:u(e.workspaceId,"target.workspaceId")}:{},...e.teamId?{teamId:u(e.teamId,"target.teamId")}:{},...e.environmentId?{environmentId:u(e.environmentId,"target.environmentId")}:{},...e.repositoryId?{repositoryId:u(e.repositoryId,"target.repositoryId")}:{}}}function He(e){let t={};for(let r of["sessionId","runId","hostedRunId","checkpointId","transcriptEventId"])e[r]&&(t[r]=u(e[r],`resume.${r}`));if(e.artifactIds?.length&&(t.artifactIds=b(e.artifactIds,"resume.artifactIds")),e.taskIds?.length&&(t.taskIds=b(e.taskIds,"resume.taskIds")),!Object.keys(t).length)throw new Error("Handoff resume point cannot be empty");return t}function Fe(e){return{filesystem:e.filesystem,network:e.network,externalActions:e.externalActions,secretRefs:b(e.secretRefs,"authority.secretRefs")}}function De(e,t,r,n){if(e==="workspace"&&!t)throw new Error("workspace visibility requires workspaceId");if(e==="team"&&!r)throw new Error("team visibility requires teamId");if(e==="private"&&n?.length)throw new Error("private shares cannot add allowed principals; use link/workspace/team visibility")}function W(e,t){if(!e)return;let r=e;return typeof r.get=="function"?r.get(t):e[t]}function Z(e){return(0,c.createHash)("sha256").update(e).digest("hex")}function b(e,t){return[...new Set(e.map(r=>u(r,t)))].sort()}function u(e,t){let r=e.trim();if(!r||r.length>500||w(r))throw new Error(`${t} is invalid`);return r}function Y(e,t){let r=e.trim();if(!/^[A-Za-z0-9:+._-]{7,256}$/.test(r))throw new Error(`${t} is invalid`);return r}function I(e,t,r){let n=e.trim();if(!n||n.length>r||w(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function $e(e,t){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${t} must be a positive integer`);return e}function O(e,t){let r=I(e,t,2e3),n=new URL(r);if(n.username||n.password)throw new Error(`${t} cannot contain credentials`);if(!["https:","xeno:","artifact:","urn:"].includes(n.protocol))throw new Error(`${t} uses an unsupported scheme`);return n.toString()}var H=require("node:crypto"),l=require("node:fs/promises"),m=require("node:path");var f=he(require("node:fs/promises"),1);var G=Symbol.for("@xenosystem/agent-sdk/file-cache"),Q=globalThis,_=Q[G]??{entries:new Map,counters:{reads:0,hits:0}};Q[G]=_;var ct=_.entries,dt=_.counters;var Be=new Set(["EACCES","EBUSY","EPERM"]),Je=[10,20,40,80,160,320,640];async function ee(e,t){for(let r=0;;r+=1)try{await f.rename(e,t);return}catch(n){let i=n.code,o=Je[r];if(process.platform!=="win32"||!i||!Be.has(i)||o===void 0)throw n;await new Promise(s=>setTimeout(s,o))}}var g=require("node:fs"),V=require("node:os"),re=require("node:path");function Me(){return new Date().toISOString()}function Ke(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function ne(e){try{return JSON.parse((0,g.readFileSync)(e,"utf8"))}catch{return null}}function ze(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function je(e){return e.hostname!==(0,V.hostname)()?!0:ze(e.pid)}function te(e,t){(0,g.mkdirSync)((0,re.dirname)(e),{recursive:!0}),(0,g.writeFileSync)(e,JSON.stringify(t,null,2)+`
3
+ `,{encoding:"utf8",flag:"wx"})}function qe(e,t){let r=ne(e);r?.pid!==t.pid||r.hostname!==t.hostname||(0,g.rmSync)(e,{force:!0})}function ie(e,t,r){let n=Me(),i={schemaVersion:1,name:t,pid:process.pid,hostname:(0,V.hostname)(),processStartedAt:Ke(),version:r,acquiredAt:n,updatedAt:n};try{te(e,i)}catch(o){if(o.code!=="EEXIST")throw o;let a=ne(e);if(a&&je(a))throw new Error(`${t} is already locked by PID ${a.pid} on ${a.hostname}.`);(0,g.rmSync)(e,{force:!0}),te(e,i)}return{record:i,release:()=>{qe(e,i)}}}var L=class{directory;snapshotPath;lockPath;now;constructor(t){this.directory=(0,m.resolve)(t.directory),this.snapshotPath=(0,m.join)(this.directory,"registry.json"),this.lockPath=(0,m.join)(this.directory,"registry.lock"),this.now=t.now??(()=>new Date)}async register(t,r="created"){return this.mutate(n=>{let i=n.records.find(s=>s.shareId===t.payload.shareId);if(i){if(X(i.envelope)!==X(t))throw new Error(`Share ${t.payload.shareId} already exists with different content`);return{snapshot:n,result:i}}let o={shareId:t.payload.shareId,envelope:t,status:Date.parse(t.payload.expiresAt)<=this.now().getTime()?"expired":"active",registeredAt:this.now().toISOString(),origin:r};return{snapshot:oe(n,[...n.records,o],this.now()),result:o}})}async revoke(t,r,n){return this.mutate(i=>{let o=i.records.findIndex(y=>y.shareId===t);if(o<0)throw new Error(`Share not found: ${t}`);let s=i.records[o];if(s.status==="revoked")return{snapshot:i,result:s};let a={...s,status:"revoked",revokedAt:this.now().toISOString(),revokedBy:se(r,"actor"),revocationReason:se(n,"reason")},d=[...i.records];return d[o]=a,{snapshot:oe(i,d,this.now()),result:a}})}async get(t){return(await this.load()).records.find(r=>r.shareId===t)??null}async list(){let t=this.now().getTime();return(await this.load()).records.map(r=>r.status==="active"&&Date.parse(r.envelope.payload.expiresAt)<=t?{...r,status:"expired"}:r).sort((r,n)=>n.registeredAt.localeCompare(r.registeredAt))}async revokedIds(){return new Set((await this.list()).filter(t=>t.status==="revoked").map(t=>t.shareId))}async load(){try{let t=await(0,l.readFile)(this.snapshotPath,"utf8"),r=JSON.parse(t);return We(r),r}catch(t){if(t.code==="ENOENT")return Ue(this.now());throw t}}async mutate(t){await(0,l.mkdir)(this.directory,{recursive:!0,mode:448});let r=ie(this.lockPath,"xeno secure-share registry","1");try{let n=await this.load(),{snapshot:i,result:o}=t(n);return i!==n&&await Ze(this.snapshotPath,`${JSON.stringify(i,null,2)}
4
+ `),o}finally{r.release()}}};function Ue(e){return ae({schemaVersion:1,generation:0,updatedAt:e.toISOString(),records:[]})}function oe(e,t,r){return ae({schemaVersion:1,generation:e.generation+1,updatedAt:r.toISOString(),records:[...t].sort((n,i)=>n.shareId.localeCompare(i.shareId))})}function ae(e){return{...e,checksum:{algorithm:"sha256",value:(0,H.createHash)("sha256").update(X(e)).digest("hex")}}}function We(e){if(e.schemaVersion!==1||!Array.isArray(e.records))throw new Error("Invalid secure-share registry snapshot");let{checksum:t,...r}=e,n=(0,H.createHash)("sha256").update(X(r)).digest("hex");if(t?.algorithm!=="sha256"||t.value!==n)throw new Error("Secure-share registry checksum mismatch");let i=new Set;for(let o of e.records){if(o.shareId!==o.envelope?.payload?.shareId)throw new Error("Secure-share registry identity mismatch");if(i.has(o.shareId))throw new Error(`Duplicate secure-share registry record: ${o.shareId}`);i.add(o.shareId)}}async function Ze(e,t){await(0,l.mkdir)((0,m.dirname)(e),{recursive:!0,mode:448});let r=`${e}.${process.pid}.${Date.now()}.tmp`,n;try{n=await(0,l.open)(r,"wx",384),await n.writeFile(t,"utf8"),await n.sync(),await n.close(),n=void 0,await ee(r,e),await(0,l.chmod)(e,384).catch(()=>{})}finally{n&&await n.close().catch(()=>{}),await(0,l.unlink)(r).catch(()=>{})}}function X(e){return S(e)}function se(e,t){let r=e.trim();if(!r||r.length>500||w(r))throw new Error(`${t} is invalid`);return r}0&&(module.exports={FileXenoShareRegistry,XENO_HANDOFF_SCHEMA_VERSION,XENO_SHARE_REGISTRY_SCHEMA_VERSION,XENO_SHARE_SCHEMA_VERSION,createXenoSecureShare,createXenoSessionHandoff,createXenoShareSigningIdentity,publicKeyFingerprint,redactXenoShareValue,signSharePayload,verifyXenoSecureShare,verifyXenoSessionHandoff});
@@ -1,4 +1,4 @@
1
- var E=2,X=1,m=1;var ne=/(?:^|[_-])(api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|auth(?:orization)?|bearer|secret|password|passwd|credential|cookie|private[_-]?key|client[_-]?secret)(?:$|[_-])/i,ie=/\b([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|PRIVATE_KEY|CLIENT_SECRET)[A-Z0-9_]*)\s*=\s*([^\s"']+)/g,oe=/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,se=/\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[0-9A-Z]{16})\b/g,ae=/-----BEGIN (?:RSA |EC |OPENSSH |)PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH |)PRIVATE KEY-----/g,ce=/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi,de=/([?&#](?:access_token|refresh_token|token|key|secret|password|api[_-]?key|signature)=)[^&#\s]+/gi;function T(e,t={}){let r={options:{...t,redactEmails:t.redactEmails??!0,maxDepth:t.maxDepth??48,maxStringLength:t.maxStringLength??2e5,maxEvents:t.maxEvents??256},seen:new Set,events:[],byCategory:{},total:0};return{value:b(e,"$","",0,r),report:{schemaVersion:1,total:r.total,byCategory:r.byCategory,events:r.events,eventsTruncated:r.total>r.events.length}}}function f(e,t,r){e.total+=1,e.byCategory[r]=(e.byCategory[r]??0)+1,e.events.length<e.options.maxEvents&&e.events.push({path:t,category:r})}function b(e,t,r,n,i){if(ne.test(r))return e!=null&&e!==""&&f(i,t,"secret-field"),e==null||e===""?null:"[redacted]";if(n>i.options.maxDepth)return f(i,t,"truncated"),"[redacted:depth-limit]";if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="string")return ue(e,t,i);if(e instanceof Date)return e.toISOString();if(e instanceof Uint8Array)return f(i,t,"binary"),`[redacted:binary:${e.byteLength}-bytes]`;if(Array.isArray(e)){if(i.seen.has(e))return f(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o=e.map((s,a)=>b(s,`${t}[${a}]`,"",n+1,i));return i.seen.delete(e),o}if(e&&typeof e=="object"){if(i.seen.has(e))return f(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o={};for(let[s,a]of Object.entries(e))o[s]=b(a,`${t}.${fe(s)}`,s,n+1,i);return i.seen.delete(e),o}return null}function ue(e,t,r){let n=e;return n=l(n,ae,"[redacted:private-key]",t,"private-key",r),n=l(n,oe,"$1[redacted]",t,"authorization",r),n=l(n,se,"[redacted:credential]",t,"credential-pattern",r),n=l(n,ie,"$1=[redacted]",t,"environment-secret",r),n=l(n,de,"$1[redacted]",t,"url-secret",r),r.options.redactEmails&&(n=l(n,ce,"[redacted:email]",t,"email",r)),n=P(n,r.options.workspaceRoot,"<workspace>",t,"workspace-path",r),n=P(n,r.options.homeDirectory,"<home>",t,"home-path",r),n.length>r.options.maxStringLength&&(f(r,t,"truncated"),n=`${n.slice(0,r.options.maxStringLength)}
2
- [truncated]`),n}function l(e,t,r,n,i,o){t.lastIndex=0;let s=0,a=e.replace(t,(...c)=>(s+=1,r.includes("$1")?r.replace("$1",String(c[1]??"")):r));for(let c=0;c<s;c+=1)f(o,n,i);return t.lastIndex=0,a}function P(e,t,r,n,i,o){let s=t?.trim().replace(/[\\/]+$/,"");if(!s)return e;let a=new RegExp(le(s).replace(/[\\/]+/g,"[\\\\/]"),process.platform==="win32"?"gi":"g");return l(e,a,r,n,i,o)}function le(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function fe(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}import{createHash as C,createPrivateKey as ge,createPublicKey as O,generateKeyPairSync as pe,randomBytes as he,randomUUID as _,sign as me,timingSafeEqual as ye,verify as Se}from"node:crypto";function p(e){return JSON.stringify(R(e,new Set))}function R(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(i=>R(i,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((i,o)=>i.localeCompare(o))){let i=e[n];if(i===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=R(i,t)}return t.delete(e),r}function h(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}var we=10080*60*1e3,Ie=365*24*60*60*1e3;function ot(){let{publicKey:e,privateKey:t}=pe("ed25519"),r=e.export({type:"spki",format:"pem"}).toString(),n=t.export({type:"pkcs8",format:"pem"}).toString();return{keyId:N(r),publicKeyPem:r,privateKeyPem:n}}function N(e){let t=O(e).export({type:"spki",format:"der"});return`ed25519:${C("sha256").update(t).digest("hex").slice(0,32)}`}function st(e){let t=e.now??new Date,r=t.toISOString(),n=H(t,e.expiresAt,e.ttlMs),i=he(32).toString("base64url"),o=T(e.content,e.redaction),s=e.visibility??"private";ve(s,e.workspaceId,e.teamId,e.allowedPrincipalIds);let a={schemaVersion:2,kind:"xeno-secure-share",shareId:d(e.shareId??`share_${_()}`,"shareId"),createdAt:r,expiresAt:n,issuer:D(e.issuer),session:$({...e.session,name:e.session.name??e.name}),access:{mode:"read-only",visibility:s,...e.workspaceId?{workspaceId:d(e.workspaceId,"workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"teamId")}:{},...e.allowedPrincipalIds?.length?{allowedPrincipalIds:S(e.allowedPrincipalIds,"allowedPrincipalIds")}:{},capabilityToken:{algorithm:"sha256",hash:B(i)}},content:o.value,references:F(e.references??[]),redaction:o.report};return{envelope:xe(a,e.signingIdentity),capabilityToken:i,url:be(e.baseUrl,a.shareId,i)}}function xe(e,t){if(t.keyId!==N(t.publicKeyPem))throw new Error("Signing identity keyId does not match public key");let r=V(e,t);return{payload:e,signature:r}}function at(e,t={}){let r=[],n=!1,i=!1;if(e?.payload?.kind!=="xeno-secure-share"||e.payload.schemaVersion!==2)r.push("Unsupported secure-share envelope");else{let A=J(t.trustedPublicKeys,e.signature.keyId),v=A??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki);if(i=!!A,!v)r.push("No trusted or embedded issuer public key is available");else try{n=L(e.payload,e.signature,v),n||r.push("Share signature is invalid")}catch(x){r.push(x instanceof Error?x.message:String(x))}}let o=(t.now??new Date).getTime(),s=Date.parse(e?.payload?.expiresAt??""),c=t.revokedShareIds?.has(e?.payload?.shareId??"")??!1?"revoked":Number.isFinite(s)&&s<=o?"expired":"active";c==="revoked"&&r.push("Share has been revoked"),c==="expired"&&r.push("Share has expired");let g=Ee(e?.payload,t.capabilityToken);g||r.push("Capability token is missing or invalid");let I=Xe(e?.payload,t.principal);return I||r.push("Principal is outside the share audience"),{valid:n&&g&&I&&c==="active",integrityValid:n,issuerTrusted:i,capabilityValid:g,audienceAllowed:I,status:c,errors:r}}function ct(e){let t=e.now??new Date,r={schemaVersion:1,kind:"xeno-session-handoff",handoffId:d(e.handoffId??`handoff_${_()}`,"handoffId"),createdAt:t.toISOString(),expiresAt:H(t,e.expiresAt,e.ttlMs??1440*60*1e3),issuer:D(e.issuer),source:$(e.source),target:Re(e.target),resume:ke(e.resume),authority:Ae(e.authority),references:F(e.references??[]),...e.shareId?{shareId:d(e.shareId,"shareId")}:{}};return{payload:r,signature:V(r,e.signingIdentity)}}function dt(e,t={}){let r=[];if(e?.payload?.kind!=="xeno-session-handoff"||e.payload.schemaVersion!==1)return{valid:!1,integrityValid:!1,issuerTrusted:!1,expired:!1,errors:["Unsupported handoff envelope"]};let n=J(t.trustedPublicKeys,e.signature.keyId),i=n??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki),o=!!n,s=!1;if(!i)r.push("No trusted or embedded issuer public key is available");else try{s=L(e.payload,e.signature,i),s||r.push("Handoff signature is invalid")}catch(c){r.push(c instanceof Error?c.message:String(c))}let a=Date.parse(e.payload.expiresAt)<=(t.now??new Date).getTime();return a&&r.push("Handoff has expired"),{valid:s&&!a,integrityValid:s,issuerTrusted:o,expired:a,errors:r}}function V(e,t){let r=p(e),n=me(null,Buffer.from(r),ge(t.privateKeyPem)).toString("base64");return{algorithm:"ed25519",keyId:t.keyId,value:n,publicKeySpki:t.publicKeyPem}}function L(e,t,r){if(t.algorithm!=="ed25519")return!1;let n=Buffer.from(t.value,"base64");if(n.toString("base64")!==t.value)throw new Error("Signature is not canonical base64");return Se(null,Buffer.from(p(e)),O(r),n)}function Ee(e,t){if(!e||!t)return!1;let r=Buffer.from(e.access.capabilityToken.hash,"hex"),n=Buffer.from(B(t),"hex");return r.length===n.length&&ye(r,n)}function Xe(e,t){if(!e)return!1;let r=e.access;return r.allowedPrincipalIds?.length&&(!t?.id||!r.allowedPrincipalIds.includes(t.id))?!1:r.visibility==="workspace"?!!(t?.workspaceId&&t.workspaceId===r.workspaceId):r.visibility==="team"?!!(r.teamId&&t?.teamIds?.includes(r.teamId)):r.visibility==="private"?!!(t?.id&&t.id===e.issuer.id):r.visibility==="link"}function be(e,t,r){let n=new URL(e??"xeno://share/");if(n.username||n.password)throw new Error("Share base URL cannot contain credentials");if(n.protocol!=="https:"&&n.protocol!=="xeno:")throw new Error("Share base URL must use https: or xeno:");return n.pathname=`${n.pathname.replace(/\/$/,"")}/${encodeURIComponent(t)}`,n.search="",n.hash=new URLSearchParams({access_token:r}).toString(),n.toString()}function H(e,t,r=we){let n=t?new Date(t):new Date(e.getTime()+r);if(!Number.isFinite(n.getTime()))throw new Error("expiresAt must be a valid timestamp");let i=n.getTime()-e.getTime();if(i<=0)throw new Error("expiresAt must be in the future");if(i>Ie)throw new Error("Share and handoff expiry cannot exceed 365 days");return n.toISOString()}function D(e){return{id:d(e.id,"issuer.id"),...e.displayName?.trim()?{displayName:e.displayName.trim().slice(0,160)}:{},...e.workspaceId?{workspaceId:d(e.workspaceId,"issuer.workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"issuer.teamId")}:{}}}function $(e){let t={name:y(e.name,"session.name",200),surface:e.surface};for(let r of["sessionId","runId","hostedRunId","conversationId","parentSessionId","forkedFromSessionId","forkedAtEventId"])e[r]&&(t[r]=d(e[r],`session.${r}`));if(!t.sessionId&&!t.runId&&!t.hostedRunId&&!t.conversationId)throw new Error("Session identity requires sessionId, runId, hostedRunId, or conversationId");return e.git&&(t.git={...e.git.repositoryId?{repositoryId:d(e.git.repositoryId,"git.repositoryId")}:{},...e.git.remoteUrl?{remoteUrl:k(e.git.remoteUrl,"git.remoteUrl")}:{},...e.git.branch?{branch:y(e.git.branch,"git.branch",300)}:{},...e.git.commit?{commit:K(e.git.commit,"git.commit")}:{},...e.git.pullRequest?{pullRequest:{provider:e.git.pullRequest.provider,repository:y(e.git.pullRequest.repository,"git.pullRequest.repository",300),number:Pe(e.git.pullRequest.number,"git.pullRequest.number"),...e.git.pullRequest.url?{url:k(e.git.pullRequest.url,"git.pullRequest.url")}:{}}}:{}}),t}function F(e){let t=new Set;return e.map(r=>{let n=`${r.kind}:${r.id}`;if(t.has(n))throw new Error(`Duplicate share reference: ${n}`);return t.add(n),{kind:r.kind,id:d(r.id,"reference.id"),...r.title?.trim()?{title:r.title.trim().slice(0,300)}:{},...r.uri?{uri:k(r.uri,"reference.uri")}:{},...r.hash?{hash:K(r.hash,"reference.hash")}:{}}})}function Re(e){return{surface:e.surface,...e.workspaceId?{workspaceId:d(e.workspaceId,"target.workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"target.teamId")}:{},...e.environmentId?{environmentId:d(e.environmentId,"target.environmentId")}:{},...e.repositoryId?{repositoryId:d(e.repositoryId,"target.repositoryId")}:{}}}function ke(e){let t={};for(let r of["sessionId","runId","hostedRunId","checkpointId","transcriptEventId"])e[r]&&(t[r]=d(e[r],`resume.${r}`));if(e.artifactIds?.length&&(t.artifactIds=S(e.artifactIds,"resume.artifactIds")),e.taskIds?.length&&(t.taskIds=S(e.taskIds,"resume.taskIds")),!Object.keys(t).length)throw new Error("Handoff resume point cannot be empty");return t}function Ae(e){return{filesystem:e.filesystem,network:e.network,externalActions:e.externalActions,secretRefs:S(e.secretRefs,"authority.secretRefs")}}function ve(e,t,r,n){if(e==="workspace"&&!t)throw new Error("workspace visibility requires workspaceId");if(e==="team"&&!r)throw new Error("team visibility requires teamId");if(e==="private"&&n?.length)throw new Error("private shares cannot add allowed principals; use link/workspace/team visibility")}function J(e,t){if(!e)return;let r=e;return typeof r.get=="function"?r.get(t):e[t]}function B(e){return C("sha256").update(e).digest("hex")}function S(e,t){return[...new Set(e.map(r=>d(r,t)))].sort()}function d(e,t){let r=e.trim();if(!r||r.length>500||h(r))throw new Error(`${t} is invalid`);return r}function K(e,t){let r=e.trim();if(!/^[A-Za-z0-9:+._-]{7,256}$/.test(r))throw new Error(`${t} is invalid`);return r}function y(e,t,r){let n=e.trim();if(!n||n.length>r||h(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function Pe(e,t){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${t} must be a positive integer`);return e}function k(e,t){let r=y(e,t,2e3),n=new URL(r);if(n.username||n.password)throw new Error(`${t} cannot contain credentials`);if(!["https:","xeno:","artifact:","urn:"].includes(n.protocol))throw new Error(`${t} uses an unsupported scheme`);return n.toString()}import{createHash as ee}from"node:crypto";import{chmod as Je,mkdir as te,open as Be,readFile as Ke,unlink as Me}from"node:fs/promises";import{dirname as je,join as Z,resolve as qe}from"node:path";import*as u from"node:fs/promises";var Te=new Set(["EACCES","EBUSY","EPERM"]),Ce=[10,20,40,80,160,320,640];async function M(e,t){for(let r=0;;r+=1)try{await u.rename(e,t);return}catch(n){let i=n.code,o=Ce[r];if(process.platform!=="win32"||!i||!Te.has(i)||o===void 0)throw n;await new Promise(s=>setTimeout(s,o))}}import{mkdirSync as Oe,readFileSync as _e,rmSync as q,writeFileSync as Ne}from"node:fs";import{hostname as z}from"node:os";import{dirname as Ve}from"node:path";function Le(){return new Date().toISOString()}function He(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function U(e){try{return JSON.parse(_e(e,"utf8"))}catch{return null}}function De(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function $e(e){return e.hostname!==z()?!0:De(e.pid)}function j(e,t){Oe(Ve(e),{recursive:!0}),Ne(e,JSON.stringify(t,null,2)+`
3
- `,{encoding:"utf8",flag:"wx"})}function Fe(e,t){let r=U(e);r?.pid!==t.pid||r.hostname!==t.hostname||q(e,{force:!0})}function W(e,t,r){let n=Le(),i={schemaVersion:1,name:t,pid:process.pid,hostname:z(),processStartedAt:He(),version:r,acquiredAt:n,updatedAt:n};try{j(e,i)}catch(o){if(o.code!=="EEXIST")throw o;let a=U(e);if(a&&$e(a))throw new Error(`${t} is already locked by PID ${a.pid} on ${a.hostname}.`);q(e,{force:!0}),j(e,i)}return{record:i,release:()=>{Fe(e,i)}}}var Y=class{directory;snapshotPath;lockPath;now;constructor(t){this.directory=qe(t.directory),this.snapshotPath=Z(this.directory,"registry.json"),this.lockPath=Z(this.directory,"registry.lock"),this.now=t.now??(()=>new Date)}async register(t,r="created"){return this.mutate(n=>{let i=n.records.find(s=>s.shareId===t.payload.shareId);if(i){if(w(i.envelope)!==w(t))throw new Error(`Share ${t.payload.shareId} already exists with different content`);return{snapshot:n,result:i}}let o={shareId:t.payload.shareId,envelope:t,status:Date.parse(t.payload.expiresAt)<=this.now().getTime()?"expired":"active",registeredAt:this.now().toISOString(),origin:r};return{snapshot:G(n,[...n.records,o],this.now()),result:o}})}async revoke(t,r,n){return this.mutate(i=>{let o=i.records.findIndex(g=>g.shareId===t);if(o<0)throw new Error(`Share not found: ${t}`);let s=i.records[o];if(s.status==="revoked")return{snapshot:i,result:s};let a={...s,status:"revoked",revokedAt:this.now().toISOString(),revokedBy:Q(r,"actor"),revocationReason:Q(n,"reason")},c=[...i.records];return c[o]=a,{snapshot:G(i,c,this.now()),result:a}})}async get(t){return(await this.load()).records.find(r=>r.shareId===t)??null}async list(){let t=this.now().getTime();return(await this.load()).records.map(r=>r.status==="active"&&Date.parse(r.envelope.payload.expiresAt)<=t?{...r,status:"expired"}:r).sort((r,n)=>n.registeredAt.localeCompare(r.registeredAt))}async revokedIds(){return new Set((await this.list()).filter(t=>t.status==="revoked").map(t=>t.shareId))}async load(){try{let t=await Ke(this.snapshotPath,"utf8"),r=JSON.parse(t);return Ue(r),r}catch(t){if(t.code==="ENOENT")return ze(this.now());throw t}}async mutate(t){await te(this.directory,{recursive:!0,mode:448});let r=W(this.lockPath,"xeno secure-share registry","1");try{let n=await this.load(),{snapshot:i,result:o}=t(n);return i!==n&&await We(this.snapshotPath,`${JSON.stringify(i,null,2)}
4
- `),o}finally{r.release()}}};function ze(e){return re({schemaVersion:1,generation:0,updatedAt:e.toISOString(),records:[]})}function G(e,t,r){return re({schemaVersion:1,generation:e.generation+1,updatedAt:r.toISOString(),records:[...t].sort((n,i)=>n.shareId.localeCompare(i.shareId))})}function re(e){return{...e,checksum:{algorithm:"sha256",value:ee("sha256").update(w(e)).digest("hex")}}}function Ue(e){if(e.schemaVersion!==1||!Array.isArray(e.records))throw new Error("Invalid secure-share registry snapshot");let{checksum:t,...r}=e,n=ee("sha256").update(w(r)).digest("hex");if(t?.algorithm!=="sha256"||t.value!==n)throw new Error("Secure-share registry checksum mismatch");let i=new Set;for(let o of e.records){if(o.shareId!==o.envelope?.payload?.shareId)throw new Error("Secure-share registry identity mismatch");if(i.has(o.shareId))throw new Error(`Duplicate secure-share registry record: ${o.shareId}`);i.add(o.shareId)}}async function We(e,t){await te(je(e),{recursive:!0,mode:448});let r=`${e}.${process.pid}.${Date.now()}.tmp`,n;try{n=await Be(r,"wx",384),await n.writeFile(t,"utf8"),await n.sync(),await n.close(),n=void 0,await M(r,e),await Je(e,384).catch(()=>{})}finally{n&&await n.close().catch(()=>{}),await Me(r).catch(()=>{})}}function w(e){return p(e)}function Q(e,t){let r=e.trim();if(!r||r.length>500||h(r))throw new Error(`${t} is invalid`);return r}export{Y as FileXenoShareRegistry,X as XENO_HANDOFF_SCHEMA_VERSION,m as XENO_SHARE_REGISTRY_SCHEMA_VERSION,E as XENO_SHARE_SCHEMA_VERSION,st as createXenoSecureShare,ct as createXenoSessionHandoff,ot as createXenoShareSigningIdentity,N as publicKeyFingerprint,T as redactXenoShareValue,xe as signSharePayload,at as verifyXenoSecureShare,dt as verifyXenoSessionHandoff};
1
+ var I=2,b=1,m=1;var se=/(?:^|[_-])(api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|auth(?:orization)?|bearer|secret|password|passwd|credential|cookie|private[_-]?key|client[_-]?secret)(?:$|[_-])/i,ae=/\b([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|PRIVATE_KEY|CLIENT_SECRET)[A-Z0-9_]*)\s*=\s*([^\s"']+)/g,ce=/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,de=/\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[0-9A-Z]{16})\b/g,ue=/-----BEGIN (?:RSA |EC |OPENSSH |)PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH |)PRIVATE KEY-----/g,le=/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi,fe=/([?&#](?:access_token|refresh_token|token|key|secret|password|api[_-]?key|signature)=)[^&#\s]+/gi;function P(e,t={}){let r={options:{...t,redactEmails:t.redactEmails??!0,maxDepth:t.maxDepth??48,maxStringLength:t.maxStringLength??2e5,maxEvents:t.maxEvents??256},seen:new Set,events:[],byCategory:{},total:0};return{value:X(e,"$","",0,r),report:{schemaVersion:1,total:r.total,byCategory:r.byCategory,events:r.events,eventsTruncated:r.total>r.events.length}}}function f(e,t,r){e.total+=1,e.byCategory[r]=(e.byCategory[r]??0)+1,e.events.length<e.options.maxEvents&&e.events.push({path:t,category:r})}function X(e,t,r,n,i){if(se.test(r))return e!=null&&e!==""&&f(i,t,"secret-field"),e==null||e===""?null:"[redacted]";if(n>i.options.maxDepth)return f(i,t,"truncated"),"[redacted:depth-limit]";if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:String(e);if(typeof e=="bigint")return e.toString();if(typeof e=="string")return ge(e,t,i);if(e instanceof Date)return e.toISOString();if(e instanceof Uint8Array)return f(i,t,"binary"),`[redacted:binary:${e.byteLength}-bytes]`;if(Array.isArray(e)){if(i.seen.has(e))return f(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o=e.map((s,a)=>X(s,`${t}[${a}]`,"",n+1,i));return i.seen.delete(e),o}if(e&&typeof e=="object"){if(i.seen.has(e))return f(i,t,"cycle"),"[redacted:cycle]";i.seen.add(e);let o={};for(let[s,a]of Object.entries(e))o[s]=X(a,`${t}.${pe(s)}`,s,n+1,i);return i.seen.delete(e),o}return null}function ge(e,t,r){let n=e;return n=l(n,ue,"[redacted:private-key]",t,"private-key",r),n=l(n,ce,"$1[redacted]",t,"authorization",r),n=l(n,de,"[redacted:credential]",t,"credential-pattern",r),n=l(n,ae,"$1=[redacted]",t,"environment-secret",r),n=l(n,fe,"$1[redacted]",t,"url-secret",r),r.options.redactEmails&&(n=l(n,le,"[redacted:email]",t,"email",r)),n=C(n,r.options.workspaceRoot,"<workspace>",t,"workspace-path",r),n=C(n,r.options.homeDirectory,"<home>",t,"home-path",r),n.length>r.options.maxStringLength&&(f(r,t,"truncated"),n=`${n.slice(0,r.options.maxStringLength)}
2
+ [truncated]`),n}function l(e,t,r,n,i,o){t.lastIndex=0;let s=0,a=e.replace(t,(...c)=>(s+=1,r.includes("$1")?r.replace("$1",String(c[1]??"")):r));for(let c=0;c<s;c+=1)f(o,n,i);return t.lastIndex=0,a}function C(e,t,r,n,i,o){let s=t?.trim().replace(/[\\/]+$/,"");if(!s)return e;let a=new RegExp(he(s).replace(/[\\/]+/g,"[\\\\/]"),process.platform==="win32"?"gi":"g");return l(e,a,r,n,i,o)}function he(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function pe(e){return e.replace(/[^A-Za-z0-9_-]/g,"_")}import{createHash as O,createPrivateKey as me,createPublicKey as N,generateKeyPairSync as ye,randomBytes as Se,randomUUID as _,sign as we,timingSafeEqual as xe,verify as Ee}from"node:crypto";function h(e){return JSON.stringify(R(e,new Set))}function R(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(i=>R(i,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((i,o)=>i.localeCompare(o))){let i=e[n];if(i===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=R(i,t)}return t.delete(e),r}function p(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}var Ie=10080*60*1e3,be=365*24*60*60*1e3;function ct(){let{publicKey:e,privateKey:t}=ye("ed25519"),r=e.export({type:"spki",format:"pem"}).toString(),n=t.export({type:"pkcs8",format:"pem"}).toString();return{keyId:V(r),publicKeyPem:r,privateKeyPem:n}}function V(e){let t=N(e).export({type:"spki",format:"der"});return`ed25519:${O("sha256").update(t).digest("hex").slice(0,32)}`}function dt(e){let t=e.now??new Date,r=t.toISOString(),n=F(t,e.expiresAt,e.ttlMs),i=Se(32).toString("base64url"),o=P(e.content,e.redaction),s=e.visibility??"private";Pe(s,e.workspaceId,e.teamId,e.allowedPrincipalIds);let a={schemaVersion:2,kind:"xeno-secure-share",shareId:d(e.shareId??`share_${_()}`,"shareId"),createdAt:r,expiresAt:n,issuer:D(e.issuer),session:$({...e.session,name:e.session.name??e.name}),access:{mode:"read-only",visibility:s,...e.workspaceId?{workspaceId:d(e.workspaceId,"workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"teamId")}:{},...e.allowedPrincipalIds?.length?{allowedPrincipalIds:S(e.allowedPrincipalIds,"allowedPrincipalIds")}:{},capabilityToken:{algorithm:"sha256",hash:M(i)}},content:o.value,references:B(e.references??[]),redaction:o.report};return{envelope:Xe(a,e.signingIdentity),capabilityToken:i,url:Ae(e.baseUrl,a.shareId,i)}}function Xe(e,t){if(t.keyId!==V(t.publicKeyPem))throw new Error("Signing identity keyId does not match public key");let r=L(e,t);return{payload:e,signature:r}}function ut(e,t={}){let r=[],n=!1,i=!1;if(e?.payload?.kind!=="xeno-secure-share"||e.payload.schemaVersion!==2)r.push("Unsupported secure-share envelope");else{let v=J(t.trustedPublicKeys,e.signature.keyId),T=v??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki);if(i=!!v,!T)r.push("No trusted or embedded issuer public key is available");else try{n=H(e.payload,e.signature,T),n||r.push("Share signature is invalid")}catch(E){r.push(E instanceof Error?E.message:String(E))}}let o=(t.now??new Date).getTime(),s=Date.parse(e?.payload?.expiresAt??""),c=t.revokedShareIds?.has(e?.payload?.shareId??"")??!1?"revoked":Number.isFinite(s)&&s<=o?"expired":"active";c==="revoked"&&r.push("Share has been revoked"),c==="expired"&&r.push("Share has expired");let g=Re(e?.payload,t.capabilityToken);g||r.push("Capability token is missing or invalid");let x=ke(e?.payload,t.principal);return x||r.push("Principal is outside the share audience"),{valid:n&&g&&x&&c==="active",integrityValid:n,issuerTrusted:i,capabilityValid:g,audienceAllowed:x,status:c,errors:r}}function lt(e){let t=e.now??new Date,r={schemaVersion:1,kind:"xeno-session-handoff",handoffId:d(e.handoffId??`handoff_${_()}`,"handoffId"),createdAt:t.toISOString(),expiresAt:F(t,e.expiresAt,e.ttlMs??1440*60*1e3),issuer:D(e.issuer),source:$(e.source),target:ve(e.target),resume:Te(e.resume),authority:Ce(e.authority),references:B(e.references??[]),...e.shareId?{shareId:d(e.shareId,"shareId")}:{}};return{payload:r,signature:L(r,e.signingIdentity)}}function ft(e,t={}){let r=[];if(e?.payload?.kind!=="xeno-session-handoff"||e.payload.schemaVersion!==1)return{valid:!1,integrityValid:!1,issuerTrusted:!1,expired:!1,errors:["Unsupported handoff envelope"]};let n=J(t.trustedPublicKeys,e.signature.keyId),i=n??(t.allowEmbeddedPublicKey===!1?void 0:e.signature.publicKeySpki),o=!!n,s=!1;if(!i)r.push("No trusted or embedded issuer public key is available");else try{s=H(e.payload,e.signature,i),s||r.push("Handoff signature is invalid")}catch(c){r.push(c instanceof Error?c.message:String(c))}let a=Date.parse(e.payload.expiresAt)<=(t.now??new Date).getTime();return a&&r.push("Handoff has expired"),{valid:s&&!a,integrityValid:s,issuerTrusted:o,expired:a,errors:r}}function L(e,t){let r=h(e),n=we(null,Buffer.from(r),me(t.privateKeyPem)).toString("base64");return{algorithm:"ed25519",keyId:t.keyId,value:n,publicKeySpki:t.publicKeyPem}}function H(e,t,r){if(t.algorithm!=="ed25519")return!1;let n=Buffer.from(t.value,"base64");if(n.toString("base64")!==t.value)throw new Error("Signature is not canonical base64");return Ee(null,Buffer.from(h(e)),N(r),n)}function Re(e,t){if(!e||!t)return!1;let r=Buffer.from(e.access.capabilityToken.hash,"hex"),n=Buffer.from(M(t),"hex");return r.length===n.length&&xe(r,n)}function ke(e,t){if(!e)return!1;let r=e.access;return r.allowedPrincipalIds?.length&&(!t?.id||!r.allowedPrincipalIds.includes(t.id))?!1:r.visibility==="workspace"?!!(t?.workspaceId&&t.workspaceId===r.workspaceId):r.visibility==="team"?!!(r.teamId&&t?.teamIds?.includes(r.teamId)):r.visibility==="private"?!!(t?.id&&t.id===e.issuer.id):r.visibility==="link"}function Ae(e,t,r){let n=new URL(e??"xeno://share/");if(n.username||n.password)throw new Error("Share base URL cannot contain credentials");if(n.protocol!=="https:"&&n.protocol!=="xeno:")throw new Error("Share base URL must use https: or xeno:");return n.pathname=`${n.pathname.replace(/\/$/,"")}/${encodeURIComponent(t)}`,n.search="",n.hash=new URLSearchParams({access_token:r}).toString(),n.toString()}function F(e,t,r=Ie){let n=t?new Date(t):new Date(e.getTime()+r);if(!Number.isFinite(n.getTime()))throw new Error("expiresAt must be a valid timestamp");let i=n.getTime()-e.getTime();if(i<=0)throw new Error("expiresAt must be in the future");if(i>be)throw new Error("Share and handoff expiry cannot exceed 365 days");return n.toISOString()}function D(e){return{id:d(e.id,"issuer.id"),...e.displayName?.trim()?{displayName:e.displayName.trim().slice(0,160)}:{},...e.workspaceId?{workspaceId:d(e.workspaceId,"issuer.workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"issuer.teamId")}:{}}}function $(e){let t={name:y(e.name,"session.name",200),surface:e.surface};for(let r of["sessionId","runId","hostedRunId","conversationId","parentSessionId","forkedFromSessionId","forkedAtEventId"])e[r]&&(t[r]=d(e[r],`session.${r}`));if(!t.sessionId&&!t.runId&&!t.hostedRunId&&!t.conversationId)throw new Error("Session identity requires sessionId, runId, hostedRunId, or conversationId");return e.git&&(t.git={...e.git.repositoryId?{repositoryId:d(e.git.repositoryId,"git.repositoryId")}:{},...e.git.remoteUrl?{remoteUrl:k(e.git.remoteUrl,"git.remoteUrl")}:{},...e.git.branch?{branch:y(e.git.branch,"git.branch",300)}:{},...e.git.commit?{commit:K(e.git.commit,"git.commit")}:{},...e.git.pullRequest?{pullRequest:{provider:e.git.pullRequest.provider,repository:y(e.git.pullRequest.repository,"git.pullRequest.repository",300),number:Oe(e.git.pullRequest.number,"git.pullRequest.number"),...e.git.pullRequest.url?{url:k(e.git.pullRequest.url,"git.pullRequest.url")}:{}}}:{}}),t}function B(e){let t=new Set;return e.map(r=>{let n=`${r.kind}:${r.id}`;if(t.has(n))throw new Error(`Duplicate share reference: ${n}`);return t.add(n),{kind:r.kind,id:d(r.id,"reference.id"),...r.title?.trim()?{title:r.title.trim().slice(0,300)}:{},...r.uri?{uri:k(r.uri,"reference.uri")}:{},...r.hash?{hash:K(r.hash,"reference.hash")}:{}}})}function ve(e){return{surface:e.surface,...e.workspaceId?{workspaceId:d(e.workspaceId,"target.workspaceId")}:{},...e.teamId?{teamId:d(e.teamId,"target.teamId")}:{},...e.environmentId?{environmentId:d(e.environmentId,"target.environmentId")}:{},...e.repositoryId?{repositoryId:d(e.repositoryId,"target.repositoryId")}:{}}}function Te(e){let t={};for(let r of["sessionId","runId","hostedRunId","checkpointId","transcriptEventId"])e[r]&&(t[r]=d(e[r],`resume.${r}`));if(e.artifactIds?.length&&(t.artifactIds=S(e.artifactIds,"resume.artifactIds")),e.taskIds?.length&&(t.taskIds=S(e.taskIds,"resume.taskIds")),!Object.keys(t).length)throw new Error("Handoff resume point cannot be empty");return t}function Ce(e){return{filesystem:e.filesystem,network:e.network,externalActions:e.externalActions,secretRefs:S(e.secretRefs,"authority.secretRefs")}}function Pe(e,t,r,n){if(e==="workspace"&&!t)throw new Error("workspace visibility requires workspaceId");if(e==="team"&&!r)throw new Error("team visibility requires teamId");if(e==="private"&&n?.length)throw new Error("private shares cannot add allowed principals; use link/workspace/team visibility")}function J(e,t){if(!e)return;let r=e;return typeof r.get=="function"?r.get(t):e[t]}function M(e){return O("sha256").update(e).digest("hex")}function S(e,t){return[...new Set(e.map(r=>d(r,t)))].sort()}function d(e,t){let r=e.trim();if(!r||r.length>500||p(r))throw new Error(`${t} is invalid`);return r}function K(e,t){let r=e.trim();if(!/^[A-Za-z0-9:+._-]{7,256}$/.test(r))throw new Error(`${t} is invalid`);return r}function y(e,t,r){let n=e.trim();if(!n||n.length>r||p(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function Oe(e,t){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${t} must be a positive integer`);return e}function k(e,t){let r=y(e,t,2e3),n=new URL(r);if(n.username||n.password)throw new Error(`${t} cannot contain credentials`);if(!["https:","xeno:","artifact:","urn:"].includes(n.protocol))throw new Error(`${t} uses an unsupported scheme`);return n.toString()}import{createHash as ne}from"node:crypto";import{chmod as Ke,mkdir as ie,open as ze,readFile as je,unlink as qe}from"node:fs/promises";import{dirname as Ue,join as Q,resolve as We}from"node:path";import*as u from"node:fs/promises";var z=Symbol.for("@xenosystem/agent-sdk/file-cache"),j=globalThis,A=j[z]??{entries:new Map,counters:{reads:0,hits:0}};j[z]=A;var ht=A.entries,pt=A.counters;var Ne=new Set(["EACCES","EBUSY","EPERM"]),_e=[10,20,40,80,160,320,640];async function q(e,t){for(let r=0;;r+=1)try{await u.rename(e,t);return}catch(n){let i=n.code,o=_e[r];if(process.platform!=="win32"||!i||!Ne.has(i)||o===void 0)throw n;await new Promise(s=>setTimeout(s,o))}}import{mkdirSync as Ve,readFileSync as Le,rmSync as W,writeFileSync as He}from"node:fs";import{hostname as Z}from"node:os";import{dirname as Fe}from"node:path";function De(){return new Date().toISOString()}function $e(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function Y(e){try{return JSON.parse(Le(e,"utf8"))}catch{return null}}function Be(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function Je(e){return e.hostname!==Z()?!0:Be(e.pid)}function U(e,t){Ve(Fe(e),{recursive:!0}),He(e,JSON.stringify(t,null,2)+`
3
+ `,{encoding:"utf8",flag:"wx"})}function Me(e,t){let r=Y(e);r?.pid!==t.pid||r.hostname!==t.hostname||W(e,{force:!0})}function G(e,t,r){let n=De(),i={schemaVersion:1,name:t,pid:process.pid,hostname:Z(),processStartedAt:$e(),version:r,acquiredAt:n,updatedAt:n};try{U(e,i)}catch(o){if(o.code!=="EEXIST")throw o;let a=Y(e);if(a&&Je(a))throw new Error(`${t} is already locked by PID ${a.pid} on ${a.hostname}.`);W(e,{force:!0}),U(e,i)}return{record:i,release:()=>{Me(e,i)}}}var ee=class{directory;snapshotPath;lockPath;now;constructor(t){this.directory=We(t.directory),this.snapshotPath=Q(this.directory,"registry.json"),this.lockPath=Q(this.directory,"registry.lock"),this.now=t.now??(()=>new Date)}async register(t,r="created"){return this.mutate(n=>{let i=n.records.find(s=>s.shareId===t.payload.shareId);if(i){if(w(i.envelope)!==w(t))throw new Error(`Share ${t.payload.shareId} already exists with different content`);return{snapshot:n,result:i}}let o={shareId:t.payload.shareId,envelope:t,status:Date.parse(t.payload.expiresAt)<=this.now().getTime()?"expired":"active",registeredAt:this.now().toISOString(),origin:r};return{snapshot:te(n,[...n.records,o],this.now()),result:o}})}async revoke(t,r,n){return this.mutate(i=>{let o=i.records.findIndex(g=>g.shareId===t);if(o<0)throw new Error(`Share not found: ${t}`);let s=i.records[o];if(s.status==="revoked")return{snapshot:i,result:s};let a={...s,status:"revoked",revokedAt:this.now().toISOString(),revokedBy:re(r,"actor"),revocationReason:re(n,"reason")},c=[...i.records];return c[o]=a,{snapshot:te(i,c,this.now()),result:a}})}async get(t){return(await this.load()).records.find(r=>r.shareId===t)??null}async list(){let t=this.now().getTime();return(await this.load()).records.map(r=>r.status==="active"&&Date.parse(r.envelope.payload.expiresAt)<=t?{...r,status:"expired"}:r).sort((r,n)=>n.registeredAt.localeCompare(r.registeredAt))}async revokedIds(){return new Set((await this.list()).filter(t=>t.status==="revoked").map(t=>t.shareId))}async load(){try{let t=await je(this.snapshotPath,"utf8"),r=JSON.parse(t);return Ye(r),r}catch(t){if(t.code==="ENOENT")return Ze(this.now());throw t}}async mutate(t){await ie(this.directory,{recursive:!0,mode:448});let r=G(this.lockPath,"xeno secure-share registry","1");try{let n=await this.load(),{snapshot:i,result:o}=t(n);return i!==n&&await Ge(this.snapshotPath,`${JSON.stringify(i,null,2)}
4
+ `),o}finally{r.release()}}};function Ze(e){return oe({schemaVersion:1,generation:0,updatedAt:e.toISOString(),records:[]})}function te(e,t,r){return oe({schemaVersion:1,generation:e.generation+1,updatedAt:r.toISOString(),records:[...t].sort((n,i)=>n.shareId.localeCompare(i.shareId))})}function oe(e){return{...e,checksum:{algorithm:"sha256",value:ne("sha256").update(w(e)).digest("hex")}}}function Ye(e){if(e.schemaVersion!==1||!Array.isArray(e.records))throw new Error("Invalid secure-share registry snapshot");let{checksum:t,...r}=e,n=ne("sha256").update(w(r)).digest("hex");if(t?.algorithm!=="sha256"||t.value!==n)throw new Error("Secure-share registry checksum mismatch");let i=new Set;for(let o of e.records){if(o.shareId!==o.envelope?.payload?.shareId)throw new Error("Secure-share registry identity mismatch");if(i.has(o.shareId))throw new Error(`Duplicate secure-share registry record: ${o.shareId}`);i.add(o.shareId)}}async function Ge(e,t){await ie(Ue(e),{recursive:!0,mode:448});let r=`${e}.${process.pid}.${Date.now()}.tmp`,n;try{n=await ze(r,"wx",384),await n.writeFile(t,"utf8"),await n.sync(),await n.close(),n=void 0,await q(r,e),await Ke(e,384).catch(()=>{})}finally{n&&await n.close().catch(()=>{}),await qe(r).catch(()=>{})}}function w(e){return h(e)}function re(e,t){let r=e.trim();if(!r||r.length>500||p(r))throw new Error(`${t} is invalid`);return r}export{ee as FileXenoShareRegistry,b as XENO_HANDOFF_SCHEMA_VERSION,m as XENO_SHARE_REGISTRY_SCHEMA_VERSION,I as XENO_SHARE_SCHEMA_VERSION,dt as createXenoSecureShare,lt as createXenoSessionHandoff,ct as createXenoShareSigningIdentity,V as publicKeyFingerprint,P as redactXenoShareValue,Xe as signSharePayload,ut as verifyXenoSecureShare,ft as verifyXenoSessionHandoff};
@@ -1 +1 @@
1
- {"inputs":{"src/sharing/types.ts":{"bytes":5121,"imports":[],"format":"esm"},"src/sharing/redaction.ts":{"bytes":6716,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/sharing/protocol.ts":{"bytes":19325,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/fs.ts":{"bytes":13746,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2496,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/sharing/file-registry.ts":{"bytes":7359,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"../control-plane/lock.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/sharing/index.ts":{"bytes":127,"imports":[{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/sharing/file-registry.ts","kind":"import-statement","original":"./file-registry.js"}],"format":"esm"}},"outputs":{"dist/sharing/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs/promises","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:fs/promises","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/sharing/index.ts","inputs":{"src/sharing/index.ts":{"bytesInOutput":413},"src/sharing/types.ts":{"bytesInOutput":16},"src/sharing/redaction.ts":{"bytesInOutput":3216},"src/sharing/protocol.ts":{"bytesInOutput":9109},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/sharing/file-registry.ts":{"bytesInOutput":3490},"src/utils/fs.ts":{"bytesInOutput":318},"src/control-plane/lock.ts":{"bytesInOutput":1059}},"bytes":19260}}}
1
+ {"inputs":{"src/sharing/types.ts":{"bytes":5121,"imports":[],"format":"esm"},"src/sharing/redaction.ts":{"bytes":6716,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/sharing/protocol.ts":{"bytes":19325,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/file-cache.ts":{"bytes":6195,"imports":[{"path":"node:fs","kind":"import-statement","external":true}],"format":"esm"},"src/utils/fs.ts":{"bytes":13885,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/file-cache.ts","kind":"import-statement","original":"./file-cache.js"}],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2496,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/sharing/file-registry.ts":{"bytes":7359,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"../control-plane/lock.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/sharing/index.ts":{"bytes":127,"imports":[{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/sharing/file-registry.ts","kind":"import-statement","original":"./file-registry.js"}],"format":"esm"}},"outputs":{"dist/sharing/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs/promises","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:fs/promises","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/sharing/index.ts","inputs":{"src/sharing/index.ts":{"bytesInOutput":413},"src/sharing/types.ts":{"bytesInOutput":16},"src/sharing/redaction.ts":{"bytesInOutput":3216},"src/sharing/protocol.ts":{"bytesInOutput":9109},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/sharing/file-registry.ts":{"bytesInOutput":3491},"src/utils/fs.ts":{"bytesInOutput":319},"src/utils/file-cache.ts":{"bytesInOutput":156},"src/control-plane/lock.ts":{"bytesInOutput":1064}},"bytes":19423}}}
@@ -1 +1 @@
1
- {"inputs":{"src/sharing/types.ts":{"bytes":5121,"imports":[],"format":"esm"},"src/sharing/redaction.ts":{"bytes":6716,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/sharing/protocol.ts":{"bytes":19325,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/fs.ts":{"bytes":13746,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2496,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/sharing/file-registry.ts":{"bytes":7359,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"../control-plane/lock.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/sharing/index.ts":{"bytes":127,"imports":[{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/sharing/file-registry.ts","kind":"import-statement","original":"./file-registry.js"}],"format":"esm"}},"outputs":{"dist/sharing/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"exports":["FileXenoShareRegistry","XENO_HANDOFF_SCHEMA_VERSION","XENO_SHARE_REGISTRY_SCHEMA_VERSION","XENO_SHARE_SCHEMA_VERSION","createXenoSecureShare","createXenoSessionHandoff","createXenoShareSigningIdentity","publicKeyFingerprint","redactXenoShareValue","signSharePayload","verifyXenoSecureShare","verifyXenoSessionHandoff"],"entryPoint":"src/sharing/index.ts","inputs":{"src/sharing/types.ts":{"bytesInOutput":16},"src/sharing/index.ts":{"bytesInOutput":0},"src/sharing/redaction.ts":{"bytesInOutput":3216},"src/sharing/protocol.ts":{"bytesInOutput":9080},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/sharing/file-registry.ts":{"bytesInOutput":3478},"src/utils/fs.ts":{"bytesInOutput":313},"src/control-plane/lock.ts":{"bytesInOutput":1041}},"bytes":18252}}}
1
+ {"inputs":{"src/sharing/types.ts":{"bytes":5121,"imports":[],"format":"esm"},"src/sharing/redaction.ts":{"bytes":6716,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/sharing/protocol.ts":{"bytes":19325,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/file-cache.ts":{"bytes":6195,"imports":[{"path":"node:fs","kind":"import-statement","external":true}],"format":"esm"},"src/utils/fs.ts":{"bytes":13885,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/file-cache.ts","kind":"import-statement","original":"./file-cache.js"}],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2496,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/sharing/file-registry.ts":{"bytes":7359,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"../control-plane/lock.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/sharing/index.ts":{"bytes":127,"imports":[{"path":"src/sharing/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/sharing/redaction.ts","kind":"import-statement","original":"./redaction.js"},{"path":"src/sharing/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/sharing/file-registry.ts","kind":"import-statement","original":"./file-registry.js"}],"format":"esm"}},"outputs":{"dist/sharing/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"exports":["FileXenoShareRegistry","XENO_HANDOFF_SCHEMA_VERSION","XENO_SHARE_REGISTRY_SCHEMA_VERSION","XENO_SHARE_SCHEMA_VERSION","createXenoSecureShare","createXenoSessionHandoff","createXenoShareSigningIdentity","publicKeyFingerprint","redactXenoShareValue","signSharePayload","verifyXenoSecureShare","verifyXenoSessionHandoff"],"entryPoint":"src/sharing/index.ts","inputs":{"src/sharing/types.ts":{"bytesInOutput":16},"src/sharing/index.ts":{"bytesInOutput":0},"src/sharing/redaction.ts":{"bytesInOutput":3216},"src/sharing/protocol.ts":{"bytesInOutput":9080},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/sharing/file-registry.ts":{"bytesInOutput":3485},"src/utils/fs.ts":{"bytesInOutput":313},"src/utils/file-cache.ts":{"bytesInOutput":156},"src/control-plane/lock.ts":{"bytesInOutput":1041}},"bytes":18416}}}