@idea1/cli 1.5.2 → 1.7.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.
Files changed (126) hide show
  1. package/README.md +123 -92
  2. package/dist/commands/approve-pr.d.ts.map +1 -1
  3. package/dist/commands/approve-pr.js +7 -163
  4. package/dist/commands/approve-pr.js.map +1 -1
  5. package/dist/commands/attach-project-item.d.ts.map +1 -1
  6. package/dist/commands/attach-project-item.js +38 -89
  7. package/dist/commands/attach-project-item.js.map +1 -1
  8. package/dist/commands/close-worktree.d.ts.map +1 -1
  9. package/dist/commands/close-worktree.js +12 -9
  10. package/dist/commands/close-worktree.js.map +1 -1
  11. package/dist/commands/create-worktree.d.ts.map +1 -1
  12. package/dist/commands/create-worktree.js +3 -2
  13. package/dist/commands/create-worktree.js.map +1 -1
  14. package/dist/commands/help.d.ts.map +1 -1
  15. package/dist/commands/help.js +19 -14
  16. package/dist/commands/help.js.map +1 -1
  17. package/dist/commands/index.d.ts +3 -2
  18. package/dist/commands/index.d.ts.map +1 -1
  19. package/dist/commands/index.js +5 -3
  20. package/dist/commands/index.js.map +1 -1
  21. package/dist/commands/join-project-item.d.ts.map +1 -1
  22. package/dist/commands/join-project-item.js +38 -77
  23. package/dist/commands/join-project-item.js.map +1 -1
  24. package/dist/commands/next-workflow-step.d.ts.map +1 -1
  25. package/dist/commands/next-workflow-step.js +66 -51
  26. package/dist/commands/next-workflow-step.js.map +1 -1
  27. package/dist/commands/push.d.ts.map +1 -1
  28. package/dist/commands/push.js +5 -3
  29. package/dist/commands/push.js.map +1 -1
  30. package/dist/commands/ready-for-approval.d.ts.map +1 -1
  31. package/dist/commands/ready-for-approval.js +7 -66
  32. package/dist/commands/ready-for-approval.js.map +1 -1
  33. package/dist/commands/release.d.ts.map +1 -1
  34. package/dist/commands/release.js +5 -4
  35. package/dist/commands/release.js.map +1 -1
  36. package/dist/commands/start-agent-implementation.d.ts +3 -0
  37. package/dist/commands/start-agent-implementation.d.ts.map +1 -0
  38. package/dist/commands/start-agent-implementation.js +41 -0
  39. package/dist/commands/start-agent-implementation.js.map +1 -0
  40. package/dist/commands/start-dev-implementation.d.ts.map +1 -1
  41. package/dist/commands/start-dev-implementation.js +8 -55
  42. package/dist/commands/start-dev-implementation.js.map +1 -1
  43. package/dist/commands/start.d.ts +13 -0
  44. package/dist/commands/start.d.ts.map +1 -0
  45. package/dist/commands/start.js +81 -0
  46. package/dist/commands/start.js.map +1 -0
  47. package/dist/interactive.d.ts.map +1 -1
  48. package/dist/interactive.js +29 -9
  49. package/dist/interactive.js.map +1 -1
  50. package/dist/lib/claude-options.d.ts +33 -0
  51. package/dist/lib/claude-options.d.ts.map +1 -0
  52. package/dist/lib/claude-options.js +83 -0
  53. package/dist/lib/claude-options.js.map +1 -0
  54. package/dist/lib/settings.d.ts +18 -0
  55. package/dist/lib/settings.d.ts.map +1 -1
  56. package/dist/lib/settings.js +23 -5
  57. package/dist/lib/settings.js.map +1 -1
  58. package/dist/lib/workflow-states.d.ts +21 -3
  59. package/dist/lib/workflow-states.d.ts.map +1 -1
  60. package/dist/lib/workflow-states.generated.d.ts +21 -0
  61. package/dist/lib/workflow-states.generated.d.ts.map +1 -0
  62. package/dist/lib/workflow-states.generated.js +34 -0
  63. package/dist/lib/workflow-states.generated.js.map +1 -0
  64. package/dist/lib/workflow-states.js +47 -26
  65. package/dist/lib/workflow-states.js.map +1 -1
  66. package/dist/services/branch-setup.d.ts +42 -0
  67. package/dist/services/branch-setup.d.ts.map +1 -0
  68. package/dist/services/branch-setup.js +118 -0
  69. package/dist/services/branch-setup.js.map +1 -0
  70. package/dist/services/claude.d.ts +14 -4
  71. package/dist/services/claude.d.ts.map +1 -1
  72. package/dist/services/claude.js +39 -4
  73. package/dist/services/claude.js.map +1 -1
  74. package/dist/services/config.d.ts +3 -3
  75. package/dist/services/config.d.ts.map +1 -1
  76. package/dist/services/config.js +6 -4
  77. package/dist/services/config.js.map +1 -1
  78. package/dist/services/git.d.ts +66 -0
  79. package/dist/services/git.d.ts.map +1 -1
  80. package/dist/services/git.js +188 -8
  81. package/dist/services/git.js.map +1 -1
  82. package/dist/services/setup.d.ts +3 -1
  83. package/dist/services/setup.d.ts.map +1 -1
  84. package/dist/services/setup.js +19 -7
  85. package/dist/services/setup.js.map +1 -1
  86. package/dist/services/workflow-engine.d.ts +67 -0
  87. package/dist/services/workflow-engine.d.ts.map +1 -0
  88. package/dist/services/workflow-engine.js +371 -0
  89. package/dist/services/workflow-engine.js.map +1 -0
  90. package/dist/services/workflow-handlers/agent-implementation.d.ts +9 -0
  91. package/dist/services/workflow-handlers/agent-implementation.d.ts.map +1 -0
  92. package/dist/services/workflow-handlers/agent-implementation.js +37 -0
  93. package/dist/services/workflow-handlers/agent-implementation.js.map +1 -0
  94. package/dist/services/workflow-handlers/approve-pr.d.ts +8 -0
  95. package/dist/services/workflow-handlers/approve-pr.d.ts.map +1 -0
  96. package/dist/services/workflow-handlers/approve-pr.js +161 -0
  97. package/dist/services/workflow-handlers/approve-pr.js.map +1 -0
  98. package/dist/services/workflow-handlers/dev-implementation.d.ts +8 -0
  99. package/dist/services/workflow-handlers/dev-implementation.d.ts.map +1 -0
  100. package/dist/services/workflow-handlers/dev-implementation.js +34 -0
  101. package/dist/services/workflow-handlers/dev-implementation.js.map +1 -0
  102. package/dist/services/workflow-handlers/index.d.ts +18 -0
  103. package/dist/services/workflow-handlers/index.d.ts.map +1 -0
  104. package/dist/services/workflow-handlers/index.js +36 -0
  105. package/dist/services/workflow-handlers/index.js.map +1 -0
  106. package/dist/services/workflow-handlers/ready-for-approval.d.ts +8 -0
  107. package/dist/services/workflow-handlers/ready-for-approval.d.ts.map +1 -0
  108. package/dist/services/workflow-handlers/ready-for-approval.js +60 -0
  109. package/dist/services/workflow-handlers/ready-for-approval.js.map +1 -0
  110. package/dist/services/workflow.d.ts +1 -21
  111. package/dist/services/workflow.d.ts.map +1 -1
  112. package/dist/services/workflow.js +1 -67
  113. package/dist/services/workflow.js.map +1 -1
  114. package/dist/services/worktree.d.ts +23 -33
  115. package/dist/services/worktree.d.ts.map +1 -1
  116. package/dist/services/worktree.js +61 -140
  117. package/dist/services/worktree.js.map +1 -1
  118. package/dist/types/index.d.ts +41 -4
  119. package/dist/types/index.d.ts.map +1 -1
  120. package/dist/version.d.ts +1 -1
  121. package/dist/version.js +1 -1
  122. package/package.json +2 -2
  123. package/dist/commands/start-project-item.d.ts +0 -27
  124. package/dist/commands/start-project-item.d.ts.map +0 -1
  125. package/dist/commands/start-project-item.js +0 -325
  126. package/dist/commands/start-project-item.js.map +0 -1
