@indigoai-us/hq-cloud 6.11.5 → 6.11.7
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/dist/bin/sync-runner.d.ts +16 -16
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +51 -41
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +108 -33
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.d.ts +23 -0
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +54 -0
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +142 -0
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.d.ts +16 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +1 -62
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/tombstones.d.ts +43 -0
- package/dist/cli/tombstones.d.ts.map +1 -0
- package/dist/cli/tombstones.js +78 -0
- package/dist/cli/tombstones.js.map +1 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +57 -17
- package/dist/context.js.map +1 -1
- package/dist/context.test.js +113 -1
- package/dist/context.test.js.map +1 -1
- package/dist/entity-resolver.test.js +3 -3
- package/dist/entity-resolver.test.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/object-io.d.ts.map +1 -1
- package/dist/object-io.js +10 -0
- package/dist/object-io.js.map +1 -1
- package/dist/personal-vault.d.ts +36 -0
- package/dist/personal-vault.d.ts.map +1 -1
- package/dist/personal-vault.js +89 -1
- package/dist/personal-vault.js.map +1 -1
- package/dist/personal-vault.test.js +143 -1
- package/dist/personal-vault.test.js.map +1 -1
- package/dist/signals/get.d.ts.map +1 -1
- package/dist/signals/get.js +7 -11
- package/dist/signals/get.js.map +1 -1
- package/dist/signals/get.test.js +65 -1
- package/dist/signals/get.test.js.map +1 -1
- package/dist/signals/internals.d.ts +47 -3
- package/dist/signals/internals.d.ts.map +1 -1
- package/dist/signals/internals.js +110 -4
- package/dist/signals/internals.js.map +1 -1
- package/dist/signals/list.d.ts.map +1 -1
- package/dist/signals/list.js +16 -23
- package/dist/signals/list.js.map +1 -1
- package/dist/signals/list.test.js +84 -1
- package/dist/signals/list.test.js.map +1 -1
- package/dist/signals/types.d.ts +18 -1
- package/dist/signals/types.d.ts.map +1 -1
- package/dist/sources/get.d.ts.map +1 -1
- package/dist/sources/get.js +10 -22
- package/dist/sources/get.js.map +1 -1
- package/dist/sources/get.test.js +85 -1
- package/dist/sources/get.test.js.map +1 -1
- package/dist/sources/internals.d.ts +50 -3
- package/dist/sources/internals.d.ts.map +1 -1
- package/dist/sources/internals.js +113 -4
- package/dist/sources/internals.js.map +1 -1
- package/dist/sources/list.d.ts.map +1 -1
- package/dist/sources/list.js +16 -23
- package/dist/sources/list.js.map +1 -1
- package/dist/sources/list.test.js +101 -1
- package/dist/sources/list.test.js.map +1 -1
- package/dist/sources/types.d.ts +18 -1
- package/dist/sources/types.d.ts.map +1 -1
- package/dist/sync/event-sync.d.ts +6 -7
- package/dist/sync/event-sync.d.ts.map +1 -1
- package/dist/sync/event-sync.js +6 -7
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/types.d.ts +33 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +14 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +20 -0
- package/dist/version.js.map +1 -0
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +22 -1
- package/dist/watcher.js.map +1 -1
- package/dist/watcher.test.js +29 -0
- package/dist/watcher.test.js.map +1 -1
- package/package.json +1 -1
- package/src/bin/sync-runner.test.ts +131 -41
- package/src/bin/sync-runner.ts +56 -48
- package/src/cli/share.test.ts +169 -0
- package/src/cli/share.ts +81 -0
- package/src/cli/sync.ts +21 -88
- package/src/cli/tombstones.ts +106 -0
- package/src/context.test.ts +139 -1
- package/src/context.ts +59 -17
- package/src/entity-resolver.test.ts +3 -3
- package/src/index.ts +2 -0
- package/src/object-io.ts +12 -0
- package/src/personal-vault.test.ts +175 -0
- package/src/personal-vault.ts +86 -1
- package/src/signals/get.test.ts +83 -1
- package/src/signals/get.ts +9 -13
- package/src/signals/internals.ts +153 -4
- package/src/signals/list.test.ts +114 -1
- package/src/signals/list.ts +16 -29
- package/src/signals/types.ts +18 -1
- package/src/sources/get.test.ts +104 -1
- package/src/sources/get.ts +12 -24
- package/src/sources/internals.ts +156 -4
- package/src/sources/list.test.ts +132 -1
- package/src/sources/list.ts +16 -29
- package/src/sources/types.ts +18 -1
- package/src/sync/event-sync.ts +6 -7
- package/src/types.ts +33 -3
- package/src/version.ts +24 -0
- package/src/watcher.test.ts +41 -0
- package/src/watcher.ts +24 -1
package/src/personal-vault.ts
CHANGED
|
@@ -125,7 +125,92 @@ export function computePersonalVaultPaths(
|
|
|
125
125
|
const companySubdirs = opts.includeLocalCompanies === true
|
|
126
126
|
? computePersonalCompanySubdirs(hqRoot, opts.teamSyncedSlugs)
|
|
127
127
|
: [];
|
|
128
|
-
|
|
128
|
+
const continuity = computeContinuityPointerPaths(hqRoot);
|
|
129
|
+
return [...topLevel, ...manifest, ...companySubdirs, ...continuity];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Fixed relative path (forward-slash, hq-root-relative) of the session
|
|
134
|
+
* continuity pointer. The continuity pointer is the ONE file under the
|
|
135
|
+
* otherwise machine-local `workspace/` that must travel across machines:
|
|
136
|
+
* `/handoff` writes it on machine A so a fresh session on machine B can
|
|
137
|
+
* resume via `/startwork`. See {@link computeContinuityPointerPaths}.
|
|
138
|
+
*/
|
|
139
|
+
export const CONTINUITY_POINTER_REL = "workspace/threads/handoff.json";
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Compute the absolute paths of the session-continuity pointer carve-out:
|
|
143
|
+
* `workspace/threads/handoff.json` plus the single thread file it points to.
|
|
144
|
+
*
|
|
145
|
+
* `workspace/` is in {@link PERSONAL_VAULT_EXCLUDED_TOP_LEVEL} — it is
|
|
146
|
+
* machine-local by design (session scratch, locks, reports, the full thread
|
|
147
|
+
* history). The continuity pointer is the one exception: without it a
|
|
148
|
+
* `/handoff` on one machine never reaches a second machine, so the session
|
|
149
|
+
* pointer doesn't follow the user even though the durable output already
|
|
150
|
+
* syncs. This carve-out pierces the exclusion for EXACTLY two files and
|
|
151
|
+
* nothing else, mirroring the `companies/manifest.yaml` special-case above
|
|
152
|
+
* (a single file pushed back in despite its parent dir being excluded).
|
|
153
|
+
*
|
|
154
|
+
* The "active thread file" is not a fixed name — it is resolved from
|
|
155
|
+
* `handoff.json.thread_path` (the pointer the finalize script writes). We
|
|
156
|
+
* read + parse `handoff.json`, then include `thread_path` ONLY when it is a
|
|
157
|
+
* relative path that resolves to an existing regular file strictly within
|
|
158
|
+
* `<hqRoot>/workspace/threads/`. This containment check is a hard security
|
|
159
|
+
* boundary: a malformed or tampered `handoff.json` must never be able to
|
|
160
|
+
* smuggle an arbitrary file (e.g. `../../.env`, an absolute path, or a
|
|
161
|
+
* symlink escaping the threads dir) into the personal vault.
|
|
162
|
+
*
|
|
163
|
+
* Fail-soft throughout: a missing/unreadable/malformed `handoff.json`, or an
|
|
164
|
+
* out-of-bounds / missing `thread_path`, silently degrades to "include
|
|
165
|
+
* whatever is valid" (handoff.json alone, or `[]`). Callers tolerate empty
|
|
166
|
+
* arrays — same contract as the manifest special-case.
|
|
167
|
+
*/
|
|
168
|
+
export function computeContinuityPointerPaths(hqRoot: string): string[] {
|
|
169
|
+
const out: string[] = [];
|
|
170
|
+
const threadsDir = path.join(hqRoot, "workspace", "threads");
|
|
171
|
+
const handoffPath = path.join(threadsDir, "handoff.json");
|
|
172
|
+
|
|
173
|
+
let raw: string;
|
|
174
|
+
try {
|
|
175
|
+
if (!fs.statSync(handoffPath).isFile()) return out;
|
|
176
|
+
raw = fs.readFileSync(handoffPath, "utf8");
|
|
177
|
+
} catch {
|
|
178
|
+
// No pointer on this machine yet (or unreadable) — nothing to carry.
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
out.push(handoffPath);
|
|
182
|
+
|
|
183
|
+
// Resolve the active thread file from the pointer's `thread_path`. Any
|
|
184
|
+
// failure leaves the pointer itself in `out` and skips the thread body —
|
|
185
|
+
// the next handoff (or a peer's push) re-converges it.
|
|
186
|
+
let threadPath: unknown;
|
|
187
|
+
try {
|
|
188
|
+
threadPath = (JSON.parse(raw) as { thread_path?: unknown })?.thread_path;
|
|
189
|
+
} catch {
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
if (typeof threadPath !== "string" || threadPath.length === 0) return out;
|
|
193
|
+
|
|
194
|
+
// Containment: the resolved file must live strictly inside the threads dir.
|
|
195
|
+
// Reject absolute paths, traversal, and symlink escapes. thread_path is
|
|
196
|
+
// hq-root-relative as written by handoff-finalize.sh, so resolve against
|
|
197
|
+
// hqRoot and re-check the realpath is still under the threads dir.
|
|
198
|
+
if (path.isAbsolute(threadPath)) return out;
|
|
199
|
+
const resolvedThreads = path.resolve(threadsDir);
|
|
200
|
+
const candidate = path.resolve(hqRoot, threadPath);
|
|
201
|
+
const withinThreads = (p: string): boolean =>
|
|
202
|
+
p === resolvedThreads || p.startsWith(resolvedThreads + path.sep);
|
|
203
|
+
if (!withinThreads(candidate)) return out;
|
|
204
|
+
try {
|
|
205
|
+
const real = fs.realpathSync(candidate);
|
|
206
|
+
if (!withinThreads(real)) return out;
|
|
207
|
+
if (!fs.statSync(real).isFile()) return out;
|
|
208
|
+
} catch {
|
|
209
|
+
// Pointer references a thread file that doesn't exist here — skip it.
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
out.push(candidate);
|
|
213
|
+
return out;
|
|
129
214
|
}
|
|
130
215
|
|
|
131
216
|
/**
|
package/src/signals/get.test.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* Unit tests for signals/get.ts.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
5
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
6
6
|
import { GetObjectCommand, type S3Client } from "@aws-sdk/client-s3";
|
|
7
7
|
import { getSignal, SignalNotFoundError } from "./get.js";
|
|
8
8
|
import {
|
|
9
9
|
_setSignalsS3Factory,
|
|
10
10
|
_resetSignalsS3Factory,
|
|
11
11
|
} from "./internals.js";
|
|
12
|
+
import type { PresignTransportClient } from "../object-io.js";
|
|
12
13
|
import type { EntityContext } from "../types.js";
|
|
13
14
|
import { InvalidSignalTypeError } from "../schemas/signal-types.js";
|
|
14
15
|
|
|
@@ -202,3 +203,84 @@ Body.
|
|
|
202
203
|
expect(doc.entityRefs).toEqual(["kept@example.com"]);
|
|
203
204
|
});
|
|
204
205
|
});
|
|
206
|
+
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// Presigned transport (vault client + company vault) — HQ-59
|
|
209
|
+
// ---------------------------------------------------------------------------
|
|
210
|
+
|
|
211
|
+
function makePresignVault(objects: Record<string, string>): PresignTransportClient {
|
|
212
|
+
vi.stubGlobal(
|
|
213
|
+
"fetch",
|
|
214
|
+
vi.fn(async (url: string) => {
|
|
215
|
+
const key = new URL(url).searchParams.get("key") ?? "";
|
|
216
|
+
const content = objects[key];
|
|
217
|
+
if (content === undefined) return new Response(null, { status: 404 });
|
|
218
|
+
return new Response(Buffer.from(content, "utf-8"), { status: 200 });
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
return {
|
|
222
|
+
presign: async (input) => ({
|
|
223
|
+
results: input.keys.map((k) => ({
|
|
224
|
+
key: k.key,
|
|
225
|
+
op: k.op ?? input.op ?? "get",
|
|
226
|
+
url: `https://signed.example/?key=${encodeURIComponent(k.key)}`,
|
|
227
|
+
})),
|
|
228
|
+
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
229
|
+
}),
|
|
230
|
+
listFiles: async () => ({ objects: [], cursor: null, truncated: false }),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
describe("getSignal — presigned transport (vault + cmp_)", () => {
|
|
235
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
236
|
+
|
|
237
|
+
it("reads via presign (no S3) and surfaces typed cross-refs", async () => {
|
|
238
|
+
_setSignalsS3Factory(
|
|
239
|
+
() =>
|
|
240
|
+
({
|
|
241
|
+
send: async () => {
|
|
242
|
+
throw new Error("S3 must not be used on the presign path");
|
|
243
|
+
},
|
|
244
|
+
}) as unknown as S3Client,
|
|
245
|
+
);
|
|
246
|
+
const vault = makePresignVault({ "signals/action_item/foo.md": ACTION_ITEM_MD });
|
|
247
|
+
|
|
248
|
+
const doc = await getSignal({
|
|
249
|
+
entity: ENTITY,
|
|
250
|
+
signalType: "action_item",
|
|
251
|
+
signalId: "foo",
|
|
252
|
+
vault,
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
expect(doc.sourceRef).toBe("abc-meeting-001");
|
|
256
|
+
expect(doc.entityRefs).toEqual(["stefan@indigoai.us", "corey@indigoai.us"]);
|
|
257
|
+
expect(doc.body).toContain("Stefan will review");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("maps a presign 404 to SignalNotFoundError", async () => {
|
|
261
|
+
const vault = makePresignVault({});
|
|
262
|
+
await expect(
|
|
263
|
+
getSignal({
|
|
264
|
+
entity: ENTITY,
|
|
265
|
+
signalType: "action_item",
|
|
266
|
+
signalId: "missing",
|
|
267
|
+
vault,
|
|
268
|
+
}),
|
|
269
|
+
).rejects.toBeInstanceOf(SignalNotFoundError);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("personal vault (prs_) ignores the vault client and stays on direct S3", async () => {
|
|
273
|
+
installStub({ "signals/action_item/foo.md": ACTION_ITEM_MD });
|
|
274
|
+
const vault = makePresignVault({});
|
|
275
|
+
const personal: EntityContext = { ...ENTITY, uid: "prs_me" };
|
|
276
|
+
|
|
277
|
+
const doc = await getSignal({
|
|
278
|
+
entity: personal,
|
|
279
|
+
signalType: "action_item",
|
|
280
|
+
signalId: "foo",
|
|
281
|
+
vault,
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(doc.body).toContain("Stefan will review");
|
|
285
|
+
});
|
|
286
|
+
});
|
package/src/signals/get.ts
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* `entityRefs` surfaced as typed fields.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
8
7
|
import { assertSignalType } from "../schemas/signal-types.js";
|
|
9
|
-
import {
|
|
8
|
+
import { readObjectText } from "./internals.js";
|
|
10
9
|
import { parseMarkdown } from "./parse.js";
|
|
11
10
|
import type { GetSignalOptions, SignalDocument } from "./types.js";
|
|
12
11
|
|
|
@@ -20,8 +19,12 @@ export class SignalNotFoundError extends Error {
|
|
|
20
19
|
function isNoSuchKey(err: unknown): boolean {
|
|
21
20
|
if (!err || typeof err !== "object") return false;
|
|
22
21
|
const name = (err as { name?: unknown }).name;
|
|
23
|
-
//
|
|
24
|
-
|
|
22
|
+
// The transport normalizes a missing object to a `NoSuchKey`-named error on
|
|
23
|
+
// both the S3 and presigned paths (a presign 404 → NoSuchKey). `NotFound` is
|
|
24
|
+
// kept for defense in depth (S3 HEAD-style errors).
|
|
25
|
+
return (
|
|
26
|
+
name === "NoSuchKey" || name === "NoSuchKeyException" || name === "NotFound"
|
|
27
|
+
);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
function asStringArray(value: unknown): string[] | undefined {
|
|
@@ -34,21 +37,14 @@ function asStringArray(value: unknown): string[] | undefined {
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
export async function getSignal(opts: GetSignalOptions): Promise<SignalDocument> {
|
|
37
|
-
// Validate signalType BEFORE any
|
|
40
|
+
// Validate signalType BEFORE any read (acceptance criterion + agent-mitigation).
|
|
38
41
|
assertSignalType(opts.signalType);
|
|
39
42
|
|
|
40
|
-
const client = getS3Client(opts.entity);
|
|
41
43
|
const key = `signals/${opts.signalType}/${opts.signalId}.md`;
|
|
42
44
|
|
|
43
45
|
let body: string;
|
|
44
46
|
try {
|
|
45
|
-
|
|
46
|
-
new GetObjectCommand({
|
|
47
|
-
Bucket: opts.entity.bucketName,
|
|
48
|
-
Key: key,
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
body = await streamToString(response.Body);
|
|
47
|
+
body = await readObjectText(opts, key);
|
|
52
48
|
} catch (err) {
|
|
53
49
|
if (isNoSuchKey(err)) {
|
|
54
50
|
throw new SignalNotFoundError(key);
|
package/src/signals/internals.ts
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal helpers shared between signals/list.ts and signals/get.ts.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Two transports back the read surface (see sources/internals.ts for the full
|
|
5
|
+
* rationale): the presigned-URL path (a vault client + a company vault, cmp_*)
|
|
6
|
+
* and the direct-S3 path (no vault client, or a personal vault prs_*). The
|
|
7
|
+
* direct-S3 path goes through `getS3Client`, whose factory hook is independent
|
|
8
|
+
* from sources/internals.ts so signals tests can swap their stub without
|
|
9
|
+
* disturbing sources tests.
|
|
7
10
|
*/
|
|
8
11
|
|
|
9
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
S3Client,
|
|
14
|
+
GetObjectCommand,
|
|
15
|
+
ListObjectsV2Command,
|
|
16
|
+
} from "@aws-sdk/client-s3";
|
|
10
17
|
import type { EntityContext } from "../types.js";
|
|
18
|
+
import { PresignObjectIO, type PresignTransportClient } from "../object-io.js";
|
|
11
19
|
|
|
12
20
|
function defaultFactory(ctx: EntityContext): S3Client {
|
|
21
|
+
if (!ctx.credentials) {
|
|
22
|
+
// The direct-S3 read path needs STS creds. A credential-less context only
|
|
23
|
+
// exists on the presign path (HQ-59 company vend-skip), which reads via the
|
|
24
|
+
// vault list/presign endpoints, not this S3 client — so arriving here with
|
|
25
|
+
// no creds is a routing bug. Fail loudly rather than 403 opaquely later.
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Signals S3 read for ${ctx.uid} requires STS credentials but got a ` +
|
|
28
|
+
`presign-only context; company presign reads must go through the ` +
|
|
29
|
+
`vault transport, not getS3Client.`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
13
32
|
return new S3Client({
|
|
14
33
|
region: ctx.region,
|
|
15
34
|
credentials: {
|
|
@@ -44,3 +63,133 @@ export async function streamToString(body: unknown): Promise<string> {
|
|
|
44
63
|
}
|
|
45
64
|
return Buffer.concat(chunks).toString("utf-8");
|
|
46
65
|
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Transport seam (presign for cmp_, direct-S3 otherwise)
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
/** Common shape of every reader's options: an entity + an optional vault client. */
|
|
72
|
+
export interface ReaderTransportOpts {
|
|
73
|
+
entity: EntityContext;
|
|
74
|
+
/**
|
|
75
|
+
* Presign-capable vault client. When supplied and the entity is a company
|
|
76
|
+
* vault (cmp_*), reads use the presigned-URL transport instead of direct S3.
|
|
77
|
+
*/
|
|
78
|
+
vault?: PresignTransportClient;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Lightweight listed object (transport-agnostic). */
|
|
82
|
+
export interface ListedKey {
|
|
83
|
+
key: string;
|
|
84
|
+
size: number;
|
|
85
|
+
lastModified: Date;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** True when this read should use the presigned-URL transport. */
|
|
89
|
+
export function usePresign(opts: ReaderTransportOpts): boolean {
|
|
90
|
+
return opts.vault != null && opts.entity.uid.startsWith("cmp_");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A not-found error normalized to the S3 `NoSuchKey` shape callers test for. */
|
|
94
|
+
function noSuchKeyError(key: string): Error {
|
|
95
|
+
return Object.assign(new Error(`No such key: ${key}`), { name: "NoSuchKey" });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isNotFound(err: unknown): boolean {
|
|
99
|
+
if (!err || typeof err !== "object") return false;
|
|
100
|
+
const name = (err as { name?: unknown }).name;
|
|
101
|
+
return (
|
|
102
|
+
name === "NoSuchKey" || name === "NoSuchKeyException" || name === "NotFound"
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Read an object's UTF-8 text. Throws a `NoSuchKey`-named error when the object
|
|
108
|
+
* is absent (both transports), so callers' existing not-found checks work
|
|
109
|
+
* unchanged.
|
|
110
|
+
*/
|
|
111
|
+
export async function readObjectText(
|
|
112
|
+
opts: ReaderTransportOpts,
|
|
113
|
+
key: string,
|
|
114
|
+
): Promise<string> {
|
|
115
|
+
if (usePresign(opts)) {
|
|
116
|
+
const io = new PresignObjectIO(opts.vault!, opts.entity.uid);
|
|
117
|
+
try {
|
|
118
|
+
const { body } = await io.getObject(key);
|
|
119
|
+
return body.toString("utf-8");
|
|
120
|
+
} catch (err) {
|
|
121
|
+
if (isNotFound(err)) throw noSuchKeyError(key);
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const client = getS3Client(opts.entity);
|
|
126
|
+
const res = await client.send(
|
|
127
|
+
new GetObjectCommand({ Bucket: opts.entity.bucketName, Key: key }),
|
|
128
|
+
);
|
|
129
|
+
return streamToString(res.Body);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Like {@link readObjectText} but returns null when the object is absent. */
|
|
133
|
+
export async function tryReadObjectText(
|
|
134
|
+
opts: ReaderTransportOpts,
|
|
135
|
+
key: string,
|
|
136
|
+
): Promise<string | null> {
|
|
137
|
+
try {
|
|
138
|
+
return await readObjectText(opts, key);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (isNotFound(err)) return null;
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* List one page of objects under `prefix`.
|
|
147
|
+
*
|
|
148
|
+
* Under the presigned transport the vault `list` endpoint is ACL-filtered and
|
|
149
|
+
* controls page size server-side, so `limit` is advisory — paginate via the
|
|
150
|
+
* returned `nextToken` (the opaque vault cursor) until it is undefined. Under
|
|
151
|
+
* direct S3, `limit` maps to `MaxKeys`.
|
|
152
|
+
*/
|
|
153
|
+
export async function listObjects(
|
|
154
|
+
opts: ReaderTransportOpts,
|
|
155
|
+
prefix: string,
|
|
156
|
+
page: { limit?: number; continuationToken?: string },
|
|
157
|
+
): Promise<{ contents: ListedKey[]; nextToken?: string }> {
|
|
158
|
+
if (usePresign(opts)) {
|
|
159
|
+
const io = new PresignObjectIO(opts.vault!, opts.entity.uid);
|
|
160
|
+
const res = await io.listObjects({
|
|
161
|
+
prefix,
|
|
162
|
+
continuationToken: page.continuationToken,
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
contents: res.objects.map((o) => ({
|
|
166
|
+
key: o.key,
|
|
167
|
+
size: o.size,
|
|
168
|
+
lastModified: o.lastModified,
|
|
169
|
+
})),
|
|
170
|
+
nextToken: res.nextContinuationToken,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const client = getS3Client(opts.entity);
|
|
174
|
+
const res = await client.send(
|
|
175
|
+
new ListObjectsV2Command({
|
|
176
|
+
Bucket: opts.entity.bucketName,
|
|
177
|
+
Prefix: prefix,
|
|
178
|
+
MaxKeys: page.limit,
|
|
179
|
+
ContinuationToken: page.continuationToken,
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
const contents: ListedKey[] = [];
|
|
183
|
+
for (const obj of res.Contents ?? []) {
|
|
184
|
+
if (!obj.Key) continue;
|
|
185
|
+
contents.push({
|
|
186
|
+
key: obj.Key,
|
|
187
|
+
size: obj.Size ?? 0,
|
|
188
|
+
lastModified: obj.LastModified ?? new Date(0),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
contents,
|
|
193
|
+
nextToken: res.IsTruncated ? res.NextContinuationToken : undefined,
|
|
194
|
+
};
|
|
195
|
+
}
|
package/src/signals/list.test.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @aws-sdk/client-s3.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
9
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
10
10
|
import {
|
|
11
11
|
GetObjectCommand,
|
|
12
12
|
ListObjectsV2Command,
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
_setSignalsS3Factory,
|
|
18
18
|
_resetSignalsS3Factory,
|
|
19
19
|
} from "./internals.js";
|
|
20
|
+
import type { PresignTransportClient } from "../object-io.js";
|
|
21
|
+
import type { VaultListedObject } from "../vault-client.js";
|
|
20
22
|
import type { EntityContext } from "../types.js";
|
|
21
23
|
import { InvalidSignalTypeError, SIGNAL_TYPES } from "../schemas/signal-types.js";
|
|
22
24
|
|
|
@@ -281,3 +283,114 @@ describe("listSignals", () => {
|
|
|
281
283
|
expect(observed.commands).toHaveLength(0);
|
|
282
284
|
});
|
|
283
285
|
});
|
|
286
|
+
|
|
287
|
+
// ---------------------------------------------------------------------------
|
|
288
|
+
// Presigned transport (vault client + company vault) — HQ-59
|
|
289
|
+
// ---------------------------------------------------------------------------
|
|
290
|
+
|
|
291
|
+
interface PresignVaultStub {
|
|
292
|
+
vault: PresignTransportClient;
|
|
293
|
+
listCalls: Array<{ prefix?: string; cursor?: string }>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function makePresignVault(
|
|
297
|
+
page: { objects: VaultListedObject[]; cursor: string | null },
|
|
298
|
+
contents: Record<string, string> = {},
|
|
299
|
+
): PresignVaultStub {
|
|
300
|
+
const listCalls: Array<{ prefix?: string; cursor?: string }> = [];
|
|
301
|
+
vi.stubGlobal(
|
|
302
|
+
"fetch",
|
|
303
|
+
vi.fn(async (url: string) => {
|
|
304
|
+
const key = new URL(url).searchParams.get("key") ?? "";
|
|
305
|
+
const c = contents[key];
|
|
306
|
+
if (c === undefined) return new Response(null, { status: 404 });
|
|
307
|
+
return new Response(Buffer.from(c, "utf-8"), { status: 200 });
|
|
308
|
+
}),
|
|
309
|
+
);
|
|
310
|
+
const vault: PresignTransportClient = {
|
|
311
|
+
presign: async (input) => ({
|
|
312
|
+
results: input.keys.map((k) => ({
|
|
313
|
+
key: k.key,
|
|
314
|
+
op: k.op ?? input.op ?? "get",
|
|
315
|
+
url: `https://signed.example/?key=${encodeURIComponent(k.key)}`,
|
|
316
|
+
})),
|
|
317
|
+
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
318
|
+
}),
|
|
319
|
+
listFiles: async (_company, prefix, cursor) => {
|
|
320
|
+
listCalls.push({ prefix, cursor });
|
|
321
|
+
return {
|
|
322
|
+
objects: page.objects,
|
|
323
|
+
cursor: page.cursor,
|
|
324
|
+
truncated: page.cursor != null,
|
|
325
|
+
};
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
return { vault, listCalls };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function listed(key: string): VaultListedObject {
|
|
332
|
+
return {
|
|
333
|
+
key,
|
|
334
|
+
size: 10,
|
|
335
|
+
lastModified: "2026-03-15T15:00:00.000Z",
|
|
336
|
+
etag: "etag",
|
|
337
|
+
permission: "read",
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
describe("listSignals — presigned transport (vault + cmp_)", () => {
|
|
342
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
343
|
+
|
|
344
|
+
it("lists via the ACL-filtered vault endpoint and never touches S3", async () => {
|
|
345
|
+
_setSignalsS3Factory(
|
|
346
|
+
() =>
|
|
347
|
+
({
|
|
348
|
+
send: async () => {
|
|
349
|
+
throw new Error("S3 must not be used on the presign path");
|
|
350
|
+
},
|
|
351
|
+
}) as unknown as S3Client,
|
|
352
|
+
);
|
|
353
|
+
const { vault, listCalls } = makePresignVault({
|
|
354
|
+
objects: [listed("signals/action_item/foo.md")],
|
|
355
|
+
cursor: null,
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const res = await listSignals({
|
|
359
|
+
entity: ENTITY,
|
|
360
|
+
signalType: "action_item",
|
|
361
|
+
vault,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
expect(res.entries.map((e) => e.signalId)).toEqual(["foo"]);
|
|
365
|
+
expect(res.entries[0].key).toBe("signals/action_item/foo.md");
|
|
366
|
+
expect(res.nextToken).toBeUndefined();
|
|
367
|
+
expect(listCalls[0].prefix).toBe("signals/action_item/");
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("surfaces the opaque vault cursor as nextToken", async () => {
|
|
371
|
+
const { vault } = makePresignVault({
|
|
372
|
+
objects: [listed("signals/action_item/foo.md")],
|
|
373
|
+
cursor: "OPAQUE_CURSOR",
|
|
374
|
+
});
|
|
375
|
+
const res = await listSignals({
|
|
376
|
+
entity: ENTITY,
|
|
377
|
+
signalType: "action_item",
|
|
378
|
+
vault,
|
|
379
|
+
});
|
|
380
|
+
expect(res.nextToken).toBe("OPAQUE_CURSOR");
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("includeFrontmatter surfaces sourceRef via a presigned GET", async () => {
|
|
384
|
+
const { vault } = makePresignVault(
|
|
385
|
+
{ objects: [listed("signals/action_item/foo.md")], cursor: null },
|
|
386
|
+
{ "signals/action_item/foo.md": ACTION_ITEM_MD },
|
|
387
|
+
);
|
|
388
|
+
const res = await listSignals({
|
|
389
|
+
entity: ENTITY,
|
|
390
|
+
signalType: "action_item",
|
|
391
|
+
includeFrontmatter: true,
|
|
392
|
+
vault,
|
|
393
|
+
});
|
|
394
|
+
expect(res.entries[0].sourceRef).toBe("abc-meeting-001");
|
|
395
|
+
});
|
|
396
|
+
});
|
package/src/signals/list.ts
CHANGED
|
@@ -6,12 +6,8 @@
|
|
|
6
6
|
* `includeFrontmatter: true` (otherwise the field is undefined).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
GetObjectCommand,
|
|
11
|
-
ListObjectsV2Command,
|
|
12
|
-
} from "@aws-sdk/client-s3";
|
|
13
9
|
import { assertSignalType } from "../schemas/signal-types.js";
|
|
14
|
-
import {
|
|
10
|
+
import { listObjects, readObjectText } from "./internals.js";
|
|
15
11
|
import { parseFrontmatter } from "./parse.js";
|
|
16
12
|
import type {
|
|
17
13
|
ListSignalsOptions,
|
|
@@ -31,44 +27,35 @@ function deriveSignalId(key: string, prefix: string): string | null {
|
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
export async function listSignals(opts: ListSignalsOptions): Promise<ListSignalsResult> {
|
|
34
|
-
// Validate signalType BEFORE any
|
|
30
|
+
// Validate signalType BEFORE any read (acceptance criterion + agent-mitigation).
|
|
35
31
|
assertSignalType(opts.signalType);
|
|
36
32
|
|
|
37
|
-
const client = getS3Client(opts.entity);
|
|
38
33
|
const prefix = `signals/${opts.signalType}/`;
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
);
|
|
35
|
+
// Presign transport ACL-filters server-side and controls page size, so
|
|
36
|
+
// `limit` is advisory there; under direct S3 it maps to MaxKeys. Paginate via
|
|
37
|
+
// the returned nextToken regardless of transport.
|
|
38
|
+
const page = await listObjects(opts, prefix, {
|
|
39
|
+
limit: opts.limit,
|
|
40
|
+
continuationToken: opts.continuationToken,
|
|
41
|
+
});
|
|
48
42
|
|
|
49
43
|
const entries: SignalSummary[] = [];
|
|
50
|
-
for (const obj of
|
|
51
|
-
|
|
52
|
-
const signalId = deriveSignalId(obj.Key, prefix);
|
|
44
|
+
for (const obj of page.contents) {
|
|
45
|
+
const signalId = deriveSignalId(obj.key, prefix);
|
|
53
46
|
if (!signalId) continue;
|
|
54
47
|
|
|
55
48
|
const summary: SignalSummary = {
|
|
56
49
|
signalId,
|
|
57
50
|
signalType: opts.signalType,
|
|
58
|
-
key: obj.
|
|
59
|
-
lastModified: obj.
|
|
60
|
-
size: obj.
|
|
51
|
+
key: obj.key,
|
|
52
|
+
lastModified: obj.lastModified,
|
|
53
|
+
size: obj.size,
|
|
61
54
|
};
|
|
62
55
|
|
|
63
56
|
if (opts.includeFrontmatter) {
|
|
64
57
|
try {
|
|
65
|
-
const
|
|
66
|
-
new GetObjectCommand({
|
|
67
|
-
Bucket: opts.entity.bucketName,
|
|
68
|
-
Key: obj.Key,
|
|
69
|
-
}),
|
|
70
|
-
);
|
|
71
|
-
const text = await streamToString(get.Body);
|
|
58
|
+
const text = await readObjectText(opts, obj.key);
|
|
72
59
|
const fm = parseFrontmatter(text);
|
|
73
60
|
if (fm) {
|
|
74
61
|
summary.frontmatter = fm;
|
|
@@ -87,6 +74,6 @@ export async function listSignals(opts: ListSignalsOptions): Promise<ListSignals
|
|
|
87
74
|
|
|
88
75
|
return {
|
|
89
76
|
entries,
|
|
90
|
-
nextToken:
|
|
77
|
+
nextToken: page.nextToken,
|
|
91
78
|
};
|
|
92
79
|
}
|
package/src/signals/types.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type { SignalType } from "../schemas/signal-types.js";
|
|
11
11
|
import type { EntityContext } from "../types.js";
|
|
12
|
+
import type { PresignTransportClient } from "../object-io.js";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Lightweight summary returned by listSignals(). `frontmatter` and
|
|
@@ -53,12 +54,23 @@ export interface SignalDocument {
|
|
|
53
54
|
export interface ListSignalsOptions {
|
|
54
55
|
entity: EntityContext;
|
|
55
56
|
signalType: SignalType;
|
|
56
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Max keys per page. Under direct S3 this maps to `MaxKeys`; under the
|
|
59
|
+
* presigned transport ({@link vault} + a company vault) it is advisory — the
|
|
60
|
+
* vault `list` endpoint controls page size server-side. Defaults to the S3
|
|
61
|
+
* default (1000) on the direct path.
|
|
62
|
+
*/
|
|
57
63
|
limit?: number;
|
|
58
64
|
/** Opaque continuation token returned by a prior page. */
|
|
59
65
|
continuationToken?: string;
|
|
60
66
|
/** When true, fetches+parses each entry's frontmatter (extra GETs). */
|
|
61
67
|
includeFrontmatter?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Presign-capable vault client. When supplied and {@link entity} is a company
|
|
70
|
+
* vault (cmp_*), reads use the presigned-URL transport (ACL-filtered, no
|
|
71
|
+
* direct S3). Personal vaults and the absent-client path stay on direct S3.
|
|
72
|
+
*/
|
|
73
|
+
vault?: PresignTransportClient;
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
export interface ListSignalsResult {
|
|
@@ -71,4 +83,9 @@ export interface GetSignalOptions {
|
|
|
71
83
|
entity: EntityContext;
|
|
72
84
|
signalType: SignalType;
|
|
73
85
|
signalId: string;
|
|
86
|
+
/**
|
|
87
|
+
* Presign-capable vault client. When supplied and {@link entity} is a company
|
|
88
|
+
* vault (cmp_*), reads use the presigned-URL transport (no direct S3).
|
|
89
|
+
*/
|
|
90
|
+
vault?: PresignTransportClient;
|
|
74
91
|
}
|