gitdone-agent 0.5.4 → 0.5.6
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/index.js +48 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import { randomUUID } from 'node:crypto'
|
|
|
27
27
|
// Reported to the server on every sync so the web UI can flag outdated agents.
|
|
28
28
|
// Keep in lockstep with packages/agent/package.json "version" AND
|
|
29
29
|
// src/lib/agentVersion.ts LATEST_AGENT_VERSION.
|
|
30
|
-
const AGENT_VERSION = '0.5.
|
|
30
|
+
const AGENT_VERSION = '0.5.6'
|
|
31
31
|
|
|
32
32
|
const AGENT_DIR = join(homedir(), '.gitdone-agent')
|
|
33
33
|
const CONFIG_PATH = join(AGENT_DIR, 'config.json')
|
|
@@ -761,6 +761,38 @@ function runAiChat(cfg, cmd, repoPath) {
|
|
|
761
761
|
})
|
|
762
762
|
}
|
|
763
763
|
|
|
764
|
+
// deploy — run the project's deploy script (scripts/deploy.sh) in the repo.
|
|
765
|
+
// Long-running (git pull + npm build + service restart), so we spawn it detached
|
|
766
|
+
// from the poll loop and report the result on exit. The agent is its OWN process
|
|
767
|
+
// (not part of any gitdone systemd service), so a `systemctl restart` inside the
|
|
768
|
+
// script doesn't kill the deploy mid-flight — which a server-side spawn would.
|
|
769
|
+
function runDeployCommand(cfg, cmd, repoPath) {
|
|
770
|
+
const script = 'scripts/deploy.sh'
|
|
771
|
+
if (!existsSync(join(repoPath, script))) {
|
|
772
|
+
reportCommandResult(cfg, cmd.id, 'error', `няма ${script} в repo-то — няма какво да деплойна`)
|
|
773
|
+
log(`✗ deploy @ ${repoPath}: липсва ${script}`)
|
|
774
|
+
return
|
|
775
|
+
}
|
|
776
|
+
log(`▸ deploy стартиран @ ${repoPath}`)
|
|
777
|
+
const child = spawn('bash', [script], { cwd: repoPath, stdio: ['ignore', 'pipe', 'pipe'] })
|
|
778
|
+
// Keep only the tail of the output — enough to explain a failure without
|
|
779
|
+
// shipping a whole build log back.
|
|
780
|
+
let tail = ''
|
|
781
|
+
const capture = (d) => { tail = (tail + d.toString()).slice(-2000) }
|
|
782
|
+
child.stdout.on('data', capture)
|
|
783
|
+
child.stderr.on('data', capture)
|
|
784
|
+
child.on('error', (err) => {
|
|
785
|
+
reportCommandResult(cfg, cmd.id, 'error', `процесна грешка: ${err.message}`)
|
|
786
|
+
log(`✗ deploy failed @ ${repoPath}: ${err.message}`)
|
|
787
|
+
})
|
|
788
|
+
child.on('close', (code) => {
|
|
789
|
+
const ok = code === 0
|
|
790
|
+
const detail = tail.trim() ? `\n${tail.trim()}` : ''
|
|
791
|
+
reportCommandResult(cfg, cmd.id, ok ? 'done' : 'error', `exit ${code}${detail}`.slice(0, 4000))
|
|
792
|
+
log(`${ok ? '✓' : '✗'} deploy @ ${repoPath} приключи (code ${code})`)
|
|
793
|
+
})
|
|
794
|
+
}
|
|
795
|
+
|
|
764
796
|
async function executeCommand(cfg, cmd, repoPath) {
|
|
765
797
|
// ai_run is long-running + streaming — launch it in the background and return
|
|
766
798
|
// so the snapshot loop keeps going. It reports its own result on exit.
|
|
@@ -773,6 +805,13 @@ async function executeCommand(cfg, cmd, repoPath) {
|
|
|
773
805
|
runAiChat(cfg, cmd, repoPath)
|
|
774
806
|
return
|
|
775
807
|
}
|
|
808
|
+
// deploy — run the repo's deploy script. Long-running (pull + build + service
|
|
809
|
+
// restart), so it's launched in the background and reports its own result on
|
|
810
|
+
// exit, same as ai_run.
|
|
811
|
+
if (cmd.type === 'deploy') {
|
|
812
|
+
runDeployCommand(cfg, cmd, repoPath)
|
|
813
|
+
return
|
|
814
|
+
}
|
|
776
815
|
|
|
777
816
|
let result = 'ok'
|
|
778
817
|
let status = 'done'
|
|
@@ -797,6 +836,14 @@ async function executeCommand(cfg, cmd, repoPath) {
|
|
|
797
836
|
result = pushOrPull(cmd.type, repoPath, auth)
|
|
798
837
|
} else if (cmd.type === 'discard') {
|
|
799
838
|
result = discardFile(repoPath, cmd.payload?.file)
|
|
839
|
+
} else {
|
|
840
|
+
// Unknown command type — almost always a newer server feature (e.g. the
|
|
841
|
+
// gd-255 `deploy` command) reaching an agent too old to handle it. Do NOT
|
|
842
|
+
// silently mark it done: an older agent used to fall through here and
|
|
843
|
+
// report status=done/result=ok, so a queued deploy looked "completed" while
|
|
844
|
+
// nothing ran. Surface it as an error so the failure is visible and the
|
|
845
|
+
// user knows to update the agent.
|
|
846
|
+
throw new Error(`непозната команда „${cmd.type}" — обнови gitdone-agent (npm i -g gitdone-agent@latest)`)
|
|
800
847
|
}
|
|
801
848
|
log(`✓ ${cmd.type} @ ${repoPath}: ${redact(result, auth?.token)}`)
|
|
802
849
|
} catch (err) {
|