sessionlog 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +388 -0
- package/dist/agent/agents/claude-code.d.ts +76 -0
- package/dist/agent/agents/claude-code.d.ts.map +1 -0
- package/dist/agent/agents/claude-code.js +769 -0
- package/dist/agent/agents/claude-code.js.map +1 -0
- package/dist/agent/agents/cursor.d.ts +35 -0
- package/dist/agent/agents/cursor.d.ts.map +1 -0
- package/dist/agent/agents/cursor.js +294 -0
- package/dist/agent/agents/cursor.js.map +1 -0
- package/dist/agent/agents/gemini-cli.d.ts +62 -0
- package/dist/agent/agents/gemini-cli.d.ts.map +1 -0
- package/dist/agent/agents/gemini-cli.js +474 -0
- package/dist/agent/agents/gemini-cli.js.map +1 -0
- package/dist/agent/agents/opencode.d.ts +100 -0
- package/dist/agent/agents/opencode.d.ts.map +1 -0
- package/dist/agent/agents/opencode.js +423 -0
- package/dist/agent/agents/opencode.js.map +1 -0
- package/dist/agent/registry.d.ts +54 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/registry.js +123 -0
- package/dist/agent/registry.js.map +1 -0
- package/dist/agent/session-types.d.ts +45 -0
- package/dist/agent/session-types.d.ts.map +1 -0
- package/dist/agent/session-types.js +48 -0
- package/dist/agent/session-types.js.map +1 -0
- package/dist/agent/types.d.ts +126 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +40 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +425 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/clean.d.ts +30 -0
- package/dist/commands/clean.d.ts.map +1 -0
- package/dist/commands/clean.js +98 -0
- package/dist/commands/clean.js.map +1 -0
- package/dist/commands/disable.d.ts +23 -0
- package/dist/commands/disable.d.ts.map +1 -0
- package/dist/commands/disable.js +57 -0
- package/dist/commands/disable.js.map +1 -0
- package/dist/commands/doctor.d.ts +43 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +97 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/enable.d.ts +37 -0
- package/dist/commands/enable.d.ts.map +1 -0
- package/dist/commands/enable.js +133 -0
- package/dist/commands/enable.js.map +1 -0
- package/dist/commands/explain.d.ts +68 -0
- package/dist/commands/explain.d.ts.map +1 -0
- package/dist/commands/explain.js +182 -0
- package/dist/commands/explain.js.map +1 -0
- package/dist/commands/reset.d.ts +23 -0
- package/dist/commands/reset.d.ts.map +1 -0
- package/dist/commands/reset.js +68 -0
- package/dist/commands/reset.js.map +1 -0
- package/dist/commands/resume.d.ts +42 -0
- package/dist/commands/resume.d.ts.map +1 -0
- package/dist/commands/resume.js +133 -0
- package/dist/commands/resume.js.map +1 -0
- package/dist/commands/rewind.d.ts +34 -0
- package/dist/commands/rewind.d.ts.map +1 -0
- package/dist/commands/rewind.js +155 -0
- package/dist/commands/rewind.js.map +1 -0
- package/dist/commands/status.d.ts +51 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +112 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config.d.ts +40 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +127 -0
- package/dist/config.js.map +1 -0
- package/dist/git-operations.d.ts +191 -0
- package/dist/git-operations.d.ts.map +1 -0
- package/dist/git-operations.js +462 -0
- package/dist/git-operations.js.map +1 -0
- package/dist/hooks/git-hooks.d.ts +22 -0
- package/dist/hooks/git-hooks.d.ts.map +1 -0
- package/dist/hooks/git-hooks.js +139 -0
- package/dist/hooks/git-hooks.js.map +1 -0
- package/dist/hooks/lifecycle.d.ts +21 -0
- package/dist/hooks/lifecycle.d.ts.map +1 -0
- package/dist/hooks/lifecycle.js +179 -0
- package/dist/hooks/lifecycle.js.map +1 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/dist/security/redaction.d.ts +35 -0
- package/dist/security/redaction.d.ts.map +1 -0
- package/dist/security/redaction.js +239 -0
- package/dist/security/redaction.js.map +1 -0
- package/dist/session/state-machine.d.ts +90 -0
- package/dist/session/state-machine.d.ts.map +1 -0
- package/dist/session/state-machine.js +345 -0
- package/dist/session/state-machine.js.map +1 -0
- package/dist/store/checkpoint-store.d.ts +59 -0
- package/dist/store/checkpoint-store.d.ts.map +1 -0
- package/dist/store/checkpoint-store.js +321 -0
- package/dist/store/checkpoint-store.js.map +1 -0
- package/dist/store/native-store.d.ts +14 -0
- package/dist/store/native-store.d.ts.map +1 -0
- package/dist/store/native-store.js +159 -0
- package/dist/store/native-store.js.map +1 -0
- package/dist/store/provider-types.d.ts +78 -0
- package/dist/store/provider-types.d.ts.map +1 -0
- package/dist/store/provider-types.js +12 -0
- package/dist/store/provider-types.js.map +1 -0
- package/dist/store/session-store.d.ts +36 -0
- package/dist/store/session-store.d.ts.map +1 -0
- package/dist/store/session-store.js +193 -0
- package/dist/store/session-store.js.map +1 -0
- package/dist/strategy/attribution.d.ts +39 -0
- package/dist/strategy/attribution.d.ts.map +1 -0
- package/dist/strategy/attribution.js +225 -0
- package/dist/strategy/attribution.js.map +1 -0
- package/dist/strategy/common.d.ts +57 -0
- package/dist/strategy/common.d.ts.map +1 -0
- package/dist/strategy/common.js +156 -0
- package/dist/strategy/common.js.map +1 -0
- package/dist/strategy/content-overlap.d.ts +33 -0
- package/dist/strategy/content-overlap.d.ts.map +1 -0
- package/dist/strategy/content-overlap.js +176 -0
- package/dist/strategy/content-overlap.js.map +1 -0
- package/dist/strategy/manual-commit.d.ts +36 -0
- package/dist/strategy/manual-commit.d.ts.map +1 -0
- package/dist/strategy/manual-commit.js +717 -0
- package/dist/strategy/manual-commit.js.map +1 -0
- package/dist/strategy/types.d.ts +163 -0
- package/dist/strategy/types.d.ts.map +1 -0
- package/dist/strategy/types.js +48 -0
- package/dist/strategy/types.js.map +1 -0
- package/dist/summarize/claude-generator.d.ts +25 -0
- package/dist/summarize/claude-generator.d.ts.map +1 -0
- package/dist/summarize/claude-generator.js +87 -0
- package/dist/summarize/claude-generator.js.map +1 -0
- package/dist/summarize/summarize.d.ts +52 -0
- package/dist/summarize/summarize.d.ts.map +1 -0
- package/dist/summarize/summarize.js +335 -0
- package/dist/summarize/summarize.js.map +1 -0
- package/dist/types.d.ts +293 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +94 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/chunk-files.d.ts +25 -0
- package/dist/utils/chunk-files.d.ts.map +1 -0
- package/dist/utils/chunk-files.js +47 -0
- package/dist/utils/chunk-files.js.map +1 -0
- package/dist/utils/commit-message.d.ts +11 -0
- package/dist/utils/commit-message.d.ts.map +1 -0
- package/dist/utils/commit-message.js +54 -0
- package/dist/utils/commit-message.js.map +1 -0
- package/dist/utils/detect-agent.d.ts +19 -0
- package/dist/utils/detect-agent.d.ts.map +1 -0
- package/dist/utils/detect-agent.js +34 -0
- package/dist/utils/detect-agent.js.map +1 -0
- package/dist/utils/hook-managers.d.ts +24 -0
- package/dist/utils/hook-managers.d.ts.map +1 -0
- package/dist/utils/hook-managers.js +96 -0
- package/dist/utils/hook-managers.js.map +1 -0
- package/dist/utils/ide-tags.d.ts +12 -0
- package/dist/utils/ide-tags.d.ts.map +1 -0
- package/dist/utils/ide-tags.js +30 -0
- package/dist/utils/ide-tags.js.map +1 -0
- package/dist/utils/paths.d.ts +32 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +55 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/preview-rewind.d.ts +23 -0
- package/dist/utils/preview-rewind.d.ts.map +1 -0
- package/dist/utils/preview-rewind.js +63 -0
- package/dist/utils/preview-rewind.js.map +1 -0
- package/dist/utils/rewind-conflict.d.ts +52 -0
- package/dist/utils/rewind-conflict.d.ts.map +1 -0
- package/dist/utils/rewind-conflict.js +79 -0
- package/dist/utils/rewind-conflict.js.map +1 -0
- package/dist/utils/shadow-branch.d.ts +44 -0
- package/dist/utils/shadow-branch.d.ts.map +1 -0
- package/dist/utils/shadow-branch.js +93 -0
- package/dist/utils/shadow-branch.js.map +1 -0
- package/dist/utils/string-utils.d.ts +24 -0
- package/dist/utils/string-utils.d.ts.map +1 -0
- package/dist/utils/string-utils.js +47 -0
- package/dist/utils/string-utils.js.map +1 -0
- package/dist/utils/todo-extract.d.ts +52 -0
- package/dist/utils/todo-extract.d.ts.map +1 -0
- package/dist/utils/todo-extract.js +167 -0
- package/dist/utils/todo-extract.js.map +1 -0
- package/dist/utils/trailers.d.ts +36 -0
- package/dist/utils/trailers.d.ts.map +1 -0
- package/dist/utils/trailers.js +148 -0
- package/dist/utils/trailers.js.map +1 -0
- package/dist/utils/transcript-parse.d.ts +57 -0
- package/dist/utils/transcript-parse.d.ts.map +1 -0
- package/dist/utils/transcript-parse.js +126 -0
- package/dist/utils/transcript-parse.js.map +1 -0
- package/dist/utils/transcript-timestamp.d.ts +22 -0
- package/dist/utils/transcript-timestamp.d.ts.map +1 -0
- package/dist/utils/transcript-timestamp.js +56 -0
- package/dist/utils/transcript-timestamp.js.map +1 -0
- package/dist/utils/tree-ops.d.ts +47 -0
- package/dist/utils/tree-ops.d.ts.map +1 -0
- package/dist/utils/tree-ops.js +145 -0
- package/dist/utils/tree-ops.js.map +1 -0
- package/dist/utils/tty.d.ts +25 -0
- package/dist/utils/tty.d.ts.map +1 -0
- package/dist/utils/tty.js +70 -0
- package/dist/utils/tty.js.map +1 -0
- package/dist/utils/validation.d.ts +31 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +59 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/worktree.d.ts +16 -0
- package/dist/utils/worktree.d.ts.map +1 -0
- package/dist/utils/worktree.js +50 -0
- package/dist/utils/worktree.js.map +1 -0
- package/package.json +64 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entire - Native TypeScript Implementation
|
|
3
|
+
*
|
|
4
|
+
* A self-contained module that implements the Entire CLI's functionality
|
|
5
|
+
* in TypeScript. Designed with clean boundaries for eventual extraction
|
|
6
|
+
* into a standalone package.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import { createRequire } from 'node:module';
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Version
|
|
13
|
+
// =============================================================================
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
const { version: VERSION } = require('../package.json');
|
|
16
|
+
/** Current package version */
|
|
17
|
+
export { VERSION };
|
|
18
|
+
/**
|
|
19
|
+
* Get the current version string.
|
|
20
|
+
*/
|
|
21
|
+
export function getVersion() {
|
|
22
|
+
return VERSION;
|
|
23
|
+
}
|
|
24
|
+
export { AGENT_NAMES, AGENT_TYPES, DEFAULT_AGENT_NAME, EventType, CheckpointType, CHECKPOINT_ID_LENGTH, CHECKPOINT_ID_PATTERN, CHECKPOINTS_BRANCH, SHADOW_BRANCH_PREFIX, ENTIRE_DIR, ENTIRE_METADATA_DIR, ENTIRE_TMP_DIR, ENTIRE_SETTINGS_FILE, ENTIRE_SETTINGS_LOCAL_FILE, SESSION_DIR_NAME, MAX_CHUNK_SIZE, DEFAULT_SETTINGS, validateCheckpointID, checkpointIDPath, emptyTokenUsage, addTokenUsage, } from './types.js';
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// Git Operations
|
|
27
|
+
// =============================================================================
|
|
28
|
+
export { git, gitSafe, getGitDir, getGitCommonDir, getWorktreeRoot, isGitRepository, getSessionsDir, getHead, getShortHash, getCurrentBranch, refExists, getTreeHash, listBranches, hashObject, mktree, commitTree, lsTree, catFile, showFile, log, diffNameOnly, diffStat, hasUncommittedChanges, getUntrackedFiles, isOnDefaultBranch, pushBranch, getGitAuthor, resolveGitDirSync, atomicWriteFile, initSessionRepo, resolveSessionRepoPath, getProjectID, GitError, } from './git-operations.js';
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// Session Store
|
|
31
|
+
// =============================================================================
|
|
32
|
+
export { createSessionStore, normalizeSessionState, } from './store/session-store.js';
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// Checkpoint Store
|
|
35
|
+
// =============================================================================
|
|
36
|
+
export { createCheckpointStore } from './store/checkpoint-store.js';
|
|
37
|
+
// =============================================================================
|
|
38
|
+
// Native Store (replaces CLI store)
|
|
39
|
+
// =============================================================================
|
|
40
|
+
export { createNativeEntireStore } from './store/native-store.js';
|
|
41
|
+
export { hasHookSupport, hasFileWatcher, hasTranscriptAnalyzer, hasTokenCalculator, hasTranscriptChunker, hasTranscriptPreparer, hasSubagentAwareExtractor, } from './agent/types.js';
|
|
42
|
+
export { registerAgent, getAgent, listAgentNames, listAgents, detectAgents, detectAgent, getAgentByType, getDefaultAgent, allProtectedDirs, resolveAgent, resetRegistry, } from './agent/registry.js';
|
|
43
|
+
// Agent Implementations
|
|
44
|
+
export { createClaudeCodeAgent, parseTranscript, extractModifiedFiles, extractLastUserPrompt, extractSpawnedAgentIDs, } from './agent/agents/claude-code.js';
|
|
45
|
+
export { createCursorAgent } from './agent/agents/cursor.js';
|
|
46
|
+
export { createGeminiCLIAgent, } from './agent/agents/gemini-cli.js';
|
|
47
|
+
export { createOpenCodeAgent, extractTextFromParts, parseExportSession, extractAllUserPrompts, } from './agent/agents/opencode.js';
|
|
48
|
+
// =============================================================================
|
|
49
|
+
// Hooks
|
|
50
|
+
// =============================================================================
|
|
51
|
+
export { installGitHooks, uninstallGitHooks, areGitHooksInstalled, } from './hooks/git-hooks.js';
|
|
52
|
+
export { createLifecycleHandler, } from './hooks/lifecycle.js';
|
|
53
|
+
// =============================================================================
|
|
54
|
+
// Security
|
|
55
|
+
// =============================================================================
|
|
56
|
+
export { shannonEntropy, detectSecrets, redactString, redactBuffer, redactJSONL, } from './security/redaction.js';
|
|
57
|
+
// =============================================================================
|
|
58
|
+
// Configuration
|
|
59
|
+
// =============================================================================
|
|
60
|
+
export { loadSettings, loadProjectSettings, loadLocalSettings, saveProjectSettings, saveLocalSettings, isEnabled, getStrategy, ensureGitignore, } from './config.js';
|
|
61
|
+
// =============================================================================
|
|
62
|
+
// Commands
|
|
63
|
+
// =============================================================================
|
|
64
|
+
export { enable } from './commands/enable.js';
|
|
65
|
+
export { disable } from './commands/disable.js';
|
|
66
|
+
export { status, formatStatusJSON, formatTokens, } from './commands/status.js';
|
|
67
|
+
export { listRewindPoints, rewindTo, listRewindPointsJSON, } from './commands/rewind.js';
|
|
68
|
+
export { diagnose, discardSession, doctor, } from './commands/doctor.js';
|
|
69
|
+
export { findOrphaned, clean, } from './commands/clean.js';
|
|
70
|
+
export { reset } from './commands/reset.js';
|
|
71
|
+
export { listCheckpoints, getCheckpointDetail, getCheckpointTranscript, explainCommit, findCheckpointByPrefix, } from './commands/explain.js';
|
|
72
|
+
export { discoverResumeInfo, listResumableBranches, } from './commands/resume.js';
|
|
73
|
+
// =============================================================================
|
|
74
|
+
// Strategy Engine
|
|
75
|
+
// =============================================================================
|
|
76
|
+
export { createManualCommitStrategy, hasUserContent, stripCheckpointTrailer, } from './strategy/manual-commit.js';
|
|
77
|
+
export { STRATEGY_NAME_MANUAL_COMMIT, MAX_COMMIT_TRAVERSAL_DEPTH } from './strategy/types.js';
|
|
78
|
+
// =============================================================================
|
|
79
|
+
// Utilities
|
|
80
|
+
// =============================================================================
|
|
81
|
+
export { parseStrategy, parseMetadata, parseTaskMetadata, parseBaseCommit, parseCondensation, parseSession, parseCheckpoint as parseCheckpointTrailer, parseAllSessions, formatStrategy, formatMetadata, formatShadowCommit, formatShadowTaskCommit, formatCheckpoint as formatCheckpointTrailer, formatSourceRef, MetadataTrailerKey, StrategyTrailerKey, SessionTrailerKey, CheckpointTrailerKey, BaseCommitTrailerKey, } from './utils/trailers.js';
|
|
82
|
+
export { stripIDEContextTags } from './utils/ide-tags.js';
|
|
83
|
+
export { truncateRunes, collapseWhitespace, capitalizeFirst, countLines, } from './utils/string-utils.js';
|
|
84
|
+
export { parseFromBytes, parseFromBytesAtLine, sliceFromLine, extractUserContent, } from './utils/transcript-parse.js';
|
|
85
|
+
export { generateCommitMessage } from './utils/commit-message.js';
|
|
86
|
+
// =============================================================================
|
|
87
|
+
// Summarization
|
|
88
|
+
// =============================================================================
|
|
89
|
+
export { buildCondensedTranscriptFromBytes, buildCondensedTranscript, formatCondensedTranscript, buildSummarizationPrompt, extractJSONFromMarkdown, generateFromTranscript, } from './summarize/summarize.js';
|
|
90
|
+
// =============================================================================
|
|
91
|
+
// Attribution
|
|
92
|
+
// =============================================================================
|
|
93
|
+
export { diffLines, getAllChangedFiles, calculateAttributionWithAccumulated, } from './strategy/attribution.js';
|
|
94
|
+
// =============================================================================
|
|
95
|
+
// Content Overlap
|
|
96
|
+
// =============================================================================
|
|
97
|
+
export { filesOverlapWithContent, stagedFilesOverlapWithContent, filesWithRemainingAgentChanges, } from './strategy/content-overlap.js';
|
|
98
|
+
// =============================================================================
|
|
99
|
+
// Validation
|
|
100
|
+
// =============================================================================
|
|
101
|
+
export { validateSessionID, validateToolUseID, validateAgentID, validateAgentSessionID, } from './utils/validation.js';
|
|
102
|
+
// =============================================================================
|
|
103
|
+
// Hook Manager Detection
|
|
104
|
+
// =============================================================================
|
|
105
|
+
export { detectHookManagers, hookManagerWarning } from './utils/hook-managers.js';
|
|
106
|
+
// =============================================================================
|
|
107
|
+
// Worktree Utilities
|
|
108
|
+
// =============================================================================
|
|
109
|
+
export { getWorktreeID } from './utils/worktree.js';
|
|
110
|
+
// =============================================================================
|
|
111
|
+
// Transcript Timestamps
|
|
112
|
+
// =============================================================================
|
|
113
|
+
export { parseTimestampFromJSONL, getLastTimestampFromBytes, getLastTimestampFromFile, } from './utils/transcript-timestamp.js';
|
|
114
|
+
// =============================================================================
|
|
115
|
+
// Summary Generator (Claude CLI)
|
|
116
|
+
// =============================================================================
|
|
117
|
+
export { createClaudeGenerator, DEFAULT_SUMMARIZE_MODEL, } from './summarize/claude-generator.js';
|
|
118
|
+
// =============================================================================
|
|
119
|
+
// Session State Machine
|
|
120
|
+
// =============================================================================
|
|
121
|
+
export { transition, applyTransition, phaseFromString, eventToString, actionToString, isStale, normalizeAfterLoad, mermaidDiagram, NoOpActionHandler, STALE_SESSION_THRESHOLD_MS, } from './session/state-machine.js';
|
|
122
|
+
// =============================================================================
|
|
123
|
+
// Todo Extraction
|
|
124
|
+
// =============================================================================
|
|
125
|
+
export { extractLastCompletedTodo, extractInProgressTodo, countTodos, extractTodoContentFromToolInput, extractLastCompletedTodoFromToolInput, countTodosFromToolInput, formatIncrementalMessage, } from './utils/todo-extract.js';
|
|
126
|
+
// =============================================================================
|
|
127
|
+
// Rewind Conflict Detection
|
|
128
|
+
// =============================================================================
|
|
129
|
+
export { classifyTimestamps, statusToText, hasConflicts, partitionConflicts, resolveAgentForRewind, } from './utils/rewind-conflict.js';
|
|
130
|
+
// =============================================================================
|
|
131
|
+
// Chunk File Naming
|
|
132
|
+
// =============================================================================
|
|
133
|
+
export { chunkFileName, parseChunkIndex, sortChunkFiles } from './utils/chunk-files.js';
|
|
134
|
+
// =============================================================================
|
|
135
|
+
// Path Classification
|
|
136
|
+
// =============================================================================
|
|
137
|
+
export { isInfrastructurePath, toRelativePath, absPath, extractSessionIDFromPath, sessionMetadataDir, } from './utils/paths.js';
|
|
138
|
+
// =============================================================================
|
|
139
|
+
// Agent Type Detection
|
|
140
|
+
// =============================================================================
|
|
141
|
+
export { detectAgentTypeFromContent } from './utils/detect-agent.js';
|
|
142
|
+
// =============================================================================
|
|
143
|
+
// TTY Interaction
|
|
144
|
+
// =============================================================================
|
|
145
|
+
export { hasTTY, askConfirmTTY } from './utils/tty.js';
|
|
146
|
+
// =============================================================================
|
|
147
|
+
// Shadow Branch Utilities
|
|
148
|
+
// =============================================================================
|
|
149
|
+
export { hashWorktreeID, shadowBranchNameForCommit, parseShadowBranchName, isShadowBranch, listShadowBranches, deleteShadowBranches, } from './utils/shadow-branch.js';
|
|
150
|
+
// =============================================================================
|
|
151
|
+
// Rewind Preview
|
|
152
|
+
// =============================================================================
|
|
153
|
+
export { previewRewind, } from './utils/preview-rewind.js';
|
|
154
|
+
// =============================================================================
|
|
155
|
+
// Normalized Agent Session
|
|
156
|
+
// =============================================================================
|
|
157
|
+
export { createAgentSession } from './agent/session-types.js';
|
|
158
|
+
// =============================================================================
|
|
159
|
+
// Strategy Infrastructure
|
|
160
|
+
// =============================================================================
|
|
161
|
+
export { validateRepository, isEmptyRepository, isAncestorOf, isInsideWorktree, ensureMetadataBranch, readCheckpointMetadata, readSessionPromptFromTree, readAgentTypeFromTree, extractFirstPrompt, ensureSetup, getMainRepoRoot, } from './strategy/common.js';
|
|
162
|
+
// =============================================================================
|
|
163
|
+
// Git Tree Manipulation
|
|
164
|
+
// =============================================================================
|
|
165
|
+
export { updateSubtree, applyTreeChanges, createTreeFromMap } from './utils/tree-ops.js';
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AAE/E,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB;;GAEG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,OAAO,CAAC;AACjB,CAAC;AAkCD,OAAO,EACL,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,oBA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Ae,GAChB,MAAM,sBAAsB,CAAC;AAE9B,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,iBAAiB,EAAa,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret Redaction
|
|
3
|
+
*
|
|
4
|
+
* Multi-layered secret detection and redaction for transcripts.
|
|
5
|
+
* Uses both entropy-based detection and pattern matching
|
|
6
|
+
* for known secret formats.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Calculate Shannon entropy of a string
|
|
10
|
+
*/
|
|
11
|
+
export declare function shannonEntropy(s: string): number;
|
|
12
|
+
interface RedactionRegion {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
source: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Detect secret regions in a string
|
|
19
|
+
*/
|
|
20
|
+
export declare function detectSecrets(text: string): RedactionRegion[];
|
|
21
|
+
/**
|
|
22
|
+
* Redact secrets from a plain string
|
|
23
|
+
*/
|
|
24
|
+
export declare function redactString(text: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Redact secrets from a Buffer
|
|
27
|
+
*/
|
|
28
|
+
export declare function redactBuffer(buf: Buffer): Buffer;
|
|
29
|
+
/**
|
|
30
|
+
* Redact secrets from JSONL content (line by line)
|
|
31
|
+
* Preserves JSON structure and skips safe fields
|
|
32
|
+
*/
|
|
33
|
+
export declare function redactJSONL(content: string): string;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=redaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.d.ts","sourceRoot":"","sources":["../../src/security/redaction.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuGH;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAehD;AAMD,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AA2BD;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,CA8B7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAejD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAqBnD"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret Redaction
|
|
3
|
+
*
|
|
4
|
+
* Multi-layered secret detection and redaction for transcripts.
|
|
5
|
+
* Uses both entropy-based detection and pattern matching
|
|
6
|
+
* for known secret formats.
|
|
7
|
+
*/
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Constants
|
|
10
|
+
// ============================================================================
|
|
11
|
+
const ENTROPY_THRESHOLD = 4.5;
|
|
12
|
+
const MIN_SECRET_LENGTH = 10;
|
|
13
|
+
const REDACTED_PLACEHOLDER = 'REDACTED';
|
|
14
|
+
/** High-entropy alphanumeric pattern (potential secrets) */
|
|
15
|
+
const HIGH_ENTROPY_PATTERN = /[A-Za-z0-9+_=-]{10,}/g;
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Known Secret Patterns (subset of gitleaks rules)
|
|
18
|
+
// ============================================================================
|
|
19
|
+
const SECRET_PATTERNS = [
|
|
20
|
+
// API Keys
|
|
21
|
+
{
|
|
22
|
+
name: 'aws-access-key',
|
|
23
|
+
pattern: /(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}/g,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'aws-secret-key',
|
|
27
|
+
pattern: /(?:aws_secret_access_key|aws_secret_key|secret_key)\s*[=:]\s*["']?([A-Za-z0-9/+=]{40})["']?/gi,
|
|
28
|
+
},
|
|
29
|
+
{ name: 'github-token', pattern: /gh[pousr]_[A-Za-z0-9_]{36,255}/g },
|
|
30
|
+
{ name: 'github-fine-grained', pattern: /github_pat_[A-Za-z0-9_]{22,255}/g },
|
|
31
|
+
{ name: 'gitlab-token', pattern: /glpat-[A-Za-z0-9=_-]{20,}/g },
|
|
32
|
+
{ name: 'google-api-key', pattern: /AIza[A-Za-z0-9_-]{35}/g },
|
|
33
|
+
{ name: 'slack-token', pattern: /xox[baprs]-[0-9]{10,13}-[0-9]{10,13}-[a-zA-Z0-9]{24,34}/g },
|
|
34
|
+
{
|
|
35
|
+
name: 'slack-webhook',
|
|
36
|
+
pattern: /https:\/\/hooks\.slack\.com\/services\/T[A-Z0-9]{10}\/B[A-Z0-9]{10}\/[a-zA-Z0-9]{24}/g,
|
|
37
|
+
},
|
|
38
|
+
{ name: 'stripe-key', pattern: /(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]{10,99}/g },
|
|
39
|
+
{ name: 'twilio-api-key', pattern: /SK[0-9a-fA-F]{32}/g },
|
|
40
|
+
{ name: 'sendgrid-api-key', pattern: /SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}/g },
|
|
41
|
+
{ name: 'npm-token', pattern: /npm_[A-Za-z0-9]{36}/g },
|
|
42
|
+
{ name: 'pypi-token', pattern: /pypi-[A-Za-z0-9_-]{100,}/g },
|
|
43
|
+
// Cloud Providers
|
|
44
|
+
{
|
|
45
|
+
name: 'azure-connection-string',
|
|
46
|
+
pattern: /DefaultEndpointsProtocol=https;AccountName=[^;]+;AccountKey=[A-Za-z0-9+/=]{88};/g,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'gcp-service-account',
|
|
50
|
+
pattern: /"private_key":\s*"-----BEGIN (?:RSA )?PRIVATE KEY-----/g,
|
|
51
|
+
},
|
|
52
|
+
// Generic Secrets
|
|
53
|
+
{ name: 'private-key', pattern: /-----BEGIN (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----/g },
|
|
54
|
+
{ name: 'jwt', pattern: /eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g },
|
|
55
|
+
{ name: 'basic-auth', pattern: /(?:basic|bearer)\s+[A-Za-z0-9+/=]{20,}/gi },
|
|
56
|
+
{ name: 'password-in-url', pattern: /[a-zA-Z]{3,10}:\/\/[^/\s:@]{3,20}:[^/\s@]{3,20}@/g },
|
|
57
|
+
// Anthropic
|
|
58
|
+
{ name: 'anthropic-api-key', pattern: /sk-ant-[A-Za-z0-9_-]{90,}/g },
|
|
59
|
+
// OpenAI
|
|
60
|
+
{ name: 'openai-api-key', pattern: /sk-[A-Za-z0-9]{20}T3BlbkFJ[A-Za-z0-9]{20}/g },
|
|
61
|
+
// Database
|
|
62
|
+
{ name: 'postgres-url', pattern: /postgres(?:ql)?:\/\/[^/\s:@]+:[^/\s@]+@[^/\s]+\/[^/\s]+/g },
|
|
63
|
+
{ name: 'mysql-url', pattern: /mysql:\/\/[^/\s:@]+:[^/\s@]+@[^/\s]+\/[^/\s]+/g },
|
|
64
|
+
{ name: 'mongodb-url', pattern: /mongodb(?:\+srv)?:\/\/[^/\s:@]+:[^/\s@]+@[^/\s]+/g },
|
|
65
|
+
// Hex-encoded secrets (generic)
|
|
66
|
+
{
|
|
67
|
+
name: 'hex-secret',
|
|
68
|
+
pattern: /(?:secret|token|key|password|api_key|apikey)\s*[=:]\s*["']?([0-9a-fA-F]{32,})["']?/gi,
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
// Fields that should be skipped during redaction
|
|
72
|
+
const SAFE_FIELDS = new Set([
|
|
73
|
+
'signature',
|
|
74
|
+
'id',
|
|
75
|
+
'uuid',
|
|
76
|
+
'sessionId',
|
|
77
|
+
'session_id',
|
|
78
|
+
'checkpointId',
|
|
79
|
+
'checkpoint_id',
|
|
80
|
+
'nodeId',
|
|
81
|
+
'node_id',
|
|
82
|
+
'toolUseId',
|
|
83
|
+
'tool_use_id',
|
|
84
|
+
'file_path',
|
|
85
|
+
'filePath',
|
|
86
|
+
'path',
|
|
87
|
+
'name',
|
|
88
|
+
'type',
|
|
89
|
+
'role',
|
|
90
|
+
]);
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// Entropy Calculation
|
|
93
|
+
// ============================================================================
|
|
94
|
+
/**
|
|
95
|
+
* Calculate Shannon entropy of a string
|
|
96
|
+
*/
|
|
97
|
+
export function shannonEntropy(s) {
|
|
98
|
+
if (s.length === 0)
|
|
99
|
+
return 0;
|
|
100
|
+
const freq = new Map();
|
|
101
|
+
for (const ch of s) {
|
|
102
|
+
freq.set(ch, (freq.get(ch) ?? 0) + 1);
|
|
103
|
+
}
|
|
104
|
+
let entropy = 0;
|
|
105
|
+
for (const count of freq.values()) {
|
|
106
|
+
const p = count / s.length;
|
|
107
|
+
if (p > 0)
|
|
108
|
+
entropy -= p * Math.log2(p);
|
|
109
|
+
}
|
|
110
|
+
return entropy;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Merge overlapping regions
|
|
114
|
+
*/
|
|
115
|
+
function mergeRegions(regions) {
|
|
116
|
+
if (regions.length === 0)
|
|
117
|
+
return [];
|
|
118
|
+
const sorted = [...regions].sort((a, b) => a.start - b.start);
|
|
119
|
+
const merged = [sorted[0]];
|
|
120
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
121
|
+
const last = merged[merged.length - 1];
|
|
122
|
+
if (sorted[i].start <= last.end) {
|
|
123
|
+
last.end = Math.max(last.end, sorted[i].end);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
merged.push(sorted[i]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return merged;
|
|
130
|
+
}
|
|
131
|
+
// ============================================================================
|
|
132
|
+
// Public API
|
|
133
|
+
// ============================================================================
|
|
134
|
+
/**
|
|
135
|
+
* Detect secret regions in a string
|
|
136
|
+
*/
|
|
137
|
+
export function detectSecrets(text) {
|
|
138
|
+
const regions = [];
|
|
139
|
+
// Entropy-based detection
|
|
140
|
+
for (const match of text.matchAll(HIGH_ENTROPY_PATTERN)) {
|
|
141
|
+
const value = match[0];
|
|
142
|
+
if (value.length < MIN_SECRET_LENGTH)
|
|
143
|
+
continue;
|
|
144
|
+
if (shannonEntropy(value) >= ENTROPY_THRESHOLD) {
|
|
145
|
+
regions.push({
|
|
146
|
+
start: match.index,
|
|
147
|
+
end: match.index + value.length,
|
|
148
|
+
source: 'entropy',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Pattern-based detection
|
|
153
|
+
for (const { name, pattern } of SECRET_PATTERNS) {
|
|
154
|
+
// Reset regex state
|
|
155
|
+
pattern.lastIndex = 0;
|
|
156
|
+
for (const match of text.matchAll(pattern)) {
|
|
157
|
+
regions.push({
|
|
158
|
+
start: match.index,
|
|
159
|
+
end: match.index + match[0].length,
|
|
160
|
+
source: name,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return mergeRegions(regions);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Redact secrets from a plain string
|
|
168
|
+
*/
|
|
169
|
+
export function redactString(text) {
|
|
170
|
+
const regions = detectSecrets(text);
|
|
171
|
+
if (regions.length === 0)
|
|
172
|
+
return text;
|
|
173
|
+
let result = '';
|
|
174
|
+
let pos = 0;
|
|
175
|
+
for (const region of regions) {
|
|
176
|
+
result += text.slice(pos, region.start);
|
|
177
|
+
result += REDACTED_PLACEHOLDER;
|
|
178
|
+
pos = region.end;
|
|
179
|
+
}
|
|
180
|
+
result += text.slice(pos);
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Redact secrets from a Buffer
|
|
185
|
+
*/
|
|
186
|
+
export function redactBuffer(buf) {
|
|
187
|
+
return Buffer.from(redactString(buf.toString('utf-8')));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Redact secrets from JSONL content (line by line)
|
|
191
|
+
* Preserves JSON structure and skips safe fields
|
|
192
|
+
*/
|
|
193
|
+
export function redactJSONL(content) {
|
|
194
|
+
const lines = content.split('\n');
|
|
195
|
+
const result = [];
|
|
196
|
+
for (const line of lines) {
|
|
197
|
+
if (!line.trim()) {
|
|
198
|
+
result.push(line);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const parsed = JSON.parse(line);
|
|
203
|
+
const redacted = redactJSONValue(parsed);
|
|
204
|
+
result.push(JSON.stringify(redacted));
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
// Not valid JSON, redact as plain text
|
|
208
|
+
result.push(redactString(line));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return result.join('\n');
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Recursively redact values in a JSON object
|
|
215
|
+
*/
|
|
216
|
+
function redactJSONValue(value, key) {
|
|
217
|
+
// Skip safe fields
|
|
218
|
+
if (key && SAFE_FIELDS.has(key))
|
|
219
|
+
return value;
|
|
220
|
+
if (typeof value === 'string') {
|
|
221
|
+
return redactString(value);
|
|
222
|
+
}
|
|
223
|
+
if (Array.isArray(value)) {
|
|
224
|
+
return value.map((item) => redactJSONValue(item));
|
|
225
|
+
}
|
|
226
|
+
if (value && typeof value === 'object') {
|
|
227
|
+
const obj = value;
|
|
228
|
+
// Skip image/base64 objects
|
|
229
|
+
if (obj.type === 'image' || obj.type === 'base64')
|
|
230
|
+
return value;
|
|
231
|
+
const result = {};
|
|
232
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
233
|
+
result[k] = redactJSONValue(v, k);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=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ACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session State Machine
|
|
3
|
+
*
|
|
4
|
+
* Pure-function state machine for session lifecycle transitions.
|
|
5
|
+
* Ported from Go: session/phase.go
|
|
6
|
+
*
|
|
7
|
+
* The state machine computes the next phase and required actions given the
|
|
8
|
+
* current phase and an event. ApplyTransition executes side effects.
|
|
9
|
+
*/
|
|
10
|
+
export type Phase = 'active' | 'idle' | 'ended';
|
|
11
|
+
/**
|
|
12
|
+
* Normalize a phase string, treating empty or unknown values as 'idle'
|
|
13
|
+
* for backward compatibility with pre-state-machine session files.
|
|
14
|
+
*/
|
|
15
|
+
export declare function phaseFromString(s: string | undefined): Phase;
|
|
16
|
+
export declare const enum StateMachineEvent {
|
|
17
|
+
TurnStart = 0,
|
|
18
|
+
TurnEnd = 1,
|
|
19
|
+
GitCommit = 2,
|
|
20
|
+
SessionStart = 3,
|
|
21
|
+
SessionStop = 4,
|
|
22
|
+
Compaction = 5
|
|
23
|
+
}
|
|
24
|
+
export declare function eventToString(e: StateMachineEvent): string;
|
|
25
|
+
export declare const enum Action {
|
|
26
|
+
Condense = 0,
|
|
27
|
+
CondenseIfFilesTouched = 1,
|
|
28
|
+
DiscardIfNoFiles = 2,
|
|
29
|
+
WarnStaleSession = 3,
|
|
30
|
+
ClearEndedAt = 4,
|
|
31
|
+
UpdateLastInteraction = 5
|
|
32
|
+
}
|
|
33
|
+
export declare function actionToString(a: Action): string;
|
|
34
|
+
export interface TransitionContext {
|
|
35
|
+
hasFilesTouched: boolean;
|
|
36
|
+
isRebaseInProgress: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface TransitionResult {
|
|
39
|
+
newPhase: Phase;
|
|
40
|
+
actions: Action[];
|
|
41
|
+
}
|
|
42
|
+
export declare function transition(current: Phase, event: StateMachineEvent, ctx: TransitionContext): TransitionResult;
|
|
43
|
+
export interface ActionHandler {
|
|
44
|
+
handleCondense(state: StateMachineState): Promise<void>;
|
|
45
|
+
handleCondenseIfFilesTouched(state: StateMachineState): Promise<void>;
|
|
46
|
+
handleDiscardIfNoFiles(state: StateMachineState): Promise<void>;
|
|
47
|
+
handleWarnStaleSession(state: StateMachineState): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
export declare class NoOpActionHandler implements ActionHandler {
|
|
50
|
+
handleCondense(): Promise<void>;
|
|
51
|
+
handleCondenseIfFilesTouched(): Promise<void>;
|
|
52
|
+
handleDiscardIfNoFiles(): Promise<void>;
|
|
53
|
+
handleWarnStaleSession(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
export interface StateMachineState {
|
|
56
|
+
sessionID: string;
|
|
57
|
+
phase: Phase;
|
|
58
|
+
filesTouched: string[];
|
|
59
|
+
lastInteractionTime?: string;
|
|
60
|
+
endedAt?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Apply a TransitionResult to state: sets the new phase, then executes
|
|
64
|
+
* all actions. Common actions (UpdateLastInteraction, ClearEndedAt)
|
|
65
|
+
* always run. Strategy-specific handler actions stop on first error.
|
|
66
|
+
*/
|
|
67
|
+
export declare function applyTransition(state: StateMachineState, result: TransitionResult, handler: ActionHandler): Promise<Error | null>;
|
|
68
|
+
/** Duration after which a session is considered stale (7 days) */
|
|
69
|
+
export declare const STALE_SESSION_THRESHOLD_MS: number;
|
|
70
|
+
/**
|
|
71
|
+
* Returns true when the session's last interaction exceeds the stale threshold.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isStale(lastInteractionTime: string | undefined): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Normalize session state after loading from disk.
|
|
76
|
+
* Migrates legacy phase values and deprecated transcript fields.
|
|
77
|
+
*/
|
|
78
|
+
export declare function normalizeAfterLoad(state: {
|
|
79
|
+
phase?: string;
|
|
80
|
+
checkpointTranscriptStart?: number;
|
|
81
|
+
condensedTranscriptLines?: number;
|
|
82
|
+
transcriptLinesAtStart?: number;
|
|
83
|
+
attributionBaseCommit?: string;
|
|
84
|
+
baseCommit?: string;
|
|
85
|
+
}): void;
|
|
86
|
+
/**
|
|
87
|
+
* Generate a Mermaid state diagram from the transition table.
|
|
88
|
+
*/
|
|
89
|
+
export declare function mermaidDiagram(): string;
|
|
90
|
+
//# sourceMappingURL=state-machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-machine.d.ts","sourceRoot":"","sources":["../../src/session/state-machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,CAa5D;AAMD,0BAAkB,iBAAiB;IACjC,SAAS,IAAI;IACb,OAAO,IAAI;IACX,SAAS,IAAI;IACb,YAAY,IAAI;IAChB,WAAW,IAAI;IACf,UAAU,IAAI;CACf;AAWD,wBAAgB,aAAa,CAAC,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAiB1D;AAMD,0BAAkB,MAAM;IACtB,QAAQ,IAAI;IACZ,sBAAsB,IAAI;IAC1B,gBAAgB,IAAI;IACpB,gBAAgB,IAAI;IACpB,YAAY,IAAI;IAChB,qBAAqB,IAAI;CAC1B;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAiBhD;AAMD,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,OAAO,CAAC;IACzB,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,KAAK,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAMD,wBAAgB,UAAU,CACxB,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,iBAAiB,EACxB,GAAG,EAAE,iBAAiB,GACrB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