git-workspace-service 0.2.0 → 0.3.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/dist/index.d.cts CHANGED
@@ -182,6 +182,53 @@ type BranchStrategy = 'feature_branch' | 'fork' | 'direct';
182
182
  */
183
183
  type WorkspaceStrategy = 'clone' | 'worktree';
184
184
  type WorkspaceStatus = 'provisioning' | 'ready' | 'in_use' | 'finalizing' | 'cleaned_up' | 'error';
185
+ /**
186
+ * Granular progress phases for workspace operations
187
+ */
188
+ type WorkspacePhase = 'initializing' | 'cloning' | 'creating_branch' | 'configuring' | 'ready' | 'committing' | 'pushing' | 'creating_pr' | 'cleaning_up' | 'done' | 'error';
189
+ /**
190
+ * Progress tracking for workspace operations
191
+ */
192
+ interface WorkspaceProgress {
193
+ /**
194
+ * Current phase of the operation
195
+ */
196
+ phase: WorkspacePhase;
197
+ /**
198
+ * Human-readable message describing current activity
199
+ */
200
+ message?: string;
201
+ /**
202
+ * Progress percentage (0-100) if determinable
203
+ */
204
+ percent?: number;
205
+ /**
206
+ * When progress was last updated
207
+ */
208
+ updatedAt: Date;
209
+ }
210
+ /**
211
+ * Completion hook configuration
212
+ */
213
+ interface CompletionHook {
214
+ /**
215
+ * Shell command to execute on completion
216
+ * Variables available: $WORKSPACE_ID, $REPO, $BRANCH, $STATUS
217
+ */
218
+ command?: string;
219
+ /**
220
+ * Webhook URL to POST to on completion
221
+ */
222
+ webhook?: string;
223
+ /**
224
+ * Custom headers for webhook request
225
+ */
226
+ webhookHeaders?: Record<string, string>;
227
+ /**
228
+ * Whether to run hook on error (default: true)
229
+ */
230
+ runOnError?: boolean;
231
+ }
185
232
  /**
186
233
  * Configuration for provisioning a workspace
187
234
  */
@@ -239,6 +286,10 @@ interface WorkspaceConfig {
239
286
  * If provided, these are used instead of managed credentials
240
287
  */
241
288
  userCredentials?: UserProvidedCredentials;
289
+ /**
290
+ * Hook to run when workspace operations complete
291
+ */
292
+ onComplete?: CompletionHook;
242
293
  }
243
294
  /**
244
295
  * A provisioned git workspace
@@ -284,6 +335,14 @@ interface Workspace {
284
335
  * Child worktree IDs (for clone workspaces that have worktrees)
285
336
  */
286
337
  worktreeIds?: string[];
338
+ /**
339
+ * Current progress of workspace operations
340
+ */
341
+ progress?: WorkspaceProgress;
342
+ /**
343
+ * Completion hook configuration
344
+ */
345
+ onComplete?: CompletionHook;
287
346
  }
288
347
  /**
289
348
  * Options for finalizing a workspace (push, PR creation, cleanup)
@@ -1185,6 +1244,14 @@ declare class WorkspaceService {
1185
1244
  private execInDir;
1186
1245
  private log;
1187
1246
  private emitEvent;
1247
+ /**
1248
+ * Update workspace progress
1249
+ */
1250
+ private updateProgress;
1251
+ /**
1252
+ * Execute completion hook if configured
1253
+ */
1254
+ private executeCompletionHook;
1188
1255
  }
1189
1256
 
1190
1257
  /**
@@ -1567,4 +1634,4 @@ declare function getGitCredentialConfig(helperScriptPath: string): string[];
1567
1634
  */
1568
1635
  declare function outputCredentials(username: string, password: string): void;
1569
1636
 
