@daytonaio/opencode 0.143.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 (86) hide show
  1. package/.opencode/plugin/daytona/core/logger.d.ts +15 -0
  2. package/.opencode/plugin/daytona/core/logger.js +64 -0
  3. package/.opencode/plugin/daytona/core/logger.js.map +1 -0
  4. package/.opencode/plugin/daytona/core/project-data-storage.d.ts +42 -0
  5. package/.opencode/plugin/daytona/core/project-data-storage.js +171 -0
  6. package/.opencode/plugin/daytona/core/project-data-storage.js.map +1 -0
  7. package/.opencode/plugin/daytona/core/session-manager.d.ts +46 -0
  8. package/.opencode/plugin/daytona/core/session-manager.js +239 -0
  9. package/.opencode/plugin/daytona/core/session-manager.js.map +1 -0
  10. package/.opencode/plugin/daytona/core/toast.d.ts +47 -0
  11. package/.opencode/plugin/daytona/core/toast.js +73 -0
  12. package/.opencode/plugin/daytona/core/toast.js.map +1 -0
  13. package/.opencode/plugin/daytona/core/types.d.ts +53 -0
  14. package/.opencode/plugin/daytona/core/types.js +15 -0
  15. package/.opencode/plugin/daytona/core/types.js.map +1 -0
  16. package/.opencode/plugin/daytona/git/host-git-manager.d.ts +40 -0
  17. package/.opencode/plugin/daytona/git/host-git-manager.js +283 -0
  18. package/.opencode/plugin/daytona/git/host-git-manager.js.map +1 -0
  19. package/.opencode/plugin/daytona/git/index.d.ts +5 -0
  20. package/.opencode/plugin/daytona/git/index.js +10 -0
  21. package/.opencode/plugin/daytona/git/index.js.map +1 -0
  22. package/.opencode/plugin/daytona/git/sandbox-git-manager.d.ts +14 -0
  23. package/.opencode/plugin/daytona/git/sandbox-git-manager.js +68 -0
  24. package/.opencode/plugin/daytona/git/sandbox-git-manager.js.map +1 -0
  25. package/.opencode/plugin/daytona/git/session-git-manager.d.ts +43 -0
  26. package/.opencode/plugin/daytona/git/session-git-manager.js +132 -0
  27. package/.opencode/plugin/daytona/git/session-git-manager.js.map +1 -0
  28. package/.opencode/plugin/daytona/index.d.ts +10 -0
  29. package/.opencode/plugin/daytona/index.js +44 -0
  30. package/.opencode/plugin/daytona/index.js.map +1 -0
  31. package/.opencode/plugin/daytona/plugins/custom-tools.d.ts +11 -0
  32. package/.opencode/plugin/daytona/plugins/custom-tools.js +26 -0
  33. package/.opencode/plugin/daytona/plugins/custom-tools.js.map +1 -0
  34. package/.opencode/plugin/daytona/plugins/index.d.ts +11 -0
  35. package/.opencode/plugin/daytona/plugins/index.js +19 -0
  36. package/.opencode/plugin/daytona/plugins/index.js.map +1 -0
  37. package/.opencode/plugin/daytona/plugins/session-cleanup.d.ts +11 -0
  38. package/.opencode/plugin/daytona/plugins/session-cleanup.js +43 -0
  39. package/.opencode/plugin/daytona/plugins/session-cleanup.js.map +1 -0
  40. package/.opencode/plugin/daytona/plugins/session-idle-auto-commit.d.ts +10 -0
  41. package/.opencode/plugin/daytona/plugins/session-idle-auto-commit.js +54 -0
  42. package/.opencode/plugin/daytona/plugins/session-idle-auto-commit.js.map +1 -0
  43. package/.opencode/plugin/daytona/plugins/system-transform.d.ts +10 -0
  44. package/.opencode/plugin/daytona/plugins/system-transform.js +29 -0
  45. package/.opencode/plugin/daytona/plugins/system-transform.js.map +1 -0
  46. package/.opencode/plugin/daytona/tools/bash.d.ts +19 -0
  47. package/.opencode/plugin/daytona/tools/bash.js +42 -0
  48. package/.opencode/plugin/daytona/tools/bash.js.map +1 -0
  49. package/.opencode/plugin/daytona/tools/edit.d.ts +21 -0
  50. package/.opencode/plugin/daytona/tools/edit.js +27 -0
  51. package/.opencode/plugin/daytona/tools/edit.js.map +1 -0
  52. package/.opencode/plugin/daytona/tools/get-preview-url.d.ts +17 -0
  53. package/.opencode/plugin/daytona/tools/get-preview-url.js +21 -0
  54. package/.opencode/plugin/daytona/tools/get-preview-url.js.map +1 -0
  55. package/.opencode/plugin/daytona/tools/glob.d.ts +17 -0
  56. package/.opencode/plugin/daytona/tools/glob.js +25 -0
  57. package/.opencode/plugin/daytona/tools/glob.js.map +1 -0
  58. package/.opencode/plugin/daytona/tools/grep.d.ts +17 -0
  59. package/.opencode/plugin/daytona/tools/grep.js +25 -0
  60. package/.opencode/plugin/daytona/tools/grep.js.map +1 -0
  61. package/.opencode/plugin/daytona/tools/ls.d.ts +17 -0
  62. package/.opencode/plugin/daytona/tools/ls.js +26 -0
  63. package/.opencode/plugin/daytona/tools/ls.js.map +1 -0
  64. package/.opencode/plugin/daytona/tools/lsp.d.ts +21 -0
  65. package/.opencode/plugin/daytona/tools/lsp.js +21 -0
  66. package/.opencode/plugin/daytona/tools/lsp.js.map +1 -0
  67. package/.opencode/plugin/daytona/tools/multiedit.d.ts +25 -0
  68. package/.opencode/plugin/daytona/tools/multiedit.js +31 -0
  69. package/.opencode/plugin/daytona/tools/multiedit.js.map +1 -0
  70. package/.opencode/plugin/daytona/tools/patch.d.ts +19 -0
  71. package/.opencode/plugin/daytona/tools/patch.js +19 -0
  72. package/.opencode/plugin/daytona/tools/patch.js.map +1 -0
  73. package/.opencode/plugin/daytona/tools/read.d.ts +17 -0
  74. package/.opencode/plugin/daytona/tools/read.js +22 -0
  75. package/.opencode/plugin/daytona/tools/read.js.map +1 -0
  76. package/.opencode/plugin/daytona/tools/write.d.ts +19 -0
  77. package/.opencode/plugin/daytona/tools/write.js +22 -0
  78. package/.opencode/plugin/daytona/tools/write.js.map +1 -0
  79. package/.opencode/plugin/daytona/tools.d.ts +129 -0
  80. package/.opencode/plugin/daytona/tools.js +38 -0
  81. package/.opencode/plugin/daytona/tools.js.map +1 -0
  82. package/.opencode/plugin/index.d.ts +9 -0
  83. package/.opencode/plugin/index.js +13 -0
  84. package/.opencode/plugin/index.js.map +1 -0
  85. package/README.md +219 -0
  86. package/package.json +55 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.toast = void 0;
