@animalabs/agent-framework 0.26.1 → 0.27.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.
- package/README.md +57 -7
- package/dist/src/agent.d.ts +263 -22
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +531 -54
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/server.d.ts.map +1 -1
- package/dist/src/api/server.js +1 -2
- package/dist/src/api/server.js.map +1 -1
- package/dist/src/auto-continue.d.ts +33 -0
- package/dist/src/auto-continue.d.ts.map +1 -0
- package/dist/src/auto-continue.js +35 -0
- package/dist/src/auto-continue.js.map +1 -0
- package/dist/src/code-execution/isolate/scripts.d.ts +11 -0
- package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
- package/dist/src/code-execution/isolate/scripts.js +5 -1
- package/dist/src/code-execution/isolate/scripts.js.map +1 -1
- package/dist/src/framework.d.ts +829 -156
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +3906 -1008
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +309 -46
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +2117 -395
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/gate/index.d.ts +2 -2
- package/dist/src/gate/index.d.ts.map +1 -1
- package/dist/src/gate/index.js +1 -1
- package/dist/src/gate/index.js.map +1 -1
- package/dist/src/gate/recipe-reconcile.d.ts +103 -0
- package/dist/src/gate/recipe-reconcile.d.ts.map +1 -0
- package/dist/src/gate/recipe-reconcile.js +325 -0
- package/dist/src/gate/recipe-reconcile.js.map +1 -0
- package/dist/src/gate/types.d.ts +68 -8
- package/dist/src/gate/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts +433 -113
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +1152 -434
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/conversation-router.d.ts +16 -8
- package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
- package/dist/src/mcpl/conversation-router.js +29 -15
- package/dist/src/mcpl/conversation-router.js.map +1 -1
- package/dist/src/mcpl/convert-block.d.ts.map +1 -1
- package/dist/src/mcpl/convert-block.js +14 -2
- package/dist/src/mcpl/convert-block.js.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts +7 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.js +32 -7
- package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +5 -1
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js +4 -0
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/inference-router.d.ts +14 -2
- package/dist/src/mcpl/inference-router.d.ts.map +1 -1
- package/dist/src/mcpl/inference-router.js +73 -28
- package/dist/src/mcpl/inference-router.js.map +1 -1
- package/dist/src/mcpl/prose-grammar.d.ts +4 -0
- package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
- package/dist/src/mcpl/prose-grammar.js +6 -0
- package/dist/src/mcpl/prose-grammar.js.map +1 -1
- package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
- package/dist/src/mcpl/protocol-family.js +3 -0
- package/dist/src/mcpl/protocol-family.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +20 -2
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
- package/dist/src/mcpl/push-coalescer.js +33 -11
- package/dist/src/mcpl/push-coalescer.js.map +1 -1
- package/dist/src/mcpl/reference-fetcher.d.ts +63 -42
- package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
- package/dist/src/mcpl/reference-fetcher.js +177 -145
- package/dist/src/mcpl/reference-fetcher.js.map +1 -1
- package/dist/src/mcpl/references.d.ts +380 -46
- package/dist/src/mcpl/references.d.ts.map +1 -1
- package/dist/src/mcpl/references.js +737 -78
- package/dist/src/mcpl/references.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +82 -3
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +132 -7
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tool-lifecycle.d.ts +11 -0
- package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
- package/dist/src/mcpl/tool-lifecycle.js +21 -0
- package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
- package/dist/src/mcpl/tool-presence.d.ts +259 -0
- package/dist/src/mcpl/tool-presence.d.ts.map +1 -0
- package/dist/src/mcpl/tool-presence.js +628 -0
- package/dist/src/mcpl/tool-presence.js.map +1 -0
- package/dist/src/mcpl/tool-result-normalize.d.ts +9 -3
- package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
- package/dist/src/mcpl/tool-result-normalize.js +14 -6
- package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
- package/dist/src/mcpl/tool-signature.d.ts +39 -0
- package/dist/src/mcpl/tool-signature.d.ts.map +1 -0
- package/dist/src/mcpl/tool-signature.js +292 -0
- package/dist/src/mcpl/tool-signature.js.map +1 -0
- package/dist/src/mcpl/toolset-host.d.ts +200 -0
- package/dist/src/mcpl/toolset-host.d.ts.map +1 -0
- package/dist/src/mcpl/toolset-host.js +621 -0
- package/dist/src/mcpl/toolset-host.js.map +1 -0
- package/dist/src/mcpl/toolsets-module.d.ts +80 -0
- package/dist/src/mcpl/toolsets-module.d.ts.map +1 -0
- package/dist/src/mcpl/toolsets-module.js +431 -0
- package/dist/src/mcpl/toolsets-module.js.map +1 -0
- package/dist/src/mcpl/transport.d.ts +2 -2
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +3 -2
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +21 -1
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/mcpl/visible-content.d.ts +7 -9
- package/dist/src/mcpl/visible-content.d.ts.map +1 -1
- package/dist/src/mcpl/visible-content.js +21 -9
- package/dist/src/mcpl/visible-content.js.map +1 -1
- package/dist/src/module-registry.d.ts +23 -8
- package/dist/src/module-registry.d.ts.map +1 -1
- package/dist/src/module-registry.js +68 -15
- package/dist/src/module-registry.js.map +1 -1
- package/dist/src/modules/discord/index.js +1 -1
- package/dist/src/modules/discord/index.js.map +1 -1
- package/dist/src/modules/history/index.d.ts +2 -1
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +51 -17
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/history/semantic.d.ts +108 -6
- package/dist/src/modules/history/semantic.d.ts.map +1 -1
- package/dist/src/modules/history/semantic.js +273 -57
- package/dist/src/modules/history/semantic.js.map +1 -1
- package/dist/src/modules/workspace/direct-write.d.ts +181 -0
- package/dist/src/modules/workspace/direct-write.d.ts.map +1 -0
- package/dist/src/modules/workspace/direct-write.js +384 -0
- package/dist/src/modules/workspace/direct-write.js.map +1 -0
- package/dist/src/modules/workspace/edit-text.d.ts +26 -12
- package/dist/src/modules/workspace/edit-text.d.ts.map +1 -1
- package/dist/src/modules/workspace/edit-text.js +58 -28
- package/dist/src/modules/workspace/edit-text.js.map +1 -1
- package/dist/src/modules/workspace/effects.d.ts +10 -0
- package/dist/src/modules/workspace/effects.d.ts.map +1 -1
- package/dist/src/modules/workspace/effects.js +1 -1
- package/dist/src/modules/workspace/effects.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +246 -27
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +1216 -236
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/read-page.d.ts +41 -0
- package/dist/src/modules/workspace/read-page.d.ts.map +1 -0
- package/dist/src/modules/workspace/read-page.js +213 -0
- package/dist/src/modules/workspace/read-page.js.map +1 -0
- package/dist/src/modules/workspace/result-text.d.ts +67 -0
- package/dist/src/modules/workspace/result-text.d.ts.map +1 -0
- package/dist/src/modules/workspace/result-text.js +94 -0
- package/dist/src/modules/workspace/result-text.js.map +1 -0
- package/dist/src/modules/workspace/text.d.ts +29 -12
- package/dist/src/modules/workspace/text.d.ts.map +1 -1
- package/dist/src/modules/workspace/text.js +35 -33
- package/dist/src/modules/workspace/text.js.map +1 -1
- package/dist/src/modules/workspace/types.d.ts +41 -17
- package/dist/src/modules/workspace/types.d.ts.map +1 -1
- package/dist/src/modules/workspace/types.js.map +1 -1
- package/dist/src/sent-rows.d.ts +59 -0
- package/dist/src/sent-rows.d.ts.map +1 -0
- package/dist/src/sent-rows.js +145 -0
- package/dist/src/sent-rows.js.map +1 -0
- package/dist/src/silent-heartbeat.d.ts +17 -10
- package/dist/src/silent-heartbeat.d.ts.map +1 -1
- package/dist/src/silent-heartbeat.js.map +1 -1
- package/dist/src/stable-hash.d.ts +3 -0
- package/dist/src/stable-hash.d.ts.map +1 -0
- package/dist/src/stable-hash.js +15 -0
- package/dist/src/stable-hash.js.map +1 -0
- package/dist/src/stored-injections.d.ts +99 -0
- package/dist/src/stored-injections.d.ts.map +1 -0
- package/dist/src/stored-injections.js +106 -0
- package/dist/src/stored-injections.js.map +1 -0
- package/dist/src/text-as-stored.d.ts +4 -3
- package/dist/src/text-as-stored.d.ts.map +1 -1
- package/dist/src/text-as-stored.js +4 -3
- package/dist/src/text-as-stored.js.map +1 -1
- package/dist/src/thinking-drops.d.ts +81 -0
- package/dist/src/thinking-drops.d.ts.map +1 -0
- package/dist/src/thinking-drops.js +103 -0
- package/dist/src/thinking-drops.js.map +1 -0
- package/dist/src/tool-image-ledger.d.ts +9 -8
- package/dist/src/tool-image-ledger.d.ts.map +1 -1
- package/dist/src/tool-image-ledger.js +9 -8
- package/dist/src/tool-image-ledger.js.map +1 -1
- package/dist/src/tool-presentation.d.ts.map +1 -1
- package/dist/src/tool-presentation.js +3 -1
- package/dist/src/tool-presentation.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +4 -2
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +21 -6
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tool-result-history.d.ts +186 -21
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +428 -89
- package/dist/src/tool-result-history.js.map +1 -1
- package/dist/src/tune-out/coordinator.d.ts +17 -9
- package/dist/src/tune-out/coordinator.d.ts.map +1 -1
- package/dist/src/tune-out/coordinator.js +84 -37
- package/dist/src/tune-out/coordinator.js.map +1 -1
- package/dist/src/types/agent.d.ts +186 -7
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +19 -2
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +24 -3
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +90 -7
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +57 -2
- package/dist/src/types/trace.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/agent.ts +593 -60
- package/src/api/server.ts +1 -2
- package/src/auto-continue.ts +42 -0
- package/src/code-execution/isolate/scripts.ts +11 -3
- package/src/framework.ts +4004 -1026
- package/src/gate/event-gate.ts +2315 -389
- package/src/gate/index.ts +2 -1
- package/src/gate/recipe-reconcile.ts +355 -0
- package/src/gate/types.ts +70 -8
- package/src/index.ts +7 -4
- package/src/mcpl/channel-registry.ts +1220 -467
- package/src/mcpl/conversation-router.ts +34 -16
- package/src/mcpl/convert-block.ts +14 -1
- package/src/mcpl/hook-orchestrator.ts +33 -6
- package/src/mcpl/index.ts +6 -1
- package/src/mcpl/inference-router.ts +79 -34
- package/src/mcpl/prose-grammar.ts +7 -0
- package/src/mcpl/protocol-family.ts +2 -0
- package/src/mcpl/push-coalescer.ts +51 -13
- package/src/mcpl/reference-fetcher.ts +201 -162
- package/src/mcpl/references.ts +852 -78
- package/src/mcpl/server-connection.ts +145 -7
- package/src/mcpl/tool-lifecycle.ts +21 -0
- package/src/mcpl/tool-presence.ts +650 -0
- package/src/mcpl/tool-result-normalize.ts +18 -6
- package/src/mcpl/tool-signature.ts +285 -0
- package/src/mcpl/toolset-host.ts +637 -0
- package/src/mcpl/toolsets-module.ts +451 -0
- package/src/mcpl/transport.ts +3 -2
- package/src/mcpl/types.ts +22 -1
- package/src/mcpl/visible-content.ts +22 -9
- package/src/module-registry.ts +77 -24
- package/src/modules/discord/index.ts +1 -1
- package/src/modules/history/index.ts +48 -18
- package/src/modules/history/semantic.ts +308 -54
- package/src/modules/workspace/direct-write.ts +425 -0
- package/src/modules/workspace/edit-text.ts +82 -35
- package/src/modules/workspace/effects.ts +1 -1
- package/src/modules/workspace/index.ts +1274 -241
- package/src/modules/workspace/read-page.ts +222 -0
- package/src/modules/workspace/result-text.ts +119 -0
- package/src/modules/workspace/text.ts +58 -32
- package/src/modules/workspace/types.ts +41 -17
- package/src/sent-rows.ts +162 -0
- package/src/silent-heartbeat.ts +17 -10
- package/src/stable-hash.ts +14 -0
- package/src/stored-injections.ts +131 -0
- package/src/text-as-stored.ts +4 -3
- package/src/thinking-drops.ts +141 -0
- package/src/tool-image-ledger.ts +9 -8
- package/src/tool-presentation.ts +3 -1
- package/src/tool-result-guard.ts +19 -6
- package/src/tool-result-history.ts +488 -88
- package/src/tune-out/coordinator.ts +80 -37
- package/src/types/agent.ts +189 -7
- package/src/types/events.ts +19 -2
- package/src/types/framework.ts +21 -3
- package/src/types/module.ts +86 -7
- package/src/types/trace.ts +58 -2
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A direct mount's writes (MountConfig.backend): disk is the only copy, so a
|
|
3
|
+
* write lands there whole when its call answers, or doesn't happen and leaves
|
|
4
|
+
* disk as it was. Ported from anima-research/hands-mcp's staged write
|
|
5
|
+
* (src/shared.ts), behind the mount's boundary as the workspace's other
|
|
6
|
+
* effects hold it (effects.ts):
|
|
7
|
+
*
|
|
8
|
+
* - The file's directory is located inside the mount (checkDir), and where
|
|
9
|
+
* the file lands is judged as a push's write judges it (refusedLanding):
|
|
10
|
+
* inside the mount, in no nested mount's directory, and covered by the
|
|
11
|
+
* mount's include. A link at the file is refused on a mount that doesn't
|
|
12
|
+
* follow links; on one that does, the write goes to the file it leads to
|
|
13
|
+
* when the call stages it, judged the same way, and the link stays.
|
|
14
|
+
* - The new bytes are staged beside the file, in `.workspace-staged-<id>`,
|
|
15
|
+
* at the file's mode, special bits included as far as the kernel lets this
|
|
16
|
+
* process set them (a setgid bit only for a member of the file's group),
|
|
17
|
+
* and renamed over it, so a reader beside the agent never sees half a file
|
|
18
|
+
* and a process killed mid-write leaves the old file whole. A file this
|
|
19
|
+
* process may not write is refused, as a push's write, which opens it for
|
|
20
|
+
* writing, is refused: the rename needs only the directory's permission.
|
|
21
|
+
* A process that dies between staging and its rename leaves the staged
|
|
22
|
+
* file, under that name, which `ls` and `git status` show; so does a
|
|
23
|
+
* refused write whose removal of its staged file fails or can't tell the
|
|
24
|
+
* file is its own, or whose directory another writer moved after the
|
|
25
|
+
* staging, since the removal goes by path (discard) and the path then
|
|
26
|
+
* leads elsewhere. Nothing sweeps it, and the answer doesn't name it.
|
|
27
|
+
* The removal checks the staged name holds that file and unlinks it with
|
|
28
|
+
* no turn of the event loop between, so only a file another writer puts
|
|
29
|
+
* there in that instant can be removed in its place, or one put there
|
|
30
|
+
* that a stat can't tell from it: on the freed inode number, with the
|
|
31
|
+
* same size, mode and owner, in the same tick of a coarse clock.
|
|
32
|
+
* - The rename gives a hard-linked path a file of its own, and the other
|
|
33
|
+
* links keep the old text: `otherLinks` counts them for the answer.
|
|
34
|
+
* - Just before the rename, an edit's file is checked unchanged since its
|
|
35
|
+
* read, by its bytes, read again, and its identity (checkUnchanged),
|
|
36
|
+
* synchronously, so the check and the renames after it run with no turn
|
|
37
|
+
* of the event loop between. Only a change landing in that instant isn't
|
|
38
|
+
* seen, which for edit_many runs from the check through its last rename:
|
|
39
|
+
* no rename can be made conditional.
|
|
40
|
+
* - No sync. The store-backed kind syncs its pushes for its agreement
|
|
41
|
+
* record (reconcile.ts), and a direct mount keeps none, so a power loss
|
|
42
|
+
* or a kernel crash can lose a direct write after its answer said it
|
|
43
|
+
* landed, as it can a hands-mcp write. A process dying can't: the rename is
|
|
44
|
+
* whole by then.
|
|
45
|
+
*
|
|
46
|
+
* Node has no openat or renameat, so the stage and the rename go through the
|
|
47
|
+
* checked directory's path: a directory replaced by another writer on disk
|
|
48
|
+
* between the directory's check and the staging, or after its last check
|
|
49
|
+
* (placedStill), can redirect them, as effects.ts says of a create. For
|
|
50
|
+
* edit_many that last check is each file's, before the other files' checks.
|
|
51
|
+
*/
|
|
52
|
+
import type { BigIntStats } from 'node:fs';
|
|
53
|
+
import { type CheckedDir, type MountView } from './observe.js';
|
|
54
|
+
/** The name a staged file starts with, beside the file it replaces. */
|
|
55
|
+
export declare const STAGED_PREFIX = ".workspace-staged-";
|
|
56
|
+
/**
|
|
57
|
+
* Why a direct write didn't happen when its mount's root was replaced under
|
|
58
|
+
* it: a direct mount keeps no root to sync to (MountConfig.backend), so its
|
|
59
|
+
* next call works beneath whatever is there then.
|
|
60
|
+
*/
|
|
61
|
+
export declare const ROOT_MOVED = "the mount root changed while this call was being applied: a new call works beneath whatever directory the mount's path leads to then";
|
|
62
|
+
/**
|
|
63
|
+
* A file's identity as a write must find it unchanged: device, inode, size,
|
|
64
|
+
* mode, owner, group, and modification and change times, to the nanosecond.
|
|
65
|
+
* The mode, owner and group are fields of their own, since a chmod or chown
|
|
66
|
+
* in the same tick of a coarse clock as the file's last change leaves its
|
|
67
|
+
* change time as it was (checkUnchanged).
|
|
68
|
+
*/
|
|
69
|
+
export interface FileIdentity {
|
|
70
|
+
dev: bigint;
|
|
71
|
+
ino: bigint;
|
|
72
|
+
size: bigint;
|
|
73
|
+
mode: bigint;
|
|
74
|
+
uid: bigint;
|
|
75
|
+
gid: bigint;
|
|
76
|
+
mtimeNs: bigint;
|
|
77
|
+
ctimeNs: bigint;
|
|
78
|
+
}
|
|
79
|
+
export declare const identityOf: (info: BigIntStats) => FileIdentity;
|
|
80
|
+
export declare const sameIdentity: (a: FileIdentity, b: FileIdentity) => boolean;
|
|
81
|
+
/** Another writer replaced, changed or removed the file between its read and its rename; nothing was written. */
|
|
82
|
+
export declare class FileChanged extends Error {
|
|
83
|
+
}
|
|
84
|
+
/** Why a direct write didn't happen, in words for its answer; disk is as it was. */
|
|
85
|
+
export declare class WriteRefused extends Error {
|
|
86
|
+
}
|
|
87
|
+
/** A file's new bytes staged beside it, ready to be renamed over it (stageContained). */
|
|
88
|
+
export interface Staged {
|
|
89
|
+
/** Where the rename lands: the file's entry in its checked directory, a followed link's file's included. */
|
|
90
|
+
path: string;
|
|
91
|
+
/** The staged file, beside it. */
|
|
92
|
+
temp: string;
|
|
93
|
+
/**
|
|
94
|
+
* Which file the staged file is, so the rename moves, and a refusal
|
|
95
|
+
* removes, that one and no other put at its name: its whole identity,
|
|
96
|
+
* since a file made where it was unlinked can take its inode number.
|
|
97
|
+
*/
|
|
98
|
+
tempIdentity: FileIdentity;
|
|
99
|
+
/** The mount's root and the file's directory, as checked when it was staged. */
|
|
100
|
+
root: CheckedDir;
|
|
101
|
+
parent: CheckedDir;
|
|
102
|
+
/**
|
|
103
|
+
* The other hard links the replaced file had, counted just before the
|
|
104
|
+
* rename and kept once it succeeds: the rename gives this path a file of
|
|
105
|
+
* its own, and they keep the old text. 0 until then, and for a new file.
|
|
106
|
+
*/
|
|
107
|
+
otherLinks: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Test seams. `afterStage` is called once a call's files are staged, before
|
|
111
|
+
* they're checked unchanged (another writer acting then); `beforeRename`
|
|
112
|
+
* just before each rename, inside its refusal, so throwing stands for the
|
|
113
|
+
* rename failing. Production sets neither.
|
|
114
|
+
*/
|
|
115
|
+
export declare const directWriteTestSeam: {
|
|
116
|
+
afterStage?: (paths: string[]) => void | Promise<void>;
|
|
117
|
+
beforeRename?: (path: string) => void;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Stage `bytes` beside the mount-relative file `rel`, to be renamed over it:
|
|
121
|
+
* the first half of a direct write. The file keeps its mode, special bits
|
|
122
|
+
* included, as far as the kernel lets this process set them; a new file
|
|
123
|
+
* takes `0666` less the umask, as a shell's would. Its owner and group are
|
|
124
|
+
* this process's and the ones its directory gives a new file, and an ACL or
|
|
125
|
+
* extended attribute on the file isn't carried over, as with any write that
|
|
126
|
+
* renames over a file. Anything there that isn't a regular file is refused,
|
|
127
|
+
* and a refusal removes the staged file it made, except where the header
|
|
128
|
+
* says one is left. The staged file is written and moded through its own
|
|
129
|
+
* handle, never through its name again.
|
|
130
|
+
*/
|
|
131
|
+
export declare function stageContained(view: MountView, rootReal: string, rel: string, bytes: Buffer, { makeDirectory }?: {
|
|
132
|
+
makeDirectory?: boolean;
|
|
133
|
+
}): Promise<Staged>;
|
|
134
|
+
/**
|
|
135
|
+
* Throw unless the root and the file's directory are still the ones the
|
|
136
|
+
* staging checked, with a push's words for the directory (effects.ts
|
|
137
|
+
* moved()).
|
|
138
|
+
*/
|
|
139
|
+
export declare function placedStill(staged: Staged): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Throw unless the file is still what its read found: FileChanged when it
|
|
142
|
+
* changed or is gone, nothing written. `expected` is null for a write, which
|
|
143
|
+
* read nothing and replaces whatever is there. Either way a link swapped in
|
|
144
|
+
* at the file the rename replaces (on a mount that follows links, the file
|
|
145
|
+
* the link at the agent's path led to when the call staged it) is refused
|
|
146
|
+
* rather than replaced, and so is a file this process may not write. It reads the entry the
|
|
147
|
+
* rename replaces, and then the file's bytes, synchronously, as renameInto
|
|
148
|
+
* runs, so a check and the renames after it run with no turn of the event
|
|
149
|
+
* loop between.
|
|
150
|
+
*
|
|
151
|
+
* The identity, taken once the bytes are read, catches a file replaced or
|
|
152
|
+
* re-moded under the call, which equal bytes wouldn't show. The bytes are
|
|
153
|
+
* compared with the ones the edit read: a kernel that stamps files from a
|
|
154
|
+
* coarse clock, as Linux before 6.13 does, leaves a file's identity as it
|
|
155
|
+
* was after a second write of the same size within one tick of its last
|
|
156
|
+
* change (on Debian's Linux 6.12.113 with ext4, 1,632 to 1,752 of 2,000
|
|
157
|
+
* such rewrites kept every stamp, in three runs), and the bytes show that
|
|
158
|
+
* change on every clock. The bytes are read through an open that follows
|
|
159
|
+
* no link and doesn't wait on a pipe put at the path since its lstat, and
|
|
160
|
+
* at most one byte past what the edit read, so the check never blocks and
|
|
161
|
+
* reads no more than that.
|
|
162
|
+
*/
|
|
163
|
+
export declare function checkUnchanged(staged: Staged, expected: {
|
|
164
|
+
identity: FileIdentity;
|
|
165
|
+
bytes: Buffer;
|
|
166
|
+
} | null): void;
|
|
167
|
+
/**
|
|
168
|
+
* Rename the staged file over the file, synchronously (checkUnchanged says
|
|
169
|
+
* why), counting the other hard links it splits the path from just before.
|
|
170
|
+
* A failed rename leaves the file as it was; the caller removes the staged
|
|
171
|
+
* file (discard).
|
|
172
|
+
*/
|
|
173
|
+
export declare function renameInto(staged: Staged): void;
|
|
174
|
+
/**
|
|
175
|
+
* Remove a staged file that won't be renamed, best effort: only the file
|
|
176
|
+
* this call staged, by its whole identity, since whatever another writer
|
|
177
|
+
* put at its name since is theirs, as renameInto leaves it too. Checked and
|
|
178
|
+
* removed synchronously, as the rename is (checkUnchanged says why).
|
|
179
|
+
*/
|
|
180
|
+
export declare function discard(staged: Staged): Promise<void>;
|
|
181
|
+
//# sourceMappingURL=direct-write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-write.d.ts","sourceRoot":"","sources":["../../../../src/modules/workspace/direct-write.ts"],"names":[],"mappings":"AAA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AO,CAAC,IAAI,CAAC,CAAC;IACvD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,CAAC;AAoBP;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,EAAE,aAAqB,EAAE,GAAE;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAO,GAC1D,OAAO,CAAC,MAAM,CAAC,CA8EjB;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/D;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE;IAAE,QAAQ,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,IAAI,CAoD/G;AAeD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAiB/C;AAWD;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D"}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A direct mount's writes (MountConfig.backend): disk is the only copy, so a
|
|
3
|
+
* write lands there whole when its call answers, or doesn't happen and leaves
|
|
4
|
+
* disk as it was. Ported from anima-research/hands-mcp's staged write
|
|
5
|
+
* (src/shared.ts), behind the mount's boundary as the workspace's other
|
|
6
|
+
* effects hold it (effects.ts):
|
|
7
|
+
*
|
|
8
|
+
* - The file's directory is located inside the mount (checkDir), and where
|
|
9
|
+
* the file lands is judged as a push's write judges it (refusedLanding):
|
|
10
|
+
* inside the mount, in no nested mount's directory, and covered by the
|
|
11
|
+
* mount's include. A link at the file is refused on a mount that doesn't
|
|
12
|
+
* follow links; on one that does, the write goes to the file it leads to
|
|
13
|
+
* when the call stages it, judged the same way, and the link stays.
|
|
14
|
+
* - The new bytes are staged beside the file, in `.workspace-staged-<id>`,
|
|
15
|
+
* at the file's mode, special bits included as far as the kernel lets this
|
|
16
|
+
* process set them (a setgid bit only for a member of the file's group),
|
|
17
|
+
* and renamed over it, so a reader beside the agent never sees half a file
|
|
18
|
+
* and a process killed mid-write leaves the old file whole. A file this
|
|
19
|
+
* process may not write is refused, as a push's write, which opens it for
|
|
20
|
+
* writing, is refused: the rename needs only the directory's permission.
|
|
21
|
+
* A process that dies between staging and its rename leaves the staged
|
|
22
|
+
* file, under that name, which `ls` and `git status` show; so does a
|
|
23
|
+
* refused write whose removal of its staged file fails or can't tell the
|
|
24
|
+
* file is its own, or whose directory another writer moved after the
|
|
25
|
+
* staging, since the removal goes by path (discard) and the path then
|
|
26
|
+
* leads elsewhere. Nothing sweeps it, and the answer doesn't name it.
|
|
27
|
+
* The removal checks the staged name holds that file and unlinks it with
|
|
28
|
+
* no turn of the event loop between, so only a file another writer puts
|
|
29
|
+
* there in that instant can be removed in its place, or one put there
|
|
30
|
+
* that a stat can't tell from it: on the freed inode number, with the
|
|
31
|
+
* same size, mode and owner, in the same tick of a coarse clock.
|
|
32
|
+
* - The rename gives a hard-linked path a file of its own, and the other
|
|
33
|
+
* links keep the old text: `otherLinks` counts them for the answer.
|
|
34
|
+
* - Just before the rename, an edit's file is checked unchanged since its
|
|
35
|
+
* read, by its bytes, read again, and its identity (checkUnchanged),
|
|
36
|
+
* synchronously, so the check and the renames after it run with no turn
|
|
37
|
+
* of the event loop between. Only a change landing in that instant isn't
|
|
38
|
+
* seen, which for edit_many runs from the check through its last rename:
|
|
39
|
+
* no rename can be made conditional.
|
|
40
|
+
* - No sync. The store-backed kind syncs its pushes for its agreement
|
|
41
|
+
* record (reconcile.ts), and a direct mount keeps none, so a power loss
|
|
42
|
+
* or a kernel crash can lose a direct write after its answer said it
|
|
43
|
+
* landed, as it can a hands-mcp write. A process dying can't: the rename is
|
|
44
|
+
* whole by then.
|
|
45
|
+
*
|
|
46
|
+
* Node has no openat or renameat, so the stage and the rename go through the
|
|
47
|
+
* checked directory's path: a directory replaced by another writer on disk
|
|
48
|
+
* between the directory's check and the staging, or after its last check
|
|
49
|
+
* (placedStill), can redirect them, as effects.ts says of a create. For
|
|
50
|
+
* edit_many that last check is each file's, before the other files' checks.
|
|
51
|
+
*/
|
|
52
|
+
import { randomUUID } from 'node:crypto';
|
|
53
|
+
import { accessSync, closeSync, constants as fsConstants, lstatSync, openSync, readSync, renameSync, unlinkSync } from 'node:fs';
|
|
54
|
+
import { lstat, open, realpath } from 'node:fs/promises';
|
|
55
|
+
import { relative, sep } from 'node:path';
|
|
56
|
+
import { refusedLanding } from './effects.js';
|
|
57
|
+
import { NONBLOCK, NOT_FOLLOWED, OUTSIDE_PARENT, checkDir, checkRoot, errno, nameOf, parentOf, } from './observe.js';
|
|
58
|
+
/** An open that follows no link at the path, where the platform has one. */
|
|
59
|
+
const NOFOLLOW = typeof fsConstants.O_NOFOLLOW === 'number' ? fsConstants.O_NOFOLLOW : 0;
|
|
60
|
+
/** The name a staged file starts with, beside the file it replaces. */
|
|
61
|
+
export const STAGED_PREFIX = '.workspace-staged-';
|
|
62
|
+
/**
|
|
63
|
+
* Why a direct write didn't happen when its mount's root was replaced under
|
|
64
|
+
* it: a direct mount keeps no root to sync to (MountConfig.backend), so its
|
|
65
|
+
* next call works beneath whatever is there then.
|
|
66
|
+
*/
|
|
67
|
+
export const ROOT_MOVED = 'the mount root changed while this call was being applied: a new call works beneath whatever directory the mount\'s path leads to then';
|
|
68
|
+
export const identityOf = (info) => ({
|
|
69
|
+
dev: info.dev,
|
|
70
|
+
ino: info.ino,
|
|
71
|
+
size: info.size,
|
|
72
|
+
mode: info.mode,
|
|
73
|
+
uid: info.uid,
|
|
74
|
+
gid: info.gid,
|
|
75
|
+
mtimeNs: info.mtimeNs,
|
|
76
|
+
ctimeNs: info.ctimeNs,
|
|
77
|
+
});
|
|
78
|
+
export const sameIdentity = (a, b) => a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mode === b.mode && a.uid === b.uid && a.gid === b.gid
|
|
79
|
+
&& a.mtimeNs === b.mtimeNs && a.ctimeNs === b.ctimeNs;
|
|
80
|
+
/** Another writer replaced, changed or removed the file between its read and its rename; nothing was written. */
|
|
81
|
+
export class FileChanged extends Error {
|
|
82
|
+
}
|
|
83
|
+
/** Why a direct write didn't happen, in words for its answer; disk is as it was. */
|
|
84
|
+
export class WriteRefused extends Error {
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Test seams. `afterStage` is called once a call's files are staged, before
|
|
88
|
+
* they're checked unchanged (another writer acting then); `beforeRename`
|
|
89
|
+
* just before each rename, inside its refusal, so throwing stands for the
|
|
90
|
+
* rename failing. Production sets neither.
|
|
91
|
+
*/
|
|
92
|
+
export const directWriteTestSeam = {};
|
|
93
|
+
/** The mount-relative path of a real path inside the mount's root, `/`-separated. */
|
|
94
|
+
function relativeTo(rootReal, real) {
|
|
95
|
+
return relative(rootReal, real).split(sep).join('/');
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The checked directory a mount-relative file lies in, beneath a checked
|
|
99
|
+
* root, or why not. With `makeDirectory`, missing directories are made, as
|
|
100
|
+
* a push's write makes them; without it, a missing one refuses the write,
|
|
101
|
+
* since an edit replaces a file that exists.
|
|
102
|
+
*/
|
|
103
|
+
async function directoryOf(view, rootReal, rel, makeDirectory) {
|
|
104
|
+
const checked = await checkDir(view, rootReal, parentOf(rel), { create: makeDirectory });
|
|
105
|
+
if (checked.kind === 'checked')
|
|
106
|
+
return checked.dir;
|
|
107
|
+
if (checked.kind === 'absent')
|
|
108
|
+
throw new FileChanged(rel);
|
|
109
|
+
throw new WriteRefused(checked.outside ? OUTSIDE_PARENT : checked.reason);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Stage `bytes` beside the mount-relative file `rel`, to be renamed over it:
|
|
113
|
+
* the first half of a direct write. The file keeps its mode, special bits
|
|
114
|
+
* included, as far as the kernel lets this process set them; a new file
|
|
115
|
+
* takes `0666` less the umask, as a shell's would. Its owner and group are
|
|
116
|
+
* this process's and the ones its directory gives a new file, and an ACL or
|
|
117
|
+
* extended attribute on the file isn't carried over, as with any write that
|
|
118
|
+
* renames over a file. Anything there that isn't a regular file is refused,
|
|
119
|
+
* and a refusal removes the staged file it made, except where the header
|
|
120
|
+
* says one is left. The staged file is written and moded through its own
|
|
121
|
+
* handle, never through its name again.
|
|
122
|
+
*/
|
|
123
|
+
export async function stageContained(view, rootReal, rel, bytes, { makeDirectory = false } = {}) {
|
|
124
|
+
const root = await checkRoot(view, rootReal);
|
|
125
|
+
if ('reason' in root)
|
|
126
|
+
throw new WriteRefused(root.reason);
|
|
127
|
+
let parent = await directoryOf(view, rootReal, rel, makeDirectory);
|
|
128
|
+
let path = parent.at(nameOf(rel));
|
|
129
|
+
let info = await lstat(path, { bigint: true }).catch((err) => {
|
|
130
|
+
if (errno(err) === 'ENOENT')
|
|
131
|
+
return null;
|
|
132
|
+
throw new WriteRefused(`cannot stat the file (${errno(err) ?? String(err)})`);
|
|
133
|
+
});
|
|
134
|
+
if (info?.isSymbolicLink()) {
|
|
135
|
+
if (!view.followSymlinks)
|
|
136
|
+
throw new WriteRefused(NOT_FOLLOWED);
|
|
137
|
+
// A followed link stands for the file it leads to, as a read takes it:
|
|
138
|
+
// the write goes there, judged where it lands, and the link stays.
|
|
139
|
+
const real = await realpath(path).catch((err) => {
|
|
140
|
+
throw new WriteRefused(errno(err) === 'ENOENT' ? "a symlink whose target doesn't exist" : `cannot resolve the symlink (${errno(err) ?? String(err)})`);
|
|
141
|
+
});
|
|
142
|
+
const leaves = await refusedLanding(view, rootReal, rel, real);
|
|
143
|
+
if (leaves !== null)
|
|
144
|
+
throw new WriteRefused(leaves);
|
|
145
|
+
const realRel = relativeTo(rootReal, real);
|
|
146
|
+
parent = await directoryOf(view, rootReal, realRel, false);
|
|
147
|
+
path = parent.at(nameOf(realRel));
|
|
148
|
+
info = await lstat(path, { bigint: true }).catch((err) => {
|
|
149
|
+
// Gone since realpath found it: another writer's change.
|
|
150
|
+
if (errno(err) === 'ENOENT')
|
|
151
|
+
throw new FileChanged(rel);
|
|
152
|
+
throw new WriteRefused(`cannot stat the file the symlink leads to (${errno(err) ?? String(err)})`);
|
|
153
|
+
});
|
|
154
|
+
if (info.isSymbolicLink())
|
|
155
|
+
throw new FileChanged(rel);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// A file, or none yet, reached through a link among its directories
|
|
159
|
+
// lands where the mount may not act: in a nested mount's directory, or
|
|
160
|
+
// on a file its own include leaves out (refusedLanding).
|
|
161
|
+
const leaves = await refusedLanding(view, rootReal, rel, path);
|
|
162
|
+
if (leaves !== null)
|
|
163
|
+
throw new WriteRefused(leaves);
|
|
164
|
+
}
|
|
165
|
+
if (info?.isDirectory())
|
|
166
|
+
throw new WriteRefused('a directory');
|
|
167
|
+
if (info && !info.isFile())
|
|
168
|
+
throw new WriteRefused('not a regular file');
|
|
169
|
+
// A fixed-length name, so a file whose own name is near the 255-byte limit can still be replaced.
|
|
170
|
+
const temp = parent.at(`${STAGED_PREFIX}${randomUUID()}`);
|
|
171
|
+
let made = false;
|
|
172
|
+
try {
|
|
173
|
+
// A new file is made at 0666 and the kernel takes the umask off as it
|
|
174
|
+
// makes it. A file being replaced gives the staged file its own mode,
|
|
175
|
+
// which only a chmod can set past the umask, and only after the bytes
|
|
176
|
+
// are written, since a write clears a set-user or set-group bit; until
|
|
177
|
+
// then the staged file is the owner's alone, so no other user can read
|
|
178
|
+
// a private file's new text while it's staged.
|
|
179
|
+
const handle = await open(temp, 'wx', info ? 0o600 : 0o666);
|
|
180
|
+
made = true;
|
|
181
|
+
let staged;
|
|
182
|
+
try {
|
|
183
|
+
await handle.writeFile(bytes);
|
|
184
|
+
if (info)
|
|
185
|
+
await handle.chmod(Number(info.mode & 4095n));
|
|
186
|
+
const own = await handle.stat({ bigint: true });
|
|
187
|
+
staged = { path, temp, tempIdentity: identityOf(own), root: root.dir, parent, otherLinks: 0 };
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
// Removed while its handle is still open, so its device and inode
|
|
191
|
+
// name it and no other file: one made at its name since can't have
|
|
192
|
+
// taken its inode number. One that can't be told is left.
|
|
193
|
+
const mine = await handle.stat({ bigint: true }).catch(() => null);
|
|
194
|
+
if (mine)
|
|
195
|
+
removeIf(temp, (there) => there.dev === mine.dev && there.ino === mine.ino);
|
|
196
|
+
await handle.close().catch(() => undefined);
|
|
197
|
+
throw err;
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
await handle.close();
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
// Closed, or not, with its bytes in doubt: removed by its whole identity, as a refusal's.
|
|
204
|
+
await discard(staged);
|
|
205
|
+
throw err;
|
|
206
|
+
}
|
|
207
|
+
return staged;
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
// A staged file that couldn't be made names the directory: a push's
|
|
211
|
+
// write in place needs only the file, and this one needs both.
|
|
212
|
+
throw new WriteRefused(made
|
|
213
|
+
? `cannot write the staged file beside it (${errno(err) ?? String(err)})`
|
|
214
|
+
: `cannot make the staged file in its directory (${errno(err) ?? String(err)}): a direct write needs to write the file's directory as well as the file`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Throw unless the root and the file's directory are still the ones the
|
|
219
|
+
* staging checked, with a push's words for the directory (effects.ts
|
|
220
|
+
* moved()).
|
|
221
|
+
*/
|
|
222
|
+
export async function placedStill(staged) {
|
|
223
|
+
if (!(await staged.root.stillHere()))
|
|
224
|
+
throw new WriteRefused(ROOT_MOVED);
|
|
225
|
+
if (!(await staged.parent.stillHere()))
|
|
226
|
+
throw new WriteRefused('the directory changed since it was checked');
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Throw unless the file is still what its read found: FileChanged when it
|
|
230
|
+
* changed or is gone, nothing written. `expected` is null for a write, which
|
|
231
|
+
* read nothing and replaces whatever is there. Either way a link swapped in
|
|
232
|
+
* at the file the rename replaces (on a mount that follows links, the file
|
|
233
|
+
* the link at the agent's path led to when the call staged it) is refused
|
|
234
|
+
* rather than replaced, and so is a file this process may not write. It reads the entry the
|
|
235
|
+
* rename replaces, and then the file's bytes, synchronously, as renameInto
|
|
236
|
+
* runs, so a check and the renames after it run with no turn of the event
|
|
237
|
+
* loop between.
|
|
238
|
+
*
|
|
239
|
+
* The identity, taken once the bytes are read, catches a file replaced or
|
|
240
|
+
* re-moded under the call, which equal bytes wouldn't show. The bytes are
|
|
241
|
+
* compared with the ones the edit read: a kernel that stamps files from a
|
|
242
|
+
* coarse clock, as Linux before 6.13 does, leaves a file's identity as it
|
|
243
|
+
* was after a second write of the same size within one tick of its last
|
|
244
|
+
* change (on Debian's Linux 6.12.113 with ext4, 1,632 to 1,752 of 2,000
|
|
245
|
+
* such rewrites kept every stamp, in three runs), and the bytes show that
|
|
246
|
+
* change on every clock. The bytes are read through an open that follows
|
|
247
|
+
* no link and doesn't wait on a pipe put at the path since its lstat, and
|
|
248
|
+
* at most one byte past what the edit read, so the check never blocks and
|
|
249
|
+
* reads no more than that.
|
|
250
|
+
*/
|
|
251
|
+
export function checkUnchanged(staged, expected) {
|
|
252
|
+
let now;
|
|
253
|
+
try {
|
|
254
|
+
now = lstatSync(staged.path, { bigint: true });
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
if (errno(err) !== 'ENOENT')
|
|
258
|
+
throw new WriteRefused(`cannot check that it hadn't changed (${errno(err) ?? String(err)})`);
|
|
259
|
+
if (expected !== null)
|
|
260
|
+
throw new FileChanged(staged.path);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (now.isSymbolicLink())
|
|
264
|
+
throw new WriteRefused('it became a symlink while this call was being applied');
|
|
265
|
+
if (now.isDirectory())
|
|
266
|
+
throw new WriteRefused('a directory');
|
|
267
|
+
if (!now.isFile())
|
|
268
|
+
throw new WriteRefused('not a regular file');
|
|
269
|
+
// As a push's write, which opens the file for writing, would be refused:
|
|
270
|
+
// the rename needs only the directory's permission, and would replace a
|
|
271
|
+
// file its owner made read-only.
|
|
272
|
+
try {
|
|
273
|
+
accessSync(staged.path, fsConstants.W_OK);
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
const code = errno(err);
|
|
277
|
+
// Removed since the lstat: a write makes the file anew; an edit's read is gone.
|
|
278
|
+
if (code === 'ENOENT') {
|
|
279
|
+
if (expected === null)
|
|
280
|
+
return;
|
|
281
|
+
throw new FileChanged(staged.path);
|
|
282
|
+
}
|
|
283
|
+
if (code === 'EACCES' || code === 'EPERM') {
|
|
284
|
+
throw new WriteRefused(`a file the host's process may not write (${code}): its mode or owner keeps that process out, and calling again is refused until the file's owner, or whoever runs the host, changes that`);
|
|
285
|
+
}
|
|
286
|
+
throw new WriteRefused(`cannot check that the host's process may write it (${code ?? String(err)})`);
|
|
287
|
+
}
|
|
288
|
+
if (expected === null)
|
|
289
|
+
return;
|
|
290
|
+
let bytes;
|
|
291
|
+
let after;
|
|
292
|
+
try {
|
|
293
|
+
// No link followed, and no wait on a pipe, if either was put at the path since the lstat.
|
|
294
|
+
const fd = openSync(staged.path, fsConstants.O_RDONLY | NOFOLLOW | NONBLOCK);
|
|
295
|
+
try {
|
|
296
|
+
// One byte past what the edit read, enough to see the file differs:
|
|
297
|
+
// a file another writer made larger, or a pipe a writer keeps
|
|
298
|
+
// filling, put at the path since, costs no more than that.
|
|
299
|
+
bytes = readBounded(fd, expected.bytes.length + 1);
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
closeSync(fd);
|
|
303
|
+
}
|
|
304
|
+
// And the entry is still the file the edit read, after its bytes were read.
|
|
305
|
+
after = lstatSync(staged.path, { bigint: true });
|
|
306
|
+
}
|
|
307
|
+
catch (err) {
|
|
308
|
+
// ELOOP: a link put at the path since the lstat; EAGAIN: a pipe, with a
|
|
309
|
+
// writer and nothing in it yet. Either is another writer's change.
|
|
310
|
+
if (errno(err) === 'ENOENT' || errno(err) === 'ELOOP' || errno(err) === 'EAGAIN')
|
|
311
|
+
throw new FileChanged(staged.path);
|
|
312
|
+
throw new WriteRefused(`cannot check that it hadn't changed (${errno(err) ?? String(err)})`);
|
|
313
|
+
}
|
|
314
|
+
if (!sameIdentity(identityOf(after), expected.identity) || !bytes.equals(expected.bytes))
|
|
315
|
+
throw new FileChanged(staged.path);
|
|
316
|
+
}
|
|
317
|
+
/** Up to `limit` bytes from the start of `fd`, fewer at its end. */
|
|
318
|
+
function readBounded(fd, limit) {
|
|
319
|
+
const buffer = Buffer.alloc(limit);
|
|
320
|
+
let filled = 0;
|
|
321
|
+
while (filled < limit) {
|
|
322
|
+
// From where the last read ended (a pipe has no positions to read at).
|
|
323
|
+
const got = readSync(fd, buffer, filled, limit - filled, null);
|
|
324
|
+
if (got === 0)
|
|
325
|
+
break;
|
|
326
|
+
filled += got;
|
|
327
|
+
}
|
|
328
|
+
return buffer.subarray(0, filled);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Rename the staged file over the file, synchronously (checkUnchanged says
|
|
332
|
+
* why), counting the other hard links it splits the path from just before.
|
|
333
|
+
* A failed rename leaves the file as it was; the caller removes the staged
|
|
334
|
+
* file (discard).
|
|
335
|
+
*/
|
|
336
|
+
export function renameInto(staged) {
|
|
337
|
+
let otherLinks;
|
|
338
|
+
try {
|
|
339
|
+
directWriteTestSeam.beforeRename?.(staged.path);
|
|
340
|
+
// The staged file is still the one this call wrote, not another put at its name.
|
|
341
|
+
const temp = lstatSync(staged.temp, { bigint: true });
|
|
342
|
+
if (!temp.isFile() || !sameIdentity(identityOf(temp), staged.tempIdentity)) {
|
|
343
|
+
throw new WriteRefused('another writer replaced the staged copy of the new text before it could be renamed over the file, which is as it was');
|
|
344
|
+
}
|
|
345
|
+
otherLinks = otherLinksAt(staged.path);
|
|
346
|
+
renameSync(staged.temp, staged.path);
|
|
347
|
+
}
|
|
348
|
+
catch (err) {
|
|
349
|
+
if (err instanceof WriteRefused)
|
|
350
|
+
throw err;
|
|
351
|
+
throw new WriteRefused(`cannot rename the staged file over it (${errno(err) ?? (err instanceof Error ? err.message : String(err))})`);
|
|
352
|
+
}
|
|
353
|
+
// Set once the rename has happened, so a count never stands for a split that didn't.
|
|
354
|
+
staged.otherLinks = otherLinks;
|
|
355
|
+
}
|
|
356
|
+
/** The other hard links of what the entry at `path` holds: 0 for none there, and when lstat fails, since the count only informs the answer. */
|
|
357
|
+
function otherLinksAt(path) {
|
|
358
|
+
try {
|
|
359
|
+
return lstatSync(path).nlink - 1;
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return 0;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Remove a staged file that won't be renamed, best effort: only the file
|
|
367
|
+
* this call staged, by its whole identity, since whatever another writer
|
|
368
|
+
* put at its name since is theirs, as renameInto leaves it too. Checked and
|
|
369
|
+
* removed synchronously, as the rename is (checkUnchanged says why).
|
|
370
|
+
*/
|
|
371
|
+
export async function discard(staged) {
|
|
372
|
+
removeIf(staged.temp, (there) => there.isFile() && sameIdentity(identityOf(there), staged.tempIdentity));
|
|
373
|
+
}
|
|
374
|
+
/** Unlink what's at `path` if `ours` says it's the file meant; best effort, with no turn of the event loop between the check and the unlink. */
|
|
375
|
+
function removeIf(path, ours) {
|
|
376
|
+
try {
|
|
377
|
+
if (ours(lstatSync(path, { bigint: true })))
|
|
378
|
+
unlinkSync(path);
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
// Gone already, or not ours to know: left, as the header says.
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
//# sourceMappingURL=direct-write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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