@posthog/agent 2.3.401 → 2.3.403
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/README.md +11 -14
- package/dist/agent.js +1 -7
- package/dist/agent.js.map +1 -1
- package/dist/handoff-checkpoint.d.ts +0 -3
- package/dist/handoff-checkpoint.js +38 -69
- package/dist/handoff-checkpoint.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/posthog-api.js +1 -5
- package/dist/posthog-api.js.map +1 -1
- package/dist/resume.d.ts +5 -6
- package/dist/resume.js +2 -41
- package/dist/resume.js.map +1 -1
- package/dist/server/agent-server.d.ts +1 -2
- package/dist/server/agent-server.js +103 -815
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +101 -806
- package/dist/server/bin.cjs.map +1 -1
- package/dist/types.d.ts +2 -13
- package/dist/types.js.map +1 -1
- package/package.json +3 -7
- package/src/acp-extensions.ts +0 -3
- package/src/handoff-checkpoint.test.ts +2 -17
- package/src/handoff-checkpoint.ts +15 -61
- package/src/resume.ts +5 -11
- package/src/sagas/resume-saga.test.ts +27 -77
- package/src/sagas/resume-saga.ts +3 -44
- package/src/sagas/test-fixtures.ts +17 -76
- package/src/server/agent-server.ts +22 -103
- package/src/test/fixtures/api.ts +2 -15
- package/src/types.ts +0 -16
- package/dist/tree-tracker.d.ts +0 -68
- package/dist/tree-tracker.js +0 -6462
- package/dist/tree-tracker.js.map +0 -1
- package/src/sagas/apply-snapshot-saga.test.ts +0 -691
- package/src/sagas/apply-snapshot-saga.ts +0 -114
- package/src/sagas/capture-tree-saga.test.ts +0 -910
- package/src/sagas/capture-tree-saga.ts +0 -165
- package/src/tree-tracker.ts +0 -173
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { mkdir, readdir, rm, rmdir, writeFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { ApplyTreeSaga as GitApplyTreeSaga } from "@posthog/git/sagas/tree";
|
|
4
|
-
import { Saga } from "@posthog/shared";
|
|
5
|
-
import type { PostHogAPIClient } from "../posthog-api";
|
|
6
|
-
import type { TreeSnapshot } from "../types";
|
|
7
|
-
|
|
8
|
-
export interface ApplySnapshotInput {
|
|
9
|
-
snapshot: TreeSnapshot;
|
|
10
|
-
repositoryPath: string;
|
|
11
|
-
apiClient: PostHogAPIClient;
|
|
12
|
-
taskId: string;
|
|
13
|
-
runId: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ApplySnapshotOutput {
|
|
17
|
-
treeHash: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class ApplySnapshotSaga extends Saga<
|
|
21
|
-
ApplySnapshotInput,
|
|
22
|
-
ApplySnapshotOutput
|
|
23
|
-
> {
|
|
24
|
-
readonly sagaName = "ApplySnapshotSaga";
|
|
25
|
-
|
|
26
|
-
private archivePath: string | null = null;
|
|
27
|
-
|
|
28
|
-
protected async execute(
|
|
29
|
-
input: ApplySnapshotInput,
|
|
30
|
-
): Promise<ApplySnapshotOutput> {
|
|
31
|
-
const { snapshot, repositoryPath, apiClient, taskId, runId } = input;
|
|
32
|
-
const tmpDir = join(repositoryPath, ".posthog", "tmp");
|
|
33
|
-
|
|
34
|
-
if (!snapshot.archiveUrl) {
|
|
35
|
-
throw new Error("Cannot apply snapshot: no archive URL");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const archiveUrl = snapshot.archiveUrl;
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
await this.step({
|
|
42
|
-
name: "create_tmp_dir",
|
|
43
|
-
execute: () => mkdir(tmpDir, { recursive: true }),
|
|
44
|
-
rollback: async () => {},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const archivePath = join(tmpDir, `${snapshot.treeHash}.tar.gz`);
|
|
48
|
-
this.archivePath = archivePath;
|
|
49
|
-
await this.step({
|
|
50
|
-
name: "download_archive",
|
|
51
|
-
execute: async () => {
|
|
52
|
-
const arrayBuffer = await apiClient.downloadArtifact(
|
|
53
|
-
taskId,
|
|
54
|
-
runId,
|
|
55
|
-
archiveUrl,
|
|
56
|
-
);
|
|
57
|
-
if (!arrayBuffer) {
|
|
58
|
-
throw new Error("Failed to download archive");
|
|
59
|
-
}
|
|
60
|
-
const base64Content = Buffer.from(arrayBuffer).toString("utf-8");
|
|
61
|
-
const binaryContent = Buffer.from(base64Content, "base64");
|
|
62
|
-
await writeFile(archivePath, binaryContent);
|
|
63
|
-
this.log.info("Tree archive downloaded", {
|
|
64
|
-
treeHash: snapshot.treeHash,
|
|
65
|
-
snapshotBytes: binaryContent.byteLength,
|
|
66
|
-
snapshotWireBytes: arrayBuffer.byteLength,
|
|
67
|
-
totalBytes: binaryContent.byteLength,
|
|
68
|
-
totalWireBytes: arrayBuffer.byteLength,
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
rollback: async () => {
|
|
72
|
-
if (this.archivePath) {
|
|
73
|
-
await rm(this.archivePath, { force: true }).catch(() => {});
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const gitApplySaga = new GitApplyTreeSaga(this.log);
|
|
79
|
-
const applyResult = await gitApplySaga.run({
|
|
80
|
-
baseDir: repositoryPath,
|
|
81
|
-
treeHash: snapshot.treeHash,
|
|
82
|
-
baseCommit: snapshot.baseCommit,
|
|
83
|
-
changes: snapshot.changes,
|
|
84
|
-
archivePath: this.archivePath,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (!applyResult.success) {
|
|
88
|
-
throw new Error(`Failed to apply tree: ${applyResult.error}`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this.log.info("Tree snapshot applied", {
|
|
92
|
-
treeHash: snapshot.treeHash,
|
|
93
|
-
totalChanges: snapshot.changes.length,
|
|
94
|
-
deletedFiles: snapshot.changes.filter((c) => c.status === "D").length,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return { treeHash: snapshot.treeHash };
|
|
98
|
-
} finally {
|
|
99
|
-
if (this.archivePath) {
|
|
100
|
-
await rm(this.archivePath, { force: true }).catch(() => {});
|
|
101
|
-
}
|
|
102
|
-
await this.removeTmpDirIfEmpty(tmpDir);
|
|
103
|
-
this.archivePath = null;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
private async removeTmpDirIfEmpty(tmpDir: string): Promise<void> {
|
|
108
|
-
const entries = await readdir(tmpDir).catch(() => null);
|
|
109
|
-
if (!entries || entries.length > 0) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
await rmdir(tmpDir).catch(() => {});
|
|
113
|
-
}
|
|
114
|
-
}
|