orbitmap 0.7.0 → 0.9.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 +45 -10
- package/dist/adapters/cloud.d.ts +6 -3
- package/dist/adapters/cloud.js +59 -6
- package/dist/adapters/cloud.js.map +1 -1
- package/dist/adapters/local/adapter.d.ts +6 -3
- package/dist/adapters/local/adapter.js +9 -2
- package/dist/adapters/local/adapter.js.map +1 -1
- package/dist/adapters/types.d.ts +36 -2
- package/dist/agent-instructions.d.ts +25 -10
- package/dist/agent-instructions.js +143 -59
- package/dist/agent-instructions.js.map +1 -1
- package/dist/commands/context.js +15 -5
- package/dist/commands/context.js.map +1 -1
- package/dist/commands/doc-errors.d.ts +43 -0
- package/dist/commands/doc-errors.js +77 -0
- package/dist/commands/doc-errors.js.map +1 -0
- package/dist/commands/doc-import.d.ts +9 -0
- package/dist/commands/doc-import.js +36 -3
- package/dist/commands/doc-import.js.map +1 -1
- package/dist/commands/doc-patch.d.ts +1 -3
- package/dist/commands/doc-patch.js +62 -21
- package/dist/commands/doc-patch.js.map +1 -1
- package/dist/commands/doc-share.d.ts +1 -0
- package/dist/commands/doc-share.js +17 -8
- package/dist/commands/doc-share.js.map +1 -1
- package/dist/commands/doc-update.js +20 -2
- package/dist/commands/doc-update.js.map +1 -1
- package/dist/commands/init.js +0 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/intent.js +42 -6
- package/dist/commands/intent.js.map +1 -1
- package/dist/commands/setup-agent.d.ts +35 -14
- package/dist/commands/setup-agent.js +128 -57
- package/dist/commands/setup-agent.js.map +1 -1
- package/dist/index.js +27 -10
- package/dist/index.js.map +1 -1
- package/dist/list-options.d.ts +33 -0
- package/dist/list-options.js +55 -0
- package/dist/list-options.js.map +1 -1
- package/dist/write-target.d.ts +15 -4
- package/dist/write-target.js +2 -1
- package/dist/write-target.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The document surface's refusal vocabulary, in ONE place (IN-jnz64x / S10).
|
|
3
|
+
*
|
|
4
|
+
* Every document command can now be refused for a reason that is about *scope* rather than
|
|
5
|
+
* about the reference the caller typed: the document exists, but it lives at a scope the
|
|
6
|
+
* caller did not address, or in an area the caller cannot write to. The intent's binding
|
|
7
|
+
* decision is that such a refusal must name the real cause — "wrong slug" was exactly the
|
|
8
|
+
* lie that made IS-fzczuw and IS-2psuq5 undiagnosable — so the wire codes are translated
|
|
9
|
+
* once, here, instead of once per command file.
|
|
10
|
+
*
|
|
11
|
+
* The map was born inside `doc-patch.ts`; the patch-only entries stay there and are merged
|
|
12
|
+
* on top of these by {@link printDocumentError}'s caller.
|
|
13
|
+
*/
|
|
14
|
+
import { OrbitMapAPIError } from '../errors.js';
|
|
15
|
+
import { printError } from '../output.js';
|
|
16
|
+
/**
|
|
17
|
+
* A write the server acknowledged as NOT having happened (`updated: false` / `imported:
|
|
18
|
+
* false` in an otherwise successful envelope).
|
|
19
|
+
*
|
|
20
|
+
* It is not a server error code: a server that knows a write failed answers
|
|
21
|
+
* `STORAGE_WRITE_FAILED` 503. This code exists for the contract violation in between — a
|
|
22
|
+
* 2xx whose own acknowledgement says the write did not land. Reporting success off the
|
|
23
|
+
* version number alone (what the CLI did before) is the one outcome that must not survive.
|
|
24
|
+
*/
|
|
25
|
+
export const WRITE_NOT_ACKNOWLEDGED = 'WRITE_NOT_ACKNOWLEDGED';
|
|
26
|
+
/** Friendly text for the server codes the document commands can be refused with. */
|
|
27
|
+
export const DOCUMENT_FRIENDLY_ERRORS = {
|
|
28
|
+
DOCUMENT_NOT_REACHABLE: 'The document exists, but none of the areas it is linked to are areas you reach — ' +
|
|
29
|
+
'this is a scope refusal, not a wrong reference. Ask for access to one of its areas, ' +
|
|
30
|
+
'or have it shared into an area you belong to (`orbitmap doc-share`).',
|
|
31
|
+
DOCUMENT_NOT_WRITABLE: 'The document exists and you can read it, but your role in its area(s) is too low to ' +
|
|
32
|
+
'write to it. A workspace-level document (linked to no area) needs the matching ' +
|
|
33
|
+
'workspace role.',
|
|
34
|
+
LAST_AREA_DETACH: 'This is the document\'s last area: detaching it makes the document workspace-level ' +
|
|
35
|
+
'and drops the per-agent restrictions on that share. Re-run with ' +
|
|
36
|
+
'--confirm-workspace-scope if that is what you want.',
|
|
37
|
+
STORAGE_WRITE_FAILED: 'The content could not be stored, so NOTHING was written — the version was not bumped ' +
|
|
38
|
+
'and the previous content is intact. Try again; if it persists, the object storage is ' +
|
|
39
|
+
'down.',
|
|
40
|
+
CROSS_WORKSPACE: 'That area belongs to a different workspace. A document lives in exactly one workspace ' +
|
|
41
|
+
'and can only be linked to areas of that workspace.',
|
|
42
|
+
NOT_SHARED: 'The document is not shared with that area, so there was nothing to remove. Run ' +
|
|
43
|
+
'`orbitmap doc <id-or-slug>` to see where it is linked.',
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Print an error, replacing the server's text with the friendly one when we have it.
|
|
47
|
+
*
|
|
48
|
+
* The lookup goes through the CANONICAL code (`ERROR_CODE_ALIASES` in `errors.ts`) while
|
|
49
|
+
* the reported code stays the wire one, so nothing a user sees changes across the API's
|
|
50
|
+
* `PROJECT_*` → `AREA_*` rename. Exit code is the caller's business — every command sets
|
|
51
|
+
* `process.exitCode = 1` in its catch, as it always did.
|
|
52
|
+
*
|
|
53
|
+
* @param extra Command-specific entries (e.g. `doc-patch`'s), merged over the shared map.
|
|
54
|
+
*/
|
|
55
|
+
export function printDocumentError(error, jsonMode, extra) {
|
|
56
|
+
if (error instanceof OrbitMapAPIError) {
|
|
57
|
+
const friendly = extra?.[error.canonicalCode] ?? DOCUMENT_FRIENDLY_ERRORS[error.canonicalCode];
|
|
58
|
+
if (friendly) {
|
|
59
|
+
// Re-wrap rather than hand-rolling the envelope: the `--json` consumer keeps the same
|
|
60
|
+
// `code`/`status` it always got, and still gets `details` like every other error.
|
|
61
|
+
printError(new OrbitMapAPIError(friendly, error.code, error.status, error.details), jsonMode);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
printError(error, jsonMode);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The error a command raises when the server's own acknowledgement says the write did not
|
|
69
|
+
* land. `subject` is what the user typed (title or reference), so the message names the
|
|
70
|
+
* thing that was NOT written.
|
|
71
|
+
*/
|
|
72
|
+
export function writeNotAcknowledged(operation, subject, details) {
|
|
73
|
+
return new OrbitMapAPIError(`The server accepted the request but reported that "${subject}" was NOT ${operation}. ` +
|
|
74
|
+
'Nothing was written — do not treat this as a success. Re-read the document to see ' +
|
|
75
|
+
'its current state before retrying.', WRITE_NOT_ACKNOWLEDGED, 500, details);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=doc-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-errors.js","sourceRoot":"","sources":["../../src/commands/doc-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D,oFAAoF;AACpF,MAAM,CAAC,MAAM,wBAAwB,GAA2B;IAC9D,sBAAsB,EACpB,mFAAmF;QACnF,sFAAsF;QACtF,sEAAsE;IACxE,qBAAqB,EACnB,sFAAsF;QACtF,iFAAiF;QACjF,iBAAiB;IACnB,gBAAgB,EACd,qFAAqF;QACrF,kEAAkE;QAClE,qDAAqD;IACvD,oBAAoB,EAClB,uFAAuF;QACvF,uFAAuF;QACvF,OAAO;IACT,eAAe,EACb,wFAAwF;QACxF,oDAAoD;IACtD,UAAU,EACR,iFAAiF;QACjF,wDAAwD;CAC3D,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAc,EACd,QAAiB,EACjB,KAA8B;IAE9B,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;QACtC,MAAM,QAAQ,GACZ,KAAK,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,wBAAwB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAChF,IAAI,QAAQ,EAAE,CAAC;YACb,sFAAsF;YACtF,kFAAkF;YAClF,UAAU,CACR,IAAI,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,EACvE,QAAQ,CACT,CAAC;YACF,OAAO;QACT,CAAC;IACH,CAAC;IACD,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAiB,EACjB,OAAe,EACf,OAAiC;IAEjC,OAAO,IAAI,gBAAgB,CACzB,sDAAsD,OAAO,aAAa,SAAS,IAAI;QACrF,oFAAoF;QACpF,oCAAoC,EACtC,sBAAsB,EACtB,GAAG,EACH,OAAO,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { DocumentScope } from '../adapters/types.js';
|
|
2
|
+
/** The two spellings `--scope` accepts — the server's own enum (`workspace` | `area`). */
|
|
3
|
+
export declare const DOCUMENT_SCOPES: readonly DocumentScope[];
|
|
1
4
|
export declare function docImportCommand(title: string, options: {
|
|
2
5
|
json: boolean;
|
|
3
6
|
area?: string;
|
|
@@ -7,4 +10,10 @@ export declare function docImportCommand(title: string, options: {
|
|
|
7
10
|
sourcePath?: string;
|
|
8
11
|
context?: string;
|
|
9
12
|
workspaceId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* `--scope workspace|area`. Where the document LANDS. Separate from `workspaceId`,
|
|
15
|
+
* which only says WHICH workspace — the two used to be the same flag, and a caller who
|
|
16
|
+
* meant "workspace level" got an area document whenever the presigned path was taken.
|
|
17
|
+
*/
|
|
18
|
+
scope?: string;
|
|
10
19
|
}): Promise<void>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { readFileSync, statSync } from 'node:fs';
|
|
2
2
|
import { createAdapter } from '../adapters/factory.js';
|
|
3
3
|
import { confirmWriteTarget } from '../write-target.js';
|
|
4
|
-
import { formatOutput,
|
|
4
|
+
import { formatOutput, printSuccess, printValidationError } from '../output.js';
|
|
5
5
|
import { DOCUMENT_TYPES } from '../enums.js';
|
|
6
|
+
import { printDocumentError, writeNotAcknowledged } from './doc-errors.js';
|
|
7
|
+
/** The two spellings `--scope` accepts — the server's own enum (`workspace` | `area`). */
|
|
8
|
+
export const DOCUMENT_SCOPES = ['workspace', 'area'];
|
|
6
9
|
function formatBytes(bytes) {
|
|
7
10
|
if (bytes < 1024)
|
|
8
11
|
return `${bytes} B`;
|
|
@@ -16,6 +19,15 @@ export async function docImportCommand(title, options) {
|
|
|
16
19
|
printValidationError(msg, options.json);
|
|
17
20
|
return;
|
|
18
21
|
}
|
|
22
|
+
if (options.scope !== undefined &&
|
|
23
|
+
!DOCUMENT_SCOPES.includes(options.scope)) {
|
|
24
|
+
const msg = `Invalid --scope "${options.scope}". Valid: ${DOCUMENT_SCOPES.join(', ')} — ` +
|
|
25
|
+
'`workspace` links the document to no area (reachable from every one), `area` links ' +
|
|
26
|
+
'it to the area this invocation is scoped to.';
|
|
27
|
+
printValidationError(msg, options.json);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const scope = options.scope;
|
|
19
31
|
// Verify file is readable before doing anything
|
|
20
32
|
try {
|
|
21
33
|
statSync(options.file);
|
|
@@ -26,7 +38,9 @@ export async function docImportCommand(title, options) {
|
|
|
26
38
|
return;
|
|
27
39
|
}
|
|
28
40
|
try {
|
|
29
|
-
|
|
41
|
+
// `--scope workspace` creates ABOVE every area, so the echo must name the workspace
|
|
42
|
+
// rather than promise an area the document will not be linked to (see write-target.ts).
|
|
43
|
+
await confirmWriteTarget('import document', options, scope === 'workspace' ? 'workspace' : 'new');
|
|
30
44
|
const client = await createAdapter(options.area);
|
|
31
45
|
// Try presigned URL upload first
|
|
32
46
|
const presignedResult = await client.presignedImport(options.file, {
|
|
@@ -35,6 +49,7 @@ export async function docImportCommand(title, options) {
|
|
|
35
49
|
source_path: options.sourcePath,
|
|
36
50
|
context: options.context,
|
|
37
51
|
workspace_id: options.workspaceId,
|
|
52
|
+
scope,
|
|
38
53
|
}, options.json
|
|
39
54
|
? undefined
|
|
40
55
|
: (uploaded, total) => {
|
|
@@ -44,6 +59,16 @@ export async function docImportCommand(title, options) {
|
|
|
44
59
|
if (!options.json) {
|
|
45
60
|
process.stderr.write('\n');
|
|
46
61
|
}
|
|
62
|
+
// The server's own acknowledgement, not the fact that a 2xx came back: `imported:
|
|
63
|
+
// false` means the document was NOT created, and printing a slug for it would send
|
|
64
|
+
// the caller looking for something that does not exist.
|
|
65
|
+
if (presignedResult.data.imported === false) {
|
|
66
|
+
throw writeNotAcknowledged('imported', title, {
|
|
67
|
+
document_id: presignedResult.data.document_id,
|
|
68
|
+
slug: presignedResult.data.slug,
|
|
69
|
+
upload_method: 'presigned',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
47
72
|
if (options.json) {
|
|
48
73
|
console.log(formatOutput({ ...presignedResult, upload_method: 'presigned' }, true));
|
|
49
74
|
return;
|
|
@@ -60,7 +85,15 @@ export async function docImportCommand(title, options) {
|
|
|
60
85
|
source_path: options.sourcePath,
|
|
61
86
|
context: options.context,
|
|
62
87
|
workspace_id: options.workspaceId,
|
|
88
|
+
scope,
|
|
63
89
|
}));
|
|
90
|
+
if (response.data.imported === false) {
|
|
91
|
+
throw writeNotAcknowledged('imported', title, {
|
|
92
|
+
document_id: response.data.document_id,
|
|
93
|
+
slug: response.data.slug,
|
|
94
|
+
upload_method: 'direct',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
64
97
|
if (options.json) {
|
|
65
98
|
console.log(formatOutput({ ...response, upload_method: 'direct' }, true));
|
|
66
99
|
return;
|
|
@@ -72,7 +105,7 @@ export async function docImportCommand(title, options) {
|
|
|
72
105
|
// Clear progress line if present
|
|
73
106
|
process.stderr.write('\n');
|
|
74
107
|
}
|
|
75
|
-
|
|
108
|
+
printDocumentError(error, options.json);
|
|
76
109
|
process.exitCode = 1;
|
|
77
110
|
}
|
|
78
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-import.js","sourceRoot":"","sources":["../../src/commands/doc-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"doc-import.js","sourceRoot":"","sources":["../../src/commands/doc-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAU3E,0FAA0F;AAC1F,MAAM,CAAC,MAAM,eAAe,GAA6B,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AAE/E,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,GAAG,KAAK,IAAI,CAAC;IACtC,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,OAAO,GAAG,CAAC,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AC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,iCAAiC;YACjC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QACD,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -1,20 +1,64 @@
|
|
|
1
1
|
import { createAdapter } from '../adapters/factory.js';
|
|
2
2
|
import { confirmWriteTarget } from '../write-target.js';
|
|
3
|
-
import { formatOutput,
|
|
4
|
-
import {
|
|
3
|
+
import { formatOutput, printSuccess, printValidationError } from '../output.js';
|
|
4
|
+
import { printDocumentError } from './doc-errors.js';
|
|
5
|
+
/**
|
|
6
|
+
* The refusals only a PATCH can raise. Everything a document write can be refused with in
|
|
7
|
+
* general — the scope and storage codes — lives in `doc-errors.ts` and is merged under
|
|
8
|
+
* these by {@link printDocumentError}.
|
|
9
|
+
*/
|
|
5
10
|
const FRIENDLY_ERRORS = {
|
|
6
11
|
CONTENT_UNAVAILABLE: 'Storage unavailable — patch aborted to prevent data loss. Try again later.',
|
|
7
12
|
PATCH_RESULT_EMPTY: 'Patch would result in an empty document — aborted.',
|
|
13
|
+
DOCUMENT_FENCES_IMBALANCED: 'Document has an unclosed code fence — patch refused. Repair it with a full doc-update.',
|
|
14
|
+
PATCH_RESULT_MALFORMED: 'The patch would leave an unclosed code fence — refused.',
|
|
8
15
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
/** `240–297`, or `—` when the operation matched nothing and the server sent null bounds. */
|
|
17
|
+
function formatRange(start, end) {
|
|
18
|
+
if (start === null || end === null) {
|
|
19
|
+
return '—';
|
|
20
|
+
}
|
|
21
|
+
return `${start}–${end}`;
|
|
22
|
+
}
|
|
23
|
+
/** Signed so a reader can tell growth from shrinkage at a glance: `+18`, `-4`, `0`. */
|
|
24
|
+
function formatDelta(delta) {
|
|
25
|
+
return delta > 0 ? `+${delta}` : String(delta);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Render a dry run: one line per operation, then the warnings the real patch would emit,
|
|
29
|
+
* then the fact that nothing was written.
|
|
30
|
+
*
|
|
31
|
+
* The "nothing was written" line comes LAST on purpose — it is the sentence that must
|
|
32
|
+
* survive a truncated read of the output, and an unmatched operation must be impossible
|
|
33
|
+
* to mistake for a matched one, hence the explicit `NOT MATCHED` marker.
|
|
34
|
+
*/
|
|
35
|
+
function printDryRun(idOrSlug, d) {
|
|
36
|
+
let header = `Dry run for document "${idOrSlug}" (version ${d.version}, unchanged).`;
|
|
37
|
+
if (d.lines_before !== undefined && d.lines_after !== undefined) {
|
|
38
|
+
header += ` ${d.lines_before} → ${d.lines_after} lines if applied.`;
|
|
39
|
+
}
|
|
40
|
+
printSuccess(header, false);
|
|
41
|
+
const operations = d.operations ?? [];
|
|
42
|
+
if (operations.length === 0) {
|
|
43
|
+
console.log(' No operations.');
|
|
44
|
+
}
|
|
45
|
+
for (const op of operations) {
|
|
46
|
+
const heading = op.heading === null ? '' : ` "${op.heading}"`;
|
|
47
|
+
if (op.matched) {
|
|
48
|
+
console.log(` [${op.index}] ${op.op}${heading} lines ${formatRange(op.line_start, op.line_end)} (${formatDelta(op.lines_delta)} lines)`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.log(` [${op.index}] ${op.op}${heading} NOT MATCHED — heading not found`);
|
|
16
52
|
}
|
|
17
53
|
}
|
|
54
|
+
if (d.warnings && d.warnings.length > 0) {
|
|
55
|
+
for (const warning of d.warnings) {
|
|
56
|
+
console.log(` Warning: ${warning}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
console.log('Nothing was written — re-run without --dry-run to apply.');
|
|
60
|
+
}
|
|
61
|
+
export async function docPatchCommand(idOrSlug, options) {
|
|
18
62
|
let operations;
|
|
19
63
|
if (options.operations) {
|
|
20
64
|
// Raw JSON operations mode
|
|
@@ -71,12 +115,19 @@ export async function docPatchCommand(idOrSlug, options) {
|
|
|
71
115
|
try {
|
|
72
116
|
await confirmWriteTarget('patch document', options, 'existing');
|
|
73
117
|
const client = await createAdapter(options.area);
|
|
74
|
-
const response = (await client.patchDocument(idOrSlug, operations, baseVersion, options.changelog));
|
|
118
|
+
const response = (await client.patchDocument(idOrSlug, operations, baseVersion, options.changelog, options.dryRun));
|
|
75
119
|
if (options.json) {
|
|
76
120
|
console.log(formatOutput(response, true));
|
|
77
121
|
return;
|
|
78
122
|
}
|
|
79
123
|
const d = response.data;
|
|
124
|
+
// Trust the server's own marker rather than the requested flag: if the server ignored
|
|
125
|
+
// `dry_run` (older API), `updated` is true and the write already happened — reporting
|
|
126
|
+
// "nothing was written" then would be a lie.
|
|
127
|
+
if (d.dry_run) {
|
|
128
|
+
printDryRun(idOrSlug, d);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
80
131
|
let msg = `Document "${idOrSlug}" patched to version ${d.version}.`;
|
|
81
132
|
if (d.lines_before !== undefined && d.lines_after !== undefined) {
|
|
82
133
|
msg += ` ${d.lines_before} → ${d.lines_after} lines.`;
|
|
@@ -89,17 +140,7 @@ export async function docPatchCommand(idOrSlug, options) {
|
|
|
89
140
|
}
|
|
90
141
|
}
|
|
91
142
|
catch (error) {
|
|
92
|
-
|
|
93
|
-
// keep reporting the wire code, so nothing the user sees changes across the API rename.
|
|
94
|
-
const friendly = error instanceof OrbitMapAPIError ? FRIENDLY_ERRORS[error.canonicalCode] : undefined;
|
|
95
|
-
if (error instanceof OrbitMapAPIError && friendly) {
|
|
96
|
-
// Re-wrap rather than hand-rolling the envelope: the `--json` consumer keeps the same
|
|
97
|
-
// `code`/`status` it always got, and now also gets `details` like every other error.
|
|
98
|
-
printError(new OrbitMapAPIError(friendly, error.code, error.status, error.details), options.json);
|
|
99
|
-
process.exitCode = 1;
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
printError(error, options.json);
|
|
143
|
+
printDocumentError(error, options.json, FRIENDLY_ERRORS);
|
|
103
144
|
process.exitCode = 1;
|
|
104
145
|
}
|
|
105
146
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-patch.js","sourceRoot":"","sources":["../../src/commands/doc-patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"doc-patch.js","sourceRoot":"","sources":["../../src/commands/doc-patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AA4BrD;;;;GAIG;AACH,MAAM,eAAe,GAA2B;IAC9C,mBAAmB,EAAE,4EAA4E;IACjG,kBAAkB,EAAE,oDAAoD;IACxE,0BAA0B,EACxB,wFAAwF;IAC1F,sBAAsB,EAAE,yDAAyD;CAClF,CAAC;AAEF,4FAA4F;AAC5F,SAAS,WAAW,CAAC,KAAoB,EAAE,GAAkB;IAC3D,IAAI,KAAK,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACnC,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC;AAC3B,CAAC;AAED,uFAAuF;AACvF,SAAS,WAAW,CAAC,KAAa;IAChC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC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vC,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QACzD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -6,6 +6,7 @@ export declare function docShareCommand(documentId: string, areaId: string, opti
|
|
|
6
6
|
export declare function docUnshareCommand(documentId: string, areaId: string, options: {
|
|
7
7
|
json: boolean;
|
|
8
8
|
area?: string;
|
|
9
|
+
confirmWorkspaceScope?: boolean;
|
|
9
10
|
}): Promise<void>;
|
|
10
11
|
export declare function docVisibilityCommand(documentId: string, areaId: string, options: {
|
|
11
12
|
json: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createAdapter } from '../adapters/factory.js';
|
|
2
2
|
import { confirmWriteTarget } from '../write-target.js';
|
|
3
|
-
import { formatOutput,
|
|
3
|
+
import { formatOutput, printSuccess } from '../output.js';
|
|
4
|
+
import { printDocumentError } from './doc-errors.js';
|
|
4
5
|
export async function docShareCommand(documentId, areaId, options) {
|
|
5
6
|
const agentIds = options.agents
|
|
6
7
|
? options.agents.split(',').map((s) => s.trim())
|
|
@@ -19,7 +20,7 @@ export async function docShareCommand(documentId, areaId, options) {
|
|
|
19
20
|
printSuccess(`Document ${documentId} shared with area ${areaId}${restriction}.`, false);
|
|
20
21
|
}
|
|
21
22
|
catch (error) {
|
|
22
|
-
|
|
23
|
+
printDocumentError(error, options.json);
|
|
23
24
|
process.exitCode = 1;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -27,15 +28,22 @@ export async function docUnshareCommand(documentId, areaId, options) {
|
|
|
27
28
|
try {
|
|
28
29
|
await confirmWriteTarget('unshare document', options, 'existing');
|
|
29
30
|
const client = await createAdapter(options.area);
|
|
30
|
-
const response = (await client.unshareDocument(documentId, areaId));
|
|
31
|
+
const response = (await client.unshareDocument(documentId, areaId, options.confirmWorkspaceScope));
|
|
31
32
|
if (options.json) {
|
|
32
33
|
console.log(formatOutput(response, true));
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
// Detaching the last area RE-SCOPES the document to the workspace and drops that
|
|
37
|
+
// share's per-agent restrictions. Saying only "unshared" would hide a change of scope
|
|
38
|
+
// behind a routine-sounding line.
|
|
39
|
+
const rescoped = response.data.scope === 'workspace'
|
|
40
|
+
? ' It was the last area, so the document is now workspace-level: reachable from ' +
|
|
41
|
+
'every area, and no longer restricted to specific agents.'
|
|
42
|
+
: '';
|
|
43
|
+
printSuccess(`Document ${documentId} unshared from area ${areaId}.${rescoped}`, false);
|
|
36
44
|
}
|
|
37
45
|
catch (error) {
|
|
38
|
-
|
|
46
|
+
printDocumentError(error, options.json);
|
|
39
47
|
process.exitCode = 1;
|
|
40
48
|
}
|
|
41
49
|
}
|
|
@@ -51,13 +59,14 @@ export async function docVisibilityCommand(documentId, areaId, options) {
|
|
|
51
59
|
console.log(formatOutput(response, true));
|
|
52
60
|
return;
|
|
53
61
|
}
|
|
54
|
-
const
|
|
55
|
-
|
|
62
|
+
const agentIdsInResponse = response.data.agent_ids ?? [];
|
|
63
|
+
const restriction = agentIdsInResponse.length > 0
|
|
64
|
+
? `Restricted to ${agentIdsInResponse.length} agent(s).`
|
|
56
65
|
: 'All agents can access.';
|
|
57
66
|
printSuccess(`Visibility updated for document ${documentId} in area ${areaId}. ${restriction}`, false);
|
|
58
67
|
}
|
|
59
68
|
catch (error) {
|
|
60
|
-
|
|
69
|
+
printDocumentError(error, options.json);
|
|
61
70
|
process.exitCode = 1;
|
|
62
71
|
}
|
|
63
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-share.js","sourceRoot":"","sources":["../../src/commands/doc-share.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,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
|
2
2
|
import { createAdapter } from '../adapters/factory.js';
|
|
3
3
|
import { confirmWriteTarget } from '../write-target.js';
|
|
4
|
-
import { formatOutput,
|
|
4
|
+
import { formatOutput, printSuccess, printValidationError } from '../output.js';
|
|
5
|
+
import { printDocumentError, writeNotAcknowledged } from './doc-errors.js';
|
|
5
6
|
function formatBytes(bytes) {
|
|
6
7
|
if (bytes < 1024)
|
|
7
8
|
return `${bytes} B`;
|
|
@@ -32,6 +33,16 @@ export async function docUpdateCommand(idOrSlug, options) {
|
|
|
32
33
|
if (!options.json) {
|
|
33
34
|
process.stderr.write('\n');
|
|
34
35
|
}
|
|
36
|
+
// The acknowledgement, not the version number: `updated: false` says the content did
|
|
37
|
+
// NOT land, and reporting "updated to version N" off the bumped counter alone is the
|
|
38
|
+
// exact lie S7 exists to remove — the caller walks away believing the write happened.
|
|
39
|
+
if (presignedResult.data.updated === false) {
|
|
40
|
+
throw writeNotAcknowledged('updated', idOrSlug, {
|
|
41
|
+
document_id: presignedResult.data.document_id,
|
|
42
|
+
version: presignedResult.data.version,
|
|
43
|
+
upload_method: 'presigned',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
35
46
|
if (options.json) {
|
|
36
47
|
console.log(formatOutput({ ...presignedResult, upload_method: 'presigned' }, true));
|
|
37
48
|
return;
|
|
@@ -42,6 +53,13 @@ export async function docUpdateCommand(idOrSlug, options) {
|
|
|
42
53
|
// Fallback: read file into memory and send as JSON body
|
|
43
54
|
const content = readFileSync(options.file, 'utf-8');
|
|
44
55
|
const response = (await client.updateDocument(idOrSlug, content, options.changelog));
|
|
56
|
+
if (response.data.updated === false) {
|
|
57
|
+
throw writeNotAcknowledged('updated', idOrSlug, {
|
|
58
|
+
document_id: response.data.document_id,
|
|
59
|
+
version: response.data.version,
|
|
60
|
+
upload_method: 'direct',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
45
63
|
if (options.json) {
|
|
46
64
|
console.log(formatOutput({ ...response, upload_method: 'direct' }, true));
|
|
47
65
|
return;
|
|
@@ -53,7 +71,7 @@ export async function docUpdateCommand(idOrSlug, options) {
|
|
|
53
71
|
// Clear progress line if present
|
|
54
72
|
process.stderr.write('\n');
|
|
55
73
|
}
|
|
56
|
-
|
|
74
|
+
printDocumentError(error, options.json);
|
|
57
75
|
process.exitCode = 1;
|
|
58
76
|
}
|
|
59
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-update.js","sourceRoot":"","sources":["../../src/commands/doc-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"doc-update.js","sourceRoot":"","sources":["../../src/commands/doc-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAU3E,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,GAAG,KAAK,IAAI,CAAC;IACtC,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,OAAO,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,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