@agentxm/workspace-operations 0.28.4-bootstrap.0

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 (45) hide show
  1. package/LICENSE +110 -0
  2. package/README.md +12 -0
  3. package/dist/src/index.d.ts +31 -0
  4. package/dist/src/index.js +42 -0
  5. package/dist/src/live.d.ts +13 -0
  6. package/dist/src/live.js +12 -0
  7. package/dist/src/operations/augment-plan.d.ts +25 -0
  8. package/dist/src/operations/augment-plan.js +51 -0
  9. package/dist/src/operations/load-workspace.d.ts +43 -0
  10. package/dist/src/operations/load-workspace.js +77 -0
  11. package/dist/src/operations/scan-plan-readiness.d.ts +22 -0
  12. package/dist/src/operations/scan-plan-readiness.js +41 -0
  13. package/dist/src/operations/transaction.d.ts +58 -0
  14. package/dist/src/operations/transaction.js +359 -0
  15. package/dist/src/operations/transition-lock.d.ts +66 -0
  16. package/dist/src/operations/transition-lock.js +291 -0
  17. package/dist/src/plan/apply-plan.d.ts +45 -0
  18. package/dist/src/plan/apply-plan.js +238 -0
  19. package/dist/src/plan/errors.d.ts +85 -0
  20. package/dist/src/plan/errors.js +101 -0
  21. package/dist/src/plan/execution-candidate.d.ts +20 -0
  22. package/dist/src/plan/execution-candidate.js +95 -0
  23. package/dist/src/plan/interruption-signal.d.ts +18 -0
  24. package/dist/src/plan/interruption-signal.js +13 -0
  25. package/dist/src/plan/job-step-message.d.ts +7 -0
  26. package/dist/src/plan/job-step-message.js +7 -0
  27. package/dist/src/plan/operation-events.d.ts +62 -0
  28. package/dist/src/plan/operation-events.js +41 -0
  29. package/dist/src/plan/operation-journal.d.ts +69 -0
  30. package/dist/src/plan/operation-journal.js +52 -0
  31. package/dist/src/plan/operation-resolution.d.ts +219 -0
  32. package/dist/src/plan/operation-resolution.js +324 -0
  33. package/dist/src/plan/plan-execution.d.ts +75 -0
  34. package/dist/src/plan/plan-execution.js +117 -0
  35. package/dist/src/plan/plan.d.ts +248 -0
  36. package/dist/src/plan/plan.js +95 -0
  37. package/dist/src/plan/resolve-plan-interaction.d.ts +79 -0
  38. package/dist/src/plan/resolve-plan-interaction.js +52 -0
  39. package/dist/src/plan/resolve-plan.d.ts +42 -0
  40. package/dist/src/plan/resolve-plan.js +694 -0
  41. package/dist/src/plan/step-failure-conversions.d.ts +33 -0
  42. package/dist/src/plan/step-failure-conversions.js +177 -0
  43. package/dist/src/testing.d.ts +11 -0
  44. package/dist/src/testing.js +11 -0
  45. package/package.json +61 -0
