@jamesmurdza/opencode-daytona 0.1.14 → 0.1.16

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 (134) hide show
  1. package/.opencode/plugin/daytona/core/logger.d.ts +15 -0
  2. package/.opencode/plugin/daytona/core/logger.d.ts.map +1 -0
  3. package/.opencode/plugin/daytona/core/logger.js +43 -0
  4. package/.opencode/plugin/daytona/core/logger.js.map +1 -0
  5. package/.opencode/plugin/daytona/core/project-data-storage.d.ts +38 -0
  6. package/.opencode/plugin/daytona/core/project-data-storage.d.ts.map +1 -0
  7. package/.opencode/plugin/daytona/core/project-data-storage.js +130 -0
  8. package/.opencode/plugin/daytona/core/project-data-storage.js.map +1 -0
  9. package/.opencode/plugin/daytona/core/session-manager.d.ts +42 -0
  10. package/.opencode/plugin/daytona/core/session-manager.d.ts.map +1 -0
  11. package/.opencode/plugin/daytona/core/session-manager.js +151 -0
  12. package/.opencode/plugin/daytona/core/session-manager.js.map +1 -0
  13. package/.opencode/plugin/daytona/core/types.d.ts +51 -0
  14. package/.opencode/plugin/daytona/core/types.d.ts.map +1 -0
  15. package/.opencode/plugin/daytona/core/types.js +11 -0
  16. package/.opencode/plugin/daytona/core/types.js.map +1 -0
  17. package/.opencode/plugin/daytona/git/host-git-manager.d.ts +13 -0
  18. package/.opencode/plugin/daytona/git/host-git-manager.d.ts.map +1 -0
  19. package/.opencode/plugin/daytona/git/host-git-manager.js +97 -0
  20. package/.opencode/plugin/daytona/git/host-git-manager.js.map +1 -0
  21. package/.opencode/plugin/daytona/git/index.d.ts +2 -0
  22. package/.opencode/plugin/daytona/git/index.d.ts.map +1 -0
  23. package/.opencode/plugin/daytona/git/index.js +2 -0
  24. package/.opencode/plugin/daytona/git/index.js.map +1 -0
  25. package/.opencode/plugin/daytona/git/sandbox-git-manager.d.ts +10 -0
  26. package/.opencode/plugin/daytona/git/sandbox-git-manager.d.ts.map +1 -0
  27. package/.opencode/plugin/daytona/git/sandbox-git-manager.js +49 -0
  28. package/.opencode/plugin/daytona/git/sandbox-git-manager.js.map +1 -0
  29. package/.opencode/plugin/daytona/git/session-git-manager.d.ts +25 -0
  30. package/.opencode/plugin/daytona/git/session-git-manager.d.ts.map +1 -0
  31. package/.opencode/plugin/daytona/git/session-git-manager.js +52 -0
  32. package/.opencode/plugin/daytona/git/session-git-manager.js.map +1 -0
  33. package/.opencode/plugin/daytona/index.d.ts +26 -0
  34. package/.opencode/plugin/daytona/index.d.ts.map +1 -0
  35. package/.opencode/plugin/daytona/index.js +37 -0
  36. package/.opencode/plugin/daytona/index.js.map +1 -0
  37. package/.opencode/plugin/daytona/plugins/custom-tools.d.ts +8 -0
  38. package/.opencode/plugin/daytona/plugins/custom-tools.d.ts.map +1 -0
  39. package/.opencode/plugin/daytona/plugins/custom-tools.js +17 -0
  40. package/.opencode/plugin/daytona/plugins/custom-tools.js.map +1 -0
  41. package/.opencode/plugin/daytona/plugins/index.d.ts +8 -0
  42. package/.opencode/plugin/daytona/plugins/index.d.ts.map +1 -0
  43. package/.opencode/plugin/daytona/plugins/{index.ts → index.js} +5 -5
  44. package/.opencode/plugin/daytona/plugins/index.js.map +1 -0
  45. package/.opencode/plugin/daytona/plugins/session-cleanup.d.ts +8 -0
  46. package/.opencode/plugin/daytona/plugins/session-cleanup.d.ts.map +1 -0
  47. package/.opencode/plugin/daytona/plugins/session-cleanup.js +19 -0
  48. package/.opencode/plugin/daytona/plugins/session-cleanup.js.map +1 -0
  49. package/.opencode/plugin/daytona/plugins/session-idle-auto-commit.d.ts +7 -0
  50. package/.opencode/plugin/daytona/plugins/session-idle-auto-commit.d.ts.map +1 -0
  51. package/.opencode/plugin/daytona/plugins/session-idle-auto-commit.js +28 -0
  52. package/.opencode/plugin/daytona/plugins/session-idle-auto-commit.js.map +1 -0
  53. package/.opencode/plugin/daytona/plugins/system-transform.d.ts +7 -0
  54. package/.opencode/plugin/daytona/plugins/system-transform.d.ts.map +1 -0
  55. package/.opencode/plugin/daytona/plugins/system-transform.js +20 -0
  56. package/.opencode/plugin/daytona/plugins/system-transform.js.map +1 -0
  57. package/.opencode/plugin/daytona/tools/bash.d.ts +15 -0
  58. package/.opencode/plugin/daytona/tools/bash.d.ts.map +1 -0
  59. package/.opencode/plugin/daytona/tools/bash.js +31 -0
  60. package/.opencode/plugin/daytona/tools/bash.js.map +1 -0
  61. package/.opencode/plugin/daytona/tools/edit.d.ts +17 -0
  62. package/.opencode/plugin/daytona/tools/edit.d.ts.map +1 -0
  63. package/.opencode/plugin/daytona/tools/edit.js +19 -0
  64. package/.opencode/plugin/daytona/tools/edit.js.map +1 -0
  65. package/.opencode/plugin/daytona/tools/get-preview-url.d.ts +13 -0
  66. package/.opencode/plugin/daytona/tools/get-preview-url.d.ts.map +1 -0
  67. package/.opencode/plugin/daytona/tools/get-preview-url.js +13 -0
  68. package/.opencode/plugin/daytona/tools/get-preview-url.js.map +1 -0
  69. package/.opencode/plugin/daytona/tools/glob.d.ts +13 -0
  70. package/.opencode/plugin/daytona/tools/glob.d.ts.map +1 -0
  71. package/.opencode/plugin/daytona/tools/glob.js +17 -0
  72. package/.opencode/plugin/daytona/tools/glob.js.map +1 -0
  73. package/.opencode/plugin/daytona/tools/grep.d.ts +13 -0
  74. package/.opencode/plugin/daytona/tools/grep.d.ts.map +1 -0
  75. package/.opencode/plugin/daytona/tools/grep.js +17 -0
  76. package/.opencode/plugin/daytona/tools/grep.js.map +1 -0
  77. package/.opencode/plugin/daytona/tools/ls.d.ts +13 -0
  78. package/.opencode/plugin/daytona/tools/ls.d.ts.map +1 -0
  79. package/.opencode/plugin/daytona/tools/ls.js +18 -0
  80. package/.opencode/plugin/daytona/tools/ls.js.map +1 -0
  81. package/.opencode/plugin/daytona/tools/lsp.d.ts +17 -0
  82. package/.opencode/plugin/daytona/tools/lsp.d.ts.map +1 -0
  83. package/.opencode/plugin/daytona/tools/lsp.js +13 -0
  84. package/.opencode/plugin/daytona/tools/lsp.js.map +1 -0
  85. package/.opencode/plugin/daytona/tools/multiedit.d.ts +21 -0
  86. package/.opencode/plugin/daytona/tools/multiedit.d.ts.map +1 -0
  87. package/.opencode/plugin/daytona/tools/multiedit.js +23 -0
  88. package/.opencode/plugin/daytona/tools/multiedit.js.map +1 -0
  89. package/.opencode/plugin/daytona/tools/patch.d.ts +17 -0
  90. package/.opencode/plugin/daytona/tools/patch.d.ts.map +1 -0
  91. package/.opencode/plugin/daytona/tools/patch.js +19 -0
  92. package/.opencode/plugin/daytona/tools/patch.js.map +1 -0
  93. package/.opencode/plugin/daytona/tools/read.d.ts +13 -0
  94. package/.opencode/plugin/daytona/tools/read.d.ts.map +1 -0
  95. package/.opencode/plugin/daytona/tools/read.js +14 -0
  96. package/.opencode/plugin/daytona/tools/read.js.map +1 -0
  97. package/.opencode/plugin/daytona/tools/write.d.ts +15 -0
  98. package/.opencode/plugin/daytona/tools/write.d.ts.map +1 -0
  99. package/.opencode/plugin/daytona/tools/write.js +14 -0
  100. package/.opencode/plugin/daytona/tools/write.js.map +1 -0
  101. package/.opencode/plugin/daytona/tools.d.ts +130 -0
  102. package/.opencode/plugin/daytona/tools.d.ts.map +1 -0
  103. package/.opencode/plugin/daytona/tools.js +30 -0
  104. package/.opencode/plugin/daytona/tools.js.map +1 -0
  105. package/.opencode/plugin/index.d.ts +6 -0
  106. package/.opencode/plugin/index.d.ts.map +1 -0
  107. package/.opencode/plugin/{index.ts → index.js} +2 -1
  108. package/.opencode/plugin/index.js.map +1 -0
  109. package/package.json +6 -1
  110. package/.opencode/plugin/daytona/core/logger.ts +0 -50
  111. package/.opencode/plugin/daytona/core/project-data-storage.ts +0 -154
  112. package/.opencode/plugin/daytona/core/session-manager.ts +0 -170
  113. package/.opencode/plugin/daytona/core/types.ts +0 -68
  114. package/.opencode/plugin/daytona/git/host-git-manager.ts +0 -94
  115. package/.opencode/plugin/daytona/git/index.ts +0 -1
  116. package/.opencode/plugin/daytona/git/sandbox-git-manager.ts +0 -51
  117. package/.opencode/plugin/daytona/git/session-git-manager.ts +0 -65
  118. package/.opencode/plugin/daytona/index.ts +0 -50
  119. package/.opencode/plugin/daytona/plugins/custom-tools.ts +0 -20
  120. package/.opencode/plugin/daytona/plugins/session-cleanup.ts +0 -22
  121. package/.opencode/plugin/daytona/plugins/session-idle-auto-commit.ts +0 -30
  122. package/.opencode/plugin/daytona/plugins/system-transform.ts +0 -28
  123. package/.opencode/plugin/daytona/tools/bash.ts +0 -32
  124. package/.opencode/plugin/daytona/tools/edit.ts +0 -21
  125. package/.opencode/plugin/daytona/tools/get-preview-url.ts +0 -15
  126. package/.opencode/plugin/daytona/tools/glob.ts +0 -16
  127. package/.opencode/plugin/daytona/tools/grep.ts +0 -16
  128. package/.opencode/plugin/daytona/tools/ls.ts +0 -18
  129. package/.opencode/plugin/daytona/tools/lsp.ts +0 -15
  130. package/.opencode/plugin/daytona/tools/multiedit.ts +0 -32
  131. package/.opencode/plugin/daytona/tools/patch.ts +0 -21
  132. package/.opencode/plugin/daytona/tools/read.ts +0 -16
  133. package/.opencode/plugin/daytona/tools/write.ts +0 -16
  134. package/.opencode/plugin/daytona/tools.ts +0 -33
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Logger class for handling plugin logging
3
+ */
4
+ import type { LogLevel } from './types';
5
+ export declare function setLogFilePath(path: string): void;
6
+ declare class Logger {
7
+ private get logFile();
8
+ log(message: string, level?: LogLevel): void;
9
+ info(message: string): void;
10
+ error(message: string): void;
11
+ warn(message: string): void;
12
+ }
13
+ export declare const logger: Logger;
14
+ export {};
15
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/core/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKvC,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,QAE1C;AAED,cAAM,MAAM;IACV,OAAO,KAAK,OAAO,GAGlB;IAED,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,QAAyB,GAAG,IAAI;IAgB5D,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI3B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI5B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAG5B;AAED,eAAO,MAAM,MAAM,QAAe,CAAA"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Logger class for handling plugin logging
3
+ */
4
+ import { appendFileSync, statSync, truncateSync } from 'fs';
5
+ import { LOG_LEVEL_INFO, LOG_LEVEL_ERROR, LOG_LEVEL_WARN } from './types';
6
+ let logFilePath;
7
+ export function setLogFilePath(path) {
8
+ logFilePath = path;
9
+ }
10
+ class Logger {
11
+ get logFile() {
12
+ if (!logFilePath)
13
+ throw new Error('Logger file path not set. Call setLogFilePath(path) before use.');
14
+ return logFilePath;
15
+ }
16
+ log(message, level = LOG_LEVEL_INFO) {
17
+ // Truncate log file if it exceeds 5MB
18
+ try {
19
+ const stats = statSync(this.logFile);
20
+ const maxSize = 5 * 1024 * 1024; // 5MB
21
+ if (stats.size > maxSize) {
22
+ truncateSync(this.logFile, 0);
23
+ }
24
+ }
25
+ catch (err) {
26
+ // File may not exist yet, ignore
27
+ }
28
+ const timestamp = new Date().toISOString();
29
+ const logEntry = `[${timestamp}] [${level}] ${message}\n`;
30
+ appendFileSync(this.logFile, logEntry);
31
+ }
32
+ info(message) {
33
+ this.log(message, LOG_LEVEL_INFO);
34
+ }
35
+ error(message) {
36
+ this.log(message, LOG_LEVEL_ERROR);
37
+ }
38
+ warn(message) {
39
+ this.log(message, LOG_LEVEL_WARN);
40
+ }
41
+ }
42
+ export const logger = new Logger();
43
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/core/logger.ts"],"names":[],"mappings":"AAAA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,OAAe;QAClB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;IACnC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAA"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Handles file storage operations for project session data
3
+ * Stores data per-project in ~/.local/share/opencode/storage/daytona/{projectId}.json
4
+ */
5
+ import type { ProjectSessionData, SessionInfo } from './types';
6
+ export declare class ProjectDataStorage {
7
+ private readonly storageDir;
8
+ constructor(storageDir: string);
9
+ /**
10
+ * Get the file path for a project's session data
11
+ */
12
+ private getProjectFilePath;
13
+ /**
14
+ * Load project session data from disk
15
+ */
16
+ load(projectId: string): ProjectSessionData | null;
17
+ /**
18
+ * Save project session data to disk
19
+ */
20
+ save(projectId: string, worktree: string, sessions: Record<string, SessionInfo>, lastBranchNumber?: number): void;
21
+ /**
22
+ * Get the next available branch number for a project
23
+ */
24
+ getNextBranchNumber(projectId: string): number;
25
+ /**
26
+ * Get branch number for a sandbox
27
+ */
28
+ getBranchNumberForSandbox(projectId: string, sandboxId: string): number | undefined;
29
+ /**
30
+ * Update a single session in the project file
31
+ */
32
+ updateSession(projectId: string, worktree: string, sessionId: string, sandboxId: string, branchNumber?: number): void;
33
+ /**
34
+ * Remove a session from the project file
35
+ */
36
+ removeSession(projectId: string, worktree: string, sessionId: string): void;
37
+ }
38
+ //# sourceMappingURL=project-data-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-data-storage.d.ts","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/core/project-data-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE9D,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;gBAEvB,UAAU,EAAE,MAAM;IAS9B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI;IAYlD;;OAEG;IACH,IAAI,CACF,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACrC,gBAAgB,CAAC,EAAE,MAAM,GACxB,IAAI;IAiBP;;OAEG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAgB9C;;OAEG;IACH,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IASnF;;OAEG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAiCrH;;OAEG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;CAQ5E"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Handles file storage operations for project session data
3
+ * Stores data per-project in ~/.local/share/opencode/storage/daytona/{projectId}.json
4
+ */
5
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
6
+ import { join } from 'path';
7
+ import { logger } from './logger';
8
+ export class ProjectDataStorage {
9
+ storageDir;
10
+ constructor(storageDir) {
11
+ this.storageDir = storageDir;
12
+ // Ensure storage directory exists
13
+ if (!existsSync(this.storageDir)) {
14
+ mkdirSync(this.storageDir, { recursive: true });
15
+ }
16
+ }
17
+ /**
18
+ * Get the file path for a project's session data
19
+ */
20
+ getProjectFilePath(projectId) {
21
+ return join(this.storageDir, `${projectId}.json`);
22
+ }
23
+ /**
24
+ * Load project session data from disk
25
+ */
26
+ load(projectId) {
27
+ const filePath = this.getProjectFilePath(projectId);
28
+ try {
29
+ if (existsSync(filePath)) {
30
+ return JSON.parse(readFileSync(filePath, 'utf-8'));
31
+ }
32
+ }
33
+ catch (err) {
34
+ logger.error(`Failed to load project data for ${projectId}: ${err}`);
35
+ }
36
+ return null;
37
+ }
38
+ /**
39
+ * Save project session data to disk
40
+ */
41
+ save(projectId, worktree, sessions, lastBranchNumber) {
42
+ const filePath = this.getProjectFilePath(projectId);
43
+ const projectData = {
44
+ projectId,
45
+ worktree,
46
+ lastBranchNumber,
47
+ sessions,
48
+ };
49
+ try {
50
+ writeFileSync(filePath, JSON.stringify(projectData, null, 2));
51
+ logger.info(`Saved project data for ${projectId}`);
52
+ }
53
+ catch (err) {
54
+ logger.error(`Failed to save project data for ${projectId}: ${err}`);
55
+ }
56
+ }
57
+ /**
58
+ * Get the next available branch number for a project
59
+ */
60
+ getNextBranchNumber(projectId) {
61
+ const projectData = this.load(projectId);
62
+ if (!projectData) {
63
+ return 1;
64
+ }
65
+ const branchNumbers = Object.values(projectData.sessions)
66
+ .map(s => s.branchNumber)
67
+ .filter((n) => n !== undefined);
68
+ // Use a persisted monotonic pointer so we never reuse deleted numbers.
69
+ const pointer = projectData.lastBranchNumber ?? 0;
70
+ const maxInSessions = branchNumbers.length > 0 ? Math.max(...branchNumbers) : 0;
71
+ return Math.max(pointer, maxInSessions) + 1;
72
+ }
73
+ /**
74
+ * Get branch number for a sandbox
75
+ */
76
+ getBranchNumberForSandbox(projectId, sandboxId) {
77
+ const projectData = this.load(projectId);
78
+ if (!projectData) {
79
+ return undefined;
80
+ }
81
+ const session = Object.values(projectData.sessions).find(s => s.sandboxId === sandboxId);
82
+ return session?.branchNumber;
83
+ }
84
+ /**
85
+ * Update a single session in the project file
86
+ */
87
+ updateSession(projectId, worktree, sessionId, sandboxId, branchNumber) {
88
+ const projectData = this.load(projectId) || {
89
+ projectId,
90
+ worktree,
91
+ lastBranchNumber: 0,
92
+ sessions: {},
93
+ };
94
+ const now = Date.now();
95
+ if (!projectData.sessions[sessionId]) {
96
+ // Assign branch number if not provided
97
+ const assignedBranchNumber = branchNumber ?? this.getNextBranchNumber(projectId);
98
+ projectData.sessions[sessionId] = {
99
+ sandboxId,
100
+ branchNumber: assignedBranchNumber,
101
+ created: now,
102
+ lastAccessed: now,
103
+ };
104
+ projectData.lastBranchNumber = Math.max(projectData.lastBranchNumber ?? 0, assignedBranchNumber);
105
+ }
106
+ else {
107
+ projectData.sessions[sessionId].sandboxId = sandboxId;
108
+ projectData.sessions[sessionId].lastAccessed = now;
109
+ // Only update branch number if it wasn't set before
110
+ if (projectData.sessions[sessionId].branchNumber === undefined) {
111
+ const assignedBranchNumber = branchNumber ?? this.getNextBranchNumber(projectId);
112
+ projectData.sessions[sessionId].branchNumber = assignedBranchNumber;
113
+ projectData.lastBranchNumber = Math.max(projectData.lastBranchNumber ?? 0, assignedBranchNumber);
114
+ }
115
+ }
116
+ this.save(projectId, worktree, projectData.sessions, projectData.lastBranchNumber);
117
+ }
118
+ /**
119
+ * Remove a session from the project file
120
+ */
121
+ removeSession(projectId, worktree, sessionId) {
122
+ const projectData = this.load(projectId);
123
+ if (projectData && projectData.sessions[sessionId]) {
124
+ delete projectData.sessions[sessionId];
125
+ // Intentionally keep lastBranchNumber so branch numbering remains monotonic
126
+ this.save(projectId, worktree, projectData.sessions, projectData.lastBranchNumber);
127
+ }
128
+ }
129
+ }
130
+ //# sourceMappingURL=project-data-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-data-storage.js","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/core/project-data-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGjC,MAAM,OAAO,kBAAkB;IACZ,UAAU,CAAQ;IAEnC,YAAY,U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,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAA;YAClG,CAAC;QACH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;IACpF,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,SAAiB,EAAE,QAAgB,EAAE,SAAiB;QAClE,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACxC,IAAI,WAAW,IAAI,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACnD,OAAO,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;YACtC,4EAA4E;YAC5E,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;QACpF,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Manages Daytona sandbox sessions and persists session-sandbox mappings
3
+ * Stores data per-project in ~/.local/share/opencode/storage/daytona/{projectId}.json
4
+ */
5
+ import { type Sandbox } from '@daytonaio/sdk';
6
+ export declare class DaytonaSessionManager {
7
+ private readonly apiKey;
8
+ private readonly dataStorage;
9
+ private sessionSandboxes;
10
+ private currentProjectId?;
11
+ private readonly repoPath;
12
+ constructor(apiKey: string, storageDir: string, repoPath: string);
13
+ /**
14
+ * Check if a sandbox is fully initialized (has process property)
15
+ */
16
+ private isFullyInitialized;
17
+ /**
18
+ * Check if a sandbox is partially initialized (has id but not process)
19
+ */
20
+ private isPartiallyInitialized;
21
+ /**
22
+ * Load sessions for a specific project into memory
23
+ */
24
+ private loadProjectSessions;
25
+ /**
26
+ * Set the current project context
27
+ */
28
+ setProjectContext(projectId: string): void;
29
+ /**
30
+ * Get branch number for a sandbox
31
+ */
32
+ getBranchNumberForSandbox(projectId: string, sandboxId: string): number | undefined;
33
+ /**
34
+ * Get or create a sandbox for the given session ID
35
+ */
36
+ getSandbox(sessionId: string, projectId: string, worktree: string): Promise<Sandbox>;
37
+ /**
38
+ * Delete the sandbox associated with the given session ID
39
+ */
40
+ deleteSandbox(sessionId: string, projectId: string): Promise<void>;
41
+ }
42
+ //# sourceMappingURL=session-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/core/session-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAMtD,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,gBAAgB,CAAC,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAErB,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAOhE;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAI9B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;OAEG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAO1C;;OAEG;IACH,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAInF;;OAEG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA2D1F;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmCzE"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Manages Daytona sandbox sessions and persists session-sandbox mappings
3
+ * Stores data per-project in ~/.local/share/opencode/storage/daytona/{projectId}.json
4
+ */
5
+ import { Daytona } from '@daytonaio/sdk';
6
+ import { logger } from './logger';
7
+ import { SessionGitManager } from '../git/session-git-manager';
8
+ import { ProjectDataStorage } from './project-data-storage';
9
+ export class DaytonaSessionManager {
10
+ apiKey;
11
+ dataStorage;
12
+ sessionSandboxes;
13
+ currentProjectId;
14
+ repoPath;
15
+ constructor(apiKey, storageDir, repoPath) {
16
+ this.apiKey = apiKey;
17
+ this.dataStorage = new ProjectDataStorage(storageDir);
18
+ this.repoPath = repoPath;
19
+ this.sessionSandboxes = new Map();
20
+ }
21
+ /**
22
+ * Check if a sandbox is fully initialized (has process property)
23
+ */
24
+ isFullyInitialized(sandbox) {
25
+ return sandbox !== undefined && 'process' in sandbox;
26
+ }
27
+ /**
28
+ * Check if a sandbox is partially initialized (has id but not process)
29
+ */
30
+ isPartiallyInitialized(sandbox) {
31
+ return sandbox !== undefined && 'id' in sandbox && !('process' in sandbox);
32
+ }
33
+ /**
34
+ * Load sessions for a specific project into memory
35
+ */
36
+ loadProjectSessions(projectId) {
37
+ const projectData = this.dataStorage.load(projectId);
38
+ if (projectData) {
39
+ for (const [sessionId, sessionInfo] of Object.entries(projectData.sessions)) {
40
+ this.sessionSandboxes.set(sessionId, { id: sessionInfo.sandboxId });
41
+ }
42
+ logger.info(`Loaded ${Object.keys(projectData.sessions).length} sessions for project ${projectId}`);
43
+ }
44
+ }
45
+ /**
46
+ * Set the current project context
47
+ */
48
+ setProjectContext(projectId) {
49
+ if (this.currentProjectId !== projectId) {
50
+ this.currentProjectId = projectId;
51
+ this.loadProjectSessions(projectId);
52
+ }
53
+ }
54
+ /**
55
+ * Get branch number for a sandbox
56
+ */
57
+ getBranchNumberForSandbox(projectId, sandboxId) {
58
+ return this.dataStorage.getBranchNumberForSandbox(projectId, sandboxId);
59
+ }
60
+ /**
61
+ * Get or create a sandbox for the given session ID
62
+ */
63
+ async getSandbox(sessionId, projectId, worktree) {
64
+ if (!this.apiKey) {
65
+ logger.error('DAYTONA_API_KEY is not set. Cannot create or retrieve sandbox.');
66
+ throw new Error('DAYTONA_API_KEY is not set. Please set the environment variable to use Daytona sandboxes.');
67
+ }
68
+ // Load project sessions if needed
69
+ this.setProjectContext(projectId);
70
+ const existing = this.sessionSandboxes.get(sessionId);
71
+ // If we have a fully initialized sandbox, reuse it
72
+ if (this.isFullyInitialized(existing)) {
73
+ logger.info(`Reusing existing sandbox for session: ${sessionId}`);
74
+ this.dataStorage.updateSession(projectId, worktree, sessionId, existing.id);
75
+ return existing;
76
+ }
77
+ // If we have a sandboxId but not a full sandbox object, reconnect to it
78
+ if (this.isPartiallyInitialized(existing)) {
79
+ logger.info(`Reconnecting to existing sandbox: ${existing.id}`);
80
+ const daytona = new Daytona({ apiKey: this.apiKey });
81
+ const sandbox = await daytona.get(existing.id);
82
+ await sandbox.start();
83
+ this.sessionSandboxes.set(sessionId, sandbox);
84
+ // Preserve branch number if it exists for this sandbox
85
+ let branchNumber = this.dataStorage.getBranchNumberForSandbox(projectId, sandbox.id);
86
+ if (!branchNumber) {
87
+ branchNumber = this.dataStorage.getNextBranchNumber(projectId);
88
+ }
89
+ this.dataStorage.updateSession(projectId, worktree, sessionId, sandbox.id, branchNumber);
90
+ return sandbox;
91
+ }
92
+ // Otherwise, create a new sandbox
93
+ logger.info(`Creating new sandbox for session: ${sessionId} in project: ${projectId}`);
94
+ const daytona = new Daytona({ apiKey: this.apiKey });
95
+ const sandbox = await daytona.create();
96
+ this.sessionSandboxes.set(sessionId, sandbox);
97
+ // Get or assign branch number for this sandbox
98
+ let branchNumber = this.dataStorage.getBranchNumberForSandbox(projectId, sandbox.id);
99
+ if (!branchNumber) {
100
+ branchNumber = this.dataStorage.getNextBranchNumber(projectId);
101
+ }
102
+ this.dataStorage.updateSession(projectId, worktree, sessionId, sandbox.id, branchNumber);
103
+ logger.info(`Sandbox created successfully: ${sandbox.id} with branch number ${branchNumber}`);
104
+ // Initialize git repo in the sandbox and sync with host
105
+ try {
106
+ const sessionGit = new SessionGitManager(sandbox, this.repoPath, branchNumber);
107
+ await sessionGit.initializeAndSync();
108
+ }
109
+ catch (err) {
110
+ logger.error(`Failed to initialize git repo or push local changes in sandbox: ${err}`);
111
+ }
112
+ return sandbox;
113
+ }
114
+ /**
115
+ * Delete the sandbox associated with the given session ID
116
+ */
117
+ async deleteSandbox(sessionId, projectId) {
118
+ let sandbox = this.sessionSandboxes.get(sessionId);
119
+ // If not in cache, try to load from storage and reconnect
120
+ if (!sandbox || this.isPartiallyInitialized(sandbox)) {
121
+ const projectData = this.dataStorage.load(projectId);
122
+ const sessionInfo = projectData?.sessions?.[sessionId];
123
+ if (sessionInfo?.sandboxId) {
124
+ const daytona = new Daytona({ apiKey: this.apiKey });
125
+ try {
126
+ sandbox = await daytona.get(sessionInfo.sandboxId);
127
+ this.sessionSandboxes.set(sessionId, sandbox);
128
+ }
129
+ catch (err) {
130
+ logger.error(`Failed to reconnect to sandbox ${sessionInfo.sandboxId}: ${err}`);
131
+ }
132
+ }
133
+ }
134
+ // Delete the sandbox if we have a fully initialized one
135
+ if (this.isFullyInitialized(sandbox)) {
136
+ logger.info(`Removing sandbox for session: ${sessionId}`);
137
+ await sandbox.delete();
138
+ this.sessionSandboxes.delete(sessionId);
139
+ // Remove from storage
140
+ const projectData = this.dataStorage.load(projectId);
141
+ if (projectData) {
142
+ this.dataStorage.removeSession(projectId, projectData.worktree, sessionId);
143
+ }
144
+ logger.info(`Sandbox deleted successfully.`);
145
+ }
146
+ else {
147
+ logger.warn(`No sandbox found for session: ${sessionId}`);
148
+ }
149
+ }
150
+ }
151
+ //# sourceMappingURL=session-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-manager.js","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/core/session-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA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I,CAAC;oBACH,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;oBAClD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;gBAC/C,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,MAAM,CAAC,KAAK,CAAC,kCAAkC,WAAW,CAAC,SAAS,KAAK,GAAG,EAAE,CAAC,CAAA;gBACjF,CAAC;YACH,CAAC;QACH,CAAC;QAED,wDAAwD;QACxD,IAAI,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAA;YACzD,MAAM,OAAO,CAAC,MAAM,EAAE,CAAA;YACtB,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAEvC,sBAAsB;YACtB,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YACpD,IAAI,WAAW,EAAE,CAAC;gBAChB,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;YAC5E,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAA;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAA;QAC3D,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Type definitions and constants for the Daytona OpenCode plugin
3
+ */
4
+ import type { Sandbox } from '@daytonaio/sdk';
5
+ export type EventSessionDeleted = {
6
+ type: 'session.deleted';
7
+ properties: {
8
+ info: {
9
+ id: string;
10
+ };
11
+ };
12
+ };
13
+ export type EventSessionIdle = {
14
+ type: 'session.idle';
15
+ properties: {
16
+ sessionID: string;
17
+ };
18
+ };
19
+ export type ExperimentalChatSystemTransformInput = {
20
+ sessionID: string;
21
+ };
22
+ export type ExperimentalChatSystemTransformOutput = {
23
+ system: string[];
24
+ };
25
+ export declare const EVENT_TYPE_SESSION_DELETED = "session.deleted";
26
+ export declare const EVENT_TYPE_SESSION_IDLE = "session.idle";
27
+ export type LogLevel = 'INFO' | 'ERROR' | 'WARN';
28
+ export type SandboxInfo = {
29
+ id: string;
30
+ };
31
+ export type SessionInfo = {
32
+ sandboxId: string;
33
+ branchNumber: number;
34
+ created: number;
35
+ lastAccessed: number;
36
+ };
37
+ export type ProjectSessionData = {
38
+ projectId: string;
39
+ worktree: string;
40
+ /**
41
+ * Monotonically increasing pointer for branch numbering.
42
+ * We persist this so we don't reuse branch numbers after sessions are deleted.
43
+ */
44
+ lastBranchNumber?: number;
45
+ sessions: Record<string, SessionInfo>;
46
+ };
47
+ export type SessionSandboxMap = Map<string, Sandbox | SandboxInfo>;
48
+ export declare const LOG_LEVEL_INFO: LogLevel;
49
+ export declare const LOG_LEVEL_ERROR: LogLevel;
50
+ export declare const LOG_LEVEL_WARN: LogLevel;
51
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAI7C,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,iBAAiB,CAAA;IACvB,UAAU,EAAE;QACV,IAAI,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAA;KACrB,CAAA;CACF,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,cAAc,CAAA;IACpB,UAAU,EAAE;QACV,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AAED,MAAM,MAAM,oCAAoC,GAAG;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAAG;IAClD,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAIF,eAAO,MAAM,0BAA0B,oBAAoB,CAAA;AAC3D,eAAO,MAAM,uBAAuB,iBAAiB,CAAA;AAIrD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;CACtC,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,GAAG,WAAW,CAAC,CAAA;AAIlE,eAAO,MAAM,cAAc,EAAE,QAAiB,CAAA;AAC9C,eAAO,MAAM,eAAe,EAAE,QAAkB,CAAA;AAChD,eAAO,MAAM,cAAc,EAAE,QAAiB,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Type definitions and constants for the Daytona OpenCode plugin
3
+ */
4
+ // OpenCode constants
5
+ export const EVENT_TYPE_SESSION_DELETED = 'session.deleted';
6
+ export const EVENT_TYPE_SESSION_IDLE = 'session.idle';
7
+ // Daytona plugin constants
8
+ export const LOG_LEVEL_INFO = 'INFO';
9
+ export const LOG_LEVEL_ERROR = 'ERROR';
10
+ export const LOG_LEVEL_WARN = 'WARN';
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA4BH,qBAAqB;AAErB,MAAM,CAAC,MAAM,0BAA0B,GAAG,iBAAiB,CAAA;AAC3D,MAAM,CAAC,MAAM,uBAAuB,GAAG,cAAc,CAAA;AA8BrD,2BAA2B;AAE3B,MAAM,CAAC,MAAM,cAAc,GAAa,MAAM,CAAA;AAC9C,MAAM,CAAC,MAAM,eAAe,GAAa,OAAO,CAAA;AAChD,MAAM,CAAC,MAAM,cAAc,GAAa,MAAM,CAAA"}
@@ -0,0 +1,13 @@
1
+ export declare class HostGitManager {
2
+ /**
3
+ * Pushes local changes to the sandbox remote, following the same steps as the standalone function.
4
+ * @param sshUrl The SSH URL of the sandbox remote.
5
+ * @param branch The branch to push to.
6
+ */
7
+ pushLocalToSandboxRemote(sshUrl: string, branch: string): void;
8
+ ensureRepo(): void;
9
+ setRemote(remoteName: string, sshUrl: string): void;
10
+ pull(remoteName: string, branch: string, localBranch?: string): void;
11
+ push(remoteName: string, branch: string): void;
12
+ }
13
+ //# sourceMappingURL=host-git-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-git-manager.d.ts","sourceRoot":"","sources":["../../../../../.opencode/plugin/daytona/git/host-git-manager.ts"],"names":[],"mappings":"AAOA,qBAAa,cAAc;IAGzB;;;;OAIG;IACH,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAyB9D,UAAU,IAAI,IAAI;IAUlB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAUnD,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAyBpE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAQ/C"}
@@ -0,0 +1,97 @@
1
+ import { logger } from '../core/logger';
2
+ import { execSync } from 'child_process';
3
+ function execSyncSilent(cmd, options = {}) {
4
+ return execSync(cmd, { stdio: 'ignore', ...options });
5
+ }
6
+ export class HostGitManager {
7
+ // No constructor needed; use global logger
8
+ /**
9
+ * Pushes local changes to the sandbox remote, following the same steps as the standalone function.
10
+ * @param sshUrl The SSH URL of the sandbox remote.
11
+ * @param branch The branch to push to.
12
+ */
13
+ pushLocalToSandboxRemote(sshUrl, branch) {
14
+ try {
15
+ logger.info(`Init in current directory, pushing to ${sshUrl} on branch ${branch}`);
16
+ try {
17
+ execSyncSilent('git rev-parse --is-inside-work-tree');
18
+ }
19
+ catch {
20
+ execSyncSilent('git init');
21
+ }
22
+ try {
23
+ execSyncSilent('git remote get-url sandbox');
24
+ execSyncSilent(`git remote set-url sandbox ${sshUrl}`);
25
+ }
26
+ catch (e) {
27
+ execSyncSilent(`git remote add sandbox ${sshUrl}`);
28
+ }
29
+ execSyncSilent('git add .');
30
+ execSyncSilent('git commit -m "Sync local changes before agent start" || echo "No changes to commit"', {
31
+ shell: '/bin/bash',
32
+ });
33
+ execSyncSilent(`git push sandbox HEAD:${branch}`);
34
+ logger.info('✓ Pushed local changes to sandbox');
35
+ }
36
+ catch (e) {
37
+ logger.error(`Error pushing to sandbox: ${e}`);
38
+ }
39
+ }
40
+ ensureRepo() {
41
+ try {
42
+ execSyncSilent('git rev-parse --is-inside-work-tree');
43
+ logger.info('Git repo already exists in local worktree.');
44
+ }
45
+ catch {
46
+ execSyncSilent('git init');
47
+ logger.info('Initialized new git repo in local worktree.');
48
+ }
49
+ }
50
+ setRemote(remoteName, sshUrl) {
51
+ try {
52
+ // remove existing remote if it exists
53
+ execSyncSilent(`git remote remove ${remoteName} || true`);
54
+ execSyncSilent(`git remote add ${remoteName} ${sshUrl}`);
55
+ }
56
+ catch (e) {
57
+ logger.warn(`Could not set sandbox remote: ${e}`);
58
+ }
59
+ }
60
+ pull(remoteName, branch, localBranch) {
61
+ let attempts = 0;
62
+ // The first pull attempt sometimes fails. I'm not sure what the cause is.
63
+ while (attempts < 3) {
64
+ try {
65
+ if (localBranch) {
66
+ // Fetch the remote branch into the specified local branch
67
+ execSyncSilent(`git fetch ${remoteName} ${branch}:${localBranch}`);
68
+ logger.info(`✓ Fetched latest changes from sandbox into ${localBranch}`);
69
+ }
70
+ else {
71
+ execSyncSilent(`git pull ${remoteName} ${branch}`);
72
+ logger.info('✓ Pulled latest changes from sandbox');
73
+ }
74
+ return;
75
+ }
76
+ catch (e) {
77
+ attempts++;
78
+ if (attempts >= 3) {
79
+ logger.error(`Error pulling from sandbox after 3 attempts: ${e}`);
80
+ }
81
+ else {
82
+ logger.warn(`Pull attempt ${attempts} failed, retrying...`);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ push(remoteName, branch) {
88
+ try {
89
+ execSyncSilent(`git push ${remoteName} HEAD:${branch}`);
90
+ logger.info('✓ Pushed changes to sandbox');
91
+ }
92
+ catch (e) {
93
+ logger.error(`Error pushing to sandbox: ${e}`);
94
+ }
95
+ }
96
+ }
97
+ //# sourceMappingURL=host-git-manager.js.map