8
+ class ToastManager {
9
+ tui = null;
10
+ queue = [];
11
+ isShowing = false;
12
+ /**
13
+ * Initialize the toast manager with the TUI instance
14
+ */
15
+ initialize(tui) {
16
+ this.tui = tui || null;
17
+ }
18
+ /**
19
+ * Show a toast notification
20
+ * If a toast is currently showing, this will be queued
21
+ */
22
+ show(options) {
23
+ const toast = {
24
+ variant: 'info',
25
+ ...options,
26
+ };
27
+ this.queue.push(toast);
28
+ this.processQueue();
29
+ }
30
+ /**
31
+ * Process the toast queue, showing one toast at a time
32
+ */
33
+ processQueue() {
34
+ if (this.isShowing || this.queue.length === 0) {
35
+ return;
36
+ }
37
+ if (!this.tui) {
38
+ // If TUI is not available, clear the queue
39
+ this.queue = [];
40
+ return;
41
+ }
42
+ this.isShowing = true;
43
+ const toast = this.queue.shift();
44
+ try {
45
+ this.tui.showToast({
46
+ body: {
47
+ title: toast.title,
48
+ message: toast.message,
49
+ variant: toast.variant || 'info',
50
+ },
51
+ });
52
+ }
53
+ catch (err) {
54
+ // If showing fails, continue with next toast
55
+ console.error('Failed to show toast:', err);
56
+ }
57
+ // Wait a bit before showing the next toast to avoid overlap
58
+ // Most toasts are visible for 2-3 seconds, so we wait 2.5 seconds
59
+ setTimeout(() => {
60
+ this.isShowing = false;
61
+ this.processQueue();
62
+ }, 2500);
63
+ }
64
+ /**
65
+ * Clear all pending toasts
66
+ */
67
+ clear() {
68
+ this.queue = [];
69
+ }
70
+ }
71
+ // Export singleton instance
72
+ exports.toast = new ToastManager();
73
+ //# sourceMappingURL=toast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toast.js","sourceRoot":"","sources":["../../../../../../../libs/opencode-plugin/.opencode/plugin/daytona/core/toast.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmBH,MAAM,YAAY;IACR,GAAG,GAAwB,IAAI,CAAA;IAC/B,KAAK,GAAmB,EAAE,CAAA;IAC1B,SAAS,GAAG,KAAK,CAAA;IAEzB;;OAEG;IACH,UAAU,CAAC,GAAoC;QAC7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AAC,KAAK,GAAG,EAAE,CAAA;IACjB,CAAC;CACF;AAED,4BAA4B;AACf,QAAA,KAAK,GAAG,IAAI,YAAY,EAAE,CAAA"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Type definitions and constants for the Daytona OpenCode plugin
7
+ */
8
+ import type { Sandbox } from '@daytonaio/sdk';
9
+ export type EventSessionDeleted = {
10
+ type: 'session.deleted';
11
+ properties: {
12
+ info: {
13
+ id: string;
14
+ };
15
+ };
16
+ };
17
+ export type EventSessionIdle = {
18
+ type: 'session.idle';
19
+ properties: {
20
+ sessionID: string;
21
+ };
22
+ };
23
+ export type ExperimentalChatSystemTransformInput = {
24
+ sessionID?: string;
25
+ model: any;
26
+ };
27
+ export type ExperimentalChatSystemTransformOutput = {
28
+ system: string[];
29
+ };
30
+ export declare const EVENT_TYPE_SESSION_DELETED = "session.deleted";
31
+ export declare const EVENT_TYPE_SESSION_IDLE = "session.idle";
32
+ export type LogLevel = 'INFO' | 'ERROR' | 'WARN';
33
+ export type SandboxInfo = {
34
+ id: string;
35
+ };
36
+ export type SessionInfo = {
37
+ sandboxId: string;
38
+ /**
39
+ * Only set when the local worktree is a git repo (used to create opencode/N branches/remotes).
40
+ */
41
+ branchNumber?: number;
42
+ created: number;
43
+ lastAccessed: number;
44
+ };
45
+ export type ProjectSessionData = {
46
+ projectId: string;
47
+ worktree: string;
48
+ sessions: Record<string, SessionInfo>;
49
+ };
50
+ export type SessionSandboxMap = Map<string, Sandbox | SandboxInfo>;
51
+ export declare const LOG_LEVEL_INFO: LogLevel;
52
+ export declare const LOG_LEVEL_ERROR: LogLevel;
53
+ export declare const LOG_LEVEL_WARN: LogLevel;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LOG_LEVEL_WARN = exports.LOG_LEVEL_ERROR = exports.LOG_LEVEL_INFO = exports.EVENT_TYPE_SESSION_IDLE = exports.EVENT_TYPE_SESSION_DELETED = void 0;
8
+ // OpenCode constants
9
+ exports.EVENT_TYPE_SESSION_DELETED = 'session.deleted';
10
+ exports.EVENT_TYPE_SESSION_IDLE = 'session.idle';
11
+ // Daytona plugin constants
12
+ exports.LOG_LEVEL_INFO = 'INFO';
13
+ exports.LOG_LEVEL_ERROR = 'ERROR';
14
+ exports.LOG_LEVEL_WARN = 'WARN';
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../libs/opencode-plugin/.opencode/plugin/daytona/core/types.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAiCH,qBAAqB;AAER,QAAA,0BAA0B,GAAG,iBAAiB,CAAA;AAC9C,QAAA,uBAAuB,GAAG,cAAc,CAAA;AA4BrD,2BAA2B;AAEd,QAAA,cAAc,GAAa,MAAM,CAAA;AACjC,QAAA,eAAe,GAAa,OAAO,CAAA;AACnC,QAAA,cAAc,GAAa,MAAM,CAAA"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ export declare class HostGitManager {
6
+ private operationQueue;
7
+ /** Cached OID of an empty commit used to reserve branch refs (branches must point at commits, not blobs). */
8
+ private emptyCommitOidCache;
9
+ /**
10
+ * Checks if a git repository exists in the current directory
11
+ * @returns true if a git repo exists, false otherwise
12
+ */
13
+ hasRepo(cwd?: string): boolean;
14
+ /**
15
+ * Allocates the next available opencode/N branch number by scanning local refs and
16
+ * reserving the chosen number by creating the ref immediately.
17
+ *
18
+ * This avoids relying on OpenCode's project ID and works even in repos with no commits.
19
+ */
20
+ allocateAndReserveBranchNumber(cwd: string, prefix?: string): number;
21
+ private refExists;
22
+ /**
23
+ * Returns a commit OID that branch refs can point at. Uses HEAD if the repo has commits,
24
+ * otherwise creates and caches an empty commit (empty tree + commit). Branch refs must
25
+ * point at commits, not blobs.
26
+ */
27
+ private getOrCreateEmptyCommitOid;
28
+ /**
29
+ * Pushes local changes to the sandbox remote.
30
+ * @param remoteName Numbered remote (e.g. sandbox-2) matching opencode/N.
31
+ * @param sshUrl The SSH URL of the sandbox remote.
32
+ * @param branch The branch to push to.
33
+ * @param cwd Worktree path to run git in.
34
+ * @returns true if push was successful, false if no repo exists
35
+ */
36
+ pushLocalToSandboxRemote(remoteName: string, sshUrl: string, branch: string, cwd: string): Promise<boolean>;
37
+ private setRemote;
38
+ pull(remoteName: string, sshUrl: string, branch: string, cwd: string, localBranch?: string): Promise<void>;
39
+ push(remoteName: string, sshUrl: string, branch: string, cwd: string): Promise<void>;
40
+ }
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.HostGitManager = void 0;
8
+ const logger_1 = require("../core/logger");
9
+ const child_process_1 = require("child_process");
10
+ function execCommand(cmd, options = {}) {
11
+ try {
12
+ const stdout = (0, child_process_1.execSync)(cmd, {
13
+ stdio: ['ignore', 'pipe', 'pipe'],
14
+ encoding: 'utf8',
15
+ ...options,
16
+ });
17
+ return { ok: true, stdout: stdout ?? '', stderr: '', status: 0 };
18
+ }
19
+ catch (err) {
20
+ const stdout = err?.stdout?.toString?.() ?? '';
21
+ const stderr = err?.stderr?.toString?.() ?? err?.message ?? String(err);
22
+ const status = typeof err?.status === 'number' ? err.status : null;
23
+ return { ok: false, stdout, stderr, status };
24
+ }
25
+ }
26
+ class HostGitManager {
27
+ // No constructor needed; use global logger
28
+ operationQueue = Promise.resolve();
29
+ /** Cached OID of an empty commit used to reserve branch refs (branches must point at commits, not blobs). */
30
+ emptyCommitOidCache = new Map();
31
+ /**
32
+ * Checks if a git repository exists in the current directory
33
+ * @returns true if a git repo exists, false otherwise
34
+ */
35
+ hasRepo(cwd) {
36
+ return execCommand('git rev-parse --is-inside-work-tree', cwd ? { cwd } : {}).ok;
37
+ }
38
+ /**
39
+ * Allocates the next available opencode/N branch number by scanning local refs and
40
+ * reserving the chosen number by creating the ref immediately.
41
+ *
42
+ * This avoids relying on OpenCode's project ID and works even in repos with no commits.
43
+ */
44
+ allocateAndReserveBranchNumber(cwd, prefix = 'opencode') {
45
+ const start = Date.now();
46
+ if (!this.hasRepo(cwd)) {
47
+ throw new Error('No local git repository found.');
48
+ }
49
+ const base = `refs/heads/${prefix}/`;
50
+ const listRes = execCommand(`git for-each-ref --format='%(refname:strip=3)' ${base}`, { cwd });
51
+ if (!listRes.ok)
52
+ throw new Error(listRes.stderr);
53
+ const list = listRes.stdout.trim();
54
+ const nums = list.length === 0
55
+ ? []
56
+ : list
57
+ .split('\n')
58
+ .map((s) => s.trim())
59
+ .filter(Boolean)
60
+ .map((s) => Number.parseInt(s, 10))
61
+ .filter((n) => Number.isFinite(n) && n > 0);
62
+ let n = (nums.length ? Math.max(...nums) : 0) + 1;
63
+ const maxAttempts = 50; // Circuit-breaker
64
+ let attempts = 0;
65
+ while (n < 1_000_000 && attempts < maxAttempts) {
66
+ attempts++;
67
+ const ref = `${base}${n}`;
68
+ if (this.refExists(cwd, ref)) {
69
+ n++;
70
+ continue;
71
+ }
72
+ const oid = this.getOrCreateEmptyCommitOid(cwd);
73
+ const result = execCommand(`git update-ref "${ref}" "${oid}"`, { cwd });
74
+ if (result.ok) {
75
+ logger_1.logger.info(`[branch-alloc] reserved ${prefix}/${n} in ${Date.now() - start}ms`);
76
+ return n;
77
+ }
78
+ else {
79
+ // If we raced or hit an edge case, try the next number.
80
+ n++;
81
+ }
82
+ }
83
+ const oid = this.getOrCreateEmptyCommitOid(cwd);
84
+ const last = execCommand(`git update-ref "${base}${n}" "${oid}"`, { cwd });
85
+ throw new Error(`Failed to allocate branch number after ${attempts} attempts. Last error: ${last.stderr}`);
86
+ }
87
+ refExists(cwd, ref) {
88
+ return execCommand(`git show-ref --verify --quiet "${ref}"`, { cwd }).ok;
89
+ }
90
+ /**
91
+ * Returns a commit OID that branch refs can point at. Uses HEAD if the repo has commits,
92
+ * otherwise creates and caches an empty commit (empty tree + commit). Branch refs must
93
+ * point at commits, not blobs.
94
+ */
95
+ getOrCreateEmptyCommitOid(cwd) {
96
+ const cached = this.emptyCommitOidCache.get(cwd);
97
+ if (cached)
98
+ return cached;
99
+ const headRes = execCommand('git rev-parse HEAD', { cwd });
100
+ const head = headRes.ok ? headRes.stdout.trim() : '';
101
+ if (head) {
102
+ this.emptyCommitOidCache.set(cwd, head);
103
+ return head;
104
+ }
105
+ // Create an empty tree (idempotent) then a commit pointing at it.
106
+ // Branch refs must point at commits, so we can't reserve with a blob.
107
+ const treeResult = (0, child_process_1.spawnSync)('git', ['hash-object', '-t', 'tree', '-w', '--stdin'], {
108
+ // Empty stdin => empty tree
109
+ input: '',
110
+ cwd,
111
+ encoding: 'utf8',
112
+ });
113
+ const treeOid = treeResult.stdout?.trim();
114
+ if (treeResult.status !== 0 || !treeOid) {
115
+ const errorMsg = treeResult.stderr?.toString() || treeResult.error?.message || String(treeResult.error || 'unknown');
116
+ throw new Error(`Failed to create empty tree: ${errorMsg}`);
117
+ }
118
+ // Provide a default identity for reservation commits when repo has no user.name/user.email (e.g. CI).
119
+ const reservationCommitName = 'OpenCode Plugin';
120
+ const reservationCommitEmail = 'opencode@daytona.io';
121
+ const reservationCommitMessage = 'OpenCode reservation';
122
+ const commitEnv = {
123
+ ...process.env,
124
+ GIT_AUTHOR_NAME: reservationCommitName,
125
+ GIT_AUTHOR_EMAIL: reservationCommitEmail,
126
+ GIT_COMMITTER_NAME: reservationCommitName,
127
+ GIT_COMMITTER_EMAIL: reservationCommitEmail,
128
+ };
129
+ // Create the commit
130
+ const commitRes = execCommand(`git commit-tree ${treeOid} -m "${reservationCommitMessage}"`, {
131
+ cwd,
132
+ env: commitEnv,
133
+ });
134
+ if (!commitRes.ok)
135
+ throw new Error(`Failed to create empty commit: ${commitRes.stderr}`);
136
+ const commitOid = commitRes.stdout.trim();
137
+ this.emptyCommitOidCache.set(cwd, commitOid);
138
+ return commitOid;
139
+ }
140
+ /**
141
+ * Pushes local changes to the sandbox remote.
142
+ * @param remoteName Numbered remote (e.g. sandbox-2) matching opencode/N.
143
+ * @param sshUrl The SSH URL of the sandbox remote.
144
+ * @param branch The branch to push to.
145
+ * @param cwd Worktree path to run git in.
146
+ * @returns true if push was successful, false if no repo exists
147
+ */
148
+ async pushLocalToSandboxRemote(remoteName, sshUrl, branch, cwd) {
149
+ if (!this.hasRepo(cwd)) {
150
+ logger_1.logger.warn('No local git repository found. Skipping push to sandbox.');
151
+ return false;
152
+ }
153
+ try {
154
+ logger_1.logger.info(`Pushing to ${remoteName} (${sshUrl}) on branch ${branch}`);
155
+ const operation = this.operationQueue.then(async () => {
156
+ const statusRes = execCommand('git status --porcelain', { cwd });
157
+ if (!statusRes.ok) {
158
+ throw new Error(statusRes.stderr);
159
+ }
160
+ if (statusRes.stdout.trim().length > 0) {
161
+ logger_1.logger.warn('Local repository has uncommitted changes; pushing HEAD only (no auto-commit).');
162
+ }
163
+ this.setRemote(remoteName, sshUrl, cwd);
164
+ let attempts = 0;
165
+ while (attempts < 3) {
166
+ try {
167
+ const pushRes = execCommand(`git push ${remoteName} HEAD:${branch}`, { cwd });
168
+ if (!pushRes.ok)
169
+ throw new Error(pushRes.stderr);
170
+ logger_1.logger.info(`✓ Pushed local changes to ${remoteName}`);
171
+ return;
172
+ }
173
+ catch (e) {
174
+ attempts++;
175
+ if (attempts >= 3) {
176
+ logger_1.logger.error(`Error pushing to ${remoteName} after 3 attempts: ${e}`);
177
+ }
178
+ else {
179
+ logger_1.logger.warn(`Push attempt ${attempts} failed, retrying...`);
180
+ }
181
+ }
182
+ }
183
+ });
184
+ this.operationQueue = operation;
185
+ await operation;
186
+ return true;
187
+ }
188
+ catch (e) {
189
+ logger_1.logger.error(`Error pushing to sandbox: ${e}`);
190
+ return false;
191
+ }
192
+ }
193
+ setRemote(remoteName, sshUrl, cwd) {
194
+ try {
195
+ // remove existing remote if it exists
196
+ execCommand(`git remote remove ${remoteName}`, { cwd });
197
+ execCommand(`git remote add ${remoteName} ${sshUrl}`, { cwd });
198
+ }
199
+ catch (e) {
200
+ logger_1.logger.warn(`Could not set sandbox remote: ${e}`);
201
+ }
202
+ }
203
+ async pull(remoteName, sshUrl, branch, cwd, localBranch) {
204
+ const operation = this.operationQueue.then(async () => {
205
+ this.setRemote(remoteName, sshUrl, cwd);
206
+ let attempts = 0;
207
+ let lastError = undefined;
208
+ // The first pull attempt sometimes fails. I'm not sure what the cause is.
209
+ while (attempts < 3) {
210
+ try {
211
+ if (localBranch) {
212
+ // Fetch into FETCH_HEAD only (never into refs/heads) so we don't hit
213
+ // "refusing to fetch into branch checked out" when this branch is checked out.
214
+ const fetchRes = execCommand(`git fetch ${remoteName} ${branch}`, { cwd });
215
+ if (!fetchRes.ok)
216
+ throw new Error(fetchRes.stderr);
217
+ const updateRefRes = execCommand(`git update-ref refs/heads/${localBranch} FETCH_HEAD`, { cwd });
218
+ if (!updateRefRes.ok)
219
+ throw new Error(updateRefRes.stderr);
220
+ // Only reset working directory if we're currently on this branch
221
+ const currentBranchRes = execCommand(`git rev-parse --abbrev-ref HEAD`, { cwd });
222
+ const currentBranch = currentBranchRes.ok ? currentBranchRes.stdout.trim() : '';
223
+ if (currentBranch === localBranch) {
224
+ const resetRes = execCommand(`git reset --hard refs/heads/${localBranch}`, { cwd });
225
+ if (!resetRes.ok)
226
+ throw new Error(resetRes.stderr);
227
+ }
228
+ logger_1.logger.info(`✓ Force pulled latest changes from sandbox into ${localBranch}`);
229
+ }
230
+ else {
231
+ const pullRes = execCommand(`git pull ${remoteName} ${branch}`, { cwd });
232
+ if (!pullRes.ok)
233
+ throw new Error(pullRes.stderr);
234
+ logger_1.logger.info('✓ Pulled latest changes from sandbox');
235
+ }
236
+ return;
237
+ }
238
+ catch (e) {
239
+ lastError = e;
240
+ attempts++;
241
+ if (attempts >= 3) {
242
+ logger_1.logger.error(`Error pulling from sandbox after 3 attempts: ${e}`);
243
+ }
244
+ else {
245
+ logger_1.logger.warn(`Pull attempt ${attempts} failed, retrying...`);
246
+ }
247
+ }
248
+ }
249
+ // If we got here, all attempts failed.
250
+ throw lastError ?? new Error('Pull failed after 3 attempts');
251
+ });
252
+ this.operationQueue = operation;
253
+ await operation;
254
+ }
255
+ async push(remoteName, sshUrl, branch, cwd) {
256
+ const operation = this.operationQueue.then(async () => {
257
+ this.setRemote(remoteName, sshUrl, cwd);
258
+ let attempts = 0;
259
+ while (attempts < 3) {
260
+ try {
261
+ const pushRes = execCommand(`git push ${remoteName} HEAD:${branch}`, { cwd });
262
+ if (!pushRes.ok)
263
+ throw new Error(pushRes.stderr);
264
+ logger_1.logger.info('✓ Pushed changes to sandbox');
265
+ return;
266
+ }
267
+ catch (e) {
268
+ attempts++;
269
+ if (attempts >= 3) {
270
+ logger_1.logger.error(`Error pushing to sandbox after 3 attempts: ${e}`);
271
+ }
272
+ else {
273
+ logger_1.logger.warn(`Push attempt ${attempts} failed, retrying...`);
274
+ }
275
+ }
276
+ }
277
+ });
278
+ this.operationQueue = operation;
279
+ await operation;
280
+ }
281
+ }
282
+ exports.HostGitManager = HostGitManager;
283
+ //# sourceMappingURL=host-git-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-git-manager.js","sourceRoot":"","sources":["../../../../../../../libs/opencode-plugin/.opencode/plugin/daytona/git/host-git-manager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAAuC;AACvC,iDAAmD;AASnD,SAAS,WAAW,CAAC,GAAW,EAAE,UAAe,EAAE;IACjD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,GAAG,EAAE;YAC3B,KAAK,EAAE,CAAC,QAAQ,EAAE,MA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AC,KAAK,IAAI,EAAE;YACpD,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;YACvC,IAAI,QAAQ,GAAG,CAAC,CAAA;YAChB,OAAO,QAAQ,GAAG,CAAC,EAAE,CAAC;gBACpB,IAAI,CAAC;oBACH,MAAM,OAAO,GAAG,WAAW,CAAC,YAAY,UAAU,SAAS,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;oBAC7E,IAAI,CAAC,OAAO,CAAC,EAAE;wBAAE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;oBAChD,eAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;oBAC1C,OAAM;gBACR,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,QAAQ,EAAE,CAAA;oBACV,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;wBAClB,eAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,EAAE,CAAC,CAAA;oBACjE,CAAC;yBAAM,CAAC;wBACN,eAAM,CAAC,IAAI,CAAC,gBAAgB,QAAQ,sBAAsB,CAAC,CAAA;oBAC7D,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,cAAc,GAAG,SAAS,CAAA;QAC/B,MAAM,SAAS,CAAA;IACjB,CAAC;CACF;AAhQD,wCAgQC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ export { SessionGitManager } from './session-git-manager';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SessionGitManager = void 0;
8
+ var session_git_manager_1 = require("./session-git-manager");
9
+ Object.defineProperty(exports, "SessionGitManager", { enumerable: true, get: function () { return session_git_manager_1.SessionGitManager; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/opencode-plugin/.opencode/plugin/daytona/git/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import type { Sandbox } from '@daytonaio/sdk';
6
+ export declare class DaytonaSandboxGitManager {
7
+ private readonly sandbox;
8
+ private readonly repoPath;
9
+ constructor(sandbox: Sandbox, repoPath: string);
10
+ ensureDirectory(): Promise<void>;
11
+ ensureRepo(): Promise<void>;
12
+ autoCommit(): Promise<boolean>;
13
+ resetToRemote(branch: string): Promise<void>;
14
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025 Daytona Platforms Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DaytonaSandboxGitManager = void 0;
8
+ const logger_1 = require("../core/logger");
9
+ class DaytonaSandboxGitManager {
10
+ sandbox;
11
+ repoPath;
12
+ constructor(sandbox, repoPath) {
13
+ this.sandbox = sandbox;
14
+ this.repoPath = repoPath;
15
+ }
16
+ async ensureDirectory() {
17
+ await this.sandbox.fs.createFolder(this.repoPath, '755');
18
+ }
19
+ async ensureRepo() {
20
+ await this.ensureDirectory();
21
+ const isGit = await this.sandbox.process.executeCommand('git rev-parse --is-inside-work-tree', this.repoPath);
22
+ if (!isGit || isGit.result.trim() !== 'true') {
23
+ await this.sandbox.process.executeCommand('git init', this.repoPath);
24
+ await this.sandbox.process.executeCommand('git config user.email "sandbox@example.com"', this.repoPath);
25
+ await this.sandbox.process.executeCommand('git config user.name "Daytona Sandbox"', this.repoPath);
26
+ logger_1.logger.info(`Initialized git repo in sandbox at ${this.repoPath}`);
27
+ }
28
+ }
29
+ async autoCommit() {
30
+ try {
31
+ // Check if there are any changes to commit
32
+ const statusResult = await this.sandbox.process.executeCommand('git status --porcelain', this.repoPath);
33
+ if (!statusResult.result.trim()) {
34
+ logger_1.logger.info(`No changes to commit in sandbox at ${this.repoPath}`);
35
+ return false;
36
+ }
37
+ await this.sandbox.process.executeCommand('git add .', this.repoPath);
38
+ await this.sandbox.process.executeCommand('git commit -am "Auto-commit from Daytona plugin"', this.repoPath);
39
+ logger_1.logger.info(`Auto-committed changes in sandbox at ${this.repoPath}`);
40
+ return true;
41
+ }
42
+ catch (err) {
43
+ logger_1.logger.error(`Failed to auto-commit in sandbox at ${this.repoPath}: ${err}`);
44
+ return false;
45
+ }
46
+ }
47
+ async resetToRemote(branch) {
48
+ try {
49
+ const result = await this.sandbox.process.executeCommand(`git checkout -B ${branch}`, this.repoPath);
50
+ logger_1.logger.info(`Checked out branch '${branch}': ${result.result}`);
51
+ await this.sandbox.process.executeCommand('git reset --hard', this.repoPath);
52
+ await this.sandbox.process.executeCommand('git clean -fd', this.repoPath);
53
+ logger_1.logger.info('Reset sandbox worktree to pushed state.');
54
+ const statusResult = await this.sandbox.process.executeCommand('git status --porcelain', this.repoPath);
55
+ if (statusResult.result.trim()) {
56
+ logger_1.logger.warn(`Sandbox has uncommitted changes after reset:\n${statusResult.result}`);
57
+ }
58
+ else {
59
+ logger_1.logger.info('No uncommitted changes in sandbox after reset.');
60
+ }
61
+ }
62
+ catch (err) {
63
+ logger_1.logger.error(`Failed to reset sandbox worktree: ${err}`);
64
+ }
65
+ }
66
+ }
67
+ exports.DaytonaSandboxGitManager = DaytonaSandboxGitManager;
68
+ //# sourceMappingURL=sandbox-git-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-git-manager.js","sourceRoot":"","sources":["../../../../../../../libs/opencode-plugin/.opencode/plugin/daytona/git/sandbox-git-man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OAAO,CAAC,cAAc,CAAC,wBAAwB,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;YACvG,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;gBAC/B,eAAM,CAAC,IAAI,CAAC,iDAAiD,YAAY,CAAC,MAAM,EAAE,CAAC,CAAA;YACrF,CAAC;iBAAM,CAAC;gBACN,eAAM,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAA;YAC/D,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,eAAM,CAAC,KAAK,CAAC,qCAAqC,GAAG,EAAE,CAAC,CAAA;QAC1D,CAAC;IACH,CAAC;CACF;AAxDD,4DAwDC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import type { Sandbox } from '@daytonaio/sdk';
6
+ import type { PluginInput } from '@opencode-ai/plugin';
7
+ /**
8
+ * SessionGitManager: Combines DaytonaSandboxGitManager and HostGitManager for session lifecycle git operations.
9
+ */
10
+ export declare class SessionGitManager {
11
+ private readonly sandboxGit;
12
+ private readonly hostGit;
13
+ private readonly sandbox;
14
+ private readonly repoPath;
15
+ private readonly worktree;
16
+ private readonly branch;
17
+ private readonly localBranch;
18
+ /** Numbered remote (sandbox-2) matches localBranch (opencode/2) */
19
+ private readonly remoteName;
20
+ constructor(sandbox: Sandbox, repoPath: string, worktree: string, branchNumber: number);
21
+ /**
22
+ * Allocate and reserve the next opencode/N number in the local repo at `worktree`.
23
+ * This keeps all host-git concerns inside the git manager layer.
24
+ */
25
+ static allocateAndReserveBranchNumber(worktree: string, prefix?: string): number;
26
+ private getSshUrl;
27
+ /**
28
+ * Check if local git repository exists
29
+ * @returns true if repo exists, false otherwise
30
+ */
31
+ hasLocalRepo(): boolean;
32
+ /**
33
+ * Initialize git in the sandbox and sync with host
34
+ * Used when a new sandbox is created for a session
35
+ */
36
+ initializeAndSync(pluginCtx?: PluginInput): Promise<void>;
37
+ /**
38
+ * Auto-commit in the sandbox and pull latest from host
39
+ * Used on session idle
40
+ * Returns true if changes were synced, false if no changes or no local repo
41
+ */
42
+ autoCommitAndPull(pluginCtx?: PluginInput): Promise<boolean>;
43
+ }