@a5c-ai/agent-runtime 5.0.1-staging.016f0b0e8119

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 (170) hide show
  1. package/README.md +23 -0
  2. package/dist/apiResult.d.ts +19 -0
  3. package/dist/apiResult.d.ts.map +1 -0
  4. package/dist/apiResult.js +16 -0
  5. package/dist/background/state.d.ts +14 -0
  6. package/dist/background/state.d.ts.map +1 -0
  7. package/dist/background/state.js +25 -0
  8. package/dist/backgroundProcessRegistry.d.ts +66 -0
  9. package/dist/backgroundProcessRegistry.d.ts.map +1 -0
  10. package/dist/backgroundProcessRegistry.js +202 -0
  11. package/dist/cost/claudeCodeParser.d.ts +81 -0
  12. package/dist/cost/claudeCodeParser.d.ts.map +1 -0
  13. package/dist/cost/claudeCodeParser.js +232 -0
  14. package/dist/cost/collector.d.ts +42 -0
  15. package/dist/cost/collector.d.ts.map +1 -0
  16. package/dist/cost/collector.js +105 -0
  17. package/dist/cost/effectCost.d.ts +23 -0
  18. package/dist/cost/effectCost.d.ts.map +1 -0
  19. package/dist/cost/effectCost.js +26 -0
  20. package/dist/cost/index.d.ts +19 -0
  21. package/dist/cost/index.d.ts.map +1 -0
  22. package/dist/cost/index.js +39 -0
  23. package/dist/cost/journal.d.ts +40 -0
  24. package/dist/cost/journal.d.ts.map +1 -0
  25. package/dist/cost/journal.js +137 -0
  26. package/dist/cost/types.d.ts +164 -0
  27. package/dist/cost/types.d.ts.map +1 -0
  28. package/dist/cost/types.js +228 -0
  29. package/dist/daemon/automationExecutor.d.ts +16 -0
  30. package/dist/daemon/automationExecutor.d.ts.map +1 -0
  31. package/dist/daemon/automationExecutor.js +222 -0
  32. package/dist/daemon/config.d.ts +8 -0
  33. package/dist/daemon/config.d.ts.map +1 -0
  34. package/dist/daemon/config.js +209 -0
  35. package/dist/daemon/daemonLog.d.ts +13 -0
  36. package/dist/daemon/daemonLog.d.ts.map +1 -0
  37. package/dist/daemon/daemonLog.js +64 -0
  38. package/dist/daemon/fileWatcher.d.ts +9 -0
  39. package/dist/daemon/fileWatcher.d.ts.map +1 -0
  40. package/dist/daemon/fileWatcher.js +141 -0
  41. package/dist/daemon/index.d.ts +13 -0
  42. package/dist/daemon/index.d.ts.map +1 -0
  43. package/dist/daemon/index.js +22 -0
  44. package/dist/daemon/lifecycle.d.ts +12 -0
  45. package/dist/daemon/lifecycle.d.ts.map +1 -0
  46. package/dist/daemon/lifecycle.js +257 -0
  47. package/dist/daemon/loop.d.ts +21 -0
  48. package/dist/daemon/loop.d.ts.map +1 -0
  49. package/dist/daemon/loop.js +196 -0
  50. package/dist/daemon/timerScheduler.d.ts +13 -0
  51. package/dist/daemon/timerScheduler.d.ts.map +1 -0
  52. package/dist/daemon/timerScheduler.js +122 -0
  53. package/dist/daemon/types.d.ts +93 -0
  54. package/dist/daemon/types.d.ts.map +1 -0
  55. package/dist/daemon/types.js +25 -0
  56. package/dist/daemon/webhookListener.d.ts +6 -0
  57. package/dist/daemon/webhookListener.d.ts.map +1 -0
  58. package/dist/daemon/webhookListener.js +110 -0
  59. package/dist/execution/index.d.ts +8 -0
  60. package/dist/execution/index.d.ts.map +1 -0
  61. package/dist/execution/index.js +12 -0
  62. package/dist/execution/modes/docker.d.ts +21 -0
  63. package/dist/execution/modes/docker.d.ts.map +1 -0
  64. package/dist/execution/modes/docker.js +125 -0
  65. package/dist/execution/modes/index.d.ts +10 -0
  66. package/dist/execution/modes/index.d.ts.map +1 -0
  67. package/dist/execution/modes/index.js +14 -0
  68. package/dist/execution/modes/kubernetes.d.ts +29 -0
  69. package/dist/execution/modes/kubernetes.d.ts.map +1 -0
  70. package/dist/execution/modes/kubernetes.js +121 -0
  71. package/dist/execution/modes/local.d.ts +23 -0
  72. package/dist/execution/modes/local.d.ts.map +1 -0
  73. package/dist/execution/modes/local.js +102 -0
  74. package/dist/execution/modes/ssh.d.ts +23 -0
  75. package/dist/execution/modes/ssh.d.ts.map +1 -0
  76. package/dist/execution/modes/ssh.js +134 -0
  77. package/dist/execution/provider.d.ts +32 -0
  78. package/dist/execution/provider.d.ts.map +1 -0
  79. package/dist/execution/provider.js +90 -0
  80. package/dist/execution/types.d.ts +105 -0
  81. package/dist/execution/types.d.ts.map +1 -0
  82. package/dist/execution/types.js +9 -0
  83. package/dist/index.d.ts +11 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +42 -0
  86. package/dist/observability/health.d.ts +19 -0
  87. package/dist/observability/health.d.ts.map +1 -0
  88. package/dist/observability/health.js +129 -0
  89. package/dist/observability/index.d.ts +6 -0
  90. package/dist/observability/index.d.ts.map +1 -0
  91. package/dist/observability/index.js +20 -0
  92. package/dist/observability/runStatus.d.ts +44 -0
  93. package/dist/observability/runStatus.d.ts.map +1 -0
  94. package/dist/observability/runStatus.js +169 -0
  95. package/dist/observability/timeline.d.ts +11 -0
  96. package/dist/observability/timeline.d.ts.map +1 -0
  97. package/dist/observability/timeline.js +176 -0
  98. package/dist/observability/types.d.ts +62 -0
  99. package/dist/observability/types.d.ts.map +1 -0
  100. package/dist/observability/types.js +8 -0
  101. package/dist/observability/webhooks.d.ts +68 -0
  102. package/dist/observability/webhooks.d.ts.map +1 -0
  103. package/dist/observability/webhooks.js +132 -0
  104. package/dist/resources/budget-tracker.d.ts +56 -0
  105. package/dist/resources/budget-tracker.d.ts.map +1 -0
  106. package/dist/resources/budget-tracker.js +131 -0
  107. package/dist/resources/concurrency-guard.d.ts +55 -0
  108. package/dist/resources/concurrency-guard.d.ts.map +1 -0
  109. package/dist/resources/concurrency-guard.js +132 -0
  110. package/dist/resources/index.d.ts +12 -0
  111. package/dist/resources/index.d.ts.map +1 -0
  112. package/dist/resources/index.js +20 -0
  113. package/dist/resources/manager.d.ts +49 -0
  114. package/dist/resources/manager.d.ts.map +1 -0
  115. package/dist/resources/manager.js +111 -0
  116. package/dist/resources/timeout-cascade.d.ts +56 -0
  117. package/dist/resources/timeout-cascade.d.ts.map +1 -0
  118. package/dist/resources/timeout-cascade.js +145 -0
  119. package/dist/resources/types.d.ts +108 -0
  120. package/dist/resources/types.d.ts.map +1 -0
  121. package/dist/resources/types.js +9 -0
  122. package/dist/session/context.d.ts +22 -0
  123. package/dist/session/context.d.ts.map +1 -0
  124. package/dist/session/context.js +113 -0
  125. package/dist/session/continuityState.d.ts +39 -0
  126. package/dist/session/continuityState.d.ts.map +1 -0
  127. package/dist/session/continuityState.js +164 -0
  128. package/dist/session/cost.d.ts +63 -0
  129. package/dist/session/cost.d.ts.map +1 -0
  130. package/dist/session/cost.js +194 -0
  131. package/dist/session/discovery.d.ts +22 -0
  132. package/dist/session/discovery.d.ts.map +1 -0
  133. package/dist/session/discovery.js +35 -0
  134. package/dist/session/history.d.ts +30 -0
  135. package/dist/session/history.d.ts.map +1 -0
  136. package/dist/session/history.js +143 -0
  137. package/dist/session/index.d.ts +20 -0
  138. package/dist/session/index.d.ts.map +1 -0
  139. package/dist/session/index.js +78 -0
  140. package/dist/session/memoryExtraction.d.ts +65 -0
  141. package/dist/session/memoryExtraction.d.ts.map +1 -0
  142. package/dist/session/memoryExtraction.js +201 -0
  143. package/dist/session/parse.d.ts +45 -0
  144. package/dist/session/parse.d.ts.map +1 -0
  145. package/dist/session/parse.js +170 -0
  146. package/dist/session/persistence.d.ts +46 -0
  147. package/dist/session/persistence.d.ts.map +1 -0
  148. package/dist/session/persistence.js +180 -0
  149. package/dist/session/types.d.ts +267 -0
  150. package/dist/session/types.d.ts.map +1 -0
  151. package/dist/session/types.js +45 -0
  152. package/dist/session/write.d.ts +61 -0
  153. package/dist/session/write.d.ts.map +1 -0
  154. package/dist/session/write.js +213 -0
  155. package/dist/telemetry/audit-log.d.ts +56 -0
  156. package/dist/telemetry/audit-log.d.ts.map +1 -0
  157. package/dist/telemetry/audit-log.js +59 -0
  158. package/dist/telemetry/index.d.ts +9 -0
  159. package/dist/telemetry/index.d.ts.map +1 -0
  160. package/dist/telemetry/index.js +15 -0
  161. package/dist/telemetry/provider.d.ts +39 -0
  162. package/dist/telemetry/provider.d.ts.map +1 -0
  163. package/dist/telemetry/provider.js +91 -0
  164. package/dist/telemetry/span-tree.d.ts +46 -0
  165. package/dist/telemetry/span-tree.d.ts.map +1 -0
  166. package/dist/telemetry/span-tree.js +93 -0
  167. package/dist/telemetry/types.d.ts +85 -0
  168. package/dist/telemetry/types.d.ts.map +1 -0
  169. package/dist/telemetry/types.js +21 -0
  170. package/package.json +90 -0
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Session state management module.
3
+ * Provides utilities for managing babysitter orchestration session state.
4
+ */
5
+ export type { SessionState, SessionFile, SessionContext, SessionDecision, SessionRunSummary, SessionContextSnapshot, SessionHistory, SessionInitOptions, SessionAssociateOptions, SessionResumeOptions, SessionStateOptions, SessionUpdateOptions, SessionInitResult, SessionAssociateResult, SessionResumeResult, SessionStateResult, SessionUpdateResult, } from './types';
6
+ export { SessionError, SessionErrorCode } from './types';
7
+ export { DEFAULT_SESSION_STATE, parseYamlFrontmatter, parseSessionState, readSessionFile, sessionFileExists, validateSessionState, getSessionFilePath, } from './parse';
8
+ export { serializeSessionState, createSessionFileContent, writeSessionFile, updateSessionState, getCurrentTimestamp, isoToEpochSeconds, updateIterationTimes, addRunToSession, getSessionRuns, } from './write';
9
+ export { getSessionContextPath, getSessionContext, updateSessionContext, } from './context';
10
+ export { HARNESS_ENV_VARS, resolveAmbientSessionId, } from './discovery';
11
+ export { getSessionHistoryPath, addDecision, addRunSummary, saveContextSnapshot, getSessionHistory, } from './history';
12
+ export type { SessionFinding, SessionFileModification, SessionBreakpointPattern, SessionPersistentState, } from './persistence';
13
+ export { SESSION_PERSISTENT_SCHEMA_VERSION, getSessionPersistentStatePath, getSessionPersistentState, addFinding, setPreference, recordFileModification, recordBreakpointInteraction, buildResumeContext, } from './persistence';
14
+ export type { ContinuityPhase, ContinuityDecision, ContinuityWorkingContext, ContinuityState, } from './continuityState';
15
+ export { CONTINUITY_STATE_SCHEMA_VERSION, getContinuityStatePath, getContinuityState, setCurrentPhase, upsertDecision, updateWorkingContext, buildContinuityResumePrompt, } from './continuityState';
16
+ export type { MemoryCategory, MemoryConfidence, MemoryEntry, LongTermMemoryStore, MemoryExtractionInput, } from './memoryExtraction';
17
+ export { LONG_TERM_MEMORY_SCHEMA_VERSION, extractMemoriesFromSession, readLongTermMemory, persistMemories, queryMemories, pruneMemories, } from './memoryExtraction';
18
+ export type { SessionBudget, SessionCostState, SessionBudgetAlert, BudgetCheckResult, RunCostUpdate, } from './cost';
19
+ export { getSessionCostPath, getSessionCost, updateSessionCost, setSessionBudget, checkBudget, markThresholdsTriggered, } from './cost';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGzD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,cAAc,EACd,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iCAAiC,EACjC,6BAA6B,EAC7B,yBAAyB,EACzB,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAGvB,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,+BAA+B,EAC/B,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACd,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,uBAAuB,GACxB,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * Session state management module.
4
+ * Provides utilities for managing babysitter orchestration session state.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getSessionCostPath = exports.pruneMemories = exports.queryMemories = exports.persistMemories = exports.readLongTermMemory = exports.extractMemoriesFromSession = exports.LONG_TERM_MEMORY_SCHEMA_VERSION = exports.buildContinuityResumePrompt = exports.updateWorkingContext = exports.upsertDecision = exports.setCurrentPhase = exports.getContinuityState = exports.getContinuityStatePath = exports.CONTINUITY_STATE_SCHEMA_VERSION = exports.buildResumeContext = exports.recordBreakpointInteraction = exports.recordFileModification = exports.setPreference = exports.addFinding = exports.getSessionPersistentState = exports.getSessionPersistentStatePath = exports.SESSION_PERSISTENT_SCHEMA_VERSION = exports.getSessionHistory = exports.saveContextSnapshot = exports.addRunSummary = exports.addDecision = exports.getSessionHistoryPath = exports.resolveAmbientSessionId = exports.HARNESS_ENV_VARS = exports.updateSessionContext = exports.getSessionContext = exports.getSessionContextPath = exports.getSessionRuns = exports.addRunToSession = exports.updateIterationTimes = exports.isoToEpochSeconds = exports.getCurrentTimestamp = exports.updateSessionState = exports.writeSessionFile = exports.createSessionFileContent = exports.serializeSessionState = exports.getSessionFilePath = exports.validateSessionState = exports.sessionFileExists = exports.readSessionFile = exports.parseSessionState = exports.parseYamlFrontmatter = exports.DEFAULT_SESSION_STATE = exports.SessionErrorCode = exports.SessionError = void 0;
8
+ exports.markThresholdsTriggered = exports.checkBudget = exports.setSessionBudget = exports.updateSessionCost = exports.getSessionCost = void 0;
9
+ var types_1 = require("./types");
10
+ Object.defineProperty(exports, "SessionError", { enumerable: true, get: function () { return types_1.SessionError; } });
11
+ Object.defineProperty(exports, "SessionErrorCode", { enumerable: true, get: function () { return types_1.SessionErrorCode; } });
12
+ // Parsing utilities
13
+ var parse_1 = require("./parse");
14
+ Object.defineProperty(exports, "DEFAULT_SESSION_STATE", { enumerable: true, get: function () { return parse_1.DEFAULT_SESSION_STATE; } });
15
+ Object.defineProperty(exports, "parseYamlFrontmatter", { enumerable: true, get: function () { return parse_1.parseYamlFrontmatter; } });
16
+ Object.defineProperty(exports, "parseSessionState", { enumerable: true, get: function () { return parse_1.parseSessionState; } });
17
+ Object.defineProperty(exports, "readSessionFile", { enumerable: true, get: function () { return parse_1.readSessionFile; } });
18
+ Object.defineProperty(exports, "sessionFileExists", { enumerable: true, get: function () { return parse_1.sessionFileExists; } });
19
+ Object.defineProperty(exports, "validateSessionState", { enumerable: true, get: function () { return parse_1.validateSessionState; } });
20
+ Object.defineProperty(exports, "getSessionFilePath", { enumerable: true, get: function () { return parse_1.getSessionFilePath; } });
21
+ // Writing utilities
22
+ var write_1 = require("./write");
23
+ Object.defineProperty(exports, "serializeSessionState", { enumerable: true, get: function () { return write_1.serializeSessionState; } });
24
+ Object.defineProperty(exports, "createSessionFileContent", { enumerable: true, get: function () { return write_1.createSessionFileContent; } });
25
+ Object.defineProperty(exports, "writeSessionFile", { enumerable: true, get: function () { return write_1.writeSessionFile; } });
26
+ Object.defineProperty(exports, "updateSessionState", { enumerable: true, get: function () { return write_1.updateSessionState; } });
27
+ Object.defineProperty(exports, "getCurrentTimestamp", { enumerable: true, get: function () { return write_1.getCurrentTimestamp; } });
28
+ Object.defineProperty(exports, "isoToEpochSeconds", { enumerable: true, get: function () { return write_1.isoToEpochSeconds; } });
29
+ Object.defineProperty(exports, "updateIterationTimes", { enumerable: true, get: function () { return write_1.updateIterationTimes; } });
30
+ Object.defineProperty(exports, "addRunToSession", { enumerable: true, get: function () { return write_1.addRunToSession; } });
31
+ Object.defineProperty(exports, "getSessionRuns", { enumerable: true, get: function () { return write_1.getSessionRuns; } });
32
+ // Context persistence (GAP-SESSION-001)
33
+ var context_1 = require("./context");
34
+ Object.defineProperty(exports, "getSessionContextPath", { enumerable: true, get: function () { return context_1.getSessionContextPath; } });
35
+ Object.defineProperty(exports, "getSessionContext", { enumerable: true, get: function () { return context_1.getSessionContext; } });
36
+ Object.defineProperty(exports, "updateSessionContext", { enumerable: true, get: function () { return context_1.updateSessionContext; } });
37
+ // Discovery (autodiscovery from markers + env)
38
+ var discovery_1 = require("./discovery");
39
+ Object.defineProperty(exports, "HARNESS_ENV_VARS", { enumerable: true, get: function () { return discovery_1.HARNESS_ENV_VARS; } });
40
+ Object.defineProperty(exports, "resolveAmbientSessionId", { enumerable: true, get: function () { return discovery_1.resolveAmbientSessionId; } });
41
+ // History persistence (GAP-SESSION-002)
42
+ var history_1 = require("./history");
43
+ Object.defineProperty(exports, "getSessionHistoryPath", { enumerable: true, get: function () { return history_1.getSessionHistoryPath; } });
44
+ Object.defineProperty(exports, "addDecision", { enumerable: true, get: function () { return history_1.addDecision; } });
45
+ Object.defineProperty(exports, "addRunSummary", { enumerable: true, get: function () { return history_1.addRunSummary; } });
46
+ Object.defineProperty(exports, "saveContextSnapshot", { enumerable: true, get: function () { return history_1.saveContextSnapshot; } });
47
+ Object.defineProperty(exports, "getSessionHistory", { enumerable: true, get: function () { return history_1.getSessionHistory; } });
48
+ var persistence_1 = require("./persistence");
49
+ Object.defineProperty(exports, "SESSION_PERSISTENT_SCHEMA_VERSION", { enumerable: true, get: function () { return persistence_1.SESSION_PERSISTENT_SCHEMA_VERSION; } });
50
+ Object.defineProperty(exports, "getSessionPersistentStatePath", { enumerable: true, get: function () { return persistence_1.getSessionPersistentStatePath; } });
51
+ Object.defineProperty(exports, "getSessionPersistentState", { enumerable: true, get: function () { return persistence_1.getSessionPersistentState; } });
52
+ Object.defineProperty(exports, "addFinding", { enumerable: true, get: function () { return persistence_1.addFinding; } });
53
+ Object.defineProperty(exports, "setPreference", { enumerable: true, get: function () { return persistence_1.setPreference; } });
54
+ Object.defineProperty(exports, "recordFileModification", { enumerable: true, get: function () { return persistence_1.recordFileModification; } });
55
+ Object.defineProperty(exports, "recordBreakpointInteraction", { enumerable: true, get: function () { return persistence_1.recordBreakpointInteraction; } });
56
+ Object.defineProperty(exports, "buildResumeContext", { enumerable: true, get: function () { return persistence_1.buildResumeContext; } });
57
+ var continuityState_1 = require("./continuityState");
58
+ Object.defineProperty(exports, "CONTINUITY_STATE_SCHEMA_VERSION", { enumerable: true, get: function () { return continuityState_1.CONTINUITY_STATE_SCHEMA_VERSION; } });
59
+ Object.defineProperty(exports, "getContinuityStatePath", { enumerable: true, get: function () { return continuityState_1.getContinuityStatePath; } });
60
+ Object.defineProperty(exports, "getContinuityState", { enumerable: true, get: function () { return continuityState_1.getContinuityState; } });
61
+ Object.defineProperty(exports, "setCurrentPhase", { enumerable: true, get: function () { return continuityState_1.setCurrentPhase; } });
62
+ Object.defineProperty(exports, "upsertDecision", { enumerable: true, get: function () { return continuityState_1.upsertDecision; } });
63
+ Object.defineProperty(exports, "updateWorkingContext", { enumerable: true, get: function () { return continuityState_1.updateWorkingContext; } });
64
+ Object.defineProperty(exports, "buildContinuityResumePrompt", { enumerable: true, get: function () { return continuityState_1.buildContinuityResumePrompt; } });
65
+ var memoryExtraction_1 = require("./memoryExtraction");
66
+ Object.defineProperty(exports, "LONG_TERM_MEMORY_SCHEMA_VERSION", { enumerable: true, get: function () { return memoryExtraction_1.LONG_TERM_MEMORY_SCHEMA_VERSION; } });
67
+ Object.defineProperty(exports, "extractMemoriesFromSession", { enumerable: true, get: function () { return memoryExtraction_1.extractMemoriesFromSession; } });
68
+ Object.defineProperty(exports, "readLongTermMemory", { enumerable: true, get: function () { return memoryExtraction_1.readLongTermMemory; } });
69
+ Object.defineProperty(exports, "persistMemories", { enumerable: true, get: function () { return memoryExtraction_1.persistMemories; } });
70
+ Object.defineProperty(exports, "queryMemories", { enumerable: true, get: function () { return memoryExtraction_1.queryMemories; } });
71
+ Object.defineProperty(exports, "pruneMemories", { enumerable: true, get: function () { return memoryExtraction_1.pruneMemories; } });
72
+ var cost_1 = require("./cost");
73
+ Object.defineProperty(exports, "getSessionCostPath", { enumerable: true, get: function () { return cost_1.getSessionCostPath; } });
74
+ Object.defineProperty(exports, "getSessionCost", { enumerable: true, get: function () { return cost_1.getSessionCost; } });
75
+ Object.defineProperty(exports, "updateSessionCost", { enumerable: true, get: function () { return cost_1.updateSessionCost; } });
76
+ Object.defineProperty(exports, "setSessionBudget", { enumerable: true, get: function () { return cost_1.setSessionBudget; } });
77
+ Object.defineProperty(exports, "checkBudget", { enumerable: true, get: function () { return cost_1.checkBudget; } });
78
+ Object.defineProperty(exports, "markThresholdsTriggered", { enumerable: true, get: function () { return cost_1.markThresholdsTriggered; } });
@@ -0,0 +1,65 @@
1
+ /**
2
+ * GAP-STATE-001: Long-Term Memory Extraction.
3
+ *
4
+ * Extract and persist important facts, decisions, and patterns from
5
+ * session history into a long-term memory store for cross-session recall.
6
+ */
7
+ export type MemoryCategory = "fact" | "decision" | "pattern" | "preference" | "architecture" | "other";
8
+ export type MemoryConfidence = "high" | "medium" | "low";
9
+ export interface MemoryEntry {
10
+ id: string;
11
+ content: string;
12
+ category: MemoryCategory;
13
+ confidence: MemoryConfidence;
14
+ sourceRunId?: string;
15
+ sourceSessionId?: string;
16
+ tags: string[];
17
+ extractedAt: string;
18
+ lastAccessedAt?: string;
19
+ }
20
+ export interface LongTermMemoryStore {
21
+ schemaVersion: string;
22
+ entries: MemoryEntry[];
23
+ updatedAt: string;
24
+ }
25
+ export interface MemoryExtractionInput {
26
+ decisions: Array<{
27
+ summary: string;
28
+ rationale?: string;
29
+ timestamp: string;
30
+ runId?: string;
31
+ }>;
32
+ findings: Array<{
33
+ content: string;
34
+ category: string;
35
+ timestamp: string;
36
+ runId?: string;
37
+ }>;
38
+ }
39
+ export declare const LONG_TERM_MEMORY_SCHEMA_VERSION = "2026.01.long-term-memory-v1";
40
+ /**
41
+ * Extract memory entries from session data. Pure function, no I/O.
42
+ * Deduplicates by content string.
43
+ */
44
+ export declare function extractMemoriesFromSession(input: MemoryExtractionInput): MemoryEntry[];
45
+ /**
46
+ * Read the long-term memory store. Returns empty store on ENOENT or corrupt JSON.
47
+ */
48
+ export declare function readLongTermMemory(globalStateDir: string): Promise<LongTermMemoryStore>;
49
+ /**
50
+ * Merge new entries into existing store. Deduplicates by id. Trims to maxEntries.
51
+ */
52
+ export declare function persistMemories(globalStateDir: string, newEntries: MemoryEntry[], maxEntries?: number): Promise<void>;
53
+ /**
54
+ * Query memories with optional filters.
55
+ */
56
+ export declare function queryMemories(globalStateDir: string, options?: {
57
+ category?: string;
58
+ tags?: string[];
59
+ limit?: number;
60
+ }): Promise<MemoryEntry[]>;
61
+ /**
62
+ * Prune memories beyond keepCount. Returns number pruned.
63
+ */
64
+ export declare function pruneMemories(globalStateDir: string, keepCount?: number): Promise<number>;
65
+ //# sourceMappingURL=memoryExtraction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryExtraction.d.ts","sourceRoot":"","sources":["../../src/session/memoryExtraction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,GAAG,OAAO,CAAC;AACvG,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7F,QAAQ,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC3F;AAMD,eAAO,MAAM,+BAA+B,gCAAgC,CAAC;AA4B7E;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,qBAAqB,GAAG,WAAW,EAAE,CAoCtF;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAkB7F;AAWD;;GAEG;AACH,wBAAsB,eAAe,CACnC,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,WAAW,EAAE,EACzB,UAAU,GAAE,MAA4B,GACvC,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/D,OAAO,CAAC,WAAW,EAAE,CAAC,CAuBxB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,cAAc,EAAE,MAAM,EACtB,SAAS,GAAE,MAA4B,GACtC,OAAO,CAAC,MAAM,CAAC,CAYjB"}
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ /**
3
+ * GAP-STATE-001: Long-Term Memory Extraction.
4
+ *
5
+ * Extract and persist important facts, decisions, and patterns from
6
+ * session history into a long-term memory store for cross-session recall.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.LONG_TERM_MEMORY_SCHEMA_VERSION = void 0;
43
+ exports.extractMemoriesFromSession = extractMemoriesFromSession;
44
+ exports.readLongTermMemory = readLongTermMemory;
45
+ exports.persistMemories = persistMemories;
46
+ exports.queryMemories = queryMemories;
47
+ exports.pruneMemories = pruneMemories;
48
+ const fs = __importStar(require("node:fs/promises"));
49
+ const path = __importStar(require("node:path"));
50
+ // ---------------------------------------------------------------------------
51
+ // Constants
52
+ // ---------------------------------------------------------------------------
53
+ exports.LONG_TERM_MEMORY_SCHEMA_VERSION = "2026.01.long-term-memory-v1";
54
+ const DEFAULT_MAX_ENTRIES = 500;
55
+ const MEMORY_FILENAME = "long-term-memory.json";
56
+ // ---------------------------------------------------------------------------
57
+ // Internal helpers
58
+ // ---------------------------------------------------------------------------
59
+ function emptyStore() {
60
+ return {
61
+ schemaVersion: exports.LONG_TERM_MEMORY_SCHEMA_VERSION,
62
+ entries: [],
63
+ updatedAt: new Date().toISOString(),
64
+ };
65
+ }
66
+ function generateMemoryId() {
67
+ return `mem-${crypto.randomUUID()}`;
68
+ }
69
+ function getStorePath(globalStateDir) {
70
+ return path.join(globalStateDir, MEMORY_FILENAME);
71
+ }
72
+ // ---------------------------------------------------------------------------
73
+ // Public API
74
+ // ---------------------------------------------------------------------------
75
+ /**
76
+ * Extract memory entries from session data. Pure function, no I/O.
77
+ * Deduplicates by content string.
78
+ */
79
+ function extractMemoriesFromSession(input) {
80
+ const seen = new Set();
81
+ const entries = [];
82
+ const now = new Date().toISOString();
83
+ for (const decision of input.decisions) {
84
+ if (seen.has(decision.summary))
85
+ continue;
86
+ seen.add(decision.summary);
87
+ entries.push({
88
+ id: generateMemoryId(),
89
+ content: decision.summary,
90
+ category: "decision",
91
+ confidence: "high",
92
+ sourceRunId: decision.runId,
93
+ tags: [],
94
+ extractedAt: now,
95
+ });
96
+ }
97
+ for (const finding of input.findings) {
98
+ if (seen.has(finding.content))
99
+ continue;
100
+ seen.add(finding.content);
101
+ const category = ["fact", "decision", "pattern", "preference", "architecture", "other"]
102
+ .find((c) => c === finding.category) ?? "other";
103
+ entries.push({
104
+ id: generateMemoryId(),
105
+ content: finding.content,
106
+ category,
107
+ confidence: "medium",
108
+ sourceRunId: finding.runId,
109
+ tags: [],
110
+ extractedAt: now,
111
+ });
112
+ }
113
+ return entries;
114
+ }
115
+ /**
116
+ * Read the long-term memory store. Returns empty store on ENOENT or corrupt JSON.
117
+ */
118
+ async function readLongTermMemory(globalStateDir) {
119
+ const filePath = getStorePath(globalStateDir);
120
+ let raw;
121
+ try {
122
+ raw = await fs.readFile(filePath, "utf8");
123
+ }
124
+ catch {
125
+ return emptyStore();
126
+ }
127
+ try {
128
+ const data = JSON.parse(raw);
129
+ return {
130
+ schemaVersion: typeof data.schemaVersion === "string" ? data.schemaVersion : exports.LONG_TERM_MEMORY_SCHEMA_VERSION,
131
+ entries: Array.isArray(data.entries) ? data.entries : [],
132
+ updatedAt: typeof data.updatedAt === "string" ? data.updatedAt : new Date().toISOString(),
133
+ };
134
+ }
135
+ catch {
136
+ return emptyStore();
137
+ }
138
+ }
139
+ async function writeStore(globalStateDir, store) {
140
+ const filePath = getStorePath(globalStateDir);
141
+ const dir = path.dirname(filePath);
142
+ const tempPath = `${filePath}.tmp.${process.pid}`;
143
+ await fs.mkdir(dir, { recursive: true });
144
+ await fs.writeFile(tempPath, JSON.stringify(store, null, 2), "utf8");
145
+ await fs.rename(tempPath, filePath);
146
+ }
147
+ /**
148
+ * Merge new entries into existing store. Deduplicates by id. Trims to maxEntries.
149
+ */
150
+ async function persistMemories(globalStateDir, newEntries, maxEntries = DEFAULT_MAX_ENTRIES) {
151
+ const store = await readLongTermMemory(globalStateDir);
152
+ const existingIds = new Set(store.entries.map((e) => e.id));
153
+ for (const entry of newEntries) {
154
+ if (!existingIds.has(entry.id)) {
155
+ store.entries.push(entry);
156
+ existingIds.add(entry.id);
157
+ }
158
+ }
159
+ // Sort by extractedAt descending (newest first), trim to maxEntries
160
+ store.entries.sort((a, b) => b.extractedAt.localeCompare(a.extractedAt));
161
+ if (store.entries.length > maxEntries) {
162
+ store.entries = store.entries.slice(0, maxEntries);
163
+ }
164
+ store.updatedAt = new Date().toISOString();
165
+ await writeStore(globalStateDir, store);
166
+ }
167
+ /**
168
+ * Query memories with optional filters.
169
+ */
170
+ async function queryMemories(globalStateDir, options) {
171
+ const store = await readLongTermMemory(globalStateDir);
172
+ let results = store.entries;
173
+ if (options?.category) {
174
+ results = results.filter((e) => e.category === options.category);
175
+ }
176
+ if (options?.tags && options.tags.length > 0) {
177
+ const filterTags = options.tags;
178
+ results = results.filter((e) => filterTags.some((t) => e.tags.includes(t)));
179
+ }
180
+ // Sort by extractedAt descending (newest first)
181
+ results.sort((a, b) => b.extractedAt.localeCompare(a.extractedAt));
182
+ if (options?.limit) {
183
+ results = results.slice(0, options.limit);
184
+ }
185
+ return results;
186
+ }
187
+ /**
188
+ * Prune memories beyond keepCount. Returns number pruned.
189
+ */
190
+ async function pruneMemories(globalStateDir, keepCount = DEFAULT_MAX_ENTRIES) {
191
+ const store = await readLongTermMemory(globalStateDir);
192
+ if (store.entries.length <= keepCount)
193
+ return 0;
194
+ // Sort by extractedAt descending, keep newest
195
+ store.entries.sort((a, b) => b.extractedAt.localeCompare(a.extractedAt));
196
+ const pruned = store.entries.length - keepCount;
197
+ store.entries = store.entries.slice(0, keepCount);
198
+ store.updatedAt = new Date().toISOString();
199
+ await writeStore(globalStateDir, store);
200
+ return pruned;
201
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Session state file parsing utilities.
3
+ * Parses markdown files with YAML frontmatter for session state.
4
+ */
5
+ import type { SessionState, SessionFile } from './types';
6
+ /**
7
+ * Default session state values.
8
+ */
9
+ export declare const DEFAULT_SESSION_STATE: SessionState;
10
+ /**
11
+ * Parse YAML frontmatter from a string.
12
+ * Expects format:
13
+ * ```
14
+ * ---
15
+ * key: value
16
+ * ---
17
+ * content
18
+ * ```
19
+ */
20
+ export declare function parseYamlFrontmatter(content: string): {
21
+ frontmatter: Record<string, string>;
22
+ body: string;
23
+ };
24
+ /**
25
+ * Parse session state from YAML frontmatter values.
26
+ */
27
+ export declare function parseSessionState(frontmatter: Record<string, string>): SessionState;
28
+ /**
29
+ * Read and parse a session state file.
30
+ */
31
+ export declare function readSessionFile(filePath: string): Promise<SessionFile>;
32
+ /**
33
+ * Check if a session state file exists.
34
+ */
35
+ export declare function sessionFileExists(filePath: string): Promise<boolean>;
36
+ /**
37
+ * Validate session state values.
38
+ * Throws SessionError if validation fails.
39
+ */
40
+ export declare function validateSessionState(state: SessionState): void;
41
+ /**
42
+ * Get the state file path for a session.
43
+ */
44
+ export declare function getSessionFilePath(stateDir: string, sessionId: string): string;
45
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/session/parse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGzD;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,YASnC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAuC3G;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CA0CnF;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CA4B5E;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO1E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAgB9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAE9E"}
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /**
3
+ * Session state file parsing utilities.
4
+ * Parses markdown files with YAML frontmatter for session state.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DEFAULT_SESSION_STATE = void 0;
8
+ exports.parseYamlFrontmatter = parseYamlFrontmatter;
9
+ exports.parseSessionState = parseSessionState;
10
+ exports.readSessionFile = readSessionFile;
11
+ exports.sessionFileExists = sessionFileExists;
12
+ exports.validateSessionState = validateSessionState;
13
+ exports.getSessionFilePath = getSessionFilePath;
14
+ const node_fs_1 = require("node:fs");
15
+ const types_1 = require("./types");
16
+ /**
17
+ * Default session state values.
18
+ */
19
+ exports.DEFAULT_SESSION_STATE = {
20
+ active: false,
21
+ iteration: 1,
22
+ maxIterations: 65_000,
23
+ runId: '',
24
+ runIds: [],
25
+ startedAt: '',
26
+ lastIterationAt: '',
27
+ iterationTimes: [],
28
+ };
29
+ /**
30
+ * Parse YAML frontmatter from a string.
31
+ * Expects format:
32
+ * ```
33
+ * ---
34
+ * key: value
35
+ * ---
36
+ * content
37
+ * ```
38
+ */
39
+ function parseYamlFrontmatter(content) {
40
+ const lines = content.split('\n');
41
+ const frontmatter = {};
42
+ let inFrontmatter = false;
43
+ let frontmatterEnd = -1;
44
+ for (let i = 0; i < lines.length; i++) {
45
+ const line = lines[i].trim();
46
+ if (line === '---') {
47
+ if (!inFrontmatter) {
48
+ inFrontmatter = true;
49
+ continue;
50
+ }
51
+ else {
52
+ frontmatterEnd = i;
53
+ break;
54
+ }
55
+ }
56
+ if (inFrontmatter && line) {
57
+ const colonIndex = line.indexOf(':');
58
+ if (colonIndex > 0) {
59
+ const key = line.slice(0, colonIndex).trim();
60
+ let value = line.slice(colonIndex + 1).trim();
61
+ // Remove surrounding quotes if present
62
+ if ((value.startsWith('"') && value.endsWith('"')) ||
63
+ (value.startsWith("'") && value.endsWith("'"))) {
64
+ value = value.slice(1, -1);
65
+ }
66
+ frontmatter[key] = value;
67
+ }
68
+ }
69
+ }
70
+ const body = frontmatterEnd >= 0
71
+ ? lines.slice(frontmatterEnd + 1).join('\n').trim()
72
+ : content;
73
+ return { frontmatter, body };
74
+ }
75
+ /**
76
+ * Parse session state from YAML frontmatter values.
77
+ */
78
+ function parseSessionState(frontmatter) {
79
+ const parseNumber = (value, defaultValue) => {
80
+ if (!value)
81
+ return defaultValue;
82
+ const parsed = parseInt(value, 10);
83
+ return Number.isFinite(parsed) ? parsed : defaultValue;
84
+ };
85
+ const parseBoolean = (value, defaultValue) => {
86
+ if (!value)
87
+ return defaultValue;
88
+ return value.toLowerCase() === 'true';
89
+ };
90
+ const parseNumberArray = (value) => {
91
+ if (!value || value.trim() === '')
92
+ return [];
93
+ return value
94
+ .split(',')
95
+ .map(s => parseInt(s.trim(), 10))
96
+ .filter(n => Number.isFinite(n) && n > 0);
97
+ };
98
+ const parseStringArray = (value) => {
99
+ if (!value || value.trim() === '')
100
+ return [];
101
+ return value.split(',').map(s => s.trim()).filter(s => s.length > 0);
102
+ };
103
+ const metadata = Object.fromEntries(Object.entries(frontmatter)
104
+ .filter(([key]) => key.startsWith('metadata_'))
105
+ .map(([key, value]) => [key.slice('metadata_'.length), value]));
106
+ return {
107
+ active: parseBoolean(frontmatter.active, exports.DEFAULT_SESSION_STATE.active),
108
+ iteration: parseNumber(frontmatter.iteration, exports.DEFAULT_SESSION_STATE.iteration),
109
+ maxIterations: parseNumber(frontmatter.max_iterations, exports.DEFAULT_SESSION_STATE.maxIterations),
110
+ runId: frontmatter.run_id ?? exports.DEFAULT_SESSION_STATE.runId,
111
+ runIds: parseStringArray(frontmatter.run_ids),
112
+ startedAt: frontmatter.started_at ?? exports.DEFAULT_SESSION_STATE.startedAt,
113
+ lastIterationAt: frontmatter.last_iteration_at ?? exports.DEFAULT_SESSION_STATE.lastIterationAt,
114
+ iterationTimes: parseNumberArray(frontmatter.iteration_times),
115
+ metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
116
+ };
117
+ }
118
+ /**
119
+ * Read and parse a session state file.
120
+ */
121
+ async function readSessionFile(filePath) {
122
+ let content;
123
+ try {
124
+ content = await node_fs_1.promises.readFile(filePath, 'utf8');
125
+ }
126
+ catch (error) {
127
+ const err = error;
128
+ if (err.code === 'ENOENT') {
129
+ throw new types_1.SessionError(`Session state file not found: ${filePath}`, types_1.SessionErrorCode.SESSION_NOT_FOUND, { filePath });
130
+ }
131
+ throw new types_1.SessionError(`Failed to read session state file: ${err.message}`, types_1.SessionErrorCode.FS_ERROR, { filePath, originalError: err.message });
132
+ }
133
+ const { frontmatter, body } = parseYamlFrontmatter(content);
134
+ const state = parseSessionState(frontmatter);
135
+ return {
136
+ state,
137
+ prompt: body,
138
+ filePath,
139
+ };
140
+ }
141
+ /**
142
+ * Check if a session state file exists.
143
+ */
144
+ async function sessionFileExists(filePath) {
145
+ try {
146
+ await node_fs_1.promises.access(filePath);
147
+ return true;
148
+ }
149
+ catch {
150
+ return false;
151
+ }
152
+ }
153
+ /**
154
+ * Validate session state values.
155
+ * Throws SessionError if validation fails.
156
+ */
157
+ function validateSessionState(state) {
158
+ if (typeof state.iteration !== 'number' || !Number.isFinite(state.iteration) || state.iteration < 0) {
159
+ throw new types_1.SessionError(`Invalid iteration value: ${state.iteration}`, types_1.SessionErrorCode.INVALID_STATE_VALUE, { field: 'iteration', value: state.iteration });
160
+ }
161
+ if (typeof state.maxIterations !== 'number' || !Number.isFinite(state.maxIterations) || state.maxIterations < 0) {
162
+ throw new types_1.SessionError(`Invalid maxIterations value: ${state.maxIterations}`, types_1.SessionErrorCode.INVALID_STATE_VALUE, { field: 'maxIterations', value: state.maxIterations });
163
+ }
164
+ }
165
+ /**
166
+ * Get the state file path for a session.
167
+ */
168
+ function getSessionFilePath(stateDir, sessionId) {
169
+ return `${stateDir}/${sessionId}.md`;
170
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * GAP-STATE-003: Session State Persistence.
3
+ *
4
+ * Stores rich persistent state: findings, file modifications, breakpoint patterns,
5
+ * and user preferences. Follows the same atomic temp-file + rename pattern
6
+ * as context.ts and history.ts.
7
+ */
8
+ export interface SessionFinding {
9
+ content: string;
10
+ category: "architecture" | "bug" | "pattern" | "dependency" | "other";
11
+ runId?: string;
12
+ timestamp: string;
13
+ }
14
+ export interface SessionFileModification {
15
+ filePath: string;
16
+ action: "create" | "modify" | "delete";
17
+ runId?: string;
18
+ timestamp: string;
19
+ }
20
+ export interface SessionBreakpointPattern {
21
+ breakpointId: string;
22
+ approvedCount: number;
23
+ rejectedCount: number;
24
+ lastAction: "approved" | "rejected";
25
+ lastInteractionAt: string;
26
+ }
27
+ export interface SessionPersistentState {
28
+ schemaVersion: string;
29
+ findings: SessionFinding[];
30
+ preferences: Record<string, string>;
31
+ fileModifications: SessionFileModification[];
32
+ breakpointPatterns: SessionBreakpointPattern[];
33
+ }
34
+ export declare const SESSION_PERSISTENT_SCHEMA_VERSION = "2026.01.session-persistent-v1";
35
+ export declare function getSessionPersistentStatePath(stateDir: string, sessionId: string): string;
36
+ export declare function getSessionPersistentState(stateDir: string, sessionId: string): Promise<SessionPersistentState>;
37
+ export declare function addFinding(stateDir: string, sessionId: string, finding: Omit<SessionFinding, "timestamp">): Promise<void>;
38
+ export declare function setPreference(stateDir: string, sessionId: string, key: string, value: string): Promise<void>;
39
+ export declare function recordFileModification(stateDir: string, sessionId: string, mod: Omit<SessionFileModification, "timestamp">): Promise<void>;
40
+ export declare function recordBreakpointInteraction(stateDir: string, sessionId: string, breakpointId: string, action: "approved" | "rejected"): Promise<void>;
41
+ /**
42
+ * Render persistent state into a markdown section for resume prompt injection.
43
+ * Returns empty string when no meaningful data exists.
44
+ */
45
+ export declare function buildResumeContext(stateDir: string, sessionId: string): Promise<string>;
46
+ //# sourceMappingURL=persistence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../src/session/persistence.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,cAAc,GAAG,KAAK,GAAG,SAAS,GAAG,YAAY,GAAG,OAAO,CAAC;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;IACpC,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,iBAAiB,EAAE,uBAAuB,EAAE,CAAC;IAC7C,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;CAChD;AAED,eAAO,MAAM,iCAAiC,kCAAkC,CAAC;AAuDjF,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzF;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAEpH;AAED,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,GACzC,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,IAAI,CAAC,uBAAuB,EAAE,WAAW,CAAC,GAC9C,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,wBAAsB,2BAA2B,CAC/C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,UAAU,GAAG,UAAU,GAC9B,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B7F"}