@posthog/agent 2.3.398 → 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.
Files changed (40) hide show
  1. package/README.md +11 -14
  2. package/dist/agent.js +1 -7
  3. package/dist/agent.js.map +1 -1
  4. package/dist/handoff-checkpoint.d.ts +0 -2
  5. package/dist/handoff-checkpoint.js +38 -53
  6. package/dist/handoff-checkpoint.js.map +1 -1
  7. package/dist/index.d.ts +0 -2
  8. package/dist/index.js +0 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/posthog-api.js +1 -5
  11. package/dist/posthog-api.js.map +1 -1
  12. package/dist/resume.d.ts +5 -6
  13. package/dist/resume.js +2 -41
  14. package/dist/resume.js.map +1 -1
  15. package/dist/server/agent-server.d.ts +1 -2
  16. package/dist/server/agent-server.js +103 -768
  17. package/dist/server/agent-server.js.map +1 -1
  18. package/dist/server/bin.cjs +101 -766
  19. package/dist/server/bin.cjs.map +1 -1
  20. package/dist/types.d.ts +2 -13
  21. package/dist/types.js.map +1 -1
  22. package/package.json +3 -7
  23. package/src/acp-extensions.ts +0 -3
  24. package/src/handoff-checkpoint.test.ts +3 -17
  25. package/src/handoff-checkpoint.ts +15 -45
  26. package/src/resume.ts +5 -11
  27. package/src/sagas/resume-saga.test.ts +27 -77
  28. package/src/sagas/resume-saga.ts +3 -44
  29. package/src/sagas/test-fixtures.ts +17 -76
  30. package/src/server/agent-server.ts +22 -103
  31. package/src/test/fixtures/api.ts +2 -15
  32. package/src/types.ts +0 -16
  33. package/dist/tree-tracker.d.ts +0 -68
  34. package/dist/tree-tracker.js +0 -6431
  35. package/dist/tree-tracker.js.map +0 -1
  36. package/src/sagas/apply-snapshot-saga.test.ts +0 -690
  37. package/src/sagas/apply-snapshot-saga.ts +0 -100
  38. package/src/sagas/capture-tree-saga.test.ts +0 -892
  39. package/src/sagas/capture-tree-saga.ts +0 -150
  40. package/src/tree-tracker.ts +0 -173
@@ -1,100 +0,0 @@
1
- import { mkdir, rm, 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
- await this.step({
41
- name: "create_tmp_dir",
42
- execute: () => mkdir(tmpDir, { recursive: true }),
43
- rollback: async () => {},
44
- });
45
-
46
- const archivePath = join(tmpDir, `${snapshot.treeHash}.tar.gz`);
47
- this.archivePath = archivePath;
48
- await this.step({
49
- name: "download_archive",
50
- execute: async () => {
51
- const arrayBuffer = await apiClient.downloadArtifact(
52
- taskId,
53
- runId,
54
- archiveUrl,
55
- );
56
- if (!arrayBuffer) {
57
- throw new Error("Failed to download archive");
58
- }
59
- const base64Content = Buffer.from(arrayBuffer).toString("utf-8");
60
- const binaryContent = Buffer.from(base64Content, "base64");
61
- await writeFile(archivePath, binaryContent);
62
- this.log.info("Tree archive downloaded", {
63
- treeHash: snapshot.treeHash,
64
- snapshotBytes: binaryContent.byteLength,
65
- snapshotWireBytes: arrayBuffer.byteLength,
66
- totalBytes: binaryContent.byteLength,
67
- totalWireBytes: arrayBuffer.byteLength,
68
- });
69
- },
70
- rollback: async () => {
71
- if (this.archivePath) {
72
- await rm(this.archivePath, { force: true }).catch(() => {});
73
- }
74
- },
75
- });
76
-
77
- const gitApplySaga = new GitApplyTreeSaga(this.log);
78
- const applyResult = await gitApplySaga.run({
79
- baseDir: repositoryPath,
80
- treeHash: snapshot.treeHash,
81
- baseCommit: snapshot.baseCommit,
82
- changes: snapshot.changes,
83
- archivePath: this.archivePath,
84
- });
85
-
86
- if (!applyResult.success) {
87
- throw new Error(`Failed to apply tree: ${applyResult.error}`);
88
- }
89
-
90
- await rm(this.archivePath, { force: true }).catch(() => {});
91
-
92
- this.log.info("Tree snapshot applied", {
93
- treeHash: snapshot.treeHash,
94
- totalChanges: snapshot.changes.length,
95
- deletedFiles: snapshot.changes.filter((c) => c.status === "D").length,
96
- });
97
-
98
- return { treeHash: snapshot.treeHash };
99
- }
100
- }