claude-code-pilot 2.0.0
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 +151 -0
- package/bin/install.js +431 -0
- package/docs/agent-guides/architecture.md +107 -0
- package/ecc/agents/architect.md +211 -0
- package/ecc/agents/code-reviewer.md +237 -0
- package/ecc/agents/doc-updater.md +107 -0
- package/ecc/agents/e2e-runner.md +107 -0
- package/ecc/agents/security-reviewer.md +108 -0
- package/ecc/agents/tdd-guide.md +91 -0
- package/ecc/commands/checkpoint.md +74 -0
- package/ecc/commands/evolve.md +178 -0
- package/ecc/commands/learn.md +70 -0
- package/ecc/commands/model-route.md +26 -0
- package/ecc/commands/quality-gate.md +29 -0
- package/ecc/commands/resume-session.md +155 -0
- package/ecc/commands/save-session.md +275 -0
- package/ecc/commands/sessions.md +305 -0
- package/ecc/commands/verify.md +59 -0
- package/ecc/contexts/dev.md +20 -0
- package/ecc/contexts/research.md +26 -0
- package/ecc/contexts/review.md +22 -0
- package/ecc/examples/CLAUDE.md +100 -0
- package/ecc/examples/django-api-CLAUDE.md +308 -0
- package/ecc/examples/go-microservice-CLAUDE.md +267 -0
- package/ecc/examples/rust-api-CLAUDE.md +285 -0
- package/ecc/examples/saas-nextjs-CLAUDE.md +166 -0
- package/ecc/examples/user-CLAUDE.md +109 -0
- package/ecc/rules/common/agents.md +49 -0
- package/ecc/rules/common/coding-style.md +48 -0
- package/ecc/rules/common/development-workflow.md +37 -0
- package/ecc/rules/common/git-workflow.md +24 -0
- package/ecc/rules/common/hooks.md +30 -0
- package/ecc/rules/common/patterns.md +31 -0
- package/ecc/rules/common/performance.md +55 -0
- package/ecc/rules/common/security.md +29 -0
- package/ecc/rules/common/testing.md +29 -0
- package/ecc/rules/golang/coding-style.md +32 -0
- package/ecc/rules/golang/hooks.md +17 -0
- package/ecc/rules/golang/patterns.md +45 -0
- package/ecc/rules/golang/security.md +34 -0
- package/ecc/rules/golang/testing.md +31 -0
- package/ecc/rules/kotlin/coding-style.md +86 -0
- package/ecc/rules/kotlin/patterns.md +146 -0
- package/ecc/rules/kotlin/security.md +82 -0
- package/ecc/rules/kotlin/testing.md +128 -0
- package/ecc/rules/perl/coding-style.md +46 -0
- package/ecc/rules/perl/hooks.md +22 -0
- package/ecc/rules/perl/patterns.md +76 -0
- package/ecc/rules/perl/security.md +69 -0
- package/ecc/rules/perl/testing.md +54 -0
- package/ecc/rules/php/coding-style.md +35 -0
- package/ecc/rules/php/hooks.md +24 -0
- package/ecc/rules/php/patterns.md +32 -0
- package/ecc/rules/php/security.md +33 -0
- package/ecc/rules/php/testing.md +34 -0
- package/ecc/rules/python/coding-style.md +42 -0
- package/ecc/rules/python/hooks.md +19 -0
- package/ecc/rules/python/patterns.md +39 -0
- package/ecc/rules/python/security.md +30 -0
- package/ecc/rules/python/testing.md +38 -0
- package/ecc/rules/swift/coding-style.md +47 -0
- package/ecc/rules/swift/hooks.md +20 -0
- package/ecc/rules/swift/patterns.md +66 -0
- package/ecc/rules/swift/security.md +33 -0
- package/ecc/rules/swift/testing.md +45 -0
- package/ecc/rules/typescript/coding-style.md +199 -0
- package/ecc/rules/typescript/hooks.md +22 -0
- package/ecc/rules/typescript/patterns.md +52 -0
- package/ecc/rules/typescript/security.md +28 -0
- package/ecc/rules/typescript/testing.md +18 -0
- package/ecc/scripts/hooks/check-hook-enabled.js +12 -0
- package/ecc/scripts/hooks/evaluate-session.js +100 -0
- package/ecc/scripts/hooks/pre-compact.js +48 -0
- package/ecc/scripts/hooks/run-with-flags-shell.sh +32 -0
- package/ecc/scripts/hooks/run-with-flags.js +120 -0
- package/ecc/scripts/hooks/session-end-marker.js +15 -0
- package/ecc/scripts/hooks/session-end.js +258 -0
- package/ecc/scripts/hooks/session-start.js +97 -0
- package/ecc/scripts/hooks/suggest-compact.js +80 -0
- package/ecc/scripts/lib/hook-flags.js +74 -0
- package/ecc/scripts/lib/package-manager.d.ts +119 -0
- package/ecc/scripts/lib/package-manager.js +431 -0
- package/ecc/scripts/lib/project-detect.js +428 -0
- package/ecc/scripts/lib/resolve-formatter.js +185 -0
- package/ecc/scripts/lib/session-aliases.d.ts +136 -0
- package/ecc/scripts/lib/session-aliases.js +481 -0
- package/ecc/scripts/lib/session-manager.d.ts +131 -0
- package/ecc/scripts/lib/session-manager.js +444 -0
- package/ecc/scripts/lib/shell-split.js +86 -0
- package/ecc/scripts/lib/utils.d.ts +183 -0
- package/ecc/scripts/lib/utils.js +543 -0
- package/ecc/skills/continuous-learning-v2/SKILL.md +365 -0
- package/ecc/skills/continuous-learning-v2/agents/observer-loop.sh +144 -0
- package/ecc/skills/continuous-learning-v2/agents/observer.md +198 -0
- package/ecc/skills/continuous-learning-v2/agents/start-observer.sh +194 -0
- package/ecc/skills/continuous-learning-v2/config.json +8 -0
- package/ecc/skills/continuous-learning-v2/hooks/observe.sh +246 -0
- package/ecc/skills/continuous-learning-v2/scripts/detect-project.sh +218 -0
- package/ecc/skills/continuous-learning-v2/scripts/instinct-cli.py +1148 -0
- package/ecc/skills/continuous-learning-v2/scripts/test_parse_instinct.py +984 -0
- package/ecc/skills/strategic-compact/SKILL.md +103 -0
- package/ecc/skills/strategic-compact/suggest-compact.sh +54 -0
- package/ecc/skills/verification-loop-SKILL.md +126 -0
- package/gsd/LICENSE +21 -0
- package/gsd/agents/gsd-codebase-mapper.md +772 -0
- package/gsd/agents/gsd-debugger.md +1257 -0
- package/gsd/agents/gsd-executor.md +489 -0
- package/gsd/agents/gsd-integration-checker.md +445 -0
- package/gsd/agents/gsd-nyquist-auditor.md +178 -0
- package/gsd/agents/gsd-phase-researcher.md +555 -0
- package/gsd/agents/gsd-plan-checker.md +708 -0
- package/gsd/agents/gsd-planner.md +1309 -0
- package/gsd/agents/gsd-project-researcher.md +631 -0
- package/gsd/agents/gsd-research-synthesizer.md +249 -0
- package/gsd/agents/gsd-roadmapper.md +652 -0
- package/gsd/agents/gsd-verifier.md +581 -0
- package/gsd/commands-gsd/add-phase.md +43 -0
- package/gsd/commands-gsd/add-tests.md +41 -0
- package/gsd/commands-gsd/add-todo.md +47 -0
- package/gsd/commands-gsd/audit-milestone.md +36 -0
- package/gsd/commands-gsd/check-todos.md +45 -0
- package/gsd/commands-gsd/cleanup.md +18 -0
- package/gsd/commands-gsd/complete-milestone.md +136 -0
- package/gsd/commands-gsd/debug.md +168 -0
- package/gsd/commands-gsd/discuss-phase.md +90 -0
- package/gsd/commands-gsd/execute-phase.md +41 -0
- package/gsd/commands-gsd/health.md +22 -0
- package/gsd/commands-gsd/help.md +22 -0
- package/gsd/commands-gsd/insert-phase.md +32 -0
- package/gsd/commands-gsd/join-discord.md +18 -0
- package/gsd/commands-gsd/list-phase-assumptions.md +46 -0
- package/gsd/commands-gsd/map-codebase.md +71 -0
- package/gsd/commands-gsd/new-milestone.md +44 -0
- package/gsd/commands-gsd/new-project.md +42 -0
- package/gsd/commands-gsd/pause-work.md +38 -0
- package/gsd/commands-gsd/plan-milestone-gaps.md +34 -0
- package/gsd/commands-gsd/plan-phase.md +45 -0
- package/gsd/commands-gsd/progress.md +24 -0
- package/gsd/commands-gsd/quick.md +45 -0
- package/gsd/commands-gsd/reapply-patches.md +123 -0
- package/gsd/commands-gsd/remove-phase.md +31 -0
- package/gsd/commands-gsd/research-phase.md +190 -0
- package/gsd/commands-gsd/resume-work.md +40 -0
- package/gsd/commands-gsd/set-profile.md +34 -0
- package/gsd/commands-gsd/settings.md +36 -0
- package/gsd/commands-gsd/update.md +37 -0
- package/gsd/commands-gsd/validate-phase.md +35 -0
- package/gsd/commands-gsd/verify-work.md +38 -0
- package/gsd/get-shit-done/bin/gsd-tools.cjs +592 -0
- package/gsd/get-shit-done/bin/lib/commands.cjs +548 -0
- package/gsd/get-shit-done/bin/lib/config.cjs +169 -0
- package/gsd/get-shit-done/bin/lib/core.cjs +492 -0
- package/gsd/get-shit-done/bin/lib/frontmatter.cjs +299 -0
- package/gsd/get-shit-done/bin/lib/init.cjs +710 -0
- package/gsd/get-shit-done/bin/lib/milestone.cjs +241 -0
- package/gsd/get-shit-done/bin/lib/phase.cjs +901 -0
- package/gsd/get-shit-done/bin/lib/roadmap.cjs +298 -0
- package/gsd/get-shit-done/bin/lib/state.cjs +721 -0
- package/gsd/get-shit-done/bin/lib/template.cjs +222 -0
- package/gsd/get-shit-done/bin/lib/verify.cjs +820 -0
- package/gsd/get-shit-done/references/checkpoints.md +776 -0
- package/gsd/get-shit-done/references/continuation-format.md +249 -0
- package/gsd/get-shit-done/references/decimal-phase-calculation.md +65 -0
- package/gsd/get-shit-done/references/git-integration.md +248 -0
- package/gsd/get-shit-done/references/git-planning-commit.md +38 -0
- package/gsd/get-shit-done/references/model-profile-resolution.md +34 -0
- package/gsd/get-shit-done/references/model-profiles.md +93 -0
- package/gsd/get-shit-done/references/phase-argument-parsing.md +61 -0
- package/gsd/get-shit-done/references/planning-config.md +200 -0
- package/gsd/get-shit-done/references/questioning.md +162 -0
- package/gsd/get-shit-done/references/tdd.md +263 -0
- package/gsd/get-shit-done/references/ui-brand.md +160 -0
- package/gsd/get-shit-done/references/verification-patterns.md +612 -0
- package/gsd/get-shit-done/templates/DEBUG.md +164 -0
- package/gsd/get-shit-done/templates/UAT.md +247 -0
- package/gsd/get-shit-done/templates/VALIDATION.md +76 -0
- package/gsd/get-shit-done/templates/codebase/architecture.md +255 -0
- package/gsd/get-shit-done/templates/codebase/concerns.md +310 -0
- package/gsd/get-shit-done/templates/codebase/conventions.md +307 -0
- package/gsd/get-shit-done/templates/codebase/integrations.md +280 -0
- package/gsd/get-shit-done/templates/codebase/stack.md +186 -0
- package/gsd/get-shit-done/templates/codebase/structure.md +285 -0
- package/gsd/get-shit-done/templates/codebase/testing.md +480 -0
- package/gsd/get-shit-done/templates/config.json +37 -0
- package/gsd/get-shit-done/templates/context.md +297 -0
- package/gsd/get-shit-done/templates/continue-here.md +78 -0
- package/gsd/get-shit-done/templates/debug-subagent-prompt.md +91 -0
- package/gsd/get-shit-done/templates/discovery.md +146 -0
- package/gsd/get-shit-done/templates/milestone-archive.md +123 -0
- package/gsd/get-shit-done/templates/milestone.md +115 -0
- package/gsd/get-shit-done/templates/phase-prompt.md +569 -0
- package/gsd/get-shit-done/templates/planner-subagent-prompt.md +117 -0
- package/gsd/get-shit-done/templates/project.md +184 -0
- package/gsd/get-shit-done/templates/requirements.md +231 -0
- package/gsd/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
- package/gsd/get-shit-done/templates/research-project/FEATURES.md +147 -0
- package/gsd/get-shit-done/templates/research-project/PITFALLS.md +200 -0
- package/gsd/get-shit-done/templates/research-project/STACK.md +120 -0
- package/gsd/get-shit-done/templates/research-project/SUMMARY.md +170 -0
- package/gsd/get-shit-done/templates/research.md +552 -0
- package/gsd/get-shit-done/templates/retrospective.md +54 -0
- package/gsd/get-shit-done/templates/roadmap.md +202 -0
- package/gsd/get-shit-done/templates/state.md +176 -0
- package/gsd/get-shit-done/templates/summary-complex.md +59 -0
- package/gsd/get-shit-done/templates/summary-minimal.md +41 -0
- package/gsd/get-shit-done/templates/summary-standard.md +48 -0
- package/gsd/get-shit-done/templates/summary.md +248 -0
- package/gsd/get-shit-done/templates/user-setup.md +311 -0
- package/gsd/get-shit-done/templates/verification-report.md +322 -0
- package/gsd/get-shit-done/workflows/add-phase.md +112 -0
- package/gsd/get-shit-done/workflows/add-tests.md +351 -0
- package/gsd/get-shit-done/workflows/add-todo.md +158 -0
- package/gsd/get-shit-done/workflows/audit-milestone.md +332 -0
- package/gsd/get-shit-done/workflows/check-todos.md +177 -0
- package/gsd/get-shit-done/workflows/cleanup.md +152 -0
- package/gsd/get-shit-done/workflows/complete-milestone.md +764 -0
- package/gsd/get-shit-done/workflows/diagnose-issues.md +219 -0
- package/gsd/get-shit-done/workflows/discovery-phase.md +289 -0
- package/gsd/get-shit-done/workflows/discuss-phase.md +676 -0
- package/gsd/get-shit-done/workflows/execute-phase.md +459 -0
- package/gsd/get-shit-done/workflows/execute-plan.md +449 -0
- package/gsd/get-shit-done/workflows/health.md +159 -0
- package/gsd/get-shit-done/workflows/help.md +489 -0
- package/gsd/get-shit-done/workflows/insert-phase.md +130 -0
- package/gsd/get-shit-done/workflows/list-phase-assumptions.md +178 -0
- package/gsd/get-shit-done/workflows/map-codebase.md +316 -0
- package/gsd/get-shit-done/workflows/new-milestone.md +384 -0
- package/gsd/get-shit-done/workflows/new-project.md +1111 -0
- package/gsd/get-shit-done/workflows/pause-work.md +122 -0
- package/gsd/get-shit-done/workflows/plan-milestone-gaps.md +274 -0
- package/gsd/get-shit-done/workflows/plan-phase.md +560 -0
- package/gsd/get-shit-done/workflows/progress.md +382 -0
- package/gsd/get-shit-done/workflows/quick.md +601 -0
- package/gsd/get-shit-done/workflows/remove-phase.md +155 -0
- package/gsd/get-shit-done/workflows/research-phase.md +74 -0
- package/gsd/get-shit-done/workflows/resume-project.md +307 -0
- package/gsd/get-shit-done/workflows/set-profile.md +81 -0
- package/gsd/get-shit-done/workflows/settings.md +214 -0
- package/gsd/get-shit-done/workflows/transition.md +544 -0
- package/gsd/get-shit-done/workflows/update.md +240 -0
- package/gsd/get-shit-done/workflows/validate-phase.md +167 -0
- package/gsd/get-shit-done/workflows/verify-phase.md +243 -0
- package/gsd/get-shit-done/workflows/verify-work.md +583 -0
- package/gsd/hooks/gsd-check-update.js +81 -0
- package/gsd/hooks/gsd-context-monitor.js +141 -0
- package/gsd/hooks/gsd-statusline.js +115 -0
- package/kit/CLAUDE.md +43 -0
- package/kit/commands/kit/update.md +46 -0
- package/kit/commands/setup-refresh.md +50 -0
- package/kit/commands/setup.md +579 -0
- package/kit/commands/tool-guide.md +44 -0
- package/kit/hooks/kit-check-update.js +54 -0
- package/kit/mcp.json +10 -0
- package/kit/rules/code-style.md +24 -0
- package/manifest.json +30 -0
- package/package.json +36 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Manager Library for Claude Code.
|
|
3
|
+
* Provides CRUD operations for session files stored as markdown in ~/.claude/sessions/.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Parsed metadata from a session filename */
|
|
7
|
+
export interface SessionFilenameMeta {
|
|
8
|
+
/** Original filename */
|
|
9
|
+
filename: string;
|
|
10
|
+
/** Short ID extracted from filename, or "no-id" for old format */
|
|
11
|
+
shortId: string;
|
|
12
|
+
/** Date string in YYYY-MM-DD format */
|
|
13
|
+
date: string;
|
|
14
|
+
/** Parsed Date object from the date string */
|
|
15
|
+
datetime: Date;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Metadata parsed from session markdown content */
|
|
19
|
+
export interface SessionMetadata {
|
|
20
|
+
title: string | null;
|
|
21
|
+
date: string | null;
|
|
22
|
+
started: string | null;
|
|
23
|
+
lastUpdated: string | null;
|
|
24
|
+
completed: string[];
|
|
25
|
+
inProgress: string[];
|
|
26
|
+
notes: string;
|
|
27
|
+
context: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Statistics computed from session content */
|
|
31
|
+
export interface SessionStats {
|
|
32
|
+
totalItems: number;
|
|
33
|
+
completedItems: number;
|
|
34
|
+
inProgressItems: number;
|
|
35
|
+
lineCount: number;
|
|
36
|
+
hasNotes: boolean;
|
|
37
|
+
hasContext: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A session object returned by getAllSessions and getSessionById */
|
|
41
|
+
export interface Session extends SessionFilenameMeta {
|
|
42
|
+
/** Full filesystem path to the session file */
|
|
43
|
+
sessionPath: string;
|
|
44
|
+
/** Whether the file has any content */
|
|
45
|
+
hasContent?: boolean;
|
|
46
|
+
/** File size in bytes */
|
|
47
|
+
size: number;
|
|
48
|
+
/** Last modification time */
|
|
49
|
+
modifiedTime: Date;
|
|
50
|
+
/** File creation time (falls back to ctime on Linux) */
|
|
51
|
+
createdTime: Date;
|
|
52
|
+
/** Session markdown content (only when includeContent=true) */
|
|
53
|
+
content?: string | null;
|
|
54
|
+
/** Parsed metadata (only when includeContent=true) */
|
|
55
|
+
metadata?: SessionMetadata;
|
|
56
|
+
/** Session statistics (only when includeContent=true) */
|
|
57
|
+
stats?: SessionStats;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Pagination result from getAllSessions */
|
|
61
|
+
export interface SessionListResult {
|
|
62
|
+
sessions: Session[];
|
|
63
|
+
total: number;
|
|
64
|
+
offset: number;
|
|
65
|
+
limit: number;
|
|
66
|
+
hasMore: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GetAllSessionsOptions {
|
|
70
|
+
/** Maximum number of sessions to return (default: 50) */
|
|
71
|
+
limit?: number;
|
|
72
|
+
/** Number of sessions to skip (default: 0) */
|
|
73
|
+
offset?: number;
|
|
74
|
+
/** Filter by date in YYYY-MM-DD format */
|
|
75
|
+
date?: string | null;
|
|
76
|
+
/** Search in short ID */
|
|
77
|
+
search?: string | null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Parse a session filename to extract date and short ID.
|
|
82
|
+
* @returns Parsed metadata, or null if the filename doesn't match the expected pattern
|
|
83
|
+
*/
|
|
84
|
+
export function parseSessionFilename(filename: string): SessionFilenameMeta | null;
|
|
85
|
+
|
|
86
|
+
/** Get the full filesystem path for a session filename */
|
|
87
|
+
export function getSessionPath(filename: string): string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Read session markdown content from disk.
|
|
91
|
+
* @returns Content string, or null if the file doesn't exist
|
|
92
|
+
*/
|
|
93
|
+
export function getSessionContent(sessionPath: string): string | null;
|
|
94
|
+
|
|
95
|
+
/** Parse session metadata from markdown content */
|
|
96
|
+
export function parseSessionMetadata(content: string | null): SessionMetadata;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Calculate statistics for a session.
|
|
100
|
+
* Accepts either a file path (absolute, ending in .tmp) or pre-read content string.
|
|
101
|
+
* Supports both Unix (/path/to/session.tmp) and Windows (C:\path\to\session.tmp) paths.
|
|
102
|
+
*/
|
|
103
|
+
export function getSessionStats(sessionPathOrContent: string): SessionStats;
|
|
104
|
+
|
|
105
|
+
/** Get the title from a session file, or "Untitled Session" if none */
|
|
106
|
+
export function getSessionTitle(sessionPath: string): string;
|
|
107
|
+
|
|
108
|
+
/** Get human-readable file size (e.g., "1.2 KB") */
|
|
109
|
+
export function getSessionSize(sessionPath: string): string;
|
|
110
|
+
|
|
111
|
+
/** Get all sessions with optional filtering and pagination */
|
|
112
|
+
export function getAllSessions(options?: GetAllSessionsOptions): SessionListResult;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Find a session by short ID or filename.
|
|
116
|
+
* @param sessionId - Short ID prefix, full filename, or filename without .tmp
|
|
117
|
+
* @param includeContent - Whether to read and parse the session content
|
|
118
|
+
*/
|
|
119
|
+
export function getSessionById(sessionId: string, includeContent?: boolean): Session | null;
|
|
120
|
+
|
|
121
|
+
/** Write markdown content to a session file */
|
|
122
|
+
export function writeSessionContent(sessionPath: string, content: string): boolean;
|
|
123
|
+
|
|
124
|
+
/** Append content to an existing session file */
|
|
125
|
+
export function appendSessionContent(sessionPath: string, content: string): boolean;
|
|
126
|
+
|
|
127
|
+
/** Delete a session file */
|
|
128
|
+
export function deleteSession(sessionPath: string): boolean;
|
|
129
|
+
|
|
130
|
+
/** Check if a session file exists and is a regular file */
|
|
131
|
+
export function sessionExists(sessionPath: string): boolean;
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Manager Library for Claude Code
|
|
3
|
+
* Provides core session CRUD operations for listing, loading, and managing sessions
|
|
4
|
+
*
|
|
5
|
+
* Sessions are stored as markdown files in ~/.claude/sessions/ with format:
|
|
6
|
+
* - YYYY-MM-DD-session.tmp (old format)
|
|
7
|
+
* - YYYY-MM-DD-<short-id>-session.tmp (new format)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
getSessionsDir,
|
|
15
|
+
readFile,
|
|
16
|
+
log
|
|
17
|
+
} = require('./utils');
|
|
18
|
+
|
|
19
|
+
// Session filename pattern: YYYY-MM-DD-[session-id]-session.tmp
|
|
20
|
+
// The session-id is optional (old format) and can include lowercase
|
|
21
|
+
// alphanumeric characters and hyphens, with a minimum length of 8.
|
|
22
|
+
// Matches: "2026-02-01-session.tmp", "2026-02-01-a1b2c3d4-session.tmp",
|
|
23
|
+
// and "2026-02-01-frontend-worktree-1-session.tmp"
|
|
24
|
+
const SESSION_FILENAME_REGEX = /^(\d{4}-\d{2}-\d{2})(?:-([a-z0-9-]{8,}))?-session\.tmp$/;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parse session filename to extract metadata
|
|
28
|
+
* @param {string} filename - Session filename (e.g., "2026-01-17-abc123-session.tmp" or "2026-01-17-session.tmp")
|
|
29
|
+
* @returns {object|null} Parsed metadata or null if invalid
|
|
30
|
+
*/
|
|
31
|
+
function parseSessionFilename(filename) {
|
|
32
|
+
const match = filename.match(SESSION_FILENAME_REGEX);
|
|
33
|
+
if (!match) return null;
|
|
34
|
+
|
|
35
|
+
const dateStr = match[1];
|
|
36
|
+
|
|
37
|
+
// Validate date components are calendar-accurate (not just format)
|
|
38
|
+
const [year, month, day] = dateStr.split('-').map(Number);
|
|
39
|
+
if (month < 1 || month > 12 || day < 1 || day > 31) return null;
|
|
40
|
+
// Reject impossible dates like Feb 31, Apr 31 — Date constructor rolls
|
|
41
|
+
// over invalid days (e.g., Feb 31 → Mar 3), so check month roundtrips
|
|
42
|
+
const d = new Date(year, month - 1, day);
|
|
43
|
+
if (d.getMonth() !== month - 1 || d.getDate() !== day) return null;
|
|
44
|
+
|
|
45
|
+
// match[2] is undefined for old format (no ID)
|
|
46
|
+
const shortId = match[2] || 'no-id';
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
filename,
|
|
50
|
+
shortId,
|
|
51
|
+
date: dateStr,
|
|
52
|
+
// Use local-time constructor (consistent with validation on line 40)
|
|
53
|
+
// new Date(dateStr) interprets YYYY-MM-DD as UTC midnight which shows
|
|
54
|
+
// as the previous day in negative UTC offset timezones
|
|
55
|
+
datetime: new Date(year, month - 1, day)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the full path to a session file
|
|
61
|
+
* @param {string} filename - Session filename
|
|
62
|
+
* @returns {string} Full path to session file
|
|
63
|
+
*/
|
|
64
|
+
function getSessionPath(filename) {
|
|
65
|
+
return path.join(getSessionsDir(), filename);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Read and parse session markdown content
|
|
70
|
+
* @param {string} sessionPath - Full path to session file
|
|
71
|
+
* @returns {string|null} Session content or null if not found
|
|
72
|
+
*/
|
|
73
|
+
function getSessionContent(sessionPath) {
|
|
74
|
+
return readFile(sessionPath);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parse session metadata from markdown content
|
|
79
|
+
* @param {string} content - Session markdown content
|
|
80
|
+
* @returns {object} Parsed metadata
|
|
81
|
+
*/
|
|
82
|
+
function parseSessionMetadata(content) {
|
|
83
|
+
const metadata = {
|
|
84
|
+
title: null,
|
|
85
|
+
date: null,
|
|
86
|
+
started: null,
|
|
87
|
+
lastUpdated: null,
|
|
88
|
+
completed: [],
|
|
89
|
+
inProgress: [],
|
|
90
|
+
notes: '',
|
|
91
|
+
context: ''
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (!content) return metadata;
|
|
95
|
+
|
|
96
|
+
// Extract title from first heading
|
|
97
|
+
const titleMatch = content.match(/^#\s+(.+)$/m);
|
|
98
|
+
if (titleMatch) {
|
|
99
|
+
metadata.title = titleMatch[1].trim();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Extract date
|
|
103
|
+
const dateMatch = content.match(/\*\*Date:\*\*\s*(\d{4}-\d{2}-\d{2})/);
|
|
104
|
+
if (dateMatch) {
|
|
105
|
+
metadata.date = dateMatch[1];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Extract started time
|
|
109
|
+
const startedMatch = content.match(/\*\*Started:\*\*\s*([\d:]+)/);
|
|
110
|
+
if (startedMatch) {
|
|
111
|
+
metadata.started = startedMatch[1];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Extract last updated
|
|
115
|
+
const updatedMatch = content.match(/\*\*Last Updated:\*\*\s*([\d:]+)/);
|
|
116
|
+
if (updatedMatch) {
|
|
117
|
+
metadata.lastUpdated = updatedMatch[1];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Extract completed items
|
|
121
|
+
const completedSection = content.match(/### Completed\s*\n([\s\S]*?)(?=###|\n\n|$)/);
|
|
122
|
+
if (completedSection) {
|
|
123
|
+
const items = completedSection[1].match(/- \[x\]\s*(.+)/g);
|
|
124
|
+
if (items) {
|
|
125
|
+
metadata.completed = items.map(item => item.replace(/- \[x\]\s*/, '').trim());
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Extract in-progress items
|
|
130
|
+
const progressSection = content.match(/### In Progress\s*\n([\s\S]*?)(?=###|\n\n|$)/);
|
|
131
|
+
if (progressSection) {
|
|
132
|
+
const items = progressSection[1].match(/- \[ \]\s*(.+)/g);
|
|
133
|
+
if (items) {
|
|
134
|
+
metadata.inProgress = items.map(item => item.replace(/- \[ \]\s*/, '').trim());
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Extract notes
|
|
139
|
+
const notesSection = content.match(/### Notes for Next Session\s*\n([\s\S]*?)(?=###|\n\n|$)/);
|
|
140
|
+
if (notesSection) {
|
|
141
|
+
metadata.notes = notesSection[1].trim();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Extract context to load
|
|
145
|
+
const contextSection = content.match(/### Context to Load\s*\n```\n([\s\S]*?)```/);
|
|
146
|
+
if (contextSection) {
|
|
147
|
+
metadata.context = contextSection[1].trim();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return metadata;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Calculate statistics for a session
|
|
155
|
+
* @param {string} sessionPathOrContent - Full path to session file, OR
|
|
156
|
+
* the pre-read content string (to avoid redundant disk reads when
|
|
157
|
+
* the caller already has the content loaded).
|
|
158
|
+
* @returns {object} Statistics object
|
|
159
|
+
*/
|
|
160
|
+
function getSessionStats(sessionPathOrContent) {
|
|
161
|
+
// Accept pre-read content string to avoid redundant file reads.
|
|
162
|
+
// If the argument looks like a file path (no newlines, ends with .tmp,
|
|
163
|
+
// starts with / on Unix or drive letter on Windows), read from disk.
|
|
164
|
+
// Otherwise treat it as content.
|
|
165
|
+
const looksLikePath = typeof sessionPathOrContent === 'string' &&
|
|
166
|
+
!sessionPathOrContent.includes('\n') &&
|
|
167
|
+
sessionPathOrContent.endsWith('.tmp') &&
|
|
168
|
+
(sessionPathOrContent.startsWith('/') || /^[A-Za-z]:[/\\]/.test(sessionPathOrContent));
|
|
169
|
+
const content = looksLikePath
|
|
170
|
+
? getSessionContent(sessionPathOrContent)
|
|
171
|
+
: sessionPathOrContent;
|
|
172
|
+
|
|
173
|
+
const metadata = parseSessionMetadata(content);
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
totalItems: metadata.completed.length + metadata.inProgress.length,
|
|
177
|
+
completedItems: metadata.completed.length,
|
|
178
|
+
inProgressItems: metadata.inProgress.length,
|
|
179
|
+
lineCount: content ? content.split('\n').length : 0,
|
|
180
|
+
hasNotes: !!metadata.notes,
|
|
181
|
+
hasContext: !!metadata.context
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get all sessions with optional filtering and pagination
|
|
187
|
+
* @param {object} options - Options object
|
|
188
|
+
* @param {number} options.limit - Maximum number of sessions to return
|
|
189
|
+
* @param {number} options.offset - Number of sessions to skip
|
|
190
|
+
* @param {string} options.date - Filter by date (YYYY-MM-DD format)
|
|
191
|
+
* @param {string} options.search - Search in short ID
|
|
192
|
+
* @returns {object} Object with sessions array and pagination info
|
|
193
|
+
*/
|
|
194
|
+
function getAllSessions(options = {}) {
|
|
195
|
+
const {
|
|
196
|
+
limit: rawLimit = 50,
|
|
197
|
+
offset: rawOffset = 0,
|
|
198
|
+
date = null,
|
|
199
|
+
search = null
|
|
200
|
+
} = options;
|
|
201
|
+
|
|
202
|
+
// Clamp offset and limit to safe non-negative integers.
|
|
203
|
+
// Without this, negative offset causes slice() to count from the end,
|
|
204
|
+
// and NaN values cause slice() to return empty or unexpected results.
|
|
205
|
+
// Note: cannot use `|| default` because 0 is falsy — use isNaN instead.
|
|
206
|
+
const offsetNum = Number(rawOffset);
|
|
207
|
+
const offset = Number.isNaN(offsetNum) ? 0 : Math.max(0, Math.floor(offsetNum));
|
|
208
|
+
const limitNum = Number(rawLimit);
|
|
209
|
+
const limit = Number.isNaN(limitNum) ? 50 : Math.max(1, Math.floor(limitNum));
|
|
210
|
+
|
|
211
|
+
const sessionsDir = getSessionsDir();
|
|
212
|
+
|
|
213
|
+
if (!fs.existsSync(sessionsDir)) {
|
|
214
|
+
return { sessions: [], total: 0, offset, limit, hasMore: false };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const entries = fs.readdirSync(sessionsDir, { withFileTypes: true });
|
|
218
|
+
const sessions = [];
|
|
219
|
+
|
|
220
|
+
for (const entry of entries) {
|
|
221
|
+
// Skip non-files (only process .tmp files)
|
|
222
|
+
if (!entry.isFile() || !entry.name.endsWith('.tmp')) continue;
|
|
223
|
+
|
|
224
|
+
const filename = entry.name;
|
|
225
|
+
const metadata = parseSessionFilename(filename);
|
|
226
|
+
|
|
227
|
+
if (!metadata) continue;
|
|
228
|
+
|
|
229
|
+
// Apply date filter
|
|
230
|
+
if (date && metadata.date !== date) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Apply search filter (search in short ID)
|
|
235
|
+
if (search && !metadata.shortId.includes(search)) {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const sessionPath = path.join(sessionsDir, filename);
|
|
240
|
+
|
|
241
|
+
// Get file stats (wrapped in try-catch to handle TOCTOU race where
|
|
242
|
+
// file is deleted between readdirSync and statSync)
|
|
243
|
+
let stats;
|
|
244
|
+
try {
|
|
245
|
+
stats = fs.statSync(sessionPath);
|
|
246
|
+
} catch {
|
|
247
|
+
continue; // File was deleted between readdir and stat
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
sessions.push({
|
|
251
|
+
...metadata,
|
|
252
|
+
sessionPath,
|
|
253
|
+
hasContent: stats.size > 0,
|
|
254
|
+
size: stats.size,
|
|
255
|
+
modifiedTime: stats.mtime,
|
|
256
|
+
createdTime: stats.birthtime || stats.ctime
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Sort by modified time (newest first)
|
|
261
|
+
sessions.sort((a, b) => b.modifiedTime - a.modifiedTime);
|
|
262
|
+
|
|
263
|
+
// Apply pagination
|
|
264
|
+
const paginatedSessions = sessions.slice(offset, offset + limit);
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
sessions: paginatedSessions,
|
|
268
|
+
total: sessions.length,
|
|
269
|
+
offset,
|
|
270
|
+
limit,
|
|
271
|
+
hasMore: offset + limit < sessions.length
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Get a single session by ID (short ID or full path)
|
|
277
|
+
* @param {string} sessionId - Short ID or session filename
|
|
278
|
+
* @param {boolean} includeContent - Include session content
|
|
279
|
+
* @returns {object|null} Session object or null if not found
|
|
280
|
+
*/
|
|
281
|
+
function getSessionById(sessionId, includeContent = false) {
|
|
282
|
+
const sessionsDir = getSessionsDir();
|
|
283
|
+
|
|
284
|
+
if (!fs.existsSync(sessionsDir)) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const entries = fs.readdirSync(sessionsDir, { withFileTypes: true });
|
|
289
|
+
|
|
290
|
+
for (const entry of entries) {
|
|
291
|
+
if (!entry.isFile() || !entry.name.endsWith('.tmp')) continue;
|
|
292
|
+
|
|
293
|
+
const filename = entry.name;
|
|
294
|
+
const metadata = parseSessionFilename(filename);
|
|
295
|
+
|
|
296
|
+
if (!metadata) continue;
|
|
297
|
+
|
|
298
|
+
// Check if session ID matches (short ID or full filename without .tmp)
|
|
299
|
+
const shortIdMatch = sessionId.length > 0 && metadata.shortId !== 'no-id' && metadata.shortId.startsWith(sessionId);
|
|
300
|
+
const filenameMatch = filename === sessionId || filename === `${sessionId}.tmp`;
|
|
301
|
+
const noIdMatch = metadata.shortId === 'no-id' && filename === `${sessionId}-session.tmp`;
|
|
302
|
+
|
|
303
|
+
if (!shortIdMatch && !filenameMatch && !noIdMatch) {
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const sessionPath = path.join(sessionsDir, filename);
|
|
308
|
+
let stats;
|
|
309
|
+
try {
|
|
310
|
+
stats = fs.statSync(sessionPath);
|
|
311
|
+
} catch {
|
|
312
|
+
return null; // File was deleted between readdir and stat
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const session = {
|
|
316
|
+
...metadata,
|
|
317
|
+
sessionPath,
|
|
318
|
+
size: stats.size,
|
|
319
|
+
modifiedTime: stats.mtime,
|
|
320
|
+
createdTime: stats.birthtime || stats.ctime
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
if (includeContent) {
|
|
324
|
+
session.content = getSessionContent(sessionPath);
|
|
325
|
+
session.metadata = parseSessionMetadata(session.content);
|
|
326
|
+
// Pass pre-read content to avoid a redundant disk read
|
|
327
|
+
session.stats = getSessionStats(session.content || '');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return session;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Get session title from content
|
|
338
|
+
* @param {string} sessionPath - Full path to session file
|
|
339
|
+
* @returns {string} Title or default text
|
|
340
|
+
*/
|
|
341
|
+
function getSessionTitle(sessionPath) {
|
|
342
|
+
const content = getSessionContent(sessionPath);
|
|
343
|
+
const metadata = parseSessionMetadata(content);
|
|
344
|
+
|
|
345
|
+
return metadata.title || 'Untitled Session';
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Format session size in human-readable format
|
|
350
|
+
* @param {string} sessionPath - Full path to session file
|
|
351
|
+
* @returns {string} Formatted size (e.g., "1.2 KB")
|
|
352
|
+
*/
|
|
353
|
+
function getSessionSize(sessionPath) {
|
|
354
|
+
let stats;
|
|
355
|
+
try {
|
|
356
|
+
stats = fs.statSync(sessionPath);
|
|
357
|
+
} catch {
|
|
358
|
+
return '0 B';
|
|
359
|
+
}
|
|
360
|
+
const size = stats.size;
|
|
361
|
+
|
|
362
|
+
if (size < 1024) return `${size} B`;
|
|
363
|
+
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;
|
|
364
|
+
return `${(size / (1024 * 1024)).toFixed(1)} MB`;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Write session content to file
|
|
369
|
+
* @param {string} sessionPath - Full path to session file
|
|
370
|
+
* @param {string} content - Markdown content to write
|
|
371
|
+
* @returns {boolean} Success status
|
|
372
|
+
*/
|
|
373
|
+
function writeSessionContent(sessionPath, content) {
|
|
374
|
+
try {
|
|
375
|
+
fs.writeFileSync(sessionPath, content, 'utf8');
|
|
376
|
+
return true;
|
|
377
|
+
} catch (err) {
|
|
378
|
+
log(`[SessionManager] Error writing session: ${err.message}`);
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Append content to a session
|
|
385
|
+
* @param {string} sessionPath - Full path to session file
|
|
386
|
+
* @param {string} content - Content to append
|
|
387
|
+
* @returns {boolean} Success status
|
|
388
|
+
*/
|
|
389
|
+
function appendSessionContent(sessionPath, content) {
|
|
390
|
+
try {
|
|
391
|
+
fs.appendFileSync(sessionPath, content, 'utf8');
|
|
392
|
+
return true;
|
|
393
|
+
} catch (err) {
|
|
394
|
+
log(`[SessionManager] Error appending to session: ${err.message}`);
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Delete a session file
|
|
401
|
+
* @param {string} sessionPath - Full path to session file
|
|
402
|
+
* @returns {boolean} Success status
|
|
403
|
+
*/
|
|
404
|
+
function deleteSession(sessionPath) {
|
|
405
|
+
try {
|
|
406
|
+
if (fs.existsSync(sessionPath)) {
|
|
407
|
+
fs.unlinkSync(sessionPath);
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
return false;
|
|
411
|
+
} catch (err) {
|
|
412
|
+
log(`[SessionManager] Error deleting session: ${err.message}`);
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Check if a session exists
|
|
419
|
+
* @param {string} sessionPath - Full path to session file
|
|
420
|
+
* @returns {boolean} True if session exists
|
|
421
|
+
*/
|
|
422
|
+
function sessionExists(sessionPath) {
|
|
423
|
+
try {
|
|
424
|
+
return fs.statSync(sessionPath).isFile();
|
|
425
|
+
} catch {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
module.exports = {
|
|
431
|
+
parseSessionFilename,
|
|
432
|
+
getSessionPath,
|
|
433
|
+
getSessionContent,
|
|
434
|
+
parseSessionMetadata,
|
|
435
|
+
getSessionStats,
|
|
436
|
+
getSessionTitle,
|
|
437
|
+
getSessionSize,
|
|
438
|
+
getAllSessions,
|
|
439
|
+
getSessionById,
|
|
440
|
+
writeSessionContent,
|
|
441
|
+
appendSessionContent,
|
|
442
|
+
deleteSession,
|
|
443
|
+
sessionExists
|
|
444
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Split a shell command into segments by operators (&&, ||, ;, &)
|
|
5
|
+
* while respecting quoting (single/double) and escaped characters.
|
|
6
|
+
* Redirection operators (&>, >&, 2>&1) are NOT treated as separators.
|
|
7
|
+
*/
|
|
8
|
+
function splitShellSegments(command) {
|
|
9
|
+
const segments = [];
|
|
10
|
+
let current = '';
|
|
11
|
+
let quote = null;
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < command.length; i++) {
|
|
14
|
+
const ch = command[i];
|
|
15
|
+
|
|
16
|
+
// Inside quotes: handle escapes and closing quote
|
|
17
|
+
if (quote) {
|
|
18
|
+
if (ch === '\\' && i + 1 < command.length) {
|
|
19
|
+
current += ch + command[i + 1];
|
|
20
|
+
i++;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (ch === quote) quote = null;
|
|
24
|
+
current += ch;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Backslash escape outside quotes
|
|
29
|
+
if (ch === '\\' && i + 1 < command.length) {
|
|
30
|
+
current += ch + command[i + 1];
|
|
31
|
+
i++;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Opening quote
|
|
36
|
+
if (ch === '"' || ch === "'") {
|
|
37
|
+
quote = ch;
|
|
38
|
+
current += ch;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const next = command[i + 1] || '';
|
|
43
|
+
const prev = i > 0 ? command[i - 1] : '';
|
|
44
|
+
|
|
45
|
+
// && operator
|
|
46
|
+
if (ch === '&' && next === '&') {
|
|
47
|
+
if (current.trim()) segments.push(current.trim());
|
|
48
|
+
current = '';
|
|
49
|
+
i++;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// || operator
|
|
54
|
+
if (ch === '|' && next === '|') {
|
|
55
|
+
if (current.trim()) segments.push(current.trim());
|
|
56
|
+
current = '';
|
|
57
|
+
i++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ; separator
|
|
62
|
+
if (ch === ';') {
|
|
63
|
+
if (current.trim()) segments.push(current.trim());
|
|
64
|
+
current = '';
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Single & — but skip redirection patterns (&>, >&, digit>&)
|
|
69
|
+
if (ch === '&' && next !== '&') {
|
|
70
|
+
if (next === '>' || prev === '>') {
|
|
71
|
+
current += ch;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (current.trim()) segments.push(current.trim());
|
|
75
|
+
current = '';
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
current += ch;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (current.trim()) segments.push(current.trim());
|
|
83
|
+
return segments;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = { splitShellSegments };
|