@goodandready/dsh-goal 0.2.11 → 0.2.13

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.
@@ -0,0 +1,99 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs';
4
+
5
+ /**
6
+ * Git snapshot and checkpoint manager for goal milestones
7
+ */
8
+ export class GitSnapshotManager {
9
+ constructor(addonStore, { logger = console } = {}) {
10
+ this.store = addonStore;
11
+ this.logger = logger;
12
+ }
13
+
14
+ isGitRepository(workspaceRoot) {
15
+ if (!workspaceRoot || typeof workspaceRoot !== 'string') return false;
16
+ try {
17
+ if (!fs.existsSync(workspaceRoot)) return false;
18
+ execFileSync('git', ['rev-parse', '--is-inside-work-tree'], {
19
+ cwd: workspaceRoot,
20
+ stdio: ['ignore', 'pipe', 'ignore'],
21
+ timeout: 2000,
22
+ });
23
+ return true;
24
+ } catch {
25
+ return false;
26
+ }
27
+ }
28
+
29
+ createSnapshot(goalId, milestoneId, workspaceRoot, message = '') {
30
+ if (!goalId || !milestoneId || !this.isGitRepository(workspaceRoot)) {
31
+ return null;
32
+ }
33
+
34
+ try {
35
+ const commit = execFileSync('git', ['rev-parse', '--short', 'HEAD'], {
36
+ cwd: workspaceRoot,
37
+ encoding: 'utf8',
38
+ stdio: ['ignore', 'pipe', 'ignore'],
39
+ timeout: 2000,
40
+ }).trim();
41
+
42
+ const safeGoalId = String(goalId).replace(/[^a-zA-Z0-9_-]/g, '_');
43
+ const safeMilestoneId = String(milestoneId).replace(/[^a-zA-Z0-9_-]/g, '_');
44
+ const tagName = `dsh-goal-snapshot/${safeGoalId}/${safeMilestoneId}-${commit}`;
45
+
46
+ try {
47
+ execFileSync('git', ['tag', '-f', tagName, 'HEAD'], {
48
+ cwd: workspaceRoot,
49
+ stdio: ['ignore', 'pipe', 'ignore'],
50
+ timeout: 2000,
51
+ });
52
+ } catch (tagErr) {
53
+ // Tag creation non-fatal
54
+ }
55
+
56
+ const snapshot = {
57
+ goalId,
58
+ milestoneId,
59
+ commit,
60
+ tag: tagName,
61
+ timestamp: Date.now(),
62
+ message: message || `Milestone ${milestoneId} checkpoint`,
63
+ };
64
+
65
+ if (this.store) {
66
+ this.store.addSnapshot(goalId, snapshot);
67
+ }
68
+ this.logger.info?.(`[GitSnapshotManager] Created snapshot for milestone "${milestoneId}" at commit ${commit}`);
69
+ return snapshot;
70
+ } catch (err) {
71
+ this.logger.warn?.(`[GitSnapshotManager] Failed to create git snapshot: ${err.message}`);
72
+ return null;
73
+ }
74
+ }
75
+
76
+ rollback(goalId, milestoneId, workspaceRoot) {
77
+ if (!this.isGitRepository(workspaceRoot)) {
78
+ throw new Error(`Workspace "${workspaceRoot}" is not a valid git repository`);
79
+ }
80
+
81
+ const snapshots = this.store ? this.store.getSnapshots(goalId) : [];
82
+ const target = snapshots.find(s => s.milestoneId === milestoneId);
83
+ if (!target || !target.commit) {
84
+ throw new Error(`Snapshot for milestone "${milestoneId}" not found in goal "${goalId}"`);
85
+ }
86
+
87
+ try {
88
+ execFileSync('git', ['checkout', target.commit], {
89
+ cwd: workspaceRoot,
90
+ stdio: ['ignore', 'pipe', 'pipe'],
91
+ timeout: 5000,
92
+ });
93
+ this.logger.info?.(`[GitSnapshotManager] Rolled back workspace to commit ${target.commit}`);
94
+ return { success: true, commit: target.commit, milestoneId };
95
+ } catch (err) {
96
+ throw new Error(`Git rollback to commit ${target.commit} failed: ${err.message}`);
97
+ }
98
+ }
99
+ }
@@ -5,12 +5,12 @@ import { buildStatePromptInjection } from './engine-prompt.js';
5
5
  import { matchMilestone, parseMilestoneItems, applyMilestoneUpdate, toggleMilestoneChecklistItem } from './engine-milestones.js';
6
6
  import { applyIntervention, recordActivity, processTokenBudget } from './engine-intervention.js';
7
7
  import { createGoalBranch, sanitizeBranchSlug, getCurrentGitBranch, mergeGoalBranch, discardGoalBranch } from './engine-git-branch.js';
8
- import { parseIssueRef, syncMilestoneWithIssue } from './engine-issue-sync.js';
8
+ import { parseIssueRef, parseIssueChecklist, syncMilestoneWithIssue } from './engine-issue-sync.js';
9
9
  import { generateRetrospectiveData } from './engine-retrospective.js';
10
10
  import { generatePreplanDraft } from './engine-templates.js';
11
11
  import { pruneInactiveSessions, addNudgeToGoal, consumeGoalNudge, extendGoalBudget } from './engine-sessions.js';
12
12
 
13
- export { GoalState, MilestoneStatus, formatElapsed, formatETA, detectLanguage, sessionIdOf, matchMilestone };
13
+ export { GoalState, MilestoneStatus, formatElapsed, formatETA, detectLanguage, sessionIdOf, matchMilestone, parseIssueChecklist };
14
14
  export { getGitCurrentCommit, exportReportMarkdown, exportReportGitHubPR, createMilestoneCheckpoint, rollbackToCheckpoint, saveGoalArtifact };
15
15
 
16
16
  /**
@@ -73,7 +73,7 @@ export class GoalEngine {
73
73
  try {
74
74
  listener(snapshot, sid);
75
75
  } catch (err) {
76
- console.error('[dsh-goal] Error in GoalEngine listener:', err);
76
+ this.logger?.error?.('[dsh-goal] Error in GoalEngine listener:', err);
77
77
  }
78
78
  }
79
79
  }
@@ -234,6 +234,13 @@ export class GoalEngine {
234
234
  }
235
235
  }
236
236
 
237
+ if (options.issueBody && (!options.milestones || options.milestones.length === 0)) {
238
+ const items = parseIssueChecklist(options.issueBody);
239
+ if (items.length > 0) {
240
+ options.milestones = items.map((it) => ({ title: it.text, status: it.done ? MilestoneStatus.COMPLETED : MilestoneStatus.PENDING }));
241
+ }
242
+ }
243
+
237
244
  if (this.enablePreplanning && options.preplan !== false && (!options.milestones || options.milestones.length === 0)) {
238
245
  goal.preplan = { active: true, draftMilestones: generatePreplanDraft(cleanTitle) };
239
246
  }