@@ -0,0 +1,67 @@
1
+ import type { BranchMetadata, WorkflowContext, WorkflowState } from '../types/index.js';
2
+ /**
3
+ * The workflow engine. A transition is "enter state X": every state's handler
4
+ * runs its `prepare` side effects, the new state is recorded once (branch
5
+ * metadata on origin, the item's status on idea1.ai, local git config), then the
6
+ * handlers' `complete` side effects run. Before any transition, `ensureManaged`
7
+ * guarantees the item has a branch on origin carrying `.idea1/<branch>.json`.
8
+ */
9
+ export interface ResolveContextInput {
10
+ /** Project item URL; required when the current branch is not the item's branch. */
11
+ projectItemUrl?: string;
12
+ /** Resolved command options, handed to the state handlers. */
13
+ options: Record<string, string>;
14
+ }
15
+ /**
16
+ * Work out which project item and branch a command operates on.
17
+ *
18
+ * On a managed branch (the current branch carries workflow metadata locally or
19
+ * on origin) the branch is the target — its state is first synced from origin.
20
+ * Otherwise the item URL is required: its branch is located on origin (and, if
21
+ * checked out somewhere locally, that checkout becomes the working directory),
22
+ * or, for an item without a branch, the current state is read from idea1.ai.
23
+ */
24
+ export declare function resolveContext(input: ResolveContextInput): Promise<WorkflowContext>;
25
+ /**
26
+ * Adopt the workflow metadata committed on `origin/<branch>` — the durable copy,
27
+ * which the web client also writes — into local git config, and fast-forward a
28
+ * local checkout when it is strictly behind origin so its committed file matches.
29
+ * Local commits are never rewritten: a diverged checkout only gets a warning.
30
+ * Returns the metadata found on origin, or null when the branch has none.
31
+ */
32
+ export declare function syncBranchStateFromRemote(branchName: string): Promise<BranchMetadata | null>;
33
+ export interface EnsureManagedOptions {
34
+ /**
35
+ * Skip writing the item's status to idea1.ai here because the caller is about
36
+ * to advance the workflow and will write the final status itself.
37
+ */
38
+ deferItemStatusWrite: boolean;
39
+ }
40
+ /**
41
+ * Put the project item under workflow management: make sure it has exactly one
42
+ * branch on origin carrying `.idea1/<branch>.json` with its current state. An
43
+ * item that has never been started enters "Build Spec in Progress". Creating
44
+ * the branch needs no checkout, so nothing is written to the working tree and
45
+ * no code changes are made. Idempotent for an already-managed item.
46
+ */
47
+ export declare function ensureManaged(context: WorkflowContext, options: EnsureManagedOptions): Promise<void>;
48
+ /**
49
+ * Move the item to `targetState`, running the handlers of every state passed
50
+ * through on the way: all `prepare` steps, then a single persist of the target
51
+ * state, then all `complete` steps. Requires a managed item (see ensureManaged).
52
+ */
53
+ export declare function advanceTo(context: WorkflowContext, targetState: WorkflowState): Promise<void>;
54
+ /**
55
+ * Guard for the dedicated transition commands: they only run from the state
56
+ * immediately before their target.
57
+ */
58
+ export declare function requireCurrentState(context: WorkflowContext, expectedState: WorkflowState, commandName: string): void;
59
+ /**
60
+ * The branch a handler works on; every handler runs after ensureManaged.
61
+ */
62
+ export declare function requireBranch(context: WorkflowContext): string;
63
+ /**
64
+ * The local checkout a handler needs, with guidance when there is none.
65
+ */
66
+ export declare function requireWorkingPath(context: WorkflowContext, purpose: string): string;
67
+ //# sourceMappingURL=workflow-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-engine.d.ts","sourceRoot":"","sources":["../../src/services/workflow-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA4B,eAAe,EAAE,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAexI;;;;;;GAMG;AAEH,MAAM,WAAW,mBAAmB;IAClC,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC,CAuCzF;AAuDD;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAgClG;AAgBD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0E1G;AAoDD;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAgCnG;AAsDD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAMrH;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAK9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAOpF"}
@@ -0,0 +1,371 @@
1
+ import { logger } from '../lib/logger.js';
2
+ import { WorkflowStates, getWorkflowStatesBetween, isStateAtOrAfter, normalizeWorkflowState } from '../lib/workflow-states.js';
3
+ import { resolveOptions } from '../cli/resolver.js';
4
+ import * as git from './git.js';
5
+ import * as claude from './claude.js';
6
+ import * as worktree from './worktree.js';
7
+ import { collectBranchCreationChoices } from './branch-setup.js';
8
+ import { HANDLERS_BY_STATE } from './workflow-handlers/index.js';
9
+ /**
10
+ * Work out which project item and branch a command operates on.
11
+ *
12
+ * On a managed branch (the current branch carries workflow metadata locally or
13
+ * on origin) the branch is the target — its state is first synced from origin.
14
+ * Otherwise the item URL is required: its branch is located on origin (and, if
15
+ * checked out somewhere locally, that checkout becomes the working directory),
16
+ * or, for an item without a branch, the current state is read from idea1.ai.
17
+ */
18
+ export async function resolveContext(input) {
19
+ const requestedUrl = input.projectItemUrl || null;
20
+ const currentBranch = await git.getCurrentBranch();
21
+ const managedUrl = currentBranch !== 'HEAD' ? await getManagedProjectItemUrl(currentBranch) : null;
22
+ if (managedUrl && (!requestedUrl || requestedUrl === managedUrl)) {
23
+ return contextForManagedBranch(currentBranch, managedUrl, input.options);
24
+ }
25
+ if (!requestedUrl) {
26
+ throw new Error('This branch is not under workflow management. Pass --url <project item url>, or run this from the item\'s branch.');
27
+ }
28
+ if (managedUrl) {
29
+ logger.dim(`Current branch belongs to ${managedUrl}; operating on ${requestedUrl} instead.`);
30
+ }
31
+ const branch = await git.resolveBranchFromProjectItemUrl(requestedUrl);
32
+ if (branch) {
33
+ logger.info(`Resolved branch for ${requestedUrl}: ${branch}`);
34
+ return contextForManagedBranch(branch, requestedUrl, input.options);
35
+ }
36
+ const currentState = normalizeWorkflowState(await claude.getWorkflowStatus(requestedUrl));
37
+ return {
38
+ projectItemUrl: requestedUrl,
39
+ branchName: null,
40
+ baseBranch: input.options['base-branch'] || await worktree.resolveBaseBranch(),
41
+ devWorkflowType: (input.options['workflow-type'] || 'independent'),
42
+ stackBranch: null,
43
+ integrationBranch: null,
44
+ currentState,
45
+ workingPath: null,
46
+ branchRetired: false,
47
+ options: input.options
48
+ };
49
+ }
50
+ /**
51
+ * The project item a branch is attached to, from local git config, the local
52
+ * metadata file, or the metadata committed on origin. Null when unmanaged.
53
+ */
54
+ async function getManagedProjectItemUrl(branchName) {
55
+ const localUrl = await git.getProjectItemUrl(branchName);
56
+ if (localUrl) {
57
+ return localUrl;
58
+ }
59
+ const remote = await git.readBranchMetadataFromRef(branchName);
60
+ return remote?.projectItemUrl ?? null;
61
+ }
62
+ /**
63
+ * Build the context for a branch that is already under workflow management,
64
+ * syncing its state from origin first and moving into its local checkout when
65
+ * that is somewhere other than the current directory.
66
+ */
67
+ async function contextForManagedBranch(branchName, projectItemUrl, options) {
68
+ await syncBranchStateFromRemote(branchName);
69
+ const workingPath = await git.getCheckoutPathForBranch(branchName);
70
+ if (workingPath && workingPath !== (await git.getRepoRoot()).trim()) {
71
+ logger.dim(`Working in ${workingPath}`);
72
+ process.chdir(workingPath);
73
+ }
74
+ const [baseBranch, devWorkflowType, stackBranch, integrationBranch, rawState] = await Promise.all([
75
+ git.getBaseBranch(branchName),
76
+ git.getDevWorkflowType(branchName),
77
+ git.getStackBranch(branchName),
78
+ git.getIntegrationBranch(branchName),
79
+ git.getWorkflowState(branchName)
80
+ ]);
81
+ return {
82
+ projectItemUrl,
83
+ branchName,
84
+ baseBranch: baseBranch ?? await worktree.resolveBaseBranch(),
85
+ devWorkflowType: (devWorkflowType ?? 'independent'),
86
+ stackBranch,
87
+ integrationBranch,
88
+ currentState: normalizeWorkflowState(rawState),
89
+ workingPath,
90
+ branchRetired: false,
91
+ options
92
+ };
93
+ }
94
+ /**
95
+ * Adopt the workflow metadata committed on `origin/<branch>` — the durable copy,
96
+ * which the web client also writes — into local git config, and fast-forward a
97
+ * local checkout when it is strictly behind origin so its committed file matches.
98
+ * Local commits are never rewritten: a diverged checkout only gets a warning.
99
+ * Returns the metadata found on origin, or null when the branch has none.
100
+ */
101
+ export async function syncBranchStateFromRemote(branchName) {
102
+ const remoteExists = await git.fetchRemoteBranch(branchName);
103
+ if (!remoteExists) {
104
+ logger.dim(`Branch ${branchName} is not on origin; using local workflow state`);
105
+ return null;
106
+ }
107
+ const remote = await git.readBranchMetadataFromRef(branchName);
108
+ if (!remote) {
109
+ return null;
110
+ }
111
+ await adoptRemoteValue(remote.projectItemUrl, () => git.getProjectItemUrl(branchName), value => git.storeProjectItemUrl(value, branchName));
112
+ await adoptRemoteValue(remote.baseBranch, () => git.getBaseBranch(branchName), value => git.storeBaseBranch(value, branchName));
113
+ await adoptRemoteValue(remote.workflowState, () => git.getWorkflowState(branchName), value => git.storeWorkflowState(value, branchName));
114
+ await adoptRemoteValue(remote.devWorkflowType, () => git.getDevWorkflowType(branchName), value => git.storeDevWorkflowType(value, branchName));
115
+ await adoptRemoteValue(remote.stackBranch, () => git.getStackBranch(branchName), value => git.storeStackBranch(value, branchName));
116
+ await adoptRemoteValue(remote.integrationBranch, () => git.getIntegrationBranch(branchName), value => git.storeIntegrationBranch(value, branchName));
117
+ const checkoutPath = await git.getCheckoutPathForBranch(branchName);
118
+ if (checkoutPath) {
119
+ const result = await git.fastForwardCheckoutToOrigin(branchName, checkoutPath);
120
+ if (result === 'fast-forwarded') {
121
+ logger.dim(`Fast-forwarded ${branchName} to origin`);
122
+ }
123
+ else if (result === 'diverged') {
124
+ logger.warning(`Local branch ${branchName} has diverged from origin. Run 'idea1 update-branch' to merge before continuing.`);
125
+ }
126
+ else if (result === 'blocked') {
127
+ logger.warning(`Could not fast-forward ${branchName} to origin because of local changes. Commit or stash them, then pull.`);
128
+ }
129
+ }
130
+ return remote;
131
+ }
132
+ async function adoptRemoteValue(remoteValue, readLocal, store) {
133
+ if (!remoteValue) {
134
+ return;
135
+ }
136
+ const localValue = await readLocal();
137
+ if (localValue !== remoteValue) {
138
+ await store(remoteValue);
139
+ }
140
+ }
141
+ /**
142
+ * Put the project item under workflow management: make sure it has exactly one
143
+ * branch on origin carrying `.idea1/<branch>.json` with its current state. An
144
+ * item that has never been started enters "Build Spec in Progress". Creating
145
+ * the branch needs no checkout, so nothing is written to the working tree and
146
+ * no code changes are made. Idempotent for an already-managed item.
147
+ */
148
+ export async function ensureManaged(context, options) {
149
+ if (context.branchName) {
150
+ await ensureMetadataOnBranch(context);
151
+ return;
152
+ }
153
+ const hadState = context.currentState !== null;
154
+ const state = context.currentState ?? WorkflowStates.BuildSpecInProgress;
155
+ const choices = await collectBranchCreationChoices(context.options);
156
+ const shortBranchName = choices.shortBranchName ?? await claude.generateBranchName(context.projectItemUrl);
157
+ if (!shortBranchName) {
158
+ throw new Error('Failed to generate a branch name');
159
+ }
160
+ await git.fetchLatest();
161
+ let prTargetBranch = choices.baseBranch;
162
+ let fullBranchName = `${await worktree.resolveBranchPrefix()}/${shortBranchName}`;
163
+ if (choices.integrationSelection) {
164
+ const { integrationName, integrationBranchName, isNew } = choices.integrationSelection;
165
+ if (isNew && !await git.branchExists(integrationBranchName)) {
166
+ await git.createRemoteBranchFrom(integrationBranchName, `origin/${choices.baseBranch}`);
167
+ }
168
+ prTargetBranch = integrationBranchName;
169
+ fullBranchName = await worktree.buildIntegrationWorkBranchName(integrationName, shortBranchName);
170
+ logger.info(`Integration branch: ${integrationBranchName}`);
171
+ }
172
+ const sourceBranch = choices.stackBranch ?? prTargetBranch;
173
+ if (choices.stackBranch) {
174
+ await git.ensureStackBranchReady(choices.stackBranch);
175
+ logger.info(`Stacked workflow: branching from ${choices.stackBranch}, PR will target ${prTargetBranch}`);
176
+ }
177
+ if (!await git.branchExists(sourceBranch)) {
178
+ throw new Error(`Source branch '${sourceBranch}' does not exist locally or on origin`);
179
+ }
180
+ if (await git.branchExists(fullBranchName)) {
181
+ throw new Error(`Branch '${fullBranchName}' already exists. Pass --branch-name to choose a different name.`);
182
+ }
183
+ const metadata = {
184
+ branchName: fullBranchName,
185
+ projectItemUrl: context.projectItemUrl,
186
+ baseBranch: prTargetBranch,
187
+ workflowState: state,
188
+ devWorkflowType: choices.workflowType
189
+ };
190
+ if (choices.stackBranch) {
191
+ metadata.stackBranch = choices.stackBranch;
192
+ }
193
+ if (choices.integrationSelection) {
194
+ metadata.integrationBranch = choices.integrationSelection.integrationBranchName;
195
+ }
196
+ await git.createBranchWithMetadataDetached(fullBranchName, `origin/${sourceBranch}`, metadata);
197
+ await seedLocalConfig(metadata);
198
+ context.branchName = fullBranchName;
199
+ context.baseBranch = prTargetBranch;
200
+ context.devWorkflowType = choices.workflowType;
201
+ context.stackBranch = choices.stackBranch;
202
+ context.integrationBranch = choices.integrationSelection?.integrationBranchName ?? null;
203
+ context.currentState = state;
204
+ context.workingPath = null;
205
+ if (!hadState) {
206
+ logger.info(`${context.projectItemUrl} enters "${state}"`);
207
+ }
208
+ if (!options.deferItemStatusWrite) {
209
+ await claude.setWorkflowStatus(context.projectItemUrl, state, fullBranchName);
210
+ }
211
+ }
212
+ /**
213
+ * A branch attached to an item before metadata files existed (git config only)
214
+ * gets its `.idea1/<branch>.json` written at the current state.
215
+ */
216
+ async function ensureMetadataOnBranch(context) {
217
+ const branchName = context.branchName;
218
+ const remote = await git.readBranchMetadataFromRef(branchName);
219
+ if (remote) {
220
+ return;
221
+ }
222
+ const state = context.currentState ?? WorkflowStates.BuildSpecInProgress;
223
+ await git.storeWorkflowState(state, branchName);
224
+ context.currentState = state;
225
+ if (context.workingPath) {
226
+ await git.commitBranchMetadata(context.workingPath, branchName, context.projectItemUrl);
227
+ await git.pushToRemote(branchName);
228
+ return;
229
+ }
230
+ const metadata = {
231
+ branchName,
232
+ projectItemUrl: context.projectItemUrl,
233
+ baseBranch: context.baseBranch,
234
+ workflowState: state,
235
+ devWorkflowType: context.devWorkflowType
236
+ };
237
+ if (context.stackBranch) {
238
+ metadata.stackBranch = context.stackBranch;
239
+ }
240
+ if (context.integrationBranch) {
241
+ metadata.integrationBranch = context.integrationBranch;
242
+ }
243
+ await git.updateBranchMetadataDetached(branchName, metadata);
244
+ }
245
+ /**
246
+ * Seed the local git config fast path from freshly created branch metadata.
247
+ */
248
+ async function seedLocalConfig(metadata) {
249
+ const branch = metadata.branchName;
250
+ if (metadata.projectItemUrl)
251
+ await git.storeProjectItemUrl(metadata.projectItemUrl, branch);
252
+ if (metadata.baseBranch)
253
+ await git.storeBaseBranch(metadata.baseBranch, branch);
254
+ if (metadata.workflowState)
255
+ await git.storeWorkflowState(metadata.workflowState, branch);
256
+ if (metadata.devWorkflowType)
257
+ await git.storeDevWorkflowType(metadata.devWorkflowType, branch);
258
+ if (metadata.stackBranch)
259
+ await git.storeStackBranch(metadata.stackBranch, branch);
260
+ if (metadata.integrationBranch)
261
+ await git.storeIntegrationBranch(metadata.integrationBranch, branch);
262
+ }
263
+ /**
264
+ * Move the item to `targetState`, running the handlers of every state passed
265
+ * through on the way: all `prepare` steps, then a single persist of the target
266
+ * state, then all `complete` steps. Requires a managed item (see ensureManaged).
267
+ */
268
+ export async function advanceTo(context, targetState) {
269
+ if (!context.branchName) {
270
+ throw new Error('The project item has no branch yet; call ensureManaged before advancing the workflow.');
271
+ }
272
+ if (context.currentState !== null && isStateAtOrAfter(context.currentState, targetState)) {
273
+ logger.info(`Already at "${context.currentState}"; nothing to advance to reach "${targetState}".`);
274
+ return;
275
+ }
276
+ const steps = getWorkflowStatesBetween(context.currentState, targetState);
277
+ const handlers = steps
278
+ .map(state => HANDLERS_BY_STATE.get(state))
279
+ .filter((handler) => handler !== undefined);
280
+ await resolveHandlerOptions(context, handlers);
281
+ logger.info(`Workflow: ${context.currentState ?? '(not started)'} → ${targetState}`);
282
+ for (const handler of handlers) {
283
+ if (handler.prepare) {
284
+ await handler.prepare(context);
285
+ }
286
+ }
287
+ await persistState(context, targetState);
288
+ for (const handler of handlers) {
289
+ if (handler.complete) {
290
+ await handler.complete(context);
291
+ }
292
+ }
293
+ }
294
+ /**
295
+ * Prompt for any handler option that was not supplied on the command line, so
296
+ * a handler reached through `next` asks the same questions as its dedicated
297
+ * command would.
298
+ */
299
+ async function resolveHandlerOptions(context, handlers) {
300
+ for (const handler of handlers) {
301
+ if (!handler.options || handler.options.length === 0) {
302
+ continue;
303
+ }
304
+ const pseudoCommand = {
305
+ name: handler.state,
306
+ aliases: [],
307
+ description: `Options for entering ${handler.state}`,
308
+ options: handler.options,
309
+ execute: async () => undefined
310
+ };
311
+ const supplied = {};
312
+ for (const option of handler.options) {
313
+ if (option.longName in context.options) {
314
+ supplied[option.longName] = context.options[option.longName];
315
+ }
316
+ }
317
+ Object.assign(context.options, await resolveOptions(pseudoCommand, supplied));
318
+ }
319
+ }
320
+ /**
321
+ * Record the new state everywhere it lives: the branch's committed metadata
322
+ * (unless a handler retired the branch), local git config, and the item on
323
+ * idea1.ai (with the branch name, so the web client can find the branch).
324
+ */
325
+ async function persistState(context, targetState) {
326
+ const branchName = context.branchName;
327
+ if (context.branchRetired) {
328
+ await git.storeWorkflowState(targetState, branchName);
329
+ }
330
+ else if (context.workingPath) {
331
+ await git.storeWorkflowState(targetState, branchName);
332
+ const committed = await git.commitBranchMetadataIfChanged(branchName);
333
+ if (committed) {
334
+ await git.pushToRemote(branchName);
335
+ }
336
+ }
337
+ else {
338
+ await git.updateBranchMetadataDetached(branchName, { workflowState: targetState });
339
+ await git.storeWorkflowState(targetState, branchName);
340
+ }
341
+ await claude.setWorkflowStatus(context.projectItemUrl, targetState, context.branchRetired ? undefined : branchName);
342
+ context.currentState = targetState;
343
+ }
344
+ /**
345
+ * Guard for the dedicated transition commands: they only run from the state
346
+ * immediately before their target.
347
+ */
348
+ export function requireCurrentState(context, expectedState, commandName) {
349
+ if (context.currentState !== expectedState) {
350
+ throw new Error(`Cannot perform '${commandName}' from state '${context.currentState ?? '(not started)'}'. It requires state '${expectedState}'. Use 'idea1 next' to advance one step at a time.`);
351
+ }
352
+ }
353
+ /**
354
+ * The branch a handler works on; every handler runs after ensureManaged.
355
+ */
356
+ export function requireBranch(context) {
357
+ if (!context.branchName) {
358
+ throw new Error('The project item has no branch yet.');
359
+ }
360
+ return context.branchName;
361
+ }
362
+ /**
363
+ * The local checkout a handler needs, with guidance when there is none.
364
+ */
365
+ export function requireWorkingPath(context, purpose) {
366
+ if (!context.workingPath) {
367
+ throw new Error(`Branch ${context.branchName ?? ''} has no local checkout, which is needed to ${purpose}. Run: idea1 join-project-item --project-item-url ${context.projectItemUrl}`);
368
+ }
369
+ return context.workingPath;
370
+ }
371
+ //# sourceMappingURL=workflow-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-engine.js","sourceRoot":"","sources":["../../src/services/workflow-engine.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": make sure the branch is checked out locally
4
+ * (worktree or main repo, per the isolation mode), then — once the state is
5
+ * recorded — launch Claude to implement the item. This is the only transition
6
+ * that starts code-writing automation.
7
+ */
8
+ export declare const agentImplementationHandler: WorkflowStateHandler;
9
+ //# sourceMappingURL=agent-implementation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-implementation.d.ts","sourceRoot":"","sources":["../../../src/services/workflow-handlers/agent-implementation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAQjE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,oBA4BxC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { WorkflowStates } from '../../lib/workflow-states.js';
2
+ import { isolationModeOption, resolveIsolationMode } from '../../lib/isolation.js';
3
+ import { claudeEntryPointOption, claudeSessionOptions, resolveClaudeSessionOptions } from '../../lib/claude-options.js';
4
+ import * as git from '../git.js';
5
+ import * as worktree from '../worktree.js';
6
+ import { requireBranch, requireWorkingPath } from '../workflow-engine.js';
7
+ /**
8
+ * Entering "Agent Implementation": make sure the branch is checked out locally
9
+ * (worktree or main repo, per the isolation mode), then — once the state is
10
+ * recorded — launch Claude to implement the item. This is the only transition
11
+ * that starts code-writing automation.
12
+ */
13
+ export const agentImplementationHandler = {
14
+ state: WorkflowStates.AgentImplementation,
15
+ options: [isolationModeOption, ...claudeSessionOptions(true), claudeEntryPointOption],
16
+ async prepare(context) {
17
+ const branchName = requireBranch(context);
18
+ const isolationMode = resolveIsolationMode(context.options);
19
+ const { workingPath } = await worktree.ensureBranchEnvironment(isolationMode, branchName);
20
+ context.workingPath = workingPath;
21
+ if ((await git.getRepoRoot()).trim() !== workingPath) {
22
+ process.chdir(workingPath);
23
+ }
24
+ },
25
+ async complete(context) {
26
+ const workingPath = requireWorkingPath(context, 'run the implementation session');
27
+ const { permissionMode, model, effort, claudeEntryPointMode } = resolveClaudeSessionOptions(context.options);
28
+ await worktree.launchClaudeForBranch(workingPath, {
29
+ projectItemUrl: context.projectItemUrl,
30
+ permissionMode,
31
+ model,
32
+ effort,
33
+ claudeEntryPointMode
34
+ });
35
+ }
36
+ };
37
+ //# sourceMappingURL=agent-implementation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-implementation.js","sourceRoot":"","sources":["../../../src/services/workflow-handlers/agent-implementation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AACxH,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAyB;IAC9D,KAAK,EAAE,cAAc,CAAC,mBAAmB;IACzC,OAAO,EAAE,CAAC,mBAAmB,EAAE,GAAG,oBAAoB,CAAC,IAAI,CAAC,EAAE,sBAAsB,CAAC;IAErF,KAAK,CAAC,OAAO,CAAC,OAAO;QACnB,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,aAAa,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE5D,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,QAAQ,CAAC,uBAAuB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;QAC1F,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;QAElC,IAAI,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,WAAW,EAAE,CAAC;YACrD,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAO;QACpB,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,EAAE,gCAAgC,CAAC,CAAC;QAClF,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,GAAG,2BAA2B,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE7G,MAAM,QAAQ,CAAC,qBAAqB,CAAC,WAAW,EAAE;YAChD,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,cAAc;YACd,KAAK;YACL,MAAM;YACN,oBAAoB;SACrB,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { WorkflowStateHandler } from '../../types/index.js';
2
+ /**
3
+ * Entering "Approved and Merged": approve the PR when the user is a requested
4
+ * reviewer, drop the branch's metadata file so it does not leak into the target
5
+ * branch, and merge. Afterwards the branch and any worktree are cleaned up.
6
+ */
7
+ export declare const approvePrHandler: WorkflowStateHandler;
8
+ //# sourceMappingURL=approve-pr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approve-pr.d.ts","sourceRoot":"","sources":["../../../src/services/workflow-handlers/approve-pr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AASjE;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,oBA+F9B,CAAC"}