@agent-watch-ai/edge 0.2.5
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/CHANGELOG.md +251 -0
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/billing/billing-mode.d.ts +16 -0
- package/dist/billing/billing-mode.js +139 -0
- package/dist/billing/constants/billing.constants.d.ts +37 -0
- package/dist/billing/constants/billing.constants.js +38 -0
- package/dist/billing/index.d.ts +6 -0
- package/dist/billing/index.js +6 -0
- package/dist/cli/args.d.ts +29 -0
- package/dist/cli/args.js +61 -0
- package/dist/cli/constants/cli.constants.d.ts +60 -0
- package/dist/cli/constants/cli.constants.js +60 -0
- package/dist/cli/context.d.ts +51 -0
- package/dist/cli/context.js +108 -0
- package/dist/cli/doctor.d.ts +15 -0
- package/dist/cli/doctor.js +416 -0
- package/dist/cli/hook.d.ts +20 -0
- package/dist/cli/hook.js +166 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.js +8 -0
- package/dist/cli/misc.d.ts +31 -0
- package/dist/cli/misc.js +63 -0
- package/dist/cli/setup.d.ts +32 -0
- package/dist/cli/setup.js +298 -0
- package/dist/cli/status.d.ts +11 -0
- package/dist/cli/status.js +174 -0
- package/dist/cli/types/cli.types.d.ts +69 -0
- package/dist/cli/types/cli.types.js +1 -0
- package/dist/cli/ui.d.ts +41 -0
- package/dist/cli/ui.js +78 -0
- package/dist/cli/uninstall.d.ts +13 -0
- package/dist/cli/uninstall.js +83 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +124 -0
- package/dist/config/config-store.d.ts +29 -0
- package/dist/config/config-store.js +75 -0
- package/dist/config/config.d.ts +73 -0
- package/dist/config/config.js +115 -0
- package/dist/config/constants/config.constants.d.ts +62 -0
- package/dist/config/constants/config.constants.js +70 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +5 -0
- package/dist/config/repo-config.d.ts +37 -0
- package/dist/config/repo-config.js +178 -0
- package/dist/config/schemas/config.schema.d.ts +409 -0
- package/dist/config/schemas/config.schema.js +97 -0
- package/dist/config/types/config.types.d.ts +33 -0
- package/dist/config/types/config.types.js +1 -0
- package/dist/core/async.d.ts +20 -0
- package/dist/core/async.js +32 -0
- package/dist/core/constants/core.constants.d.ts +18 -0
- package/dist/core/constants/core.constants.js +18 -0
- package/dist/core/env.d.ts +12 -0
- package/dist/core/env.js +20 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/logger.d.ts +27 -0
- package/dist/core/logger.js +82 -0
- package/dist/core/number.d.ts +33 -0
- package/dist/core/number.js +47 -0
- package/dist/core/object.d.ts +78 -0
- package/dist/core/object.js +127 -0
- package/dist/core/pipe.d.ts +55 -0
- package/dist/core/pipe.js +81 -0
- package/dist/core/types/core.types.d.ts +54 -0
- package/dist/core/types/core.types.js +4 -0
- package/dist/core/version.d.ts +19 -0
- package/dist/core/version.js +35 -0
- package/dist/core/which.d.ts +13 -0
- package/dist/core/which.js +57 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +23 -0
- package/dist/enforcement/constants/enforcement.constants.js +22 -0
- package/dist/enforcement/decision-cache.d.ts +57 -0
- package/dist/enforcement/decision-cache.js +138 -0
- package/dist/enforcement/decision-client.d.ts +14 -0
- package/dist/enforcement/decision-client.js +84 -0
- package/dist/enforcement/enforcement.d.ts +17 -0
- package/dist/enforcement/enforcement.js +90 -0
- package/dist/enforcement/index.d.ts +11 -0
- package/dist/enforcement/index.js +10 -0
- package/dist/enforcement/schemas/enforcement.schema.d.ts +30 -0
- package/dist/enforcement/schemas/enforcement.schema.js +36 -0
- package/dist/enforcement/types/enforcement.types.d.ts +59 -0
- package/dist/enforcement/types/enforcement.types.js +1 -0
- package/dist/enrollment/constants/enrollment.constants.d.ts +6 -0
- package/dist/enrollment/constants/enrollment.constants.js +6 -0
- package/dist/enrollment/enrollment-provider.d.ts +5 -0
- package/dist/enrollment/enrollment-provider.js +1 -0
- package/dist/enrollment/index.d.ts +7 -0
- package/dist/enrollment/index.js +1 -0
- package/dist/enrollment/manual-enrollment.d.ts +32 -0
- package/dist/enrollment/manual-enrollment.js +72 -0
- package/dist/enrollment/types/enrollment.types.d.ts +25 -0
- package/dist/enrollment/types/enrollment.types.js +1 -0
- package/dist/events/canonical-event.d.ts +10 -0
- package/dist/events/canonical-event.js +9 -0
- package/dist/events/constants/enrich.constants.d.ts +14 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +35 -0
- package/dist/events/constants/events.constants.js +57 -0
- package/dist/events/enrich.d.ts +16 -0
- package/dist/events/enrich.js +226 -0
- package/dist/events/event-id.d.ts +32 -0
- package/dist/events/event-id.js +49 -0
- package/dist/events/index.d.ts +14 -0
- package/dist/events/index.js +5 -0
- package/dist/events/llm-call.d.ts +14 -0
- package/dist/events/llm-call.js +84 -0
- package/dist/events/product-event.d.ts +39 -0
- package/dist/events/product-event.js +19 -0
- package/dist/events/types/enrich.types.d.ts +25 -0
- package/dist/events/types/enrich.types.js +1 -0
- package/dist/events/types/events.types.d.ts +112 -0
- package/dist/events/types/events.types.js +1 -0
- package/dist/events/types/llm-call.types.d.ts +79 -0
- package/dist/events/types/llm-call.types.js +1 -0
- package/dist/events/types/repo-snapshot.types.d.ts +32 -0
- package/dist/events/types/repo-snapshot.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +10 -0
- package/dist/feature/constants/feature.constants.js +10 -0
- package/dist/feature/index.d.ts +6 -0
- package/dist/feature/index.js +6 -0
- package/dist/feature/ticket-candidates.d.ts +13 -0
- package/dist/feature/ticket-candidates.js +26 -0
- package/dist/git/constants/git.constants.d.ts +84 -0
- package/dist/git/constants/git.constants.js +113 -0
- package/dist/git/git-context.d.ts +52 -0
- package/dist/git/git-context.js +226 -0
- package/dist/git/index.d.ts +9 -0
- package/dist/git/index.js +3 -0
- package/dist/git/remote-sanitize.d.ts +26 -0
- package/dist/git/remote-sanitize.js +92 -0
- package/dist/git/repo-snapshot.d.ts +40 -0
- package/dist/git/repo-snapshot.js +95 -0
- package/dist/git/types/git.types.d.ts +36 -0
- package/dist/git/types/git.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +25 -0
- package/dist/git/types/snapshot.types.js +1 -0
- package/dist/otlp/constants/otlp.constants.d.ts +84 -0
- package/dist/otlp/constants/otlp.constants.js +99 -0
- package/dist/otlp/http.d.ts +24 -0
- package/dist/otlp/http.js +37 -0
- package/dist/otlp/index.d.ts +9 -0
- package/dist/otlp/index.js +3 -0
- package/dist/otlp/normalize.d.ts +14 -0
- package/dist/otlp/normalize.js +404 -0
- package/dist/otlp/types/otlp.types.d.ts +69 -0
- package/dist/otlp/types/otlp.types.js +1 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +23 -0
- package/dist/pipeline/constants/pipeline.constants.js +22 -0
- package/dist/pipeline/hook-pipeline.d.ts +14 -0
- package/dist/pipeline/hook-pipeline.js +297 -0
- package/dist/pipeline/index.d.ts +6 -0
- package/dist/pipeline/index.js +1 -0
- package/dist/pipeline/types/pipeline.types.d.ts +48 -0
- package/dist/pipeline/types/pipeline.types.js +1 -0
- package/dist/privacy/constants/privacy.constants.d.ts +23 -0
- package/dist/privacy/constants/privacy.constants.js +38 -0
- package/dist/privacy/index.d.ts +7 -0
- package/dist/privacy/index.js +2 -0
- package/dist/privacy/sanitizer.d.ts +20 -0
- package/dist/privacy/sanitizer.js +52 -0
- package/dist/privacy/types/privacy.types.d.ts +13 -0
- package/dist/privacy/types/privacy.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +54 -0
- package/dist/providers/antigravity/antigravity.adapter.js +311 -0
- package/dist/providers/antigravity/antigravity.detect.d.ts +25 -0
- package/dist/providers/antigravity/antigravity.detect.js +64 -0
- package/dist/providers/antigravity/antigravity.hooks.d.ts +24 -0
- package/dist/providers/antigravity/antigravity.hooks.js +126 -0
- package/dist/providers/antigravity/antigravity.provider.d.ts +2 -0
- package/dist/providers/antigravity/antigravity.provider.js +22 -0
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +72 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +75 -0
- package/dist/providers/antigravity/schemas/antigravity.schema.d.ts +521 -0
- package/dist/providers/antigravity/schemas/antigravity.schema.js +64 -0
- package/dist/providers/antigravity/types/antigravity.types.d.ts +13 -0
- package/dist/providers/antigravity/types/antigravity.types.js +1 -0
- package/dist/providers/claude/claude.adapter.d.ts +15 -0
- package/dist/providers/claude/claude.adapter.js +141 -0
- package/dist/providers/claude/claude.detect.d.ts +20 -0
- package/dist/providers/claude/claude.detect.js +57 -0
- package/dist/providers/claude/claude.hooks.d.ts +23 -0
- package/dist/providers/claude/claude.hooks.js +94 -0
- package/dist/providers/claude/claude.otel.d.ts +95 -0
- package/dist/providers/claude/claude.otel.js +331 -0
- package/dist/providers/claude/claude.provider.d.ts +2 -0
- package/dist/providers/claude/claude.provider.js +26 -0
- package/dist/providers/claude/constants/claude.constants.d.ts +34 -0
- package/dist/providers/claude/constants/claude.constants.js +54 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +17 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +17 -0
- package/dist/providers/claude/schemas/claude.schema.d.ts +72 -0
- package/dist/providers/claude/schemas/claude.schema.js +32 -0
- package/dist/providers/claude/types/claude.types.d.ts +3 -0
- package/dist/providers/claude/types/claude.types.js +1 -0
- package/dist/providers/codex/codex.adapter.d.ts +11 -0
- package/dist/providers/codex/codex.adapter.js +106 -0
- package/dist/providers/codex/codex.detect.d.ts +30 -0
- package/dist/providers/codex/codex.detect.js +58 -0
- package/dist/providers/codex/codex.hooks.d.ts +27 -0
- package/dist/providers/codex/codex.hooks.js +129 -0
- package/dist/providers/codex/codex.otel.d.ts +51 -0
- package/dist/providers/codex/codex.otel.js +325 -0
- package/dist/providers/codex/codex.provider.d.ts +2 -0
- package/dist/providers/codex/codex.provider.js +25 -0
- package/dist/providers/codex/constants/codex.constants.d.ts +41 -0
- package/dist/providers/codex/constants/codex.constants.js +62 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +22 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +22 -0
- package/dist/providers/codex/schemas/codex.schema.d.ts +70 -0
- package/dist/providers/codex/schemas/codex.schema.js +32 -0
- package/dist/providers/codex/types/codex.types.d.ts +3 -0
- package/dist/providers/codex/types/codex.types.js +1 -0
- package/dist/providers/constants/provider.constants.d.ts +33 -0
- package/dist/providers/constants/provider.constants.js +33 -0
- package/dist/providers/cursor/constants/cursor.constants.d.ts +58 -0
- package/dist/providers/cursor/constants/cursor.constants.js +95 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +11 -0
- package/dist/providers/cursor/cursor.adapter.js +331 -0
- package/dist/providers/cursor/cursor.detect.d.ts +23 -0
- package/dist/providers/cursor/cursor.detect.js +66 -0
- package/dist/providers/cursor/cursor.hooks.d.ts +25 -0
- package/dist/providers/cursor/cursor.hooks.js +95 -0
- package/dist/providers/cursor/cursor.provider.d.ts +2 -0
- package/dist/providers/cursor/cursor.provider.js +27 -0
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +130 -0
- package/dist/providers/cursor/schemas/cursor.schema.js +62 -0
- package/dist/providers/cursor/types/cursor.types.d.ts +3 -0
- package/dist/providers/cursor/types/cursor.types.js +1 -0
- package/dist/providers/gemini/constants/gemini.constants.d.ts +36 -0
- package/dist/providers/gemini/constants/gemini.constants.js +58 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +34 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.js +48 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +15 -0
- package/dist/providers/gemini/gemini.adapter.js +146 -0
- package/dist/providers/gemini/gemini.detect.d.ts +23 -0
- package/dist/providers/gemini/gemini.detect.js +78 -0
- package/dist/providers/gemini/gemini.hooks.d.ts +22 -0
- package/dist/providers/gemini/gemini.hooks.js +93 -0
- package/dist/providers/gemini/gemini.otel.d.ts +62 -0
- package/dist/providers/gemini/gemini.otel.js +274 -0
- package/dist/providers/gemini/gemini.provider.d.ts +2 -0
- package/dist/providers/gemini/gemini.provider.js +22 -0
- package/dist/providers/gemini/schemas/gemini.schema.d.ts +81 -0
- package/dist/providers/gemini/schemas/gemini.schema.js +35 -0
- package/dist/providers/gemini/types/gemini.types.d.ts +3 -0
- package/dist/providers/gemini/types/gemini.types.js +1 -0
- package/dist/providers/index.d.ts +14 -0
- package/dist/providers/index.js +8 -0
- package/dist/providers/provider.d.ts +16 -0
- package/dist/providers/provider.js +149 -0
- package/dist/providers/registry.d.ts +12 -0
- package/dist/providers/registry.js +23 -0
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +6 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +6 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +25 -0
- package/dist/providers/shared/constants/tooling.constants.js +25 -0
- package/dist/providers/shared/event-builder.d.ts +85 -0
- package/dist/providers/shared/event-builder.js +166 -0
- package/dist/providers/shared/hook-config.d.ts +80 -0
- package/dist/providers/shared/hook-config.js +164 -0
- package/dist/providers/shared/hook-refusal.d.ts +16 -0
- package/dist/providers/shared/hook-refusal.js +33 -0
- package/dist/providers/shared/install-record.d.ts +75 -0
- package/dist/providers/shared/install-record.js +113 -0
- package/dist/providers/shared/tooling.d.ts +58 -0
- package/dist/providers/shared/tooling.js +103 -0
- package/dist/providers/shared/types/adapter.types.d.ts +54 -0
- package/dist/providers/shared/types/adapter.types.js +1 -0
- package/dist/providers/shared/types/hook-config.types.d.ts +32 -0
- package/dist/providers/shared/types/hook-config.types.js +1 -0
- package/dist/providers/types/provider.types.d.ts +98 -0
- package/dist/providers/types/provider.types.js +1 -0
- package/dist/snapshot/branch-selection.d.ts +37 -0
- package/dist/snapshot/branch-selection.js +69 -0
- package/dist/snapshot/budget.d.ts +41 -0
- package/dist/snapshot/budget.js +67 -0
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +11 -0
- package/dist/snapshot/constants/snapshot-stages.constants.js +11 -0
- package/dist/snapshot/constants/snapshot.constants.d.ts +56 -0
- package/dist/snapshot/constants/snapshot.constants.js +56 -0
- package/dist/snapshot/index.d.ts +16 -0
- package/dist/snapshot/index.js +6 -0
- package/dist/snapshot/snapshot-event.d.ts +17 -0
- package/dist/snapshot/snapshot-event.js +66 -0
- package/dist/snapshot/snapshot-pipeline.d.ts +14 -0
- package/dist/snapshot/snapshot-pipeline.js +163 -0
- package/dist/snapshot/snapshot-state.d.ts +55 -0
- package/dist/snapshot/snapshot-state.js +100 -0
- package/dist/snapshot/types/snapshot.types.d.ts +86 -0
- package/dist/snapshot/types/snapshot.types.js +1 -0
- package/dist/storage/atomic-file.d.ts +25 -0
- package/dist/storage/atomic-file.js +76 -0
- package/dist/storage/constants/storage.constants.d.ts +34 -0
- package/dist/storage/constants/storage.constants.js +35 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.js +5 -0
- package/dist/storage/install-state.d.ts +20 -0
- package/dist/storage/install-state.js +40 -0
- package/dist/storage/json-file.d.ts +13 -0
- package/dist/storage/json-file.js +31 -0
- package/dist/storage/lock.d.ts +15 -0
- package/dist/storage/lock.js +70 -0
- package/dist/storage/paths.d.ts +14 -0
- package/dist/storage/paths.js +42 -0
- package/dist/storage/schemas/storage.schema.d.ts +128 -0
- package/dist/storage/schemas/storage.schema.js +27 -0
- package/dist/storage/types/storage.types.d.ts +36 -0
- package/dist/storage/types/storage.types.js +1 -0
- package/dist/transport/constants/transport.constants.d.ts +47 -0
- package/dist/transport/constants/transport.constants.js +47 -0
- package/dist/transport/cooldown.d.ts +35 -0
- package/dist/transport/cooldown.js +62 -0
- package/dist/transport/delivery-stats.d.ts +65 -0
- package/dist/transport/delivery-stats.js +186 -0
- package/dist/transport/delivery.d.ts +26 -0
- package/dist/transport/delivery.js +80 -0
- package/dist/transport/headers.d.ts +12 -0
- package/dist/transport/headers.js +19 -0
- package/dist/transport/http-transport.d.ts +39 -0
- package/dist/transport/http-transport.js +106 -0
- package/dist/transport/index.d.ts +13 -0
- package/dist/transport/index.js +7 -0
- package/dist/transport/queue.d.ts +177 -0
- package/dist/transport/queue.js +474 -0
- package/dist/transport/schemas/queue.schema.d.ts +30 -0
- package/dist/transport/schemas/queue.schema.js +18 -0
- package/dist/transport/transport.d.ts +6 -0
- package/dist/transport/transport.js +1 -0
- package/dist/transport/types/transport.types.d.ts +102 -0
- package/dist/transport/types/transport.types.js +1 -0
- package/dist/turns/aggregate-usage.d.ts +20 -0
- package/dist/turns/aggregate-usage.js +269 -0
- package/dist/turns/claude-transcript.d.ts +18 -0
- package/dist/turns/claude-transcript.js +80 -0
- package/dist/turns/constants/turns.constants.d.ts +69 -0
- package/dist/turns/constants/turns.constants.js +86 -0
- package/dist/turns/cursor-transcript.d.ts +21 -0
- package/dist/turns/cursor-transcript.js +66 -0
- package/dist/turns/index.d.ts +17 -0
- package/dist/turns/index.js +7 -0
- package/dist/turns/transcript.d.ts +74 -0
- package/dist/turns/transcript.js +188 -0
- package/dist/turns/turn-state.d.ts +94 -0
- package/dist/turns/turn-state.js +234 -0
- package/dist/turns/turn-summary.d.ts +27 -0
- package/dist/turns/turn-summary.js +164 -0
- package/dist/turns/turn-tracker.d.ts +14 -0
- package/dist/turns/turn-tracker.js +521 -0
- package/dist/turns/types/aggregate-usage.types.d.ts +26 -0
- package/dist/turns/types/aggregate-usage.types.js +1 -0
- package/dist/turns/types/transcript.types.d.ts +41 -0
- package/dist/turns/types/transcript.types.js +1 -0
- package/dist/turns/types/turn-state.types.d.ts +37 -0
- package/dist/turns/types/turn-state.types.js +1 -0
- package/dist/turns/types/turn-summary.types.d.ts +106 -0
- package/dist/turns/types/turn-summary.types.js +1 -0
- package/dist/turns/types/turn-tracker.types.d.ts +27 -0
- package/dist/turns/types/turn-tracker.types.js +1 -0
- package/example/README.md +43 -0
- package/example/server.mjs +240 -0
- package/package.json +89 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { RepoSnapshotEvent } from '../../events/types/repo-snapshot.types.js';
|
|
2
|
+
import type { BranchRef, SnapshotBranch } from '../../git/types/snapshot.types.js';
|
|
3
|
+
import type { GitRunner } from '../../git/types/git.types.js';
|
|
4
|
+
/** What was last reported about one branch. */
|
|
5
|
+
export interface SnapshotStateEntry {
|
|
6
|
+
readonly headSha: string;
|
|
7
|
+
/** Epoch milliseconds, so an unchanged branch is still re-offered eventually. */
|
|
8
|
+
readonly lastSentAt: number;
|
|
9
|
+
}
|
|
10
|
+
/** What was last reported about one repository. */
|
|
11
|
+
export interface SnapshotState {
|
|
12
|
+
/**
|
|
13
|
+
* The default branch the last send computed its deltas against.
|
|
14
|
+
*
|
|
15
|
+
* Part of the state, not incidental: a clone that could not name its trunk
|
|
16
|
+
* sent every branch with no commits, and once `origin/HEAD` appears those
|
|
17
|
+
* branches have to be re-sent even though no head moved.
|
|
18
|
+
*/
|
|
19
|
+
readonly defaultBranch?: string;
|
|
20
|
+
readonly branches: Record<string, SnapshotStateEntry>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Who and where a snapshot is about: everything the event itself carries.
|
|
24
|
+
*
|
|
25
|
+
* Split from the flow's input so the builder cannot reach the git runner or the
|
|
26
|
+
* deadline — a field named `identity` that also holds a subprocess launcher is
|
|
27
|
+
* one a reader has to check rather than read.
|
|
28
|
+
*/
|
|
29
|
+
export interface SnapshotIdentity {
|
|
30
|
+
readonly repository: string;
|
|
31
|
+
readonly provider: string;
|
|
32
|
+
readonly surface: string;
|
|
33
|
+
readonly agentName: string;
|
|
34
|
+
readonly developerId?: string;
|
|
35
|
+
readonly installationId?: string;
|
|
36
|
+
readonly sessionId?: string;
|
|
37
|
+
readonly capturedAt: string;
|
|
38
|
+
}
|
|
39
|
+
/** Everything the snapshot flow needs to decide and build one event. */
|
|
40
|
+
export interface SnapshotFlowInput extends SnapshotIdentity {
|
|
41
|
+
readonly cwd: string;
|
|
42
|
+
readonly deadline: number;
|
|
43
|
+
readonly run: GitRunner;
|
|
44
|
+
}
|
|
45
|
+
/** What the selection compares, and what the write-back records. */
|
|
46
|
+
export interface SelectionInput {
|
|
47
|
+
readonly refs: readonly BranchRef[];
|
|
48
|
+
readonly stored: SnapshotState;
|
|
49
|
+
readonly defaultBranch?: string;
|
|
50
|
+
readonly now: number;
|
|
51
|
+
}
|
|
52
|
+
/** Identity, base branch and the branches one event describes. */
|
|
53
|
+
export interface BuildSnapshotInput {
|
|
54
|
+
readonly identity: SnapshotIdentity;
|
|
55
|
+
readonly defaultBranch?: string;
|
|
56
|
+
readonly branches: readonly SnapshotBranch[];
|
|
57
|
+
}
|
|
58
|
+
/** Everything one run of the flow needs beyond its own state. */
|
|
59
|
+
export interface SnapshotPipelineInput {
|
|
60
|
+
readonly input: SnapshotFlowInput;
|
|
61
|
+
readonly store: SnapshotStateReader;
|
|
62
|
+
readonly queue: SnapshotQueue;
|
|
63
|
+
}
|
|
64
|
+
/** State threaded through the snapshot flow's stages. */
|
|
65
|
+
export interface SnapshotFlowState {
|
|
66
|
+
readonly input: SnapshotFlowInput;
|
|
67
|
+
readonly store: SnapshotStateReader;
|
|
68
|
+
readonly queue: SnapshotQueue;
|
|
69
|
+
/** The budgeted runner every stage uses; built once, where the budget is set. */
|
|
70
|
+
readonly run: GitRunner;
|
|
71
|
+
readonly stored?: SnapshotState;
|
|
72
|
+
readonly defaultBranch?: string;
|
|
73
|
+
readonly refs: readonly BranchRef[];
|
|
74
|
+
readonly selected: readonly BranchRef[];
|
|
75
|
+
readonly branches: readonly SnapshotBranch[];
|
|
76
|
+
readonly event?: RepoSnapshotEvent;
|
|
77
|
+
}
|
|
78
|
+
/** The cache the flow reads and writes; narrowed so tests need no filesystem. */
|
|
79
|
+
export interface SnapshotStateReader {
|
|
80
|
+
read(repository: string): Promise<SnapshotState>;
|
|
81
|
+
write(repository: string, state: SnapshotState): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
/** The one thing the flow asks of the offline queue. */
|
|
84
|
+
export interface SnapshotQueue {
|
|
85
|
+
enqueue(events: readonly RepoSnapshotEvent[]): Promise<void>;
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write a file so readers never observe a partial one: temp file, fsync,
|
|
3
|
+
* rename.
|
|
4
|
+
*
|
|
5
|
+
* The fsync is not optional. `rename` orders metadata, not contents, so a
|
|
6
|
+
* crash shortly after it can leave the new name pointing at zero-length data.
|
|
7
|
+
*
|
|
8
|
+
* With no explicit mode the target's existing mode is preserved: renaming a
|
|
9
|
+
* default-mode temp file over a 0600 config must not loosen its permissions.
|
|
10
|
+
*
|
|
11
|
+
* @param filePath - Destination path; parent directories are created.
|
|
12
|
+
* @param contents - Full file contents.
|
|
13
|
+
* @param mode - Permission bits to force, or undefined to preserve the
|
|
14
|
+
* target's.
|
|
15
|
+
*/
|
|
16
|
+
export declare function writeFileAtomic(filePath: string, contents: string, mode?: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Copy a file into the backups directory before we mutate it.
|
|
19
|
+
*
|
|
20
|
+
* @param filePath - File about to be modified.
|
|
21
|
+
* @param backupsDir - Directory backups are collected in.
|
|
22
|
+
* @param now - Timestamp for the backup name.
|
|
23
|
+
* @returns The backup path, or undefined when there was nothing to copy.
|
|
24
|
+
*/
|
|
25
|
+
export declare function backupFile(filePath: string, backupsDir: string, now: Date): Promise<string | undefined>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { PERMISSION_MASK, RE_UNSAFE_STAMP_CHARS } from './constants/storage.constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* Write a file so readers never observe a partial one: temp file, fsync,
|
|
7
|
+
* rename.
|
|
8
|
+
*
|
|
9
|
+
* The fsync is not optional. `rename` orders metadata, not contents, so a
|
|
10
|
+
* crash shortly after it can leave the new name pointing at zero-length data.
|
|
11
|
+
*
|
|
12
|
+
* With no explicit mode the target's existing mode is preserved: renaming a
|
|
13
|
+
* default-mode temp file over a 0600 config must not loosen its permissions.
|
|
14
|
+
*
|
|
15
|
+
* @param filePath - Destination path; parent directories are created.
|
|
16
|
+
* @param contents - Full file contents.
|
|
17
|
+
* @param mode - Permission bits to force, or undefined to preserve the
|
|
18
|
+
* target's.
|
|
19
|
+
*/
|
|
20
|
+
export async function writeFileAtomic(filePath, contents, mode) {
|
|
21
|
+
const dir = path.dirname(filePath);
|
|
22
|
+
await fs.mkdir(dir, { recursive: true });
|
|
23
|
+
const effectiveMode = mode ?? (await currentMode(filePath));
|
|
24
|
+
const tmp = path.join(dir, `.${path.basename(filePath)}.${crypto.randomBytes(6).toString('hex')}.tmp`);
|
|
25
|
+
try {
|
|
26
|
+
const handle = await fs.open(tmp, 'w', effectiveMode);
|
|
27
|
+
try {
|
|
28
|
+
await handle.writeFile(contents);
|
|
29
|
+
await handle.sync();
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
await handle.close();
|
|
33
|
+
}
|
|
34
|
+
await fs.rename(tmp, filePath);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
await fs.rm(tmp, { force: true });
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Copy a file into the backups directory before we mutate it.
|
|
43
|
+
*
|
|
44
|
+
* @param filePath - File about to be modified.
|
|
45
|
+
* @param backupsDir - Directory backups are collected in.
|
|
46
|
+
* @param now - Timestamp for the backup name.
|
|
47
|
+
* @returns The backup path, or undefined when there was nothing to copy.
|
|
48
|
+
*/
|
|
49
|
+
export async function backupFile(filePath, backupsDir, now) {
|
|
50
|
+
const sourceMode = await currentMode(filePath);
|
|
51
|
+
if (sourceMode === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
await fs.mkdir(backupsDir, { recursive: true });
|
|
54
|
+
const stamp = now.toISOString().replace(RE_UNSAFE_STAMP_CHARS, '-');
|
|
55
|
+
const target = path.join(backupsDir, `${path.basename(filePath)}.${stamp}.bak`);
|
|
56
|
+
await fs.copyFile(filePath, target);
|
|
57
|
+
// A backup of a credential-bearing file must never end up more readable
|
|
58
|
+
// than the file it copies, whatever the platform's copy semantics.
|
|
59
|
+
await fs.chmod(target, sourceMode);
|
|
60
|
+
return target;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Permission bits of an existing file.
|
|
64
|
+
*
|
|
65
|
+
* @param filePath - File to inspect.
|
|
66
|
+
* @returns Its mode, or undefined when the file does not exist.
|
|
67
|
+
*/
|
|
68
|
+
async function currentMode(filePath) {
|
|
69
|
+
try {
|
|
70
|
+
return (await fs.stat(filePath)).mode & PERMISSION_MASK;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// New file: the platform default applies.
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Directory name AgentWatch owns under $HOME. */
|
|
2
|
+
export declare const AGENTWATCH_DIR_NAME = "agentwatch";
|
|
3
|
+
export declare const AGENTWATCH_HOME_DIR_NAME = ".agentwatch";
|
|
4
|
+
/** Environment overrides for the two roots, used by the test suite. */
|
|
5
|
+
export declare const CONFIG_DIR_VAR = "AGENTWATCH_CONFIG_DIR";
|
|
6
|
+
export declare const DATA_DIR_VAR = "AGENTWATCH_DATA_DIR";
|
|
7
|
+
export declare const CONFIG_FILE_NAME = "config.json";
|
|
8
|
+
export declare const INSTALL_STATE_FILE_NAME = "install-state.json";
|
|
9
|
+
/** Sub-directories of the data root. */
|
|
10
|
+
export declare const QUEUE_DIR_NAME = "queue";
|
|
11
|
+
export declare const LOCKS_DIR_NAME = "locks";
|
|
12
|
+
export declare const BACKUPS_DIR_NAME = "backups";
|
|
13
|
+
export declare const TURNS_DIR_NAME = "turns";
|
|
14
|
+
/** What the last repository snapshot reported, so the next one can send only changes. */
|
|
15
|
+
export declare const SNAPSHOTS_DIR_NAME = "snapshots";
|
|
16
|
+
/** XDG / Windows locations consulted for the data root, in order. */
|
|
17
|
+
export declare const LOCAL_APP_DATA_VAR = "LOCALAPPDATA";
|
|
18
|
+
export declare const XDG_DATA_HOME_VAR = "XDG_DATA_HOME";
|
|
19
|
+
export declare const POSIX_DATA_FALLBACK: string;
|
|
20
|
+
/**
|
|
21
|
+
* Files that may hold a backend token or raw prompt text are owner-only.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SECRET_FILE_MODE = 384;
|
|
24
|
+
/** Mask isolating the permission bits of a stat mode. */
|
|
25
|
+
export declare const PERMISSION_MASK = 511;
|
|
26
|
+
/**
|
|
27
|
+
* Locks older than this are broken: hook processes are short-lived and can die
|
|
28
|
+
* abruptly, and a leaked lock file must not stall every later hook forever.
|
|
29
|
+
*/
|
|
30
|
+
export declare const STALE_LOCK_MS = 30000;
|
|
31
|
+
/** Attempts one acquireLock call makes, including breaking one stale lock. */
|
|
32
|
+
export declare const LOCK_ACQUIRE_ATTEMPTS = 2;
|
|
33
|
+
/** Characters that are unsafe in a timestamped backup filename. */
|
|
34
|
+
export declare const RE_UNSAFE_STAMP_CHARS: RegExp;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/** Directory name AgentWatch owns under $HOME. */
|
|
3
|
+
export const AGENTWATCH_DIR_NAME = 'agentwatch';
|
|
4
|
+
export const AGENTWATCH_HOME_DIR_NAME = '.agentwatch';
|
|
5
|
+
/** Environment overrides for the two roots, used by the test suite. */
|
|
6
|
+
export const CONFIG_DIR_VAR = 'AGENTWATCH_CONFIG_DIR';
|
|
7
|
+
export const DATA_DIR_VAR = 'AGENTWATCH_DATA_DIR';
|
|
8
|
+
export const CONFIG_FILE_NAME = 'config.json';
|
|
9
|
+
export const INSTALL_STATE_FILE_NAME = 'install-state.json';
|
|
10
|
+
/** Sub-directories of the data root. */
|
|
11
|
+
export const QUEUE_DIR_NAME = 'queue';
|
|
12
|
+
export const LOCKS_DIR_NAME = 'locks';
|
|
13
|
+
export const BACKUPS_DIR_NAME = 'backups';
|
|
14
|
+
export const TURNS_DIR_NAME = 'turns';
|
|
15
|
+
/** What the last repository snapshot reported, so the next one can send only changes. */
|
|
16
|
+
export const SNAPSHOTS_DIR_NAME = 'snapshots';
|
|
17
|
+
/** XDG / Windows locations consulted for the data root, in order. */
|
|
18
|
+
export const LOCAL_APP_DATA_VAR = 'LOCALAPPDATA';
|
|
19
|
+
export const XDG_DATA_HOME_VAR = 'XDG_DATA_HOME';
|
|
20
|
+
export const POSIX_DATA_FALLBACK = path.join('.local', 'share');
|
|
21
|
+
/**
|
|
22
|
+
* Files that may hold a backend token or raw prompt text are owner-only.
|
|
23
|
+
*/
|
|
24
|
+
export const SECRET_FILE_MODE = 0o600;
|
|
25
|
+
/** Mask isolating the permission bits of a stat mode. */
|
|
26
|
+
export const PERMISSION_MASK = 0o777;
|
|
27
|
+
/**
|
|
28
|
+
* Locks older than this are broken: hook processes are short-lived and can die
|
|
29
|
+
* abruptly, and a leaked lock file must not stall every later hook forever.
|
|
30
|
+
*/
|
|
31
|
+
export const STALE_LOCK_MS = 30_000;
|
|
32
|
+
/** Attempts one acquireLock call makes, including breaking one stale lock. */
|
|
33
|
+
export const LOCK_ACQUIRE_ATTEMPTS = 2;
|
|
34
|
+
/** Characters that are unsafe in a timestamped backup filename. */
|
|
35
|
+
export const RE_UNSAFE_STAMP_CHARS = /[:.]/g;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable local state: where it lives, and how it is read and written without
|
|
3
|
+
* ever leaving a half-file or clobbering something we could not parse.
|
|
4
|
+
*/
|
|
5
|
+
export type { AgentInstallState, AgentWatchPaths, InstallState, JsonReadResult, ReleaseLock } from './types/storage.types.js';
|
|
6
|
+
export { resolvePaths } from './paths.js';
|
|
7
|
+
export { readJsonFile } from './json-file.js';
|
|
8
|
+
export { backupFile, writeFileAtomic } from './atomic-file.js';
|
|
9
|
+
export { acquireLock } from './lock.js';
|
|
10
|
+
export { loadInstallState, saveInstallState } from './install-state.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { resolvePaths } from './paths.js';
|
|
2
|
+
export { readJsonFile } from './json-file.js';
|
|
3
|
+
export { backupFile, writeFileAtomic } from './atomic-file.js';
|
|
4
|
+
export { acquireLock } from './lock.js';
|
|
5
|
+
export { loadInstallState, saveInstallState } from './install-state.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AgentWatchPaths, InstallState } from './types/storage.types.js';
|
|
2
|
+
export type { AgentInstallState, InstallState } from './types/storage.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read what setup previously wrote into agent configs.
|
|
5
|
+
*
|
|
6
|
+
* Never fails: a missing or corrupt state file degrades to "nothing
|
|
7
|
+
* installed", which makes the next setup re-register hooks rather than leave
|
|
8
|
+
* the user with an agent nobody is watching.
|
|
9
|
+
*
|
|
10
|
+
* @param paths - Resolved AgentWatch paths.
|
|
11
|
+
* @returns The stored state, or an empty one.
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadInstallState(paths: AgentWatchPaths): Promise<InstallState>;
|
|
14
|
+
/**
|
|
15
|
+
* Persist install state atomically.
|
|
16
|
+
*
|
|
17
|
+
* @param paths - Resolved AgentWatch paths.
|
|
18
|
+
* @param state - State to write.
|
|
19
|
+
*/
|
|
20
|
+
export declare function saveInstallState(paths: AgentWatchPaths, state: InstallState): Promise<void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readJsonFile } from './json-file.js';
|
|
2
|
+
import { writeFileAtomic } from './atomic-file.js';
|
|
3
|
+
import { SECRET_FILE_MODE } from './constants/storage.constants.js';
|
|
4
|
+
import { installStateSchema } from './schemas/storage.schema.js';
|
|
5
|
+
/**
|
|
6
|
+
* Read what setup previously wrote into agent configs.
|
|
7
|
+
*
|
|
8
|
+
* Never fails: a missing or corrupt state file degrades to "nothing
|
|
9
|
+
* installed", which makes the next setup re-register hooks rather than leave
|
|
10
|
+
* the user with an agent nobody is watching.
|
|
11
|
+
*
|
|
12
|
+
* @param paths - Resolved AgentWatch paths.
|
|
13
|
+
* @returns The stored state, or an empty one.
|
|
14
|
+
*/
|
|
15
|
+
export async function loadInstallState(paths) {
|
|
16
|
+
const result = await readJsonFile(paths.installStateFile);
|
|
17
|
+
if (result.state !== 'ok')
|
|
18
|
+
return emptyInstallState();
|
|
19
|
+
const parsed = installStateSchema.safeParse(result.value);
|
|
20
|
+
if (!parsed.success)
|
|
21
|
+
return emptyInstallState();
|
|
22
|
+
return parsed.data;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Persist install state atomically.
|
|
26
|
+
*
|
|
27
|
+
* @param paths - Resolved AgentWatch paths.
|
|
28
|
+
* @param state - State to write.
|
|
29
|
+
*/
|
|
30
|
+
export async function saveInstallState(paths, state) {
|
|
31
|
+
await writeFileAtomic(paths.installStateFile, JSON.stringify(state, null, 2) + '\n', SECRET_FILE_MODE);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A state file describing no installation at all.
|
|
35
|
+
*
|
|
36
|
+
* @returns A fresh empty state.
|
|
37
|
+
*/
|
|
38
|
+
function emptyInstallState() {
|
|
39
|
+
return { schemaVersion: 1, agents: {} };
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JsonReadResult } from './types/storage.types.js';
|
|
2
|
+
export type { JsonReadResult } from './types/storage.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Tolerant JSON read.
|
|
5
|
+
*
|
|
6
|
+
* A missing file is normal (nothing is installed yet); an unparseable file is
|
|
7
|
+
* *reported* rather than treated as empty, because every caller's next move
|
|
8
|
+
* would otherwise be to overwrite a config it could not understand.
|
|
9
|
+
*
|
|
10
|
+
* @param filePath - File to read.
|
|
11
|
+
* @returns Missing, invalid with a reason, or the decoded value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readJsonFile(filePath: string): Promise<JsonReadResult>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
/**
|
|
3
|
+
* Tolerant JSON read.
|
|
4
|
+
*
|
|
5
|
+
* A missing file is normal (nothing is installed yet); an unparseable file is
|
|
6
|
+
* *reported* rather than treated as empty, because every caller's next move
|
|
7
|
+
* would otherwise be to overwrite a config it could not understand.
|
|
8
|
+
*
|
|
9
|
+
* @param filePath - File to read.
|
|
10
|
+
* @returns Missing, invalid with a reason, or the decoded value.
|
|
11
|
+
*/
|
|
12
|
+
export async function readJsonFile(filePath) {
|
|
13
|
+
let raw;
|
|
14
|
+
try {
|
|
15
|
+
raw = await fs.readFile(filePath, 'utf8');
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
const code = error.code;
|
|
19
|
+
if (code === 'ENOENT')
|
|
20
|
+
return { state: 'missing' };
|
|
21
|
+
return { state: 'invalid', error: `unreadable: ${error.message}` };
|
|
22
|
+
}
|
|
23
|
+
if (raw.trim() === '')
|
|
24
|
+
return { state: 'missing' };
|
|
25
|
+
try {
|
|
26
|
+
return { state: 'ok', value: JSON.parse(raw) };
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return { state: 'invalid', error: `invalid JSON: ${error.message}` };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReleaseLock } from './types/storage.types.js';
|
|
2
|
+
export type { ReleaseLock } from './types/storage.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Best-effort advisory lock built on `O_CREAT|O_EXCL`.
|
|
5
|
+
*
|
|
6
|
+
* Hook processes are short-lived and can die abruptly, so a lock older than
|
|
7
|
+
* STALE_LOCK_MS is broken and retried once — otherwise one crashed hook would
|
|
8
|
+
* stall every later one for good.
|
|
9
|
+
*
|
|
10
|
+
* @param locksDir - Directory lock files live in; created if absent.
|
|
11
|
+
* @param name - Lock name; one file per name.
|
|
12
|
+
* @param now - Clock, injectable for tests.
|
|
13
|
+
* @returns A release function, or undefined when the lock is held elsewhere.
|
|
14
|
+
*/
|
|
15
|
+
export declare function acquireLock(locksDir: string, name: string, now?: () => Date): Promise<ReleaseLock | undefined>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { LOCK_ACQUIRE_ATTEMPTS, STALE_LOCK_MS } from './constants/storage.constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* Best-effort advisory lock built on `O_CREAT|O_EXCL`.
|
|
7
|
+
*
|
|
8
|
+
* Hook processes are short-lived and can die abruptly, so a lock older than
|
|
9
|
+
* STALE_LOCK_MS is broken and retried once — otherwise one crashed hook would
|
|
10
|
+
* stall every later one for good.
|
|
11
|
+
*
|
|
12
|
+
* @param locksDir - Directory lock files live in; created if absent.
|
|
13
|
+
* @param name - Lock name; one file per name.
|
|
14
|
+
* @param now - Clock, injectable for tests.
|
|
15
|
+
* @returns A release function, or undefined when the lock is held elsewhere.
|
|
16
|
+
*/
|
|
17
|
+
export async function acquireLock(locksDir, name, now = () => new Date()) {
|
|
18
|
+
await fs.mkdir(locksDir, { recursive: true });
|
|
19
|
+
const lockPath = path.join(locksDir, `${name}.lock`);
|
|
20
|
+
for (let attempt = 0; attempt < LOCK_ACQUIRE_ATTEMPTS; attempt++) {
|
|
21
|
+
const acquired = await tryCreateLock(lockPath, now);
|
|
22
|
+
if (acquired === 'held')
|
|
23
|
+
return () => fs.rm(lockPath, { force: true });
|
|
24
|
+
if (acquired === 'taken')
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One attempt at creating the lock file, breaking it when it is stale.
|
|
31
|
+
*
|
|
32
|
+
* @param lockPath - Lock file path.
|
|
33
|
+
* @param now - Clock used for the stamp and the staleness check.
|
|
34
|
+
* @returns `held` on success, `taken` when someone else owns a fresh lock,
|
|
35
|
+
* `retry` when a stale lock was broken and the caller should try again.
|
|
36
|
+
*/
|
|
37
|
+
async function tryCreateLock(lockPath, now) {
|
|
38
|
+
try {
|
|
39
|
+
const handle = await fs.open(lockPath, 'wx');
|
|
40
|
+
await handle.writeFile(JSON.stringify({ pid: process.pid, at: now().toISOString() }));
|
|
41
|
+
await handle.close();
|
|
42
|
+
return 'held';
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error.code !== 'EEXIST')
|
|
46
|
+
throw error;
|
|
47
|
+
return breakIfStale(lockPath, now);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Remove a lock whose owner is presumed dead.
|
|
52
|
+
*
|
|
53
|
+
* @param lockPath - Lock file path.
|
|
54
|
+
* @param now - Clock the age is measured against.
|
|
55
|
+
* @returns `retry` when the lock was broken or vanished, `taken` when it is
|
|
56
|
+
* still fresh.
|
|
57
|
+
*/
|
|
58
|
+
async function breakIfStale(lockPath, now) {
|
|
59
|
+
try {
|
|
60
|
+
const stat = await fs.stat(lockPath);
|
|
61
|
+
if (now().getTime() - stat.mtimeMs <= STALE_LOCK_MS)
|
|
62
|
+
return 'taken';
|
|
63
|
+
await fs.rm(lockPath, { force: true });
|
|
64
|
+
return 'retry';
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// The lock vanished between open and stat; the next attempt can have it.
|
|
68
|
+
return 'retry';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Env } from '../core/env.js';
|
|
2
|
+
import type { AgentWatchPaths } from './types/storage.types.js';
|
|
3
|
+
export type { AgentWatchPaths } from './types/storage.types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Every path AgentWatch reads or writes, derived from the environment alone.
|
|
6
|
+
*
|
|
7
|
+
* Config and data are deliberately separate roots: config is small, precious
|
|
8
|
+
* and backed up by the user, while data (queue, locks, per-turn state) is
|
|
9
|
+
* disposable and follows the platform's cache/state conventions.
|
|
10
|
+
*
|
|
11
|
+
* @param env - Environment supplying HOME, the platform and any overrides.
|
|
12
|
+
* @returns The resolved path set.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolvePaths(env: Env): AgentWatchPaths;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { AGENTWATCH_DIR_NAME, AGENTWATCH_HOME_DIR_NAME, BACKUPS_DIR_NAME, CONFIG_DIR_VAR, CONFIG_FILE_NAME, DATA_DIR_VAR, INSTALL_STATE_FILE_NAME, LOCAL_APP_DATA_VAR, LOCKS_DIR_NAME, POSIX_DATA_FALLBACK, QUEUE_DIR_NAME, SNAPSHOTS_DIR_NAME, TURNS_DIR_NAME, XDG_DATA_HOME_VAR } from './constants/storage.constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Every path AgentWatch reads or writes, derived from the environment alone.
|
|
5
|
+
*
|
|
6
|
+
* Config and data are deliberately separate roots: config is small, precious
|
|
7
|
+
* and backed up by the user, while data (queue, locks, per-turn state) is
|
|
8
|
+
* disposable and follows the platform's cache/state conventions.
|
|
9
|
+
*
|
|
10
|
+
* @param env - Environment supplying HOME, the platform and any overrides.
|
|
11
|
+
* @returns The resolved path set.
|
|
12
|
+
*/
|
|
13
|
+
export function resolvePaths(env) {
|
|
14
|
+
const configDir = env.vars[CONFIG_DIR_VAR] ?? path.join(env.home, AGENTWATCH_HOME_DIR_NAME);
|
|
15
|
+
const dataDir = env.vars[DATA_DIR_VAR] ?? defaultDataDir(env);
|
|
16
|
+
return {
|
|
17
|
+
configDir,
|
|
18
|
+
configFile: path.join(configDir, CONFIG_FILE_NAME),
|
|
19
|
+
installStateFile: path.join(configDir, INSTALL_STATE_FILE_NAME),
|
|
20
|
+
dataDir,
|
|
21
|
+
queueDir: path.join(dataDir, QUEUE_DIR_NAME),
|
|
22
|
+
locksDir: path.join(dataDir, LOCKS_DIR_NAME),
|
|
23
|
+
backupsDir: path.join(dataDir, BACKUPS_DIR_NAME),
|
|
24
|
+
turnsDir: path.join(dataDir, TURNS_DIR_NAME),
|
|
25
|
+
snapshotsDir: path.join(dataDir, SNAPSHOTS_DIR_NAME)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Platform-conventional location for disposable state.
|
|
30
|
+
*
|
|
31
|
+
* @param env - Environment supplying the platform and HOME.
|
|
32
|
+
* @returns Absolute data directory.
|
|
33
|
+
*/
|
|
34
|
+
function defaultDataDir(env) {
|
|
35
|
+
const localAppData = env.vars[LOCAL_APP_DATA_VAR];
|
|
36
|
+
if (env.platform === 'win32' && localAppData)
|
|
37
|
+
return path.join(localAppData, AGENTWATCH_DIR_NAME);
|
|
38
|
+
const xdg = env.vars[XDG_DATA_HOME_VAR];
|
|
39
|
+
if (xdg)
|
|
40
|
+
return path.join(xdg, AGENTWATCH_DIR_NAME);
|
|
41
|
+
return path.join(env.home, POSIX_DATA_FALLBACK, AGENTWATCH_DIR_NAME);
|
|
42
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Records exactly what `agentwatch setup` wrote into one agent's native
|
|
4
|
+
* configuration, so uninstall removes only AgentWatch-owned entries.
|
|
5
|
+
*
|
|
6
|
+
* Passthrough: a state file written by a newer version must survive a
|
|
7
|
+
* downgrade with its unknown fields intact.
|
|
8
|
+
*/
|
|
9
|
+
export declare const agentInstallSchema: z.ZodObject<{
|
|
10
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
11
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
12
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
13
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
14
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
15
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
16
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
17
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
18
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
19
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
20
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
21
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
22
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
23
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
24
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
25
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
26
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
27
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
28
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
29
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
30
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
31
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
32
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
33
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
34
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
35
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
36
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
37
|
+
/** The whole install-state file: one entry per agent. */
|
|
38
|
+
export declare const installStateSchema: z.ZodObject<{
|
|
39
|
+
schemaVersion: z.ZodDefault<z.ZodLiteral<1>>;
|
|
40
|
+
agents: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
41
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
42
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
43
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
44
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
45
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
46
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
47
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
48
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
49
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
50
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
51
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
52
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
53
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
54
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
55
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
56
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
57
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
58
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
59
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
60
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
61
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
62
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
63
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
64
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
65
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
66
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
67
|
+
}, z.ZodTypeAny, "passthrough">>>>;
|
|
68
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
69
|
+
schemaVersion: z.ZodDefault<z.ZodLiteral<1>>;
|
|
70
|
+
agents: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
71
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
72
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
73
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
74
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
75
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
76
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
77
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
78
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
79
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
80
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
81
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
82
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
83
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
84
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
85
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
86
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
87
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
88
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
89
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
90
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
91
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
92
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
93
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
94
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
95
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
96
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
97
|
+
}, z.ZodTypeAny, "passthrough">>>>;
|
|
98
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
99
|
+
schemaVersion: z.ZodDefault<z.ZodLiteral<1>>;
|
|
100
|
+
agents: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
101
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
102
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
103
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
104
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
105
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
106
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
107
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
108
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
109
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
110
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
111
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
112
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
113
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
114
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
115
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
116
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
117
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
118
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
119
|
+
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
120
|
+
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
121
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
122
|
+
hookCommand: z.ZodOptional<z.ZodString>;
|
|
123
|
+
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
124
|
+
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
125
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
126
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
127
|
+
}, z.ZodTypeAny, "passthrough">>>>;
|
|
128
|
+
}, z.ZodTypeAny, "passthrough">>;
|