1570
- export { type AgentPermissions, type AuthPrompt, type AuthPromptEmitter, type AuthResult, type BranchConfig, type BranchInfo, type BranchNamingOptions, type BranchStrategy, type CreateIssueOptions, type CredentialContext, type CredentialGrant, type CredentialGrantStore, type CredentialHelperContext, CredentialService, type CredentialServiceConfig, type CredentialServiceLogger, type CredentialServiceOptions, type CredentialType, DEFAULT_AGENT_PERMISSIONS, DEFAULT_BRANCH_PREFIX, type DeviceCodeResponse, FileTokenStore, type GitCredential, type GitCredentialRequest, type GitHubAppConfig, type GitHubAppInstallation, GitHubPatClient, type GitHubPatClientLogger, type GitHubPatClientOptions, GitHubProvider, type GitHubProviderConfig, type GitHubProviderLogger, type GitProvider, type GitProviderAdapter, type IssueComment, type IssueCommentOptions, type IssueInfo, type IssueState, MemoryTokenStore, OAuthDeviceFlow, type OAuthDeviceFlowConfig, type OAuthDeviceFlowLogger, type OAuthToken, type PermissionLevel, type PullRequestInfo, READONLY_AGENT_PERMISSIONS, type RepositoryScope, type SshCredentials, type TokenCredentials, TokenStore, type TokenStoreOptions, type UserProvidedCredentials, type Workspace, type WorkspaceConfig, type WorkspaceEvent, type WorkspaceEventHandler, type WorkspaceEventType, type WorkspaceFinalization, WorkspaceService, type WorkspaceServiceConfig, type WorkspaceServiceLogger, type WorkspaceServiceOptions, type WorkspaceStatus, type WorkspaceStrategy, cleanupCredentialFiles, configureCredentialHelper, createBranchInfo, createNodeCredentialHelperScript, createShellCredentialHelperScript, filterBranchesByExecution, generateBranchName, generateSlug, getGitCredentialConfig, isManagedBranch, outputCredentials, parseBranchName, updateCredentials };
1637
+ export { type AgentPermissions, type AuthPrompt, type AuthPromptEmitter, type AuthResult, type BranchConfig, type BranchInfo, type BranchNamingOptions, type BranchStrategy, type CompletionHook, type CreateIssueOptions, type CredentialContext, type CredentialGrant, type CredentialGrantStore, type CredentialHelperContext, CredentialService, type CredentialServiceConfig, type CredentialServiceLogger, type CredentialServiceOptions, type CredentialType, DEFAULT_AGENT_PERMISSIONS, DEFAULT_BRANCH_PREFIX, type DeviceCodeResponse, FileTokenStore, type GitCredential, type GitCredentialRequest, type GitHubAppConfig, type GitHubAppInstallation, GitHubPatClient, type GitHubPatClientLogger, type GitHubPatClientOptions, GitHubProvider, type GitHubProviderConfig, type GitHubProviderLogger, type GitProvider, type GitProviderAdapter, type IssueComment, type IssueCommentOptions, type IssueInfo, type IssueState, MemoryTokenStore, OAuthDeviceFlow, type OAuthDeviceFlowConfig, type OAuthDeviceFlowLogger, type OAuthToken, type PermissionLevel, type PullRequestInfo, READONLY_AGENT_PERMISSIONS, type RepositoryScope, type SshCredentials, type TokenCredentials, TokenStore, type TokenStoreOptions, type UserProvidedCredentials, type Workspace, type WorkspaceConfig, type WorkspaceEvent, type WorkspaceEventHandler, type WorkspaceEventType, type WorkspaceFinalization, type WorkspacePhase, type WorkspaceProgress, WorkspaceService, type WorkspaceServiceConfig, type WorkspaceServiceLogger, type WorkspaceServiceOptions, type WorkspaceStatus, type WorkspaceStrategy, cleanupCredentialFiles, configureCredentialHelper, createBranchInfo, createNodeCredentialHelperScript, createShellCredentialHelperScript, filterBranchesByExecution, generateBranchName, generateSlug, getGitCredentialConfig, isManagedBranch, outputCredentials, parseBranchName, updateCredentials };
package/dist/index.d.ts CHANGED
@@ -182,6 +182,53 @@ type BranchStrategy = 'feature_branch' | 'fork' | 'direct';
182
182
  */
183
183
  type WorkspaceStrategy = 'clone' | 'worktree';
184
184
  type WorkspaceStatus = 'provisioning' | 'ready' | 'in_use' | 'finalizing' | 'cleaned_up' | 'error';