package/LICENSE ADDED
@@ -0,0 +1,110 @@
1
+ # Functional Source License, Version 1.1, MIT Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-MIT
6
+
7
+ ## Notice
8
+
9
+ Copyright 2025-2026 AgentXM, Inc.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the MIT license that is effective on the second anniversary of the date we make
91
+ the Software available. On or after that date, you may use the Software under
92
+ the MIT license, in which case the following will apply:
93
+
94
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
95
+ this software and associated documentation files (the "Software"), to deal in
96
+ the Software without restriction, including without limitation the rights to
97
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98
+ of the Software, and to permit persons to whom the Software is furnished to do
99
+ so, subject to the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be included in all
102
+ copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
106
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
107
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
108
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
109
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @agentxm/workspace-operations
2
+
3
+ The AXM workspace-operations kernel: plan vocabulary and execution, operation
4
+ resolutions and journals, plan readiness and reconciliation gating, and the
5
+ workspace transaction and transition-lock machinery.
6
+
7
+ The package root is the public API; the composed workspace layer lives behind
8
+ `./live`, and deterministic in-memory test layers behind `./testing`. The
9
+ surface is unsupported and may change in any release. Ordinary users should
10
+ use the [`axm` CLI](https://axm.sh) instead.
11
+
12
+ Part of the [AgentXM](https://agentxm.ai) toolchain.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @agentxm/workspace-operations public API.
3
+ *
4
+ * The workspace-operations kernel: plan vocabulary and execution, the
5
+ * interactive preview/apply orchestration (`previewOrApplyPlan`), operation
6
+ * resolutions and journals, plan readiness and reconciliation gating, and the
7
+ * workspace transaction and transition-lock machinery. The composed workspace
8
+ * layer lives behind `./live`.
9
+ *
10
+ * @experimental This API is unstable and may change without notice.
11
+ * @packageDocumentation
12
+ */
13
+ export { BlockingClassSchema, defaultOperationPresentation, operationPresentation, presentationOf, ArtifactMechanismSchema, OperationPreconditionSchema, PlanPolicyIdSchema, PlanPolicyIds, PlanRiskConditionSchema, } from "./plan/plan.js";
14
+ export type { ArtifactMechanism, BlockingClass, CompletedJobStep, ErrorJobStep, ExecutedJob, ExecutedPlan, Job, JobStepArtifact, JobStepArtifactSource, JobStepArtifactTarget, JobStepResult, Operation, OperationPrecondition, OperationPresentation, Plan, PlanPolicyId, PlanRiskCondition, PlannedJobStep, ReadyJobStep, RegistryLifecycleEvidence, UnitBlocking, WarnJobStep, } from "./plan/plan.js";
15
+ export { AtomicityClassSchema, OperationOutcomeSchema, OperationPhaseSchema, UnitDispositionSchema, UnitStateSchema, countUnitStates, declaredAtomicity, deriveOperationOutcome, executedUnits, makeOperationResolution, plannedUnits, unitIdOf, unitsByStableIdentity, } from "./plan/operation-resolution.js";
16
+ export type { AtomicityClass, MakeOperationResolutionArgs, OperationAtomicity, OperationBlock, OperationFootprintEntry, OperationInterruption, OperationOutcome, OperationPhase, OperationRecovery, OperationResolution, ResolvedUnit, UnitDisposition, UnitState, UnitStateCounts, } from "./plan/operation-resolution.js";
17
+ export { OperationJournal, appendResolvedUnit, appendStartedUnit, recordJournalPhase, getOperationJournal, makeOperationJournal, recordOperationJournal, updateOperationJournal, type OperationJournalService, type OperationJournalState, } from "./plan/operation-journal.js";
18
+ export { applyPlan, type ApplyPlanOptions, type OperationHandler } from "./plan/apply-plan.js";
19
+ export { OperationLifecycle, makeOperationLifecycle, publishLifecycleEvent, publishPhaseStarted, subscribeToLifecycle, type OperationLifecycleEvent, type OperationLifecycleService, } from "./plan/operation-events.js";
20
+ export { ApprovalRecoveryMissing, CandidateFingerprintFailed, OPERATION_ERROR_CATEGORIES, OperationErrorCategorySchema, PlanInteractionFailed, STALE_CANDIDATE_DETAIL, StaleExecutionCandidate, StepFailure, type OperationErrorCategory, } from "./plan/errors.js";
21
+ export { previewOrApplyPlan } from "./plan/resolve-plan.js";
22
+ export { ResolvePlanInteraction, type ApplyConfirmation, type ResolvePlanInteractionService, } from "./plan/resolve-plan-interaction.js";
23
+ export { InterruptionSignalSource, type InterruptionSignalSourceService, } from "./plan/interruption-signal.js";
24
+ export { isExecutionCandidateFresh, makeExecutionCandidate, type ExecutionCandidate, } from "./plan/execution-candidate.js";
25
+ export { applyPlanExecution, confirmationRecoverySuggestions, namedPolicyRecoverySuggestions, credentialFreeLocatorRecoveryValue, preapprovedPlanExecution, promptablePlanExecution, previewPlanExecution, protectedRecoveryValue, publicRecoveryValue, recoveryOption, recoveryPositional, recoverySwitch, renderConfirmationRecoveryCommand, unclassifiedRecoveryValue, type ConfirmationRecovery, type ConfirmationRecoveryArgument, type ConfirmationRecoveryValue, type ConfiguredAgentOperation, type PlanExecution, type PlanExecutionRequest, } from "./plan/plan-execution.js";
26
+ export * from "./plan/job-step-message.js";
27
+ export { scanPlanReadiness, type PlanReadinessReport } from "./operations/scan-plan-readiness.js";
28
+ export { augmentPlanWithReconciliation, type AugmentedPlanResult, type DegradedLockfileState, } from "./operations/augment-plan.js";
29
+ export { rollbackWorkspaceClosure, runWorkspaceTransaction, settleWorkspaceClosure, withWorkspaceClosure, type WorkspaceTransactionArgs, } from "./operations/transaction.js";
30
+ export { TRANSITION_WAIT_BOUND_MILLIS, acquireWorkspaceTransitionLock, heldWorkspaceTransition, isWorkspaceTransitionHeldByThisInvocation, transitionLockPath, type HeldWorkspaceTransition, } from "./operations/transition-lock.js";
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @agentxm/workspace-operations public API.
3
+ *
4
+ * The workspace-operations kernel: plan vocabulary and execution, the
5
+ * interactive preview/apply orchestration (`previewOrApplyPlan`), operation
6
+ * resolutions and journals, plan readiness and reconciliation gating, and the
7
+ * workspace transaction and transition-lock machinery. The composed workspace
8
+ * layer lives behind `./live`.
9
+ *
10
+ * @experimental This API is unstable and may change without notice.
11
+ * @packageDocumentation
12
+ */
13
+ // Plan types
14
+ export { BlockingClassSchema, defaultOperationPresentation, operationPresentation, presentationOf, ArtifactMechanismSchema, OperationPreconditionSchema, PlanPolicyIdSchema, PlanPolicyIds, PlanRiskConditionSchema, } from "./plan/plan.js";
15
+ // Operation resolution — the single value every plan-family command
16
+ // terminates with, with its pure outcome derivations.
17
+ export { AtomicityClassSchema, OperationOutcomeSchema, OperationPhaseSchema, UnitDispositionSchema, UnitStateSchema, countUnitStates, declaredAtomicity, deriveOperationOutcome, executedUnits, makeOperationResolution, plannedUnits, unitIdOf, unitsByStableIdentity, } from "./plan/operation-resolution.js";
18
+ // Operation journal — invocation-scoped progress record for interruption.
19
+ export { OperationJournal, appendResolvedUnit, appendStartedUnit, recordJournalPhase, getOperationJournal, makeOperationJournal, recordOperationJournal, updateOperationJournal, } from "./plan/operation-journal.js";
20
+ // Apply plan + operation handler registry
21
+ export { applyPlan } from "./plan/apply-plan.js";
22
+ export { OperationLifecycle, makeOperationLifecycle, publishLifecycleEvent, publishPhaseStarted, subscribeToLifecycle, } from "./plan/operation-events.js";
23
+ // Serialized error vocabulary and the plan-family tagged errors.
24
+ export { ApprovalRecoveryMissing, CandidateFingerprintFailed, OPERATION_ERROR_CATEGORIES, OperationErrorCategorySchema, PlanInteractionFailed, STALE_CANDIDATE_DETAIL, StaleExecutionCandidate, StepFailure, } from "./plan/errors.js";
25
+ // Interactive preview/apply orchestration over the workspace read model.
26
+ export { previewOrApplyPlan } from "./plan/resolve-plan.js";
27
+ // Interaction port for preview/apply presentation, progress, and confirmation.
28
+ // The CLI runtime provides the Live implementation.
29
+ export { ResolvePlanInteraction, } from "./plan/resolve-plan-interaction.js";
30
+ export { InterruptionSignalSource, } from "./plan/interruption-signal.js";
31
+ export { isExecutionCandidateFresh, makeExecutionCandidate, } from "./plan/execution-candidate.js";
32
+ export { applyPlanExecution, confirmationRecoverySuggestions, namedPolicyRecoverySuggestions, credentialFreeLocatorRecoveryValue, preapprovedPlanExecution, promptablePlanExecution, previewPlanExecution, protectedRecoveryValue, publicRecoveryValue, recoveryOption, recoveryPositional, recoverySwitch, renderConfirmationRecoveryCommand, unclassifiedRecoveryValue, } from "./plan/plan-execution.js";
33
+ // Job step messaging
34
+ export * from "./plan/job-step-message.js";
35
+ // Plan readiness and reconciliation gating
36
+ export { scanPlanReadiness } from "./operations/scan-plan-readiness.js";
37
+ export { augmentPlanWithReconciliation, } from "./operations/augment-plan.js";
38
+ // Workspace transaction runner and closure lifecycle
39
+ export { rollbackWorkspaceClosure, runWorkspaceTransaction, settleWorkspaceClosure, withWorkspaceClosure, } from "./operations/transaction.js";
40
+ // Transition lock runtime
41
+ export { TRANSITION_WAIT_BOUND_MILLIS, acquireWorkspaceTransitionLock, heldWorkspaceTransition, isWorkspaceTransitionHeldByThisInvocation, transitionLockPath, } from "./operations/transition-lock.js";
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @agentxm/workspace-operations environment-backed composition.
3
+ *
4
+ * The composed workspace layer every entry point provides. Only application
5
+ * composition roots import this module; feature logic keeps
6
+ * `WorkspaceMutations` in its Effect environment.
7
+ *
8
+ * @experimental This API is unstable and may change without notice.
9
+ * @packageDocumentation
10
+ */
11
+ export { layer, loadWorkspace, makeWorkspaceTransactionCapabilities, } from "./operations/load-workspace.js";
12
+ export type { WorkspaceLayerOptions } from "@agentxm/workspace-state";
13
+ //# sourceMappingURL=live.d.ts.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @agentxm/workspace-operations environment-backed composition.
3
+ *
4
+ * The composed workspace layer every entry point provides. Only application
5
+ * composition roots import this module; feature logic keeps
6
+ * `WorkspaceMutations` in its Effect environment.
7
+ *
8
+ * @experimental This API is unstable and may change without notice.
9
+ * @packageDocumentation
10
+ */
11
+ export { layer, loadWorkspace, makeWorkspaceTransactionCapabilities, } from "./operations/load-workspace.js";
12
+ //# sourceMappingURL=live.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Gate a plan on authoritative lockfile health.
3
+ *
4
+ * A missing lockfile is an absent accepted-resolution set: the already-resolved
5
+ * lifecycle plan may establish needed rows atomically. An invalid lockfile is
6
+ * authoritative but unreadable, so execution blocks without reconstructing it
7
+ * from canonical content, manifests, or observation.
8
+ *
9
+ * @experimental This API is unstable and may change without notice.
10
+ */
11
+ import * as Effect from "effect/Effect";
12
+ import type { Plan } from "../plan/plan.js";
13
+ import type { LockfileState } from "@agentxm/workspace-state";
14
+ export type DegradedLockfileState = Exclude<LockfileState, "ok">;
15
+ export interface AugmentedPlanResult<Requirements = never, Output = never> {
16
+ readonly plan: Plan<Requirements, Output>;
17
+ readonly reconciliationTriggered: boolean;
18
+ readonly reason?: DegradedLockfileState;
19
+ }
20
+ /**
21
+ * Return the plan unchanged when authority is readable or absent. Replace it
22
+ * with one explicit blocker when the authoritative file is unreadable.
23
+ */
24
+ export declare const augmentPlanWithReconciliation: <Requirements, Output, LoadError>(plan: Plan<Requirements, Output>, getLockfileState: () => Effect.Effect<LockfileState, LoadError>) => Effect.Effect<AugmentedPlanResult<Requirements, Output>, LoadError>;
25
+ //# sourceMappingURL=augment-plan.d.ts.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Gate a plan on authoritative lockfile health.
3
+ *
4
+ * A missing lockfile is an absent accepted-resolution set: the already-resolved
5
+ * lifecycle plan may establish needed rows atomically. An invalid lockfile is
6
+ * authoritative but unreadable, so execution blocks without reconstructing it
7
+ * from canonical content, manifests, or observation.
8
+ *
9
+ * @experimental This API is unstable and may change without notice.
10
+ */
11
+ import * as Effect from "effect/Effect";
12
+ // -----------------------------------------------------------------------------
13
+ // Implementation
14
+ // -----------------------------------------------------------------------------
15
+ /**
16
+ * Return the plan unchanged when authority is readable or absent. Replace it
17
+ * with one explicit blocker when the authoritative file is unreadable.
18
+ */
19
+ export const augmentPlanWithReconciliation = (plan, getLockfileState) => Effect.gen(function* () {
20
+ const lockfileState = yield* getLockfileState();
21
+ if (lockfileState !== "invalid") {
22
+ return {
23
+ plan,
24
+ reconciliationTriggered: lockfileState === "missing",
25
+ ...(lockfileState === "missing" ? { reason: "missing" } : {}),
26
+ };
27
+ }
28
+ return {
29
+ plan: {
30
+ _tag: "Plan",
31
+ name: plan.name,
32
+ description: plan.description,
33
+ jobs: [
34
+ {
35
+ concurrency: 1,
36
+ steps: [
37
+ {
38
+ key: "workspace:lockfile-invalid",
39
+ readiness: "error",
40
+ label: "Read accepted external resolutions",
41
+ errorMessage: "The authoritative lockfile is invalid and cannot be reconstructed from workspace observation.",
42
+ },
43
+ ],
44
+ },
45
+ ],
46
+ },
47
+ reconciliationTriggered: true,
48
+ reason: "invalid",
49
+ };
50
+ });
51
+ //# sourceMappingURL=augment-plan.js.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Live workspace composition: the one seam that needs both the workspace
3
+ * state facade and the operations-side transaction machinery. Supplies the
4
+ * transaction capabilities to `makeWorkspaceMutations` and publishes the
5
+ * `loadWorkspace` effect and `layer` every entry point composes.
6
+ *
7
+ * @experimental This API is unstable and may change without notice.
8
+ */
9
+ import * as Effect from "effect/Effect";
10
+ import * as FileSystem from "effect/FileSystem";
11
+ import * as Layer from "effect/Layer";
12
+ import * as Path from "effect/Path";
13
+ import { WorkspaceMutations, type MakeWorkspaceTransactionCapabilities, type WorkspaceLayerOptions, type WorkspaceMutationsError, type WorkspaceMutationsService } from "@agentxm/workspace-state";
14
+ /**
15
+ * The live transaction capabilities: the runner claims the shared settings
16
+ * and lockfile targets by default, and both members eliminate FileSystem and
17
+ * Path so the facade's methods stay `R = never` for callers.
18
+ */
19
+ export declare const makeWorkspaceTransactionCapabilities: MakeWorkspaceTransactionCapabilities;
20
+ /**
21
+ * Create workspace mutations effect.
22
+ *
23
+ * Loads an existing workspace from disk.
24
+ *
25
+ * The workspace must already be initialized. Missing or invalid settings fail
26
+ * fast with an `AppError`.
27
+ *
28
+ * @param options - WorkspaceMutations layer options
29
+ * @returns Effect yielding WorkspaceMutationsService
30
+ */
31
+ export declare const loadWorkspace: (options: WorkspaceLayerOptions) => Effect.Effect<WorkspaceMutationsService, WorkspaceMutationsError, FileSystem.FileSystem | Path.Path>;
32
+ /**
33
+ * Create a layer that loads workspace read model from disk.
34
+ *
35
+ * The workspace must already be initialized.
36
+ *
37
+ * @param options - WorkspaceMutations layer options
38
+ * @returns Layer providing WorkspaceMutations
39
+ *
40
+ * @experimental This API is unstable and may change without notice.
41
+ */
42
+ export declare const layer: (options: WorkspaceLayerOptions) => Layer.Layer<WorkspaceMutations, WorkspaceMutationsError, Path.Path | FileSystem.FileSystem>;
43
+ //# sourceMappingURL=load-workspace.d.ts.map
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Live workspace composition: the one seam that needs both the workspace
3
+ * state facade and the operations-side transaction machinery. Supplies the
4
+ * transaction capabilities to `makeWorkspaceMutations` and publishes the
5
+ * `loadWorkspace` effect and `layer` every entry point composes.
6
+ *
7
+ * @experimental This API is unstable and may change without notice.
8
+ */
9
+ import * as Effect from "effect/Effect";
10
+ import * as FileSystem from "effect/FileSystem";
11
+ import * as Layer from "effect/Layer";
12
+ import * as Path from "effect/Path";
13
+ import * as Semaphore from "effect/Semaphore";
14
+ import { WorkspaceMutations, makeWorkspaceMutations, } from "@agentxm/workspace-state";
15
+ import { runWorkspaceTransaction } from "./transaction.js";
16
+ import { acquireWorkspaceTransitionLock } from "./transition-lock.js";
17
+ /**
18
+ * The live transaction capabilities: the runner claims the shared settings
19
+ * and lockfile targets by default, and both members eliminate FileSystem and
20
+ * Path so the facade's methods stay `R = never` for callers.
21
+ */
22
+ export const makeWorkspaceTransactionCapabilities = ({ workspaceDir, settingsPath, lockPath, }) => Effect.gen(function* () {
23
+ const fs = yield* FileSystem.FileSystem;
24
+ const path = yield* Path.Path;
25
+ // Transaction admission must be distinct from the facade's mutation
26
+ // mutex: a transaction calls the same service's mutation methods while
27
+ // it owns the outer admission permit.
28
+ const transactionSemaphore = yield* Semaphore.make(1);
29
+ const fsLayer = Layer.mergeAll(Layer.succeed(FileSystem.FileSystem, fs), Layer.succeed(Path.Path, path));
30
+ const runTransaction = (args) => runWorkspaceTransaction({
31
+ workspaceDir,
32
+ semaphore: transactionSemaphore,
33
+ targets: [
34
+ ...(args.claimDefaultTargets === false ? [] : [settingsPath, lockPath]),
35
+ ...(args.targets ?? []),
36
+ ],
37
+ transition: args.transition,
38
+ validate: args.validate,
39
+ ...(args.onRestorationStarted === undefined
40
+ ? {}
41
+ : { onRestorationStarted: args.onRestorationStarted }),
42
+ }).pipe(Effect.provide(fsLayer));
43
+ const acquireTransition = (request) => acquireWorkspaceTransitionLock({
44
+ workspaceDir,
45
+ holder: {
46
+ command: request.command,
47
+ pid: process.pid,
48
+ ...(request.candidateId === undefined ? {} : { candidateId: request.candidateId }),
49
+ },
50
+ ...(request.onWaiting === undefined ? {} : { onWaiting: request.onWaiting }),
51
+ }).pipe(Effect.provide(fsLayer));
52
+ return { runTransaction, acquireTransition };
53
+ });
54
+ /**
55
+ * Create workspace mutations effect.
56
+ *
57
+ * Loads an existing workspace from disk.
58
+ *
59
+ * The workspace must already be initialized. Missing or invalid settings fail
60
+ * fast with an `AppError`.
61
+ *
62
+ * @param options - WorkspaceMutations layer options
63
+ * @returns Effect yielding WorkspaceMutationsService
64
+ */
65
+ export const loadWorkspace = (options) => makeWorkspaceMutations(options, makeWorkspaceTransactionCapabilities);
66
+ /**
67
+ * Create a layer that loads workspace read model from disk.
68
+ *
69
+ * The workspace must already be initialized.
70
+ *
71
+ * @param options - WorkspaceMutations layer options
72
+ * @returns Layer providing WorkspaceMutations
73
+ *
74
+ * @experimental This API is unstable and may change without notice.
75
+ */
76
+ export const layer = (options) => Layer.effect(WorkspaceMutations, loadWorkspace(options));
77
+ //# sourceMappingURL=load-workspace.js.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Pure function to scan a plan's steps and collect readiness statistics.
3
+ *
4
+ * Extracts from the inline logic in `previewOrApplyPlan` so it can be tested
5
+ * independently and reused from core without CLI dependencies.
6
+ *
7
+ * @experimental This API is unstable and may change without notice.
8
+ */
9
+ import type { Plan } from "../plan/plan.js";
10
+ export interface PlanReadinessReport {
11
+ readonly hasErrors: boolean;
12
+ readonly hasWarnings: boolean;
13
+ readonly errorMessages: ReadonlyArray<string>;
14
+ readonly warnMessages: ReadonlyArray<string>;
15
+ }
16
+ /**
17
+ * Scan all steps in a plan and collect readiness statistics.
18
+ *
19
+ * Pure function: no side effects, no service dependencies.
20
+ */
21
+ export declare const scanPlanReadiness: (plan: Plan<unknown, unknown>) => PlanReadinessReport;
22
+ //# sourceMappingURL=scan-plan-readiness.d.ts.map
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Pure function to scan a plan's steps and collect readiness statistics.
3
+ *
4
+ * Extracts from the inline logic in `previewOrApplyPlan` so it can be tested
5
+ * independently and reused from core without CLI dependencies.
6
+ *
7
+ * @experimental This API is unstable and may change without notice.
8
+ */
9
+ // -----------------------------------------------------------------------------
10
+ // Implementation
11
+ // -----------------------------------------------------------------------------
12
+ /**
13
+ * Scan all steps in a plan and collect readiness statistics.
14
+ *
15
+ * Pure function: no side effects, no service dependencies.
16
+ */
17
+ export const scanPlanReadiness = (plan) => {
18
+ const errorMessages = [];
19
+ const warnMessages = [];
20
+ for (const job of plan.jobs) {
21
+ for (const step of job.steps) {
22
+ switch (step.readiness) {
23
+ case "error":
24
+ errorMessages.push(`${step.label}: ${step.errorMessage}`);
25
+ break;
26
+ case "warn":
27
+ warnMessages.push(`${step.label}: ${step.warnMessage}`);
28
+ break;
29
+ case "ready":
30
+ break;
31
+ }
32
+ }
33
+ }
34
+ return {
35
+ hasErrors: errorMessages.length > 0,
36
+ hasWarnings: warnMessages.length > 0,
37
+ errorMessages,
38
+ warnMessages,
39
+ };
40
+ };
41
+ //# sourceMappingURL=scan-plan-readiness.js.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Workspace transaction mechanics: the snapshot/restore/validate/rollback
3
+ * runner and the closure settlement operations, implemented against the
4
+ * ambient authority context declared in `../transaction.ts`.
5
+ *
6
+ * @experimental This API is unstable and may change without notice.
7
+ */
8
+ import * as Effect from "effect/Effect";
9
+ import * as FileSystem from "effect/FileSystem";
10
+ import * as Path from "effect/Path";
11
+ import * as Semaphore from "effect/Semaphore";
12
+ import { WorkspaceRestorationIncomplete, type WorkspaceTransactionFailure } from "@agentxm/workspace-state";
13
+ /** Run one semantic closure's mutations under its closure identity. */
14
+ export declare const withWorkspaceClosure: (closureId: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
15
+ export interface WorkspaceTransactionArgs<A, E, R> {
16
+ readonly workspaceDir: string;
17
+ /** In-process admission owned by the workspace service instance. */
18
+ readonly semaphore: Semaphore.Semaphore;
19
+ /** Authoritative files or directories that the transition may mutate. */
20
+ readonly targets: ReadonlyArray<string>;
21
+ /** Desired, lock, canonical, projection, and native-configuration mutation. */
22
+ readonly transition: Effect.Effect<A, E, R>;
23
+ /** Confirms the complete durable postcondition before the transaction commits. */
24
+ readonly validate: (value: A) => Effect.Effect<void, E, R>;
25
+ /** Observes the start of rollback restoration; never controls it. */
26
+ readonly onRestorationStarted?: Effect.Effect<void>;
27
+ }
28
+ /**
29
+ * Settle one closure: its commits stand, so its snapshots leave the
30
+ * restoration set and a later closure touching the same target takes a fresh
31
+ * post-commit preimage. No-op outside a transaction.
32
+ */
33
+ export declare const settleWorkspaceClosure: (closureId: string) => Effect.Effect<void>;
34
+ /**
35
+ * Roll back one failed closure: restore and verify exactly its snapshots, in
36
+ * reverse order, leaving every other closure's work in place. A restoration
37
+ * that does not complete and verify records a pending typed failure the
38
+ * transaction surfaces at its end — the truth travels in memory, never
39
+ * through a later workspace write. No-op outside a transaction.
40
+ */
41
+ export declare const rollbackWorkspaceClosure: (closureId: string) => Effect.Effect<void>;
42
+ /**
43
+ * Run one coupled workspace mutation under the workspace transition lock.
44
+ *
45
+ * Every authoritative target is snapshotted into a uniquely prefixed
46
+ * OS-temporary directory before the transition begins. A failed transition or
47
+ * postcondition check restores and verifies the exact pre-operation paths and
48
+ * removes the snapshots; a restoration that does not complete and verify
49
+ * fails with the typed {@link WorkspaceRestorationIncomplete}, preserving the
50
+ * snapshot directory for manual inspection. Nothing about a failure persists
51
+ * in the workspace: the next mutation plans from the current workspace state.
52
+ *
53
+ * The invocation-level transition hold is reused when a plan-family apply
54
+ * already acquired it; otherwise this transaction acquires its own for the
55
+ * duration of the mutation.
56
+ */
57
+ export declare const runWorkspaceTransaction: <A, E, R>(args: WorkspaceTransactionArgs<A, E, R>) => Effect.Effect<A, WorkspaceTransactionFailure | WorkspaceRestorationIncomplete | E, R | FileSystem.FileSystem | Path.Path>;
58
+ //# sourceMappingURL=transaction.d.ts.map