dsh-hashline-edit 0.1.0 → 0.2.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 +72 -70
- package/cordis.patch.yml +1 -1
- package/lib/index.js +4494 -4813
- package/lib/types/dsh/contracts.d.ts +69 -6
- package/lib/types/dsh/fs.d.ts +38 -3
- package/lib/types/dsh/guidance.d.ts +5 -5
- package/lib/types/dsh/hide.d.ts +78 -0
- package/lib/types/dsh/host-compat.d.ts +7 -78
- package/lib/types/dsh/index.d.ts +17 -7
- package/lib/types/dsh/metrics/events.d.ts +8 -1
- package/lib/types/dsh/metrics/instrument.d.ts +20 -14
- package/lib/types/dsh/metrics/observer.d.ts +28 -0
- package/lib/types/dsh/sandbox.d.ts +2 -2
- package/lib/types/dsh/shell-hook.d.ts +17 -8
- package/lib/types/dsh/shell-view.d.ts +65 -3
- package/lib/types/dsh/tools/apply-patch.d.ts +38 -0
- package/lib/types/dsh/tools/context.d.ts +19 -1
- package/lib/types/dsh/tools/output.d.ts +32 -4
- package/lib/types/dsh/tools/read.d.ts +12 -15
- package/lib/types/dsh/tools/undo.d.ts +5 -0
- package/lib/types/dsh/write-hook.d.ts +8 -22
- package/lib/types/src/apply-patch/commit.d.ts +49 -0
- package/lib/types/src/apply-patch/grammar.d.ts +29 -0
- package/lib/types/src/apply-patch/lifecycle.d.ts +32 -0
- package/lib/types/src/apply-patch/plan.d.ts +50 -0
- package/lib/types/src/apply-patch/render.d.ts +51 -0
- package/lib/types/src/apply-patch/resolve.d.ts +129 -0
- package/lib/types/src/apply-patch/tool.d.ts +54 -0
- package/lib/types/src/apply-patch/types.d.ts +362 -0
- package/lib/types/src/bash-view-banner.d.ts +20 -0
- package/lib/types/src/domain-errors.d.ts +16 -2
- package/lib/types/src/edit-undo.d.ts +11 -2
- package/lib/types/src/file-content/detection.d.ts +17 -0
- package/lib/types/src/file-content/index.d.ts +2 -2
- package/lib/types/src/file-content/preview.d.ts +1 -1
- package/lib/types/src/fs-lifecycle.d.ts +44 -0
- package/lib/types/src/hashline/resolve.d.ts +6 -0
- package/lib/types/src/host-utils.d.ts +63 -0
- package/lib/types/src/mutation-engine/batch-span-gate.d.ts +6 -0
- package/lib/types/src/mutation-engine/edit-request.d.ts +34 -0
- package/lib/types/src/mutation-engine/pipeline.d.ts +18 -3
- package/lib/types/src/mutation-engine/types.d.ts +50 -58
- package/lib/types/src/read-expansion/grammar-manifest.d.ts +4 -2
- package/lib/types/src/read-expansion/java-decoration.d.ts +21 -0
- package/lib/types/src/read-expansion/span-expansion.d.ts +6 -2
- package/lib/types/src/read-expansion/span-kind.d.ts +3 -2
- package/lib/types/src/read-expansion/vue-decoration.d.ts +14 -0
- package/lib/types/src/served-session/serve-render.d.ts +9 -3
- package/lib/types/src/undo-store.d.ts +17 -1
- package/package.json +10 -22
- package/prompts/apply-patch-guidelines.md +10 -0
- package/prompts/apply-patch.md +1 -0
- package/prompts/read-guidelines.md +5 -5
- package/prompts/read.md +1 -1
- package/prompts/undo-last-edit-guidelines.md +2 -2
- package/prompts/undo-last-edit-snippet.md +1 -1
- package/prompts/undo-last-edit.md +1 -1
- package/src/apply-patch/commit.ts +190 -0
- package/src/apply-patch/grammar.ts +620 -0
- package/src/apply-patch/index.ts +17 -0
- package/src/apply-patch/lifecycle.ts +195 -0
- package/src/apply-patch/plan.ts +800 -0
- package/src/apply-patch/render.ts +137 -0
- package/src/apply-patch/resolve.ts +470 -0
- package/src/apply-patch/tool.ts +257 -0
- package/src/apply-patch/types.ts +387 -0
- package/src/cut-repair.ts +77 -11
- package/src/domain-errors.ts +58 -10
- package/src/edit-undo.ts +379 -25
- package/src/file-content/detection.ts +34 -0
- package/src/file-content/index.ts +2 -2
- package/src/file-content/preview.ts +1 -1
- package/src/file-content/served-header.ts +1 -1
- package/src/fs-lifecycle.ts +201 -0
- package/src/hash-store.ts +18 -1
- package/src/hashline/lease-resolve.ts +14 -8
- package/src/hashline/resolve.ts +30 -27
- package/src/host-utils.ts +224 -0
- package/src/mutation-engine/batch-span-gate.ts +17 -4
- package/src/mutation-engine/edit-request.ts +39 -0
- package/src/mutation-engine/pipeline.ts +535 -63
- package/src/mutation-engine/types.ts +49 -65
- package/src/mutation-queue.ts +1 -1
- package/src/prompts.ts +0 -28
- package/src/read-expansion/ast-provider.ts +4 -0
- package/src/read-expansion/grammar-manifest.ts +21 -2
- package/src/read-expansion/java-decoration.ts +34 -0
- package/src/read-expansion/span-expansion.ts +6 -2
- package/src/read-expansion/span-kind.ts +3 -1
- package/src/read-expansion/vue-decoration.ts +43 -0
- package/src/served-session/serve-render.ts +5 -5
- package/src/undo-store.ts +74 -5
- package/lib/types/dsh/encoding-bridge.d.ts +0 -25
- package/lib/types/dsh/encoding.d.ts +0 -144
- package/lib/types/dsh/tools/edit.d.ts +0 -10
- package/lib/types/src/edit-tool.d.ts +0 -41
- package/lib/types/src/mutation-engine/engine.d.ts +0 -31
- package/lib/types/src/payload-contract.d.ts +0 -124
- package/prompts/edit-guidelines.md +0 -10
- package/prompts/edit-snippet.md +0 -1
- package/prompts/edit.md +0 -1
- package/src/bash-classifier.ts +0 -1626
- package/src/bash-conversion/decide.ts +0 -812
- package/src/bash-display-transform.ts +0 -50
- package/src/bash-multifile-config.ts +0 -239
- package/src/bash-view-config.ts +0 -158
- package/src/edit-normalize.ts +0 -8
- package/src/edit-render.ts +0 -161
- package/src/edit-tool.ts +0 -116
- package/src/edit.ts +0 -136
- package/src/integrations/pi-lens/command.ts +0 -712
- package/src/integrations/pi-lens/config.ts +0 -148
- package/src/integrations/pi-lens/io-bridge-adapter.ts +0 -234
- package/src/integrations/pi-lens/io-bridge.ts +0 -112
- package/src/integrations/pi-lens/settings-overlay.ts +0 -272
- package/src/lifecycle-hooks/index.ts +0 -1992
- package/src/lifecycle-hooks/types.ts +0 -64
- package/src/mutated-files.ts +0 -75
- package/src/mutation-engine/engine.ts +0 -173
- package/src/mutation-engine/index.ts +0 -17
- package/src/payload-contract.ts +0 -637
- package/src/preview-controller.ts +0 -84
- package/src/read.ts +0 -865
- package/src/search-hook.ts +0 -41
- package/src/store-config.ts +0 -73
- package/src/store-janitor-warning.ts +0 -169
- package/src/store-janitor.ts +0 -539
- package/src/store-kernel/settings.ts +0 -233
- package/src/store.ts +0 -154
- package/src/tui-presenter.ts +0 -134
- package/src/write-hook.ts +0 -130
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { type LineEnding } from "../src/edit-diff.js";
|
|
2
|
-
/** The single config knob set the admission gates read. */
|
|
3
|
-
export interface EncodingConfig {
|
|
4
|
-
/** When true, admit a probabilistic decode (the autoGuess gate). */
|
|
5
|
-
readonly autoGuessEncoding: boolean;
|
|
6
|
-
/** Legacy code pages scored for the Top-3 preview. */
|
|
7
|
-
readonly supportedEncodings: readonly string[];
|
|
8
|
-
}
|
|
9
|
-
/** Defaults mirror the reference config: deterministic until the user opts in. */
|
|
10
|
-
export declare const DEFAULT_ENCODING_CONFIG: EncodingConfig;
|
|
11
|
-
/**
|
|
12
|
-
* One file's encoding state, recorded after a governed read and inverted on save.
|
|
13
|
-
* `version` is the file-version snapshot the read observed; a memo whose version
|
|
14
|
-
* differs from the current one is stale and must not steer a write.
|
|
15
|
-
*/
|
|
16
|
-
export interface EncodingState {
|
|
17
|
-
readonly encoding: string;
|
|
18
|
-
readonly hasBOM: boolean;
|
|
19
|
-
readonly lineEnding: LineEnding;
|
|
20
|
-
readonly version: string | undefined;
|
|
21
|
-
}
|
|
22
|
-
/** One Top-3 preview row: the guessed encoding, a sample of its decode, and its score. */
|
|
23
|
-
export interface CandidatePreview {
|
|
24
|
-
readonly encoding: string;
|
|
25
|
-
readonly sample: string;
|
|
26
|
-
readonly score: number;
|
|
27
|
-
}
|
|
28
|
-
/** A successful admission. */
|
|
29
|
-
export interface DecodeResult {
|
|
30
|
-
/** The decoded text, without a BOM character. */
|
|
31
|
-
readonly text: string;
|
|
32
|
-
/** The canonical encoding that was used. */
|
|
33
|
-
readonly encoding: string;
|
|
34
|
-
/** Whether the admitted bytes carried a BOM. */
|
|
35
|
-
readonly hasBOM: boolean;
|
|
36
|
-
/** The dominant line ending of the decoded text. */
|
|
37
|
-
readonly lineEnding: LineEnding;
|
|
38
|
-
/** Top-3 previews: always empty on a deterministic/BOM/hint admission. */
|
|
39
|
-
readonly candidates: CandidatePreview[];
|
|
40
|
-
/** Auto-guess notice appended to the read text (heuristic path only). */
|
|
41
|
-
readonly footer?: string;
|
|
42
|
-
}
|
|
43
|
-
/** Caller-supplied admission overrides. */
|
|
44
|
-
export interface DecodeOptions {
|
|
45
|
-
/** Reopen-with-encoding: an explicit choice beats BOM and UTF-8 detection. */
|
|
46
|
-
encodingHint?: string;
|
|
47
|
-
/** Path used in model-facing diagnostics. */
|
|
48
|
-
displayPath?: string;
|
|
49
|
-
}
|
|
50
|
-
/** Inverse of {@link decodeForOpen}: bytes to write plus the state to record for them. */
|
|
51
|
-
export interface SaveResult {
|
|
52
|
-
readonly bytes: Uint8Array;
|
|
53
|
-
readonly state: EncodingState;
|
|
54
|
-
/**
|
|
55
|
-
* True when a legacy code page could not represent the edited text and the
|
|
56
|
-
* bytes were written as UTF-8 instead. Callers must surface this on the
|
|
57
|
-
* model-facing channel; a silent degradation is data loss the model cannot
|
|
58
|
-
* see.
|
|
59
|
-
*/
|
|
60
|
-
readonly degraded: boolean;
|
|
61
|
-
}
|
|
62
|
-
/** Caller-supplied save overrides. */
|
|
63
|
-
export interface SaveOptions {
|
|
64
|
-
/** Re-encode to this encoding instead of the recorded state. */
|
|
65
|
-
encodingHint?: string;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Canonicalize a case/separator-insensitive encoding name, or `undefined` when
|
|
69
|
-
* the name is outside the closed vocabulary. `utf-8`/`UTF_8`/`utf8` all map to
|
|
70
|
-
* `utf8`, so the model may spell the name however it read it elsewhere.
|
|
71
|
-
*/
|
|
72
|
-
export declare function normalizeEncoding(input: string): string | undefined;
|
|
73
|
-
/** Whether a name (after canonicalization) is in the closed vocabulary. */
|
|
74
|
-
export declare function isSupportedEncoding(encoding: string): boolean;
|
|
75
|
-
/** The detected BOM: the canonical encoding it announces and its byte width. */
|
|
76
|
-
export interface BomInfo {
|
|
77
|
-
readonly encoding: string;
|
|
78
|
-
readonly bomLen: number;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Sniff a leading BOM. The 4-byte UTF-32 BOMs are checked before the 2-byte
|
|
82
|
-
* UTF-16 ones because a UTF-32 BOM starts with a parent UTF-16 BOM.
|
|
83
|
-
*/
|
|
84
|
-
export declare function detectBom(bytes: Uint8Array): BomInfo | undefined;
|
|
85
|
-
/** Whether the bytes are valid strict (fatal) UTF-8. */
|
|
86
|
-
export declare function isValidUtf8(bytes: Uint8Array): boolean;
|
|
87
|
-
/** Score one decode; negative scores mark decodes that are almost certainly wrong. */
|
|
88
|
-
export declare function scoreText(text: string, encoding: string): number;
|
|
89
|
-
/**
|
|
90
|
-
* Two-axis Top-3 preview: decode under every allowlist entry, score the result,
|
|
91
|
-
* sort descending, keep three. BOM handling belongs to the caller.
|
|
92
|
-
*/
|
|
93
|
-
export declare function top3Candidates(bytes: Uint8Array, allowlist?: readonly string[]): CandidatePreview[];
|
|
94
|
-
/**
|
|
95
|
-
* Admit a raw byte buffer for a read. Pure: no IO and no memo writes; the caller
|
|
96
|
-
* records the returned state with {@link recordEncodingState}.
|
|
97
|
-
*
|
|
98
|
-
* Order is fixed: an explicit hint wins for decoding (a BOM still wins for
|
|
99
|
-
* `hasBOM`), BOM sniff always precedes strict UTF-8, and probabilistic decoding
|
|
100
|
-
* runs only when the autoGuess gate is open. A failed admission throws
|
|
101
|
-
* `E_UNSUPPORTED_FILE` carrying the Top-3 preview as its description.
|
|
102
|
-
*/
|
|
103
|
-
export declare function decodeForOpen(bytes: Uint8Array, config?: EncodingConfig, options?: DecodeOptions): DecodeResult;
|
|
104
|
-
/**
|
|
105
|
-
* Inverse of {@link decodeForOpen}: restore the recorded line ending and BOM,
|
|
106
|
-
* then encode to the recorded code page. A code page that cannot reproduce the
|
|
107
|
-
* edited text degrades to UTF-8 (never lossy bytes); an explicit hint that
|
|
108
|
-
* cannot be honored is a model-facing `E_BAD_PAYLOAD` refusal instead, because
|
|
109
|
-
* silently overriding a choice the model made would drop data the model expects
|
|
110
|
-
* to keep.
|
|
111
|
-
*/
|
|
112
|
-
export declare function encodeForSave(content: string, existing: EncodingState | undefined, options?: SaveOptions): SaveResult;
|
|
113
|
-
/**
|
|
114
|
-
* Whether the core's UTF-8 read/write path handles this recorded state without
|
|
115
|
-
* a host bridge. UTF-8 (with or without a BOM) is the only class the core can
|
|
116
|
-
* read back verbatim: its loader strips/reattaches the BOM and restores line
|
|
117
|
-
* endings itself. Every other recorded code page has to be staged as UTF-8 for
|
|
118
|
-
* the core and re-encoded afterwards.
|
|
119
|
-
*/
|
|
120
|
-
export declare function isUtf8Native(state: EncodingState): boolean;
|
|
121
|
-
/**
|
|
122
|
-
* The model-facing note for a save that had to degrade a legacy code page to
|
|
123
|
-
* UTF-8 because the edited text is not representable in it. Phrased as a fact
|
|
124
|
-
* plus the next action: the bytes on disk are now UTF-8 and future reads see
|
|
125
|
-
* that, so a re-read re-syncs the encoding state.
|
|
126
|
-
*/
|
|
127
|
-
export declare function lossyDegradeWarning(state: EncodingState): string;
|
|
128
|
-
/**
|
|
129
|
-
* The recorded state for a target, or `undefined` when absent or stale.
|
|
130
|
-
* A stale entry is dropped here so a write can never invert a state the read
|
|
131
|
-
* that recorded it no longer applies to.
|
|
132
|
-
*/
|
|
133
|
-
export declare function encodingStateFor(targetKey: string, version: string | undefined): EncodingState | undefined;
|
|
134
|
-
/** Record the state a read observed. */
|
|
135
|
-
export declare function recordEncodingState(targetKey: string, state: EncodingState): void;
|
|
136
|
-
/** Forget one target's state, or every target's when called without a key. */
|
|
137
|
-
export declare function clearEncodingState(targetKey?: string): void;
|
|
138
|
-
/** A stable version token for a `stat(2)` identity, or `undefined` when absent. */
|
|
139
|
-
export declare function versionOfStat(stat: {
|
|
140
|
-
readonly size: number;
|
|
141
|
-
readonly mtimeMs: number;
|
|
142
|
-
} | undefined): string | undefined;
|
|
143
|
-
/** Build the state to record from an admission, bound to the version it observed. */
|
|
144
|
-
export declare function stateFromDecode(result: DecodeResult, version: string | undefined): EncodingState;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from "@deepseek-ai/dsh-tools";
|
|
2
|
-
import type { ToolDependencies } from "../contracts.js";
|
|
3
|
-
/** dsh tool name; the agent-layer registration shadows the preset's built-in `edit`. */
|
|
4
|
-
export declare const EDIT_TOOL_NAME = "edit";
|
|
5
|
-
/**
|
|
6
|
-
* Build the dsh `edit` tool for one agent install.
|
|
7
|
-
* @param deps - the host seams this tool may touch; `sandbox` advertises and resolves escalation.
|
|
8
|
-
* @returns a registry-ready dsh tool definition named `edit`.
|
|
9
|
-
*/
|
|
10
|
-
export declare function buildEditTool(deps: ToolDependencies): ToolDefinition;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/** SAFETY: EditTool — deep module owning the edit Use Case seam.
|
|
2
|
-
*
|
|
3
|
-
* Graded surface: one narrow interface `EditTool { execute, preview }`
|
|
4
|
-
* hides pipeline delegation, warnings/drift stitching.
|
|
5
|
-
* Frameworks (pi TUI) never cross this seam — that lives in TuiPresenter.
|
|
6
|
-
* Clean Architecture: Use Cases depend inward only (mutation-engine),
|
|
7
|
-
* never outward to Frameworks.
|
|
8
|
-
*
|
|
9
|
-
* Typed boundaries: validate once at admission (payload-contract via normReq/assertReq),
|
|
10
|
-
* trust inside. Immutable state: never mutates caller-owned request.
|
|
11
|
-
*/
|
|
12
|
-
type EditToolContext = {
|
|
13
|
-
cwd: string;
|
|
14
|
-
sessionManager?: {
|
|
15
|
-
getSessionId(): string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export type PreviewContext = {
|
|
19
|
-
sessionManager?: {
|
|
20
|
-
getSessionId(): string;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
type PreviewResult = {
|
|
24
|
-
diff: string;
|
|
25
|
-
} | {
|
|
26
|
-
error: string;
|
|
27
|
-
};
|
|
28
|
-
export interface EditTool {
|
|
29
|
-
/** SAFETY: Execute a validated edit; returns pi tool_result or throws on failure. Admission: params validated by normReq/assertReq. */
|
|
30
|
-
execute(params: unknown, signal: AbortSignal | undefined, ctx: EditToolContext): Promise<{
|
|
31
|
-
content: Array<{
|
|
32
|
-
type: "text";
|
|
33
|
-
text: string;
|
|
34
|
-
}>;
|
|
35
|
-
details: unknown;
|
|
36
|
-
}>;
|
|
37
|
-
/** SAFETY: Preview without persisting — mirrors pi's compPreview(request, cwd, ctx). The ctx must carry the session whose serves the anchors came from (#165). */
|
|
38
|
-
preview(request: unknown, cwd: string, ctx: PreviewContext): Promise<PreviewResult>;
|
|
39
|
-
}
|
|
40
|
-
export declare function createEditTool(): EditTool;
|
|
41
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SAFETY: MutationEngine — deep module behind the mutation seam.
|
|
3
|
-
*
|
|
4
|
-
* Small interface: `execute` + `preview`. Deep implementation: load → parse
|
|
5
|
-
* → mutate → finalize → drift → persist → serve hidden inside the pipeline.
|
|
6
|
-
* Internal seams (validate, verify, mutate, guard, persist, record) stay
|
|
7
|
-
* private — not exported. The interface is the test surface.
|
|
8
|
-
*
|
|
9
|
-
* Typed boundaries: validate once at admission (edit.ts via payload-contract),
|
|
10
|
-
* trust inside. Errors fail loud with typed `MutationFailure`.
|
|
11
|
-
*/
|
|
12
|
-
import type { PipelineOptions } from "./types.js";
|
|
13
|
-
import type { MutationResult } from "./types.js";
|
|
14
|
-
import type { NormalizedEditRequest } from "../payload-contract.js";
|
|
15
|
-
declare function toFailure(error: unknown): MutationResult;
|
|
16
|
-
/**
|
|
17
|
-
* SAFETY: Execute a mutation against the file system (persist + undo + serve).
|
|
18
|
-
* Returns discriminated `MutationResult` — callers must switch on `ok`.
|
|
19
|
-
*
|
|
20
|
-
* No `any` threading: input is `NormalizedEditRequest` (validated at
|
|
21
|
-
* admission), output is typed. Failures are `ok:false` with `code`, not
|
|
22
|
-
* loose `isError` flags.
|
|
23
|
-
*/
|
|
24
|
-
export declare function execute(request: NormalizedEditRequest, cwd: string, options?: PipelineOptions): Promise<MutationResult>;
|
|
25
|
-
/**
|
|
26
|
-
* SAFETY: Preview a mutation without persisting (noPersist). Same seam as `execute`,
|
|
27
|
-
* same `MutationResult` — one interface, N call sites (preview + apply share
|
|
28
|
-
* the internal path via `runMutations` with `noPersist:true`).
|
|
29
|
-
*/
|
|
30
|
-
export declare function preview(request: NormalizedEditRequest, cwd: string, options?: Omit<PipelineOptions, "noPersist">): Promise<MutationResult>;
|
|
31
|
-
export { toFailure };
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { Type } from "typebox";
|
|
2
|
-
import type { EditPlacement } from "./hashline/resolve.js";
|
|
3
|
-
declare const normalizedEdit: unique symbol;
|
|
4
|
-
/**
|
|
5
|
-
* The `text_ref` payload: two inclusive bare anchors bounding a served span, an optional serving
|
|
6
|
-
* `file`, and a REQUIRED `mode` — `"copy"` re-inserts the span bytes, `"cut"` additionally retires
|
|
7
|
-
* them. Both modes apply to this file AND to another served file (ticket-04b): a foreign-source
|
|
8
|
-
* `"cut"` commits the insert and the source retirement as one correlated transaction (ADR-0028).
|
|
9
|
-
*/
|
|
10
|
-
type SpanRef = {
|
|
11
|
-
anchor_from: string;
|
|
12
|
-
anchor_to: string;
|
|
13
|
-
file?: string;
|
|
14
|
-
mode: "copy" | "cut";
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Wire item (ticket-04): exactly one payload per item — `text` or `text_ref` — over the inclusive
|
|
18
|
-
* anchor pair, with optional `at` placement. There is no `op` field and no verbs: the key set IS
|
|
19
|
-
* the vocabulary (ADR-0007 line 26; content comes from the copy of another served file, which the
|
|
20
|
-
* wire expresses as `text_ref.file`).
|
|
21
|
-
*/
|
|
22
|
-
export type EditItem = {
|
|
23
|
-
anchor_from: string;
|
|
24
|
-
anchor_to: string;
|
|
25
|
-
at?: "in-place" | "before" | "after";
|
|
26
|
-
text?: string;
|
|
27
|
-
text_ref?: SpanRef;
|
|
28
|
-
};
|
|
29
|
-
type EditMode = "general" | "literal";
|
|
30
|
-
/**
|
|
31
|
-
* Internal normalized vocabulary owned by the admission boundary (ticket-01, renamed ticket-04).
|
|
32
|
-
* The wire never names these shapes: `normReq` builds them once from the validated payload and
|
|
33
|
-
* everything downstream consumes the union — the engine switches on `payload.kind` exhaustively.
|
|
34
|
-
*/
|
|
35
|
-
export type Placement = "in-place" | "before" | "after";
|
|
36
|
-
/**
|
|
37
|
-
* @public Intentional surface (knip): the tuple type is the wire/engine
|
|
38
|
-
* vocabulary check, so the binding is never imported — its reason to exist
|
|
39
|
-
* is the typecheck failure it produces when the unions drift.
|
|
40
|
-
*/
|
|
41
|
-
export declare const _placementVocabularyAgreement: [
|
|
42
|
-
Placement extends EditPlacement ? true : never,
|
|
43
|
-
EditPlacement extends Placement ? true : never
|
|
44
|
-
];
|
|
45
|
-
/** The anchor pair an item targets — placement and payload are relative to its resolved span. */
|
|
46
|
-
type AnchorSpan = {
|
|
47
|
-
anchor_from: string;
|
|
48
|
-
anchor_to: string;
|
|
49
|
-
};
|
|
50
|
-
export type DesiredContent = {
|
|
51
|
-
kind: "literal";
|
|
52
|
-
text: string;
|
|
53
|
-
} | {
|
|
54
|
-
kind: "reference";
|
|
55
|
-
span: SpanRef;
|
|
56
|
-
mode: "copy" | "cut";
|
|
57
|
-
} | {
|
|
58
|
-
kind: "empty";
|
|
59
|
-
};
|
|
60
|
-
export type NormalizedEditItem = {
|
|
61
|
-
target: AnchorSpan;
|
|
62
|
-
at: Placement;
|
|
63
|
-
payload: DesiredContent;
|
|
64
|
-
};
|
|
65
|
-
export type NormalizedEditRequest = {
|
|
66
|
-
file: string;
|
|
67
|
-
edits: NormalizedEditItem[];
|
|
68
|
-
mode?: EditMode;
|
|
69
|
-
};
|
|
70
|
-
/** The wire-folded request (the admission analyzer's view): canonical keys, pre-union. */
|
|
71
|
-
type PreAdmissionRequest = {
|
|
72
|
-
file: string;
|
|
73
|
-
edits: EditItem[];
|
|
74
|
-
mode?: EditMode;
|
|
75
|
-
};
|
|
76
|
-
type NormalizedPayload = NormalizedEditRequest & {
|
|
77
|
-
readonly [normalizedEdit]: true;
|
|
78
|
-
};
|
|
79
|
-
type RawPayload = string | number | boolean | null | undefined | Record<string, unknown>;
|
|
80
|
-
export type NormReqResult = NormalizedPayload | RawPayload;
|
|
81
|
-
export declare const anchorFromSchema: Type.TString;
|
|
82
|
-
export declare const anchorToSchema: Type.TString;
|
|
83
|
-
export declare const editFileSchema: Type.TString;
|
|
84
|
-
export declare const editModeSchema: Type.TUnion<[Type.TLiteral<"general">, Type.TLiteral<"literal">]>;
|
|
85
|
-
export declare const editItemSchema: Type.TObject<{
|
|
86
|
-
anchor_from: Type.TString;
|
|
87
|
-
anchor_to: Type.TString;
|
|
88
|
-
at: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"in-place">, Type.TLiteral<"before">, Type.TLiteral<"after">]>, Type.TNull]>>;
|
|
89
|
-
text: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
90
|
-
text_ref: Type.TOptional<Type.TUnion<[Type.TObject<{
|
|
91
|
-
anchor_from: Type.TString;
|
|
92
|
-
anchor_to: Type.TString;
|
|
93
|
-
file: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
94
|
-
mode: Type.TUnion<[Type.TLiteral<"copy">, Type.TLiteral<"cut">]>;
|
|
95
|
-
}>, Type.TNull]>>;
|
|
96
|
-
}>;
|
|
97
|
-
export declare const editToolSchema: Type.TObject<{
|
|
98
|
-
file: Type.TString;
|
|
99
|
-
edits: Type.TArray<Type.TObject<{
|
|
100
|
-
anchor_from: Type.TString;
|
|
101
|
-
anchor_to: Type.TString;
|
|
102
|
-
at: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"in-place">, Type.TLiteral<"before">, Type.TLiteral<"after">]>, Type.TNull]>>;
|
|
103
|
-
text: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
104
|
-
text_ref: Type.TOptional<Type.TUnion<[Type.TObject<{
|
|
105
|
-
anchor_from: Type.TString;
|
|
106
|
-
anchor_to: Type.TString;
|
|
107
|
-
file: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
108
|
-
mode: Type.TUnion<[Type.TLiteral<"copy">, Type.TLiteral<"cut">]>;
|
|
109
|
-
}>, Type.TNull]>>;
|
|
110
|
-
}>>;
|
|
111
|
-
mode: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"general">, Type.TLiteral<"literal">]>, Type.TNull]>>;
|
|
112
|
-
}>;
|
|
113
|
-
export declare const EDIT_DESCRIPTION = "Edit a range of lines in a text file via `edit`: `{ \"file\": file, \"edits\": [{ \"anchor_from\": a, \"anchor_to\": b, \"text\": text }, ...] }` (one file per call). Use rows this session served for the file: `read`, a diff, or a bash view. `anchor_from`/`anchor_to` are bare 4-char HASH anchors. Copy the 4 chars before `\u2502` in this file's served rows (lease (session, file, anchor)). One payload per item: `text` (`\\n` joins lines, `\"\"` deletes) or `text_ref` `{anchor_from, anchor_to, mode (required), file?}`, the bytes of a served span (`mode` `\"copy\"` keeps it, `\"cut\"` removes it). `file` names another served file. `at`: \"in-place\" (default), \"before\", \"after\". A null optional field reads as absent. `[MODEL] [E_*]` is your retry instruction. `[W_*]` is informational.";
|
|
114
|
-
export declare const EDIT_SNIPPET = "Edit a file range via `edit`: `{\"file\":file,\"edits\":[{\"anchor_from\":a,\"anchor_to\":b,\"text\":text}]}` \u2014 anchors are bare 4-char hashes copied from served `HASH\u2502content` from rows this file served this session. One payload per item: `text` is bare content (`\"\"` deletes) or `text_ref` writes a served span (`\"copy\"` keeps source, `\"cut\"` removes it from this file or `file`). `at`: \"in-place\" (default), \"before\", \"after\". Chain from diff anchors.";
|
|
115
|
-
export declare const EDIT_GUIDELINES: string[];
|
|
116
|
-
export declare function editRequestFrom(input: unknown): PreAdmissionRequest | undefined;
|
|
117
|
-
export declare function normReq(input: unknown): NormReqResult;
|
|
118
|
-
export declare function prepareEditArguments(args: unknown): Record<string, unknown>;
|
|
119
|
-
export declare function getPreviewInput(args: unknown): {
|
|
120
|
-
file: string;
|
|
121
|
-
edits: EditItem[];
|
|
122
|
-
} | null;
|
|
123
|
-
export declare function assertReq(request: unknown): asserts request is NormalizedEditRequest;
|
|
124
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
- edit: an `anchor` is the bare 4-char hash (for example "wUpX"). A `HASH│content` line (for example `wUpX│ pass`) is a served row, and `│` separates the two. Copy only the 4 chars before `│` into `anchor_from`/`anchor_to`.
|
|
2
|
-
- edit: give each item two anchors and exactly one payload. `file` is the text file. One item is one edit. Several items batch to that one file. Choose one payload field: `text` or `text_ref`. `at` is optional. A null in an optional field (`text`, `text_ref`, `at`, the top-level `mode`, `text_ref.file`) reads as absent. A null in a required field (`file`, `edits`, any anchor, `text_ref.mode`) is refused.
|
|
3
|
-
- edit: `anchor_from`/`anchor_to` bound an inclusive range. In-place replaces both boundary lines. `before`/`after` insert at the boundary instead. Out-of-band writes (bash, scripts, formatters) bypass serve recording. When a served line changes, the refusal serves the current rows. Copy fresh anchors from it.
|
|
4
|
-
- edit: `text` is plain file content. Join lines with `\n`. Use `""` to delete the range. The tool refuses a line that copies a served hash echo. `text` is verbatim, so include the indentation you want.
|
|
5
|
-
- edit: place the payload with `at`. `"in-place"` (default) rewrites the range. `"before"`/`"after"` insert at its boundary and need a single-line resolved target. `text: ""` with before/after writes nothing (noop).
|
|
6
|
-
- edit: `text_ref` `{anchor_from, anchor_to, mode}` writes the bytes of a served span into the target. `mode: "copy"` keeps the source. `mode: "cut"` removes those lines from the source. When `file` names another served file, both modes apply to that file's rows. A `cut` then removes the span there in the same call. `mode` is required. Prefer `text_ref` to reproduce served bytes exactly or to move them. Use `text` for content you author.
|
|
7
|
-
- edit: an anchor is bound to the file that served it. The lease is (session, file, anchor). Copy `anchor_from`/`anchor_to` only from the served rows of the file the payload names. That is this file by default, or `text_ref.file` when it names another file.
|
|
8
|
-
- edit: after success the diff serves fresh `HASH│content` rows: context rows and `+` rows. Copy new anchors from the diff for your next call. Verify that the diff matches your intended mutation.
|
|
9
|
-
- edit: a `[MODEL] [W_*]` line in `content` is informational. The mutation was applied. A `[MODEL] [E_*]` line is your retry instruction or a rejection: follow it from the message alone. A `[MODEL]` line that presents `Current range (fresh read):` shows the current rows. Decide from them. A dimmed `[USER]` line in `details` is human info.
|
|
10
|
-
- edit: batch independent ranges in one `edits` array. Inside it, every edit validates BEFORE the first rename, and any failure there writes nothing. A foreign `cut` writes its files in a fixed order, and a defeated rollback restores captured bytes or is repaired on the next run.
|
package/prompts/edit-snippet.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Edit a file range via `edit`: `{"file":file,"edits":[{"anchor_from":a,"anchor_to":b,"text":text}]}` — anchors are bare 4-char hashes copied from served `HASH│content` from rows this file served this session. One payload per item: `text` is bare content (`""` deletes) or `text_ref` writes a served span (`"copy"` keeps source, `"cut"` removes it from this file or `file`). `at`: "in-place" (default), "before", "after". Chain from diff anchors.
|
package/prompts/edit.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Edit a range of lines in a text file via `edit`: `{ "file": file, "edits": [{ "anchor_from": a, "anchor_to": b, "text": text }, ...] }` (one file per call). Use rows this session served for the file: `read`, a diff, or a bash view. `anchor_from`/`anchor_to` are bare 4-char HASH anchors. Copy the 4 chars before `│` in this file's served rows (lease (session, file, anchor)). One payload per item: `text` (`\n` joins lines, `""` deletes) or `text_ref` `{anchor_from, anchor_to, mode (required), file?}`, the bytes of a served span (`mode` `"copy"` keeps it, `"cut"` removes it). `file` names another served file. `at`: "in-place" (default), "before", "after". A null optional field reads as absent. `[MODEL] [E_*]` is your retry instruction. `[W_*]` is informational.
|