185
+ /**
186
+ * Granular progress phases for workspace operations
187
+ */
188
+ type WorkspacePhase = 'initializing' | 'cloning' | 'creating_branch' | 'configuring' | 'ready' | 'committing' | 'pushing' | 'creating_pr' | 'cleaning_up' | 'done' | 'error';
189
+ /**
190
+ * Progress tracking for workspace operations
191
+ */
192
+ interface WorkspaceProgress {
193
+ /**
194
+ * Current phase of the operation
195
+ */
196
+ phase: WorkspacePhase;
197
+ /**
198
+ * Human-readable message describing current activity
199
+ */
200
+ message?: string;
201
+ /**
202
+ * Progress percentage (0-100) if determinable
203
+ */
204
+ percent?: number;
205
+ /**
206
+ * When progress was last updated
207
+ */
208
+ updatedAt: Date;
209
+ }
210
+ /**
211
+ * Completion hook configuration
212
+ */
213
+ interface CompletionHook {
214
+ /**
215
+ * Shell command to execute on completion
216
+ * Variables available: $WORKSPACE_ID, $REPO, $BRANCH, $STATUS
217
+ */
218
+ command?: string;
219
+ /**
220
+ * Webhook URL to POST to on completion
221
+ */
222
+ webhook?: string;
223
+ /**
224
+ * Custom headers for webhook request
225
+ */
226
+ webhookHeaders?: Record<string, string>;
227
+ /**
228
+ * Whether to run hook on error (default: true)
229
+ */
230
+ runOnError?: boolean;
231
+ }
185
232
  /**
186
233
  * Configuration for provisioning a workspace
187
234
  */
@@ -239,6 +286,10 @@ interface WorkspaceConfig {
239
286
  * If provided, these are used instead of managed credentials
240
287
  */
241
288
  userCredentials?: UserProvidedCredentials;
289
+ /**
290
+ * Hook to run when workspace operations complete
291
+ */
292
+ onComplete?: CompletionHook;
242
293
  }
243
294
  /**
244
295
  * A provisioned git workspace
@@ -284,6 +335,14 @@ interface Workspace {
284
335
  * Child worktree IDs (for clone workspaces that have worktrees)
285
336
  */
286
337
  worktreeIds?: string[];
338
+ /**
339
+ * Current progress of workspace operations
340
+ */
341
+ progress?: WorkspaceProgress;
342
+ /**
343
+ * Completion hook configuration
344
+ */
345
+ onComplete?: CompletionHook;
287
346
  }
288
347
  /**
289
348
  * Options for finalizing a workspace (push, PR creation, cleanup)
@@ -1185,6 +1244,14 @@ declare class WorkspaceService {
1185
1244
  private execInDir;
1186
1245
  private log;
1187
1246
  private emitEvent;
1247
+ /**
1248
+ * Update workspace progress
1249
+ */
1250
+ private updateProgress;
1251
+ /**
1252
+ * Execute completion hook if configured
1253
+ */
1254
+ private executeCompletionHook;
1188
1255
  }
1189
1256
 
1190
1257
  /**
@@ -1567,4 +1634,4 @@ declare function getGitCredentialConfig(helperScriptPath: string): string[];
1567
1634
  */
1568
1635
  declare function outputCredentials(username: string, password: string): void;
1569
1636
 
