@teamvibe/poller 0.1.18 → 0.1.19
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/brain-manager.js +19 -12
- package/package.json +1 -1
package/dist/brain-manager.js
CHANGED
|
@@ -5,6 +5,13 @@ import { join } from 'path';
|
|
|
5
5
|
import { config } from './config.js';
|
|
6
6
|
import { logger } from './logger.js';
|
|
7
7
|
const execAsync = promisify(exec);
|
|
8
|
+
// Clean env for git commands — npm/npx sets GIT_ASKPASS=echo which
|
|
9
|
+
// prevents git credential helpers (like gh) from working.
|
|
10
|
+
const gitEnv = { ...process.env };
|
|
11
|
+
delete gitEnv['GIT_ASKPASS'];
|
|
12
|
+
function gitExec(command, options) {
|
|
13
|
+
return execAsync(command, { ...options, env: gitEnv });
|
|
14
|
+
}
|
|
8
15
|
// Cooldown tracker per brain
|
|
9
16
|
const lastUpdateTimes = new Map();
|
|
10
17
|
/**
|
|
@@ -48,17 +55,17 @@ export async function getBrainPath(brain, channelId, workspaceId) {
|
|
|
48
55
|
const brainDir = join(config.BRAINS_PATH, brain.brainId);
|
|
49
56
|
if (!existsSync(brainDir)) {
|
|
50
57
|
logger.info(`Cloning brain ${brain.brainId} from ${brain.gitRepoUrl} (branch: ${brain.branch})...`);
|
|
51
|
-
await
|
|
58
|
+
await gitExec(`git clone --recurse-submodules ${brain.gitRepoUrl} ${brainDir}`);
|
|
52
59
|
// Ensure the desired branch exists (handles empty repos and missing branches)
|
|
53
|
-
const { stdout: currentBranch } = await
|
|
60
|
+
const { stdout: currentBranch } = await gitExec('git branch --show-current', { cwd: brainDir });
|
|
54
61
|
if (currentBranch.trim() !== brain.branch) {
|
|
55
62
|
// Check if the branch exists on remote
|
|
56
|
-
const { stdout: remoteBranches } = await
|
|
63
|
+
const { stdout: remoteBranches } = await gitExec('git branch -r', { cwd: brainDir });
|
|
57
64
|
if (remoteBranches.includes(`origin/${brain.branch}`)) {
|
|
58
|
-
await
|
|
65
|
+
await gitExec(`git checkout ${brain.branch}`, { cwd: brainDir });
|
|
59
66
|
}
|
|
60
67
|
else {
|
|
61
|
-
await
|
|
68
|
+
await gitExec(`git checkout -b ${brain.branch}`, { cwd: brainDir });
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
logger.info(`Brain ${brain.brainId} cloned successfully`);
|
|
@@ -84,7 +91,7 @@ async function updateBrain(brainDir, brainId, branch) {
|
|
|
84
91
|
}
|
|
85
92
|
try {
|
|
86
93
|
logger.info(`Updating brain ${brainId} at ${brainDir}...`);
|
|
87
|
-
await
|
|
94
|
+
await gitExec(`git fetch origin ${branch} && git reset --hard origin/${branch} && git submodule update --init --recursive`, {
|
|
88
95
|
cwd: brainDir,
|
|
89
96
|
});
|
|
90
97
|
lastUpdateTimes.set(brainId, Date.now());
|
|
@@ -103,7 +110,7 @@ export async function ensureBaseBrain() {
|
|
|
103
110
|
const brainDir = config.BASE_BRAIN_PATH;
|
|
104
111
|
if (!existsSync(brainDir)) {
|
|
105
112
|
logger.info(`Cloning base brain from ${config.BASE_BRAIN_REPO} (branch: ${config.BASE_BRAIN_BRANCH})...`);
|
|
106
|
-
await
|
|
113
|
+
await gitExec(`git clone --recurse-submodules --branch ${config.BASE_BRAIN_BRANCH} ${config.BASE_BRAIN_REPO} ${brainDir}`);
|
|
107
114
|
lastUpdateTimes.set('__base_brain__', Date.now());
|
|
108
115
|
logger.info('Base brain cloned successfully');
|
|
109
116
|
}
|
|
@@ -125,17 +132,17 @@ export async function pushBrainChanges(brainDir, brainId, workspaceId) {
|
|
|
125
132
|
try {
|
|
126
133
|
// Check if this is a git repo with a remote
|
|
127
134
|
try {
|
|
128
|
-
await
|
|
135
|
+
await gitExec('git remote get-url origin', { cwd: brainDir });
|
|
129
136
|
}
|
|
130
137
|
catch {
|
|
131
138
|
logger.debug(`Brain ${brainId} has no git remote, skipping push`);
|
|
132
139
|
return;
|
|
133
140
|
}
|
|
134
141
|
// Stage all changes
|
|
135
|
-
await
|
|
142
|
+
await gitExec('git add -A', { cwd: brainDir });
|
|
136
143
|
// Check if there are staged changes
|
|
137
144
|
try {
|
|
138
|
-
await
|
|
145
|
+
await gitExec('git diff --cached --quiet', { cwd: brainDir });
|
|
139
146
|
// If the command succeeds (exit 0), there are no changes
|
|
140
147
|
logger.debug(`Brain ${brainId} has no changes to push`);
|
|
141
148
|
return;
|
|
@@ -143,8 +150,8 @@ export async function pushBrainChanges(brainDir, brainId, workspaceId) {
|
|
|
143
150
|
catch {
|
|
144
151
|
// Exit code 1 means there are changes — continue
|
|
145
152
|
}
|
|
146
|
-
await
|
|
147
|
-
await
|
|
153
|
+
await gitExec('git commit -m "auto: session update"', { cwd: brainDir });
|
|
154
|
+
await gitExec('git push', { cwd: brainDir });
|
|
148
155
|
logger.info(`Brain ${brainId} changes pushed successfully`);
|
|
149
156
|
if (workspaceId)
|
|
150
157
|
reportBrainSync(brainId, workspaceId, 'pushed');
|