@namzu/sdk 74.0.0 → 75.0.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/CHANGELOG.md +65 -0
- package/dist/bridge/acp/server.d.ts +2 -0
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +9 -1
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/config/runtime.d.ts +3 -3
- package/dist/connector/mcp/adapter.d.ts +1 -1
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +3 -2
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +4 -25
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +32 -32
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts +1 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +31 -7
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/pricing/catalogue.generated.d.ts.map +1 -1
- package/dist/pricing/catalogue.generated.js +176 -21
- package/dist/pricing/catalogue.generated.js.map +1 -1
- package/dist/provider/errors.d.ts.map +1 -1
- package/dist/provider/errors.js +13 -18
- package/dist/provider/errors.js.map +1 -1
- package/dist/provider/stream-request-timeout.d.ts +9 -0
- package/dist/provider/stream-request-timeout.d.ts.map +1 -0
- package/dist/provider/stream-request-timeout.js +34 -0
- package/dist/provider/stream-request-timeout.js.map +1 -0
- package/dist/public-runtime.d.ts +2 -0
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +2 -0
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -1
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +1 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +3 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +15 -3
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/file-evidence-replay.d.ts +1 -0
- package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-replay.js +64 -21
- package/dist/runtime/query/file-evidence-replay.js.map +1 -1
- package/dist/runtime/query/file-evidence-seed.d.ts +7 -0
- package/dist/runtime/query/file-evidence-seed.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-seed.js +12 -1
- package/dist/runtime/query/file-evidence-seed.js.map +1 -1
- package/dist/runtime/query/guard.d.ts.map +1 -1
- package/dist/runtime/query/guard.js +12 -2
- package/dist/runtime/query/guard.js.map +1 -1
- package/dist/runtime/query/index.d.ts +2 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +6 -2
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +3 -0
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +32 -11
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.js +2 -2
- package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
- package/dist/runtime/query/path-escalation.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.js +4 -3
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
- package/dist/runtime/query/prepare-turn.js +1 -1
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +2 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +1 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/sandbox/file-walk-program.js +1 -1
- package/dist/sandbox/ignore-matcher.d.ts +2 -0
- package/dist/sandbox/ignore-matcher.d.ts.map +1 -1
- package/dist/sandbox/ignore-matcher.js +8 -2
- package/dist/sandbox/ignore-matcher.js.map +1 -1
- package/dist/sandbox/ignore-source.d.ts.map +1 -1
- package/dist/sandbox/ignore-source.js +51 -7
- package/dist/sandbox/ignore-source.js.map +1 -1
- package/dist/sandbox/limit-error.d.ts +7 -0
- package/dist/sandbox/limit-error.d.ts.map +1 -0
- package/dist/sandbox/limit-error.js +13 -0
- package/dist/sandbox/limit-error.js.map +1 -0
- package/dist/sandbox/provider/local.d.ts +1 -0
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +95 -31
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/schedules/cron.js +1 -1
- package/dist/schedules/cron.js.map +1 -1
- package/dist/schedules/describe.js +1 -1
- package/dist/schedules/describe.js.map +1 -1
- package/dist/schedules/next-fire.d.ts +2 -2
- package/dist/schedules/next-fire.d.ts.map +1 -1
- package/dist/schedules/next-fire.js +7 -4
- package/dist/schedules/next-fire.js.map +1 -1
- package/dist/schedules/spec.d.ts.map +1 -1
- package/dist/schedules/spec.js +23 -7
- package/dist/schedules/spec.js.map +1 -1
- package/dist/schedules/types.d.ts +2 -0
- package/dist/schedules/types.d.ts.map +1 -1
- package/dist/store/budget/ledger.d.ts +15 -1
- package/dist/store/budget/ledger.d.ts.map +1 -1
- package/dist/store/budget/ledger.js +80 -1
- package/dist/store/budget/ledger.js.map +1 -1
- package/dist/store/evidence/source-text.d.ts +1 -1
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +7 -3
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/store/session-log/core.d.ts.map +1 -1
- package/dist/store/session-log/core.js +88 -24
- package/dist/store/session-log/core.js.map +1 -1
- package/dist/store/session-log/disk.js +1 -1
- package/dist/store/session-log/disk.js.map +1 -1
- package/dist/tools/builtins/atomic-write-file.d.ts +2 -0
- package/dist/tools/builtins/atomic-write-file.d.ts.map +1 -1
- package/dist/tools/builtins/atomic-write-file.js +37 -8
- package/dist/tools/builtins/atomic-write-file.js.map +1 -1
- package/dist/tools/builtins/code-analysis.d.ts.map +1 -1
- package/dist/tools/builtins/code-analysis.js +4 -1
- package/dist/tools/builtins/code-analysis.js.map +1 -1
- package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
- package/dist/tools/builtins/edit-apply.js +24 -10
- package/dist/tools/builtins/edit-apply.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +31 -15
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/file-text.d.ts +3 -0
- package/dist/tools/builtins/file-text.d.ts.map +1 -0
- package/dist/tools/builtins/file-text.js +14 -0
- package/dist/tools/builtins/file-text.js.map +1 -0
- package/dist/tools/builtins/glob.d.ts.map +1 -1
- package/dist/tools/builtins/glob.js +7 -2
- package/dist/tools/builtins/glob.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +8 -5
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/ls.d.ts.map +1 -1
- package/dist/tools/builtins/ls.js +2 -1
- package/dist/tools/builtins/ls.js.map +1 -1
- package/dist/tools/builtins/notebook-edit.d.ts.map +1 -1
- package/dist/tools/builtins/notebook-edit.js +19 -10
- package/dist/tools/builtins/notebook-edit.js.map +1 -1
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +61 -29
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-regular-file.d.ts +5 -0
- package/dist/tools/builtins/read-regular-file.d.ts.map +1 -0
- package/dist/tools/builtins/read-regular-file.js +23 -0
- package/dist/tools/builtins/read-regular-file.js.map +1 -0
- package/dist/tools/builtins/search-support.d.ts +2 -0
- package/dist/tools/builtins/search-support.d.ts.map +1 -1
- package/dist/tools/builtins/search-support.js +14 -0
- package/dist/tools/builtins/search-support.js.map +1 -1
- package/dist/tools/builtins/stale-before-review.d.ts.map +1 -1
- package/dist/tools/builtins/stale-before-review.js +8 -5
- package/dist/tools/builtins/stale-before-review.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +17 -13
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +4 -3
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/paths.d.ts +9 -0
- package/dist/tools/paths.d.ts.map +1 -1
- package/dist/tools/paths.js +39 -9
- package/dist/tools/paths.js.map +1 -1
- package/dist/tools/posix-path.d.ts +2 -14
- package/dist/tools/posix-path.d.ts.map +1 -1
- package/dist/tools/posix-path.js +7 -0
- package/dist/tools/posix-path.js.map +1 -1
- package/dist/tools/tool-is-available.d.ts +4 -0
- package/dist/tools/tool-is-available.d.ts.map +1 -0
- package/dist/tools/tool-is-available.js +8 -0
- package/dist/tools/tool-is-available.js.map +1 -0
- package/dist/types/code-analysis/index.d.ts +1 -1
- package/dist/types/code-analysis/index.d.ts.map +1 -1
- package/dist/types/common/index.d.ts +6 -0
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/common/index.js +13 -0
- package/dist/types/common/index.js.map +1 -1
- package/dist/types/provider/errors.d.ts.map +1 -1
- package/dist/types/provider/errors.js +3 -5
- package/dist/types/provider/errors.js.map +1 -1
- package/dist/types/sandbox/index.d.ts +13 -2
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/session/checkpoint.d.ts +4 -0
- package/dist/types/session/checkpoint.d.ts.map +1 -1
- package/dist/types/session/checkpoint.js +2 -0
- package/dist/types/session/checkpoint.js.map +1 -1
- package/dist/types/session/events.d.ts +1 -0
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/session/records.d.ts +42 -6
- package/dist/types/session/records.d.ts.map +1 -1
- package/dist/types/session/records.js +1 -0
- package/dist/types/session/records.js.map +1 -1
- package/dist/types/tool/index.d.ts +2 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/utils/cost.d.ts +17 -0
- package/dist/utils/cost.d.ts.map +1 -1
- package/dist/utils/cost.js +78 -8
- package/dist/utils/cost.js.map +1 -1
- package/package.json +1 -1
- package/src/bridge/acp/server.ts +16 -7
- package/src/connector/mcp/adapter.ts +4 -3
- package/src/connector/mcp/client.ts +33 -32
- package/src/index.ts +2 -0
- package/src/manager/session/turn-recorder.ts +31 -7
- package/src/pricing/catalogue.generated.ts +176 -21
- package/src/pricing/rates.source.json +108 -33
- package/src/provider/errors.ts +12 -19
- package/src/provider/stream-request-timeout.ts +34 -0
- package/src/public-runtime.ts +2 -0
- package/src/public-tools.ts +1 -0
- package/src/runtime/query/executor.ts +29 -3
- package/src/runtime/query/file-evidence-replay.ts +73 -19
- package/src/runtime/query/file-evidence-seed.ts +16 -0
- package/src/runtime/query/guard.ts +13 -2
- package/src/runtime/query/index.ts +10 -1
- package/src/runtime/query/iteration/index.ts +32 -11
- package/src/runtime/query/iteration/phases/advisory.ts +2 -2
- package/src/runtime/query/path-escalation.ts +4 -3
- package/src/runtime/query/prepare-turn.ts +2 -1
- package/src/runtime/query/tooling.ts +3 -0
- package/src/sandbox/file-walk-program.ts +1 -1
- package/src/sandbox/ignore-matcher.ts +12 -3
- package/src/sandbox/ignore-source.ts +51 -7
- package/src/sandbox/limit-error.ts +10 -0
- package/src/sandbox/provider/local.ts +107 -48
- package/src/schedules/cron.ts +1 -1
- package/src/schedules/describe.ts +1 -1
- package/src/schedules/next-fire.ts +7 -4
- package/src/schedules/spec.ts +36 -7
- package/src/schedules/types.ts +2 -0
- package/src/store/budget/ledger.ts +93 -2
- package/src/store/session-index/sqlite.ts +8 -4
- package/src/store/session-log/core.ts +96 -25
- package/src/store/session-log/disk.ts +1 -1
- package/src/tools/builtins/atomic-write-file.ts +49 -7
- package/src/tools/builtins/code-analysis.ts +6 -1
- package/src/tools/builtins/edit-apply.ts +25 -10
- package/src/tools/builtins/edit.ts +31 -15
- package/src/tools/builtins/file-text.ts +14 -0
- package/src/tools/builtins/glob.ts +6 -1
- package/src/tools/builtins/grep.ts +7 -5
- package/src/tools/builtins/ls.ts +2 -1
- package/src/tools/builtins/notebook-edit.ts +18 -11
- package/src/tools/builtins/read-file.ts +71 -24
- package/src/tools/builtins/read-regular-file.ts +25 -0
- package/src/tools/builtins/search-support.ts +13 -0
- package/src/tools/builtins/stale-before-review.ts +8 -6
- package/src/tools/builtins/write-file.ts +18 -12
- package/src/tools/defineTool.ts +4 -3
- package/src/tools/paths.ts +49 -7
- package/src/tools/posix-path.ts +9 -0
- package/src/tools/tool-is-available.ts +11 -0
- package/src/types/code-analysis/index.ts +1 -1
- package/src/types/common/index.ts +24 -0
- package/src/types/provider/errors.ts +3 -5
- package/src/types/sandbox/index.ts +12 -1
- package/src/types/session/checkpoint.ts +2 -0
- package/src/types/session/events.ts +1 -0
- package/src/types/session/records.ts +1 -0
- package/src/types/tool/index.ts +2 -0
- package/src/utils/cost.ts +101 -8
|
@@ -6,6 +6,7 @@ import { ReadFileTool } from '../../tools/builtins/read-file.js'
|
|
|
6
6
|
import {
|
|
7
7
|
LINE_NUMBER_WIDTH,
|
|
8
8
|
type ReadWindowRequest,
|
|
9
|
+
linePrefix,
|
|
9
10
|
renderNumberedRead,
|
|
10
11
|
resolveReadWindow,
|
|
11
12
|
} from '../../tools/builtins/read-render.js'
|
|
@@ -498,6 +499,29 @@ export function replayObservationLedger(
|
|
|
498
499
|
keyOf: FileKeyResolver,
|
|
499
500
|
attributions: PathAttributions = createPathAttributions(),
|
|
500
501
|
): LedgerReplayReport {
|
|
502
|
+
const { claims, budget } = replayClaims(messages, keyOf, attributions, false)
|
|
503
|
+
return commit(tracker, claims, budget)
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export function replayComparisonClaims(
|
|
507
|
+
messages: readonly Message[],
|
|
508
|
+
keyOf: FileKeyResolver,
|
|
509
|
+
attributions: PathAttributions,
|
|
510
|
+
): ReadonlyMap<string, string> {
|
|
511
|
+
const { claims } = replayClaims(messages, keyOf, attributions, true)
|
|
512
|
+
const bodies = new Map<string, string>()
|
|
513
|
+
for (const [key, claim] of claims) {
|
|
514
|
+
if (claim.kind === 'content') bodies.set(key, claim.body)
|
|
515
|
+
}
|
|
516
|
+
return bodies
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function replayClaims(
|
|
520
|
+
messages: readonly Message[],
|
|
521
|
+
keyOf: FileKeyResolver,
|
|
522
|
+
attributions: PathAttributions,
|
|
523
|
+
compareReads: boolean,
|
|
524
|
+
): { claims: Map<string, Claim>; budget: ReplayBudget } {
|
|
501
525
|
const history = indexVisibleHistory(messages, keyOf)
|
|
502
526
|
const budget = createReplayBudget()
|
|
503
527
|
const claims = new Map<string, Claim>()
|
|
@@ -517,14 +541,15 @@ export function replayObservationLedger(
|
|
|
517
541
|
// be the one showing a body this walk is holding to be something else,
|
|
518
542
|
// and skipping the read past would keep a claim that very observation
|
|
519
543
|
// withdrew. Both get the same answer.
|
|
520
|
-
if (receipt === null) return
|
|
544
|
+
if (receipt === null) return { claims: new Map(), budget }
|
|
521
545
|
const answered = receipt !== undefined && receipt.role === 'tool' && !receipt.isError
|
|
522
546
|
if (name === 'read') {
|
|
523
547
|
// A read that never came back, or came back refused, saw no body: it
|
|
524
548
|
// can neither confirm what this pass holds nor contradict it. And a
|
|
525
549
|
// read changes no file, so a claim left standing across one is still a
|
|
526
550
|
// claim about the same bytes.
|
|
527
|
-
if (answered) observeRead(history, call, claims, withBody, budget)
|
|
551
|
+
if (answered) observeRead(history, call, claims, withBody, budget, compareReads)
|
|
552
|
+
limitBodies(claims, withBody)
|
|
528
553
|
continue
|
|
529
554
|
}
|
|
530
555
|
// One id claimed by two calls hides which of them ran. On a path this
|
|
@@ -532,7 +557,7 @@ export function replayObservationLedger(
|
|
|
532
557
|
// have replaced a body claimed somewhere else in this walk, and there
|
|
533
558
|
// is no way to tell where — so the pass establishes nothing at all
|
|
534
559
|
// rather than carry a body something unseen may have moved past.
|
|
535
|
-
if (history.calls.get(call.id) === null) return
|
|
560
|
+
if (history.calls.get(call.id) === null) return { claims: new Map(), budget }
|
|
536
561
|
// Attribution before outcome, for every mutation the walk reaches. A call
|
|
537
562
|
// the transcript never answered — the unknown-outcome result the kernel's
|
|
538
563
|
// own repair writes for one included — is precisely the call whose effect
|
|
@@ -546,28 +571,26 @@ export function replayObservationLedger(
|
|
|
546
571
|
// is still the one thing that stops the pass, because then there is no
|
|
547
572
|
// path to withdraw.
|
|
548
573
|
const key = mutatedKey(history, call, attributions)
|
|
549
|
-
if (key === undefined) return
|
|
574
|
+
if (key === undefined) return { claims: new Map(), budget }
|
|
550
575
|
const claim: Claim = answered
|
|
551
576
|
? mutate(history, call, name, key, claims.get(key), budget)
|
|
552
577
|
: { kind: 'seen' }
|
|
553
578
|
claims.set(key, claim)
|
|
554
579
|
withBody.delete(key)
|
|
555
580
|
if (claim.kind === 'content') withBody.add(key)
|
|
556
|
-
|
|
557
|
-
// path is one this pass stops vouching for: it was mutated here, and
|
|
558
|
-
// what it holds is past what the pass can carry, so it reaches the
|
|
559
|
-
// ledger as the nothing every unrebuilt path reaches it as.
|
|
560
|
-
if (withBody.size > MAX_WITNESSED_PATHS) {
|
|
561
|
-
const oldest = withBody.values().next().value as string
|
|
562
|
-
withBody.delete(oldest)
|
|
563
|
-
// Setting an existing key leaves it where it is, so the order the
|
|
564
|
-
// ledger is written in stays the order the calls arrived in.
|
|
565
|
-
claims.set(oldest, { kind: 'seen' })
|
|
566
|
-
}
|
|
581
|
+
limitBodies(claims, withBody)
|
|
567
582
|
}
|
|
568
583
|
}
|
|
569
584
|
|
|
570
|
-
return
|
|
585
|
+
return { claims, budget }
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/** Evict the oldest body while retaining its path attribution. */
|
|
589
|
+
function limitBodies(claims: Map<string, Claim>, withBody: Set<string>): void {
|
|
590
|
+
if (withBody.size <= MAX_WITNESSED_PATHS) return
|
|
591
|
+
const oldest = withBody.values().next().value as string
|
|
592
|
+
withBody.delete(oldest)
|
|
593
|
+
claims.set(oldest, { kind: 'seen' })
|
|
571
594
|
}
|
|
572
595
|
|
|
573
596
|
/** Apply a walk's surviving claims to the ledger, in the order they were made. */
|
|
@@ -673,28 +696,40 @@ function observeRead(
|
|
|
673
696
|
claims: Map<string, Claim>,
|
|
674
697
|
withBody: Set<string>,
|
|
675
698
|
budget: ReplayBudget,
|
|
699
|
+
compareReads: boolean,
|
|
676
700
|
): void {
|
|
677
701
|
const read = readWindow(history, call)
|
|
678
702
|
if (!read) return
|
|
679
703
|
const claim = claims.get(read.key)
|
|
680
|
-
if (!claim || claim.kind !== 'content') return
|
|
704
|
+
if (!compareReads && (!claim || claim.kind !== 'content')) return
|
|
681
705
|
const shown = history.results.get(call.id)?.content
|
|
682
706
|
if (visibleCall(history, call.id, 'read') && typeof shown === 'string') {
|
|
683
707
|
// A whole-file rendering is the body plus a number on every line, so one
|
|
684
708
|
// shorter than the body it would render cannot be equal to it. The cheap
|
|
685
709
|
// half of the comparison, taken before anything is measured.
|
|
686
710
|
const units =
|
|
687
|
-
shown.length
|
|
711
|
+
claim?.kind === 'content' && shown.length >= claim.body.length
|
|
712
|
+
? wholeFileRenderUnits(claim.body, read.window)
|
|
713
|
+
: undefined
|
|
688
714
|
// The rendering is content this pass materialises, so it is charged like
|
|
689
715
|
// every other body — and charged for what it will actually come to,
|
|
690
716
|
// worked out from the body and the window while the string does not exist
|
|
691
717
|
// yet. Charging the RECEIPT's length was charging one number and building
|
|
692
718
|
// another: a receipt that had been rewritten short could have the pass
|
|
693
719
|
// build a rendering the ceiling had never been asked about.
|
|
694
|
-
if (units !== undefined && spend(budget, units)) {
|
|
720
|
+
if (claim?.kind === 'content' && units !== undefined && spend(budget, units)) {
|
|
695
721
|
const rendered = renderNumberedRead(claim.body, read.window)
|
|
696
722
|
if (!rendered.partial && rendered.output === shown) return
|
|
697
723
|
}
|
|
724
|
+
if (compareReads && spend(budget, shown.length)) {
|
|
725
|
+
const body = comparisonReadBody(shown, read.window)
|
|
726
|
+
if (body !== undefined) {
|
|
727
|
+
claims.set(read.key, { kind: 'content', body, steps: [] })
|
|
728
|
+
withBody.delete(read.key)
|
|
729
|
+
withBody.add(read.key)
|
|
730
|
+
return
|
|
731
|
+
}
|
|
732
|
+
}
|
|
698
733
|
}
|
|
699
734
|
claims.set(read.key, { kind: 'seen' })
|
|
700
735
|
// Off the held list as well as out of the claim. A withdrawn path is one
|
|
@@ -705,6 +740,25 @@ function observeRead(
|
|
|
705
740
|
withBody.delete(read.key)
|
|
706
741
|
}
|
|
707
742
|
|
|
743
|
+
/**
|
|
744
|
+
* Recover a comparison baseline from a complete, unmodified numbered receipt.
|
|
745
|
+
* Numbered reads omit the final newline. This approximation is only used to
|
|
746
|
+
* request a fresh read and must never establish a mutation witness.
|
|
747
|
+
*/
|
|
748
|
+
function comparisonReadBody(shown: string, window: ReadWindowRequest): string | undefined {
|
|
749
|
+
if (shown === 'Warning: the file exists but is empty.') return ''
|
|
750
|
+
const rows = shown.split('\n')
|
|
751
|
+
const lines: string[] = []
|
|
752
|
+
for (const [index, row] of rows.entries()) {
|
|
753
|
+
const prefix = linePrefix(index + 1)
|
|
754
|
+
if (!row.startsWith(prefix)) return undefined
|
|
755
|
+
lines.push(row.slice(prefix.length))
|
|
756
|
+
}
|
|
757
|
+
const body = `${lines.join('\n')}\n`
|
|
758
|
+
const rendered = renderNumberedRead(body, window)
|
|
759
|
+
return !rendered.partial && rendered.output === shown ? body : undefined
|
|
760
|
+
}
|
|
761
|
+
|
|
708
762
|
/**
|
|
709
763
|
* What `read` would return for this whole body, in UTF-16 units, without
|
|
710
764
|
* building it — and `undefined` for a window that would leave a line out.
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type PathAttributions,
|
|
8
8
|
collectObservedPaths,
|
|
9
9
|
createPathAttributions,
|
|
10
|
+
replayComparisonClaims,
|
|
10
11
|
replayObservationLedger,
|
|
11
12
|
} from './file-evidence-replay.js'
|
|
12
13
|
|
|
@@ -92,6 +93,21 @@ export async function seedObservationLedger(
|
|
|
92
93
|
return keyOf ? replayObservationLedger(messages, tracker, keyOf, attributions) : NOTHING
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Recover bounded file bodies for change notices when a conversation is reopened.
|
|
98
|
+
* Includes complete numbered reads and edits replayed over them. Bodies recovered
|
|
99
|
+
* from reads have an ambiguous final newline and are suitable only for comparison.
|
|
100
|
+
* No file content is read from disk and no mutation witness is established.
|
|
101
|
+
*/
|
|
102
|
+
export async function replayFileComparisonBodies(
|
|
103
|
+
messages: readonly Message[],
|
|
104
|
+
context: ObservationSeedContext,
|
|
105
|
+
): Promise<ReadonlyMap<string, string>> {
|
|
106
|
+
const attributions = createPathAttributions()
|
|
107
|
+
const keyOf = await resolveObservedFileKeys(messages, context, attributions)
|
|
108
|
+
return keyOf ? replayComparisonClaims(messages, keyOf, attributions) : new Map()
|
|
109
|
+
}
|
|
110
|
+
|
|
95
111
|
/**
|
|
96
112
|
* The tools' key for every path this history names, or `undefined` when the
|
|
97
113
|
* pass should not run at all.
|
|
@@ -124,11 +124,12 @@ export class GuardCoordinator {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
beforeIteration(recorder: TurnRecorder, abortSignal: AbortSignal): GuardCheckResult {
|
|
127
|
+
const cost = recorder.treeCostInfo ?? recorder.costInfo
|
|
127
128
|
const limitState = {
|
|
128
129
|
aborted: abortSignal.aborted,
|
|
129
130
|
totalTokens: recorder.tokenUsage.totalTokens,
|
|
130
|
-
totalCost:
|
|
131
|
-
unpricedTokens:
|
|
131
|
+
totalCost: cost.totalCost,
|
|
132
|
+
unpricedTokens: cost.unpricedTokens,
|
|
132
133
|
currentIteration: recorder.currentIteration,
|
|
133
134
|
startTime: this.startTime,
|
|
134
135
|
}
|
|
@@ -152,6 +153,16 @@ export class GuardCoordinator {
|
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
|
|
156
|
+
const ancestorStop = recorder.budget?.ancestorCostStop()
|
|
157
|
+
if (ancestorStop) {
|
|
158
|
+
return {
|
|
159
|
+
shouldStop: true,
|
|
160
|
+
forceFinalize: false,
|
|
161
|
+
stopReason: ancestorStop,
|
|
162
|
+
isCancelled: false,
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
155
166
|
if (limitResult.type === 'warning') {
|
|
156
167
|
return {
|
|
157
168
|
shouldStop: false,
|
|
@@ -46,6 +46,7 @@ import { createStructuredOutputTool } from '../../tools/builtins/structuredOutpu
|
|
|
46
46
|
import {
|
|
47
47
|
HAND_BACK_GUIDANCE,
|
|
48
48
|
HAND_BACK_GUIDANCE_CONTRIBUTION_ID,
|
|
49
|
+
HAND_BACK_TOOL_NAME,
|
|
49
50
|
buildHandBackTool,
|
|
50
51
|
} from '../../tools/hand-back/index.js'
|
|
51
52
|
import { buildTaskTools } from '../../tools/task/index.js'
|
|
@@ -620,6 +621,8 @@ export interface QueryParams {
|
|
|
620
621
|
* `ToolContext.additionalDirectories`.
|
|
621
622
|
*/
|
|
622
623
|
additionalDirectories?: readonly string[]
|
|
624
|
+
/** Host-owned absolute file paths available to read, write and edit, including in a sandbox. */
|
|
625
|
+
allowedFiles?: readonly string[]
|
|
623
626
|
/**
|
|
624
627
|
* What a file tool's path outside `workingDirectory` and
|
|
625
628
|
* `additionalDirectories` becomes, on a turn with no sandbox.
|
|
@@ -1715,6 +1718,7 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
|
|
|
1715
1718
|
...(params.additionalDirectories?.length
|
|
1716
1719
|
? { additionalDirectories: params.additionalDirectories }
|
|
1717
1720
|
: {}),
|
|
1721
|
+
...(params.allowedFiles?.length ? { allowedFiles: params.allowedFiles } : {}),
|
|
1718
1722
|
...(scratchpadDirectory ? { scratchpadDirectory } : {}),
|
|
1719
1723
|
...(params.outsideRootAccess ? { outsideRootAccess: params.outsideRootAccess } : {}),
|
|
1720
1724
|
...(params.outsideRootRefusal ? { outsideRootRefusal: params.outsideRootRefusal } : {}),
|
|
@@ -1930,7 +1934,11 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
|
|
|
1930
1934
|
// The turn's own registry when the host passed none, so a hook's
|
|
1931
1935
|
// annotation has somewhere to land.
|
|
1932
1936
|
const promptContributions = params.promptContributions ?? new PromptContributionRegistry()
|
|
1933
|
-
if (
|
|
1937
|
+
if (
|
|
1938
|
+
turnConfig.handBack === true &&
|
|
1939
|
+
runtimeToolOverrides?.[HAND_BACK_TOOL_NAME] !== 'disabled' &&
|
|
1940
|
+
(effectiveAllowedTools?.includes(HAND_BACK_TOOL_NAME) ?? true)
|
|
1941
|
+
) {
|
|
1934
1942
|
promptContributions.replace({
|
|
1935
1943
|
id: HAND_BACK_GUIDANCE_CONTRIBUTION_ID,
|
|
1936
1944
|
placement: 'static',
|
|
@@ -1952,6 +1960,7 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
|
|
|
1952
1960
|
contributions: promptContributions,
|
|
1953
1961
|
})
|
|
1954
1962
|
|
|
1963
|
+
ctx.recorder.budget?.setCostLimit(turnConfig.costLimitUsd)
|
|
1955
1964
|
const guard = new GuardCoordinator({
|
|
1956
1965
|
tokenBudget: turnConfig.tokenBudget,
|
|
1957
1966
|
timeoutMs: turnConfig.timeoutMs,
|
|
@@ -389,6 +389,7 @@ export class IterationOrchestrator {
|
|
|
389
389
|
private stopHookActive = false
|
|
390
390
|
/** End-of-turn refusals honoured since the last tool call. */
|
|
391
391
|
private consecutiveHookRefusals = 0
|
|
392
|
+
private readonly schemaFailures = new Map<string, number>()
|
|
392
393
|
/** The cap was reached and its notice recorded; refusals are ignored for the rest of the turn. */
|
|
393
394
|
private hookRefusalCapReached = false
|
|
394
395
|
get turnEndHooksFired(): boolean {
|
|
@@ -1509,6 +1510,7 @@ export class IterationOrchestrator {
|
|
|
1509
1510
|
usage: recorder.tokenUsage,
|
|
1510
1511
|
budget: recorder.budget?.summary(),
|
|
1511
1512
|
cost: recorder.costInfo,
|
|
1513
|
+
...(response.usage.billingRoute ? { billingRoute: response.usage.billingRoute } : {}),
|
|
1512
1514
|
...(response.usage.cacheTtlMs !== undefined
|
|
1513
1515
|
? {
|
|
1514
1516
|
cache: {
|
|
@@ -2250,18 +2252,19 @@ export class IterationOrchestrator {
|
|
|
2250
2252
|
return
|
|
2251
2253
|
}
|
|
2252
2254
|
|
|
2253
|
-
//
|
|
2254
|
-
// answered. Every `tool_use` has its `tool_result` by now, so the
|
|
2255
|
-
// transcript is whole; what is left is to end the turn and say why.
|
|
2255
|
+
// End only after the batch has answered every tool call.
|
|
2256
2256
|
const hookHalt = this.ctx.toolExecutor.takeHalt?.()
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2257
|
+
const validationHalt = this.repeatedValidationFailure(reviewOutcome.results)
|
|
2258
|
+
if (hookHalt !== undefined || validationHalt !== undefined) {
|
|
2259
|
+
if (hookHalt !== undefined) {
|
|
2260
|
+
this.ctx.log.info('A hook stopped the turn', {
|
|
2261
|
+
[NAMZU.TURN_ID]: recorder.turnId,
|
|
2262
|
+
[NAMZU.ITERATION]: iterationNum,
|
|
2263
|
+
'namzu.hook.reason': hookHalt,
|
|
2264
|
+
})
|
|
2265
|
+
recorder.setLastError(`Stopped by a hook: ${hookHalt}`)
|
|
2266
|
+
recorder.setStopReason('stop_condition')
|
|
2267
|
+
}
|
|
2265
2268
|
await this.ctx.emitEvent({
|
|
2266
2269
|
type: 'iteration_completed',
|
|
2267
2270
|
turnId: recorder.turnId,
|
|
@@ -2269,6 +2272,9 @@ export class IterationOrchestrator {
|
|
|
2269
2272
|
hasToolCalls: true,
|
|
2270
2273
|
})
|
|
2271
2274
|
yield* this.ctx.drainPending()
|
|
2275
|
+
if (hookHalt === undefined && validationHalt !== undefined) {
|
|
2276
|
+
throw new Error(validationHalt)
|
|
2277
|
+
}
|
|
2272
2278
|
break
|
|
2273
2279
|
}
|
|
2274
2280
|
|
|
@@ -2977,6 +2983,21 @@ export class IterationOrchestrator {
|
|
|
2977
2983
|
return true
|
|
2978
2984
|
}
|
|
2979
2985
|
|
|
2986
|
+
/** Admission failures have no execution receipt for the repeat-call advisory. */
|
|
2987
|
+
private repeatedValidationFailure(results: readonly ToolCallOutcome[]): string | undefined {
|
|
2988
|
+
for (const { toolName, inputFailure, output } of results) {
|
|
2989
|
+
// Structured output has a separate, configurable correction allowance.
|
|
2990
|
+
if (inputFailure !== 'schema_validation' || toolName === STRUCTURED_OUTPUT_TOOL_NAME) continue
|
|
2991
|
+
const key = JSON.stringify([toolName, output])
|
|
2992
|
+
const count = (this.schemaFailures.get(key) ?? 0) + 1
|
|
2993
|
+
this.schemaFailures.set(key, count)
|
|
2994
|
+
if (count === 4) {
|
|
2995
|
+
return `Stopped after ${count} identical validation failures for "${toolName}" in this turn. ${output}`
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
return undefined
|
|
2999
|
+
}
|
|
3000
|
+
|
|
2980
3001
|
private async recordToolStructuredFailure(
|
|
2981
3002
|
results: readonly ToolCallOutcome[],
|
|
2982
3003
|
iteration: number,
|
|
@@ -27,7 +27,7 @@ function estimateContextWindowPercent(ctx: IterationContext): number {
|
|
|
27
27
|
function computeCostBudgetPercent(ctx: IterationContext): number | undefined {
|
|
28
28
|
const limit = ctx.turnConfig.costLimitUsd
|
|
29
29
|
if (limit === undefined || limit <= 0) return undefined
|
|
30
|
-
return (ctx.recorder.costInfo.totalCost / limit) * 100
|
|
30
|
+
return ((ctx.recorder.treeCostInfo ?? ctx.recorder.costInfo).totalCost / limit) * 100
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function extractLastToolCategory(
|
|
@@ -67,7 +67,7 @@ export async function runAdvisoryPhase(
|
|
|
67
67
|
totalToolCalls: countToolCalls(ctx),
|
|
68
68
|
totalTokens: ctx.recorder.tokenUsage.totalTokens,
|
|
69
69
|
contextWindowPercent: estimateContextWindowPercent(ctx),
|
|
70
|
-
totalCostUsd: ctx.recorder.costInfo.totalCost,
|
|
70
|
+
totalCostUsd: (ctx.recorder.treeCostInfo ?? ctx.recorder.costInfo).totalCost,
|
|
71
71
|
costBudgetPercent: computeCostBudgetPercent(ctx),
|
|
72
72
|
lastError: extractCurrentToolErrors(ctx, response),
|
|
73
73
|
lastToolCategory: extractLastToolCategory(ctx, response),
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
topLevelEntryChange,
|
|
32
32
|
} from '../../authorization/top-level-entries.js'
|
|
33
33
|
import { resolveNamzuHome } from '../../session/home.js'
|
|
34
|
-
import { canonicalize, pathOutsideRoots } from '../../tools/paths.js'
|
|
34
|
+
import { canonicalize, expandHomePath, pathOutsideRoots } from '../../tools/paths.js'
|
|
35
35
|
|
|
36
36
|
/** What the escalation records carry. */
|
|
37
37
|
export interface PathEscalations {
|
|
@@ -274,8 +274,9 @@ export async function declaredWriteEscalation(
|
|
|
274
274
|
): Promise<string | undefined> {
|
|
275
275
|
const [first] = roots
|
|
276
276
|
if (first === undefined || value === '') return undefined
|
|
277
|
-
const
|
|
278
|
-
|
|
277
|
+
const spelled = expandHomePath(value)
|
|
278
|
+
const absolute = resolve(first, spelled)
|
|
279
|
+
if (await isProtectedWrite(spelled, absolute, roots)) return absolute
|
|
279
280
|
return topLevel ? topLevelEntryChange(absolute, 'write', homedir()) : undefined
|
|
280
281
|
}
|
|
281
282
|
|
|
@@ -192,7 +192,8 @@ function assertBudgetIsMeasurable(params: QueryParams): void {
|
|
|
192
192
|
// brought one has answered the question themselves.
|
|
193
193
|
if (params.pricing !== undefined) return
|
|
194
194
|
// A driver that reports each call's billed cost measures the limit itself.
|
|
195
|
-
if (params.provider.capabilities?.reportsRequestCost === true)
|
|
195
|
+
if (params.provider.capabilities?.reportsRequestCost === true || params.provider.id === 'codex')
|
|
196
|
+
return
|
|
196
197
|
const model = params.turnConfig.model
|
|
197
198
|
if (resolveModelPricing(params.provider.id, model) !== undefined) return
|
|
198
199
|
|
|
@@ -33,6 +33,8 @@ export interface ToolingBootstrapConfig {
|
|
|
33
33
|
workingDirectory: string
|
|
34
34
|
/** See `QueryParams.additionalDirectories`. */
|
|
35
35
|
additionalDirectories?: readonly string[]
|
|
36
|
+
/** Host-owned absolute file paths available to read, write and edit, including in a sandbox. */
|
|
37
|
+
allowedFiles?: readonly string[]
|
|
36
38
|
/** See `ToolExecutorConfig.scratchpadDirectory`. */
|
|
37
39
|
scratchpadDirectory?: string
|
|
38
40
|
/** See `QueryParams.outsideRootAccess`. */
|
|
@@ -119,6 +121,7 @@ export class ToolingBootstrap {
|
|
|
119
121
|
...(config.additionalDirectories?.length
|
|
120
122
|
? { additionalDirectories: config.additionalDirectories }
|
|
121
123
|
: {}),
|
|
124
|
+
...(config.allowedFiles?.length ? { allowedFiles: config.allowedFiles } : {}),
|
|
122
125
|
...(config.scratchpadDirectory ? { scratchpadDirectory: config.scratchpadDirectory } : {}),
|
|
123
126
|
...(config.outsideRootAccess ? { outsideRootAccess: config.outsideRootAccess } : {}),
|
|
124
127
|
...(config.outsideRootRefusal ? { outsideRootRefusal: config.outsideRootRefusal } : {}),
|
|
@@ -50,7 +50,7 @@ async function run() {
|
|
|
50
50
|
let emitted = 0;
|
|
51
51
|
const matchers = plan.expressions.map(({source, flags}) => new RegExp(source, flags + 's'));
|
|
52
52
|
const maxDepth = plan.maxDepth === null ? Infinity : plan.maxDepth;
|
|
53
|
-
const ignore = plan.respectIgnore ? ignCreate({fs, path, extraFiles: []}) : null;
|
|
53
|
+
const ignore = plan.respectIgnore ? ignCreate({fs, syncFs: require('node:fs'), path, extraFiles: []}) : null;
|
|
54
54
|
const open = async (absolute, relative, depth, layered) => {
|
|
55
55
|
try {
|
|
56
56
|
const dir = await fs.opendir(absolute);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as fs from 'node:fs'
|
|
2
|
+
import * as path from 'node:path'
|
|
1
3
|
import { IGNORE_SOURCE } from './ignore-source.js'
|
|
2
4
|
|
|
3
5
|
/** One compiled ignore rule. */
|
|
@@ -29,19 +31,26 @@ export interface IgnoreDeps {
|
|
|
29
31
|
interface IgnoreModule {
|
|
30
32
|
parse(text: string): IgnoreRule[]
|
|
31
33
|
decide(rules: readonly IgnoreRule[], relative: string, isDirectory: boolean): 0 | 1 | 2
|
|
32
|
-
create(deps: IgnoreDeps): IgnoreStack
|
|
34
|
+
create(deps: IgnoreDeps & { syncFs: typeof fs }): IgnoreStack
|
|
35
|
+
gitDirectory(directory: string, syncFs: typeof fs, paths: typeof path): string | null
|
|
33
36
|
vcs: readonly string[]
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
// The same text is embedded in the guest program, so both walks share it.
|
|
37
40
|
const module_ = new Function(
|
|
38
|
-
`${IGNORE_SOURCE}\nreturn { parse: ignParse, decide: ignDecide, create: ignCreate, vcs: IGN_VCS }`,
|
|
41
|
+
`${IGNORE_SOURCE}\nreturn { parse: ignParse, decide: ignDecide, create: ignCreate, gitDirectory, vcs: IGN_VCS }`,
|
|
39
42
|
)() as IgnoreModule
|
|
40
43
|
|
|
41
44
|
/** Parse the text of one ignore file into rules; a line it cannot read is dropped. */
|
|
42
45
|
export const parseIgnoreRules = module_.parse
|
|
43
46
|
/** 0: no rule matches, 1: ignored, 2: re-included. The last matching rule wins. */
|
|
44
47
|
export const decideIgnore = module_.decide
|
|
45
|
-
export const createIgnoreStack =
|
|
48
|
+
export const createIgnoreStack = (deps: IgnoreDeps): IgnoreStack =>
|
|
49
|
+
module_.create({ ...deps, syncFs: fs })
|
|
50
|
+
|
|
51
|
+
/** @internal Check whether this directory itself has a valid checkout marker. */
|
|
52
|
+
export function hasGitCheckoutMarker(directory: string): boolean {
|
|
53
|
+
return module_.gitDirectory(directory, fs, path) !== null
|
|
54
|
+
}
|
|
46
55
|
/** Version-control directories that no walk ever descends into. */
|
|
47
56
|
export const VCS_NAMES: ReadonlySet<string> = new Set(module_.vcs)
|
|
@@ -132,10 +132,50 @@ function ignDecide(rules, relative, isDirectory) {
|
|
|
132
132
|
}
|
|
133
133
|
return 0;
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Resolve a checkout marker. A linked worktree uses its own HEAD and the
|
|
137
|
+
* objects and refs from its common directory.
|
|
138
|
+
*/
|
|
139
|
+
function gitDirectory(directory, fs, path) {
|
|
140
|
+
try {
|
|
141
|
+
const marker = path.join(directory, '.git');
|
|
142
|
+
const info = fs.statSync(marker);
|
|
143
|
+
let gitDir = marker;
|
|
144
|
+
if (info.isFile()) {
|
|
145
|
+
if (info.size > 4096) return null;
|
|
146
|
+
const pointer = /^gitdir: ([^\r\n\0]+)(?:\r?\n)?$/.exec(fs.readFileSync(marker, 'utf8'));
|
|
147
|
+
if (!pointer) return null;
|
|
148
|
+
gitDir = path.resolve(directory, pointer[1]);
|
|
149
|
+
if (!fs.statSync(gitDir).isDirectory()) return null;
|
|
150
|
+
} else if (!info.isDirectory()) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
const head = path.join(gitDir, 'HEAD');
|
|
154
|
+
const headInfo = fs.statSync(head);
|
|
155
|
+
if (!headInfo.isFile() || headInfo.size > 4096) return null;
|
|
156
|
+
const headText = fs.readFileSync(head, 'utf8');
|
|
157
|
+
if (!/^(?:ref:[ \t]*refs\/[^\r\n]+|[0-9a-f]{40}(?:[0-9a-f]{24})?)(?:\r?\n)?$/.test(headText)) return null;
|
|
158
|
+
const common = path.join(gitDir, 'commondir');
|
|
159
|
+
const commonInfo = fs.statSync(common, { throwIfNoEntry: false });
|
|
160
|
+
let storage = gitDir;
|
|
161
|
+
if (commonInfo) {
|
|
162
|
+
if (!commonInfo.isFile() || commonInfo.size > 4096) return null;
|
|
163
|
+
const target = fs.readFileSync(common, 'utf8').replace(/[\r\n]+$/, '');
|
|
164
|
+
if (!target) return null;
|
|
165
|
+
storage = path.resolve(gitDir, target);
|
|
166
|
+
}
|
|
167
|
+
if (!fs.statSync(path.join(storage, 'objects')).isDirectory() ||
|
|
168
|
+
!fs.statSync(path.join(storage, 'refs')).isDirectory()) return null;
|
|
169
|
+
return gitDir;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
135
175
|
/**
|
|
136
176
|
* The layered rules for one walk. The caller enters a directory before it
|
|
137
177
|
* reads it and leaves it after, so the layers follow the depth-first stack.
|
|
138
|
-
* deps: fs (promises), path, extraFiles (
|
|
178
|
+
* deps: fs (promises), syncFs (marker validation), path, extraFiles (host excludes).
|
|
139
179
|
*/
|
|
140
180
|
function ignCreate(deps) {
|
|
141
181
|
const fs = deps.fs;
|
|
@@ -145,6 +185,10 @@ function ignCreate(deps) {
|
|
|
145
185
|
let ancestorsInRepo = false;
|
|
146
186
|
const posix = value => path.sep === '/' ? value : value.split(path.sep).join('/');
|
|
147
187
|
const lstat = async file => { try { return await fs.lstat(file); } catch (error) { return null; } };
|
|
188
|
+
const findGitDirectory = async directory => {
|
|
189
|
+
if (!await lstat(path.join(directory, '.git'))) return null;
|
|
190
|
+
return gitDirectory(directory, deps.syncFs, path);
|
|
191
|
+
};
|
|
148
192
|
const load = async file => {
|
|
149
193
|
const info = await lstat(file);
|
|
150
194
|
if (!info || !info.isFile() || info.size > IGN_MAX_BYTES * 4) return [];
|
|
@@ -165,8 +209,8 @@ function ignCreate(deps) {
|
|
|
165
209
|
let directory = root;
|
|
166
210
|
let repo = null;
|
|
167
211
|
for (;;) {
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
212
|
+
const gitDir = await findGitDirectory(directory);
|
|
213
|
+
if (gitDir) { repo = { directory, gitDir }; break; }
|
|
170
214
|
const parent = path.dirname(directory);
|
|
171
215
|
if (parent === directory) break;
|
|
172
216
|
directory = parent;
|
|
@@ -182,7 +226,7 @@ function ignCreate(deps) {
|
|
|
182
226
|
const rules = [];
|
|
183
227
|
if (index === 0) {
|
|
184
228
|
for (const file of deps.extraFiles || []) rules.push(...await load(file));
|
|
185
|
-
if (repo.
|
|
229
|
+
if (repo.gitDir === path.join(directory, '.git')) rules.push(...await load(path.join(repo.gitDir, 'info', 'exclude')));
|
|
186
230
|
}
|
|
187
231
|
rules.push(...await loadDirectory(directory, true));
|
|
188
232
|
push(directory, rules);
|
|
@@ -193,11 +237,11 @@ function ignCreate(deps) {
|
|
|
193
237
|
let inRepo = parentInRepo;
|
|
194
238
|
const rules = [];
|
|
195
239
|
if (!parentInRepo) {
|
|
196
|
-
const
|
|
197
|
-
if (
|
|
240
|
+
const gitDir = await findGitDirectory(directory);
|
|
241
|
+
if (gitDir) {
|
|
198
242
|
inRepo = true;
|
|
199
243
|
for (const file of deps.extraFiles || []) rules.push(...await load(file));
|
|
200
|
-
if (
|
|
244
|
+
if (gitDir === path.join(directory, '.git')) rules.push(...await load(path.join(gitDir, 'info', 'exclude')));
|
|
201
245
|
}
|
|
202
246
|
}
|
|
203
247
|
rules.push(...await loadDirectory(directory, inRepo));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class SandboxLimitError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
readonly kind: 'receive-frame' | 'receive-buffer' | 'exec-output' | 'read-file',
|
|
4
|
+
readonly limit: number,
|
|
5
|
+
readonly actual: number,
|
|
6
|
+
) {
|
|
7
|
+
super(`Sandbox ${kind} exceeded the ${limit} byte limit (got ${actual} bytes)`)
|
|
8
|
+
this.name = 'SandboxLimitError'
|
|
9
|
+
}
|
|
10
|
+
}
|