1570
- export { type AgentPermissions, type AuthPrompt, type AuthPromptEmitter, type AuthResult, type BranchConfig, type BranchInfo, type BranchNamingOptions, type BranchStrategy, type CreateIssueOptions, type CredentialContext, type CredentialGrant, type CredentialGrantStore, type CredentialHelperContext, CredentialService, type CredentialServiceConfig, type CredentialServiceLogger, type CredentialServiceOptions, type CredentialType, DEFAULT_AGENT_PERMISSIONS, DEFAULT_BRANCH_PREFIX, type DeviceCodeResponse, FileTokenStore, type GitCredential, type GitCredentialRequest, type GitHubAppConfig, type GitHubAppInstallation, GitHubPatClient, type GitHubPatClientLogger, type GitHubPatClientOptions, GitHubProvider, type GitHubProviderConfig, type GitHubProviderLogger, type GitProvider, type GitProviderAdapter, type IssueComment, type IssueCommentOptions, type IssueInfo, type IssueState, MemoryTokenStore, OAuthDeviceFlow, type OAuthDeviceFlowConfig, type OAuthDeviceFlowLogger, type OAuthToken, type PermissionLevel, type PullRequestInfo, READONLY_AGENT_PERMISSIONS, type RepositoryScope, type SshCredentials, type TokenCredentials, TokenStore, type TokenStoreOptions, type UserProvidedCredentials, type Workspace, type WorkspaceConfig, type WorkspaceEvent, type WorkspaceEventHandler, type WorkspaceEventType, type WorkspaceFinalization, WorkspaceService, type WorkspaceServiceConfig, type WorkspaceServiceLogger, type WorkspaceServiceOptions, type WorkspaceStatus, type WorkspaceStrategy, cleanupCredentialFiles, configureCredentialHelper, createBranchInfo, createNodeCredentialHelperScript, createShellCredentialHelperScript, filterBranchesByExecution, generateBranchName, generateSlug, getGitCredentialConfig, isManagedBranch, outputCredentials, parseBranchName, updateCredentials };
1637
+ export { type AgentPermissions, type AuthPrompt, type AuthPromptEmitter, type AuthResult, type BranchConfig, type BranchInfo, type BranchNamingOptions, type BranchStrategy, type CompletionHook, type CreateIssueOptions, type CredentialContext, type CredentialGrant, type CredentialGrantStore, type CredentialHelperContext, CredentialService, type CredentialServiceConfig, type CredentialServiceLogger, type CredentialServiceOptions, type CredentialType, DEFAULT_AGENT_PERMISSIONS, DEFAULT_BRANCH_PREFIX, type DeviceCodeResponse, FileTokenStore, type GitCredential, type GitCredentialRequest, type GitHubAppConfig, type GitHubAppInstallation, GitHubPatClient, type GitHubPatClientLogger, type GitHubPatClientOptions, GitHubProvider, type GitHubProviderConfig, type GitHubProviderLogger, type GitProvider, type GitProviderAdapter, type IssueComment, type IssueCommentOptions, type IssueInfo, type IssueState, MemoryTokenStore, OAuthDeviceFlow, type OAuthDeviceFlowConfig, type OAuthDeviceFlowLogger, type OAuthToken, type PermissionLevel, type PullRequestInfo, READONLY_AGENT_PERMISSIONS, type RepositoryScope, type SshCredentials, type TokenCredentials, TokenStore, type TokenStoreOptions, type UserProvidedCredentials, type Workspace, type WorkspaceConfig, type WorkspaceEvent, type WorkspaceEventHandler, type WorkspaceEventType, type WorkspaceFinalization, type WorkspacePhase, type WorkspaceProgress, WorkspaceService, type WorkspaceServiceConfig, type WorkspaceServiceLogger, type WorkspaceServiceOptions, type WorkspaceStatus, type WorkspaceStrategy, cleanupCredentialFiles, configureCredentialHelper, createBranchInfo, createNodeCredentialHelperScript, createShellCredentialHelperScript, filterBranchesByExecution, generateBranchName, generateSlug, getGitCredentialConfig, isManagedBranch, outputCredentials, parseBranchName, updateCredentials };
package/dist/index.js CHANGED
@@ -336,12 +336,20 @@ var WorkspaceService = class {
336
336
  provisionedAt: /* @__PURE__ */ new Date(),
337
337
  status: "provisioning",
338
338
  strategy,
339
- parentWorkspaceId: config.parentWorkspace
339
+ parentWorkspaceId: config.parentWorkspace,
340
+ onComplete: config.onComplete,
341
+ progress: {
342
+ phase: "initializing",
343
+ message: "Initializing workspace",
344
+ updatedAt: /* @__PURE__ */ new Date()
345
+ }
340
346
  };
341
347
  this.workspaces.set(workspaceId, workspace);
342
348
  try {
343
349
  if (strategy === "clone") {
350
+ this.updateProgress(workspace, "cloning", "Cloning repository");
344
351
  await this.cloneRepo(workspace, credential.token);
352
+ this.updateProgress(workspace, "creating_branch", "Creating branch");
345
353
  await this.createBranch(workspace);
346
354
  } else {
347
355
  const parent = this.workspaces.get(config.parentWorkspace);
@@ -359,9 +367,12 @@ var WorkspaceService = class {
359
367
  data: { parentWorkspaceId: parent.id }
360
368
  });
361
369
  }
370
+ this.updateProgress(workspace, "configuring", "Configuring git");
362
371
  await this.configureGit(workspace);
363
372
  workspace.status = "ready";
373
+ this.updateProgress(workspace, "ready", "Workspace ready");
364
374
  this.workspaces.set(workspaceId, workspace);
375
+ await this.executeCompletionHook(workspace, "success");
365
376
  this.log(
366
377
  "info",
367
378
  {
@@ -381,8 +392,9 @@ var WorkspaceService = class {
381
392
  return workspace;
382
393
  } catch (error) {
383
394
  workspace.status = "error";
384
- this.workspaces.set(workspaceId, workspace);
385
395
  const errorMessage = error instanceof Error ? error.message : String(error);
396
+ this.updateProgress(workspace, "error", errorMessage);
397
+ this.workspaces.set(workspaceId, workspace);
386
398
  this.log("error", { workspaceId, error: errorMessage }, "Failed to provision workspace");
387
399
  await this.emitEvent({
388
400
  type: "workspace:error",
@@ -391,6 +403,7 @@ var WorkspaceService = class {
391
403
  timestamp: /* @__PURE__ */ new Date(),
392
404
  error: errorMessage
393
405
  });
406
+ await this.executeCompletionHook(workspace, "error");
394
407
  throw error;
395
408
  }
396
409
  }
@@ -727,6 +740,72 @@ var WorkspaceService = class {
727
740
  }
728
741
  }
729
742
  }
743
+ /**
744
+ * Update workspace progress
745
+ */
746
+ updateProgress(workspace, phase, message) {
747
+ workspace.progress = {
748
+ phase,
749
+ message,
750
+ updatedAt: /* @__PURE__ */ new Date()
751
+ };
752
+ this.workspaces.set(workspace.id, workspace);
753
+ this.log(
754
+ "debug",
755
+ { workspaceId: workspace.id, phase, message },
756
+ "Progress updated"
757
+ );
758
+ }
759
+ /**
760
+ * Execute completion hook if configured
761
+ */
762
+ async executeCompletionHook(workspace, status) {
763
+ const hook = workspace.onComplete;
764
+ if (!hook) return;
765
+ if (status === "error" && hook.runOnError === false) {
766
+ return;
767
+ }
768
+ const env = {
769
+ ...process.env,
770
+ WORKSPACE_ID: workspace.id,
771
+ REPO: workspace.repo,
772
+ BRANCH: workspace.branch.name,
773
+ STATUS: status,
774
+ WORKSPACE_PATH: workspace.path
775
+ };
776
+ if (hook.command) {
777
+ try {
778
+ this.log("info", { workspaceId: workspace.id, command: hook.command }, "Executing completion hook command");
779
+ await execAsync(hook.command, { env });
780
+ } catch (error) {
781
+ const errorMessage = error instanceof Error ? error.message : String(error);
782
+ this.log("warn", { workspaceId: workspace.id, error: errorMessage }, "Completion hook command failed");
783
+ }
784
+ }
785
+ if (hook.webhook) {
786
+ try {
787
+ this.log("info", { workspaceId: workspace.id, webhook: hook.webhook }, "Calling completion webhook");
788
+ const payload = {
789
+ workspaceId: workspace.id,
790
+ repo: workspace.repo,
791
+ branch: workspace.branch.name,
792
+ status,
793
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
794
+ };
795
+ await fetch(hook.webhook, {
796
+ method: "POST",
797
+ headers: {
798
+ "Content-Type": "application/json",
799
+ ...hook.webhookHeaders
800
+ },
801
+ body: JSON.stringify(payload)
802
+ });
803
+ } catch (error) {
804
+ const errorMessage = error instanceof Error ? error.message : String(error);
805
+ this.log("warn", { workspaceId: workspace.id, error: errorMessage }, "Completion webhook failed");
806
+ }
807
+ }
808
+ }
730
809
  };
731
810
 
732
811
  // src/oauth/device-flow.ts