@r_masseater/masseater-utils 0.15.0 → 0.17.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 +1 -34
- package/dist/cache-B2pb5ulh.mjs +20 -0
- package/dist/cache-B2pb5ulh.mjs.map +1 -0
- package/dist/cache-B_fAwTnH.d.mts +10 -0
- package/dist/cache.d.mts +2 -0
- package/dist/cache.mjs +1 -0
- package/dist/desktop-shell/media-notes.d.mts +1 -9
- package/dist/desktop-shell/media-notes.mjs +1 -1
- package/dist/desktop-shell/release-cli.mjs +1 -1
- package/dist/{socket-port-Cq7YKLFS.mjs → endpoint-BZzLgZs1.mjs} +3 -6
- package/dist/endpoint-BZzLgZs1.mjs.map +1 -0
- package/dist/github-workflow.d.mts +1 -4
- package/dist/github-workflow.mjs +2 -5
- package/dist/github-workflow.mjs.map +1 -1
- package/dist/{headers-CtvGSXbz.mjs → headers-DSqz93yF.mjs} +10 -6
- package/dist/headers-DSqz93yF.mjs.map +1 -0
- package/dist/{headers-NUwRihYD.d.mts → headers-DVWS82Vk.d.mts} +5 -22
- package/dist/{web-analytics-Cvs9PDoh.d.mts → index-B995c2b6.d.mts} +1 -0
- package/dist/{index-8ZrDzBaY.d.mts → index-MqLQZR1B.d.mts} +1 -0
- package/dist/kestrion/npm.d.mts +0 -1
- package/dist/kestrion/npm.mjs +1 -6
- package/dist/kestrion/npm.mjs.map +1 -1
- package/dist/local-server/node.mjs +5 -2
- package/dist/local-server/node.mjs.map +1 -1
- package/dist/local-server.d.mts +1 -5
- package/dist/local-server.mjs +2 -2
- package/dist/match-groups-MH1j-WE-.mjs +7 -0
- package/dist/match-groups-MH1j-WE-.mjs.map +1 -0
- package/dist/model-server.mjs.map +1 -1
- package/dist/plugin-kit.d.mts +3 -17
- package/dist/plugin-kit.mjs +35 -52
- package/dist/plugin-kit.mjs.map +1 -1
- package/dist/{process-l69KvwcT.mjs → process-DTCkAoL_.mjs} +18 -2
- package/dist/process-DTCkAoL_.mjs.map +1 -0
- package/dist/{process-BHJEIAWo.d.mts → process-z7u_XWgI.d.mts} +11 -1
- package/dist/process.d.mts +2 -2
- package/dist/process.mjs +1 -1
- package/dist/security-headers/http.d.mts +2 -4
- package/dist/security-headers/http.mjs +2 -4
- package/dist/security-headers/http.mjs.map +1 -1
- package/dist/security-headers/response.mjs +1 -1
- package/dist/security-headers/static.d.mts +1 -1
- package/dist/security-headers/static.mjs +1 -1
- package/dist/security-headers/vite.d.mts +1 -1
- package/dist/security-headers/vite.mjs +1 -1
- package/dist/security-headers.d.mts +3 -4
- package/dist/security-headers.mjs +2 -2
- package/dist/{static-page-headers-C40Ty9PI.mjs → static-page-headers-C7w-AabA.mjs} +3 -2
- package/dist/static-page-headers-C7w-AabA.mjs.map +1 -0
- package/dist/text.d.mts +4 -0
- package/dist/text.mjs +8 -0
- package/dist/text.mjs.map +1 -0
- package/dist/ui/portfolio.d.mts +0 -1
- package/dist/ui/portfolio.mjs +1 -1
- package/dist/ui/web-analytics.d.mts +1 -2
- package/dist/usage-meter/report.d.mts +18 -2
- package/dist/usage-meter/report.mjs +2 -2
- package/dist/usage-meter.d.mts +1 -2
- package/dist/usage-meter.mjs +1 -3
- package/dist/workers-tracing/effect.d.mts +1 -2
- package/dist/workers-tracing/effect.mjs +1 -1
- package/dist/workers-tracing/effect.mjs.map +1 -1
- package/package.json +3 -1
- package/skills/add-scroll-chip-row/SKILL.md +1 -1
- package/skills/assert-exported-telemetry/SKILL.md +1 -1
- package/skills/build-tauri-app/SKILL.md +1 -1
- package/skills/find-cache-folder/SKILL.md +1 -1
- package/skills/import-custom-format/SKILL.md +1 -1
- package/skills/name-stack-resources/SKILL.md +1 -1
- package/skills/read-hook-input/SKILL.md +1 -1
- package/skills/read-node-ecosystem/SKILL.md +1 -1
- package/skills/run-effect-main/SKILL.md +1 -1
- package/skills/share-types-with-rust/SKILL.md +1 -1
- package/skills/trace-workers/SKILL.md +1 -1
- package/skills/use-model-server/SKILL.md +1 -1
- package/skills/write-actions-steps/SKILL.md +1 -1
- package/dist/headers-CtvGSXbz.mjs.map +0 -1
- package/dist/index-Cz3K0tg_.d.mts +0 -3
- package/dist/process-l69KvwcT.mjs.map +0 -1
- package/dist/socket-port-Cq7YKLFS.mjs.map +0 -1
- package/dist/static-page-headers-C40Ty9PI.mjs.map +0 -1
- package/dist/usage-tally-BBhBouif.d.mts +0 -19
package/dist/plugin-kit.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-kit.mjs","names":["taggedError","taggedError","Arr","RecordSchema","StringSchema","ONE","encodeJson","Str","Arr","Rec","ONE","Str","Arr","Num","ONE","Arr","Num","Str","Arr","Arr","Str","Str","Arr","Rec","Arr","Str","Rec","Arr"],"sources":["../src/features/run-main/model/hook-io.ts","../src/features/run-main/model/run-hook.ts","../src/shared/lib/cache.ts","../src/shared/lib/record.ts","../src/features/fit-history/model/calls.ts","../src/shared/lib/tokens.ts","../src/features/fit-history/model/fitting.ts","../src/features/fit-history/model/state.ts","../src/shared/lib/owner-command.ts","../src/shared/lib/session-switch.ts","../src/shared/lib/installed-plugins.ts","../src/shared/lib/jev-backend.ts"],"sourcesContent":["import { Effect, Runtime, Schema, Stdio, Stream } from \"effect\";\n\nconst EXIT_BLOCKING = 2;\n\nconst taggedError = Schema.TaggedError;\n\n/** @internal */\nexport class HookBlocked extends taggedError<HookBlocked, { readonly brand: unique symbol }>()(\n \"HookBlocked\",\n { reason: Schema.String },\n) {\n public override readonly [Runtime.errorExitCode] = EXIT_BLOCKING;\n public override readonly [Runtime.errorReported] = false;\n}\n\n/** @internal */\nexport const isHookBlocked = Schema.is(HookBlocked);\n\n/** @internal */\nexport const blockHook = (reason: string): Effect.Effect<never, HookBlocked> =>\n Effect.fail(HookBlocked.make({ reason }));\n\n/** @internal */\nexport const readStdin: Effect.Effect<string, never, Stdio.Stdio> = Effect.gen(\n function* readStdin() {\n const stdio = yield* Stdio.Stdio;\n return yield* stdio.stdin.pipe(Stream.decodeText, Stream.mkString, Effect.orDie);\n },\n);\n\n/** @internal */\nexport const readHookInput = <Codec extends Schema.Top>(\n schema: Codec,\n): Effect.Effect<Codec[\"Type\"], Schema.SchemaError, Stdio.Stdio | Codec[\"DecodingServices\"]> =>\n Effect.gen(function* read() {\n const text = yield* readStdin;\n const json = Schema.fromJsonString(schema);\n return yield* Schema.decodeEffect(json)(text);\n });\n\n/** @internal */\nexport const writeStdout = (text: string): Effect.Effect<void, never, Stdio.Stdio> =>\n Effect.gen(function* toStdout() {\n const stdio = yield* Stdio.Stdio;\n yield* Stream.make(text).pipe(Stream.run(stdio.stdout()), Effect.orDie);\n });\n\n/** @internal */\nexport const writeStderr = (text: string): Effect.Effect<void, never, Stdio.Stdio> =>\n Effect.gen(function* toStderr() {\n const stdio = yield* Stdio.Stdio;\n yield* Stream.make(text).pipe(Stream.run(stdio.stderr()), Effect.orDie);\n });\n\n/** @internal */\nexport const writeHookOutput =\n <Codec extends Schema.Top>(schema: Codec) =>\n (value: Codec[\"Type\"]): Effect.Effect<void, never, Stdio.Stdio | Codec[\"EncodingServices\"]> =>\n Schema.encodeEffect(Schema.fromJsonString(schema))(value).pipe(\n Effect.orDie,\n Effect.flatMap(writeStdout),\n );\n","import { Cause, Effect, Layer, Option } from \"effect\";\nimport type { Stdio } from \"effect\";\n\nimport { isHookBlocked, writeStderr } from \"./hook-io.ts\";\nimport type { HookBlocked } from \"./hook-io.ts\";\nimport { runMainWith } from \"./run-main.ts\";\nimport type { Platform, Run } from \"./run-main.ts\";\n\nconst blockedIn = <Failure>(cause: Cause.Cause<Failure>): Option.Option<HookBlocked> =>\n Cause.findErrorOption(cause).pipe(\n Option.filter((error): error is Failure & HookBlocked => isHookBlocked(error)),\n );\n\nconst reportBlocked = <Failure>(\n cause: Cause.Cause<Failure>,\n): Effect.Effect<void, never, Stdio.Stdio> =>\n cause.pipe(\n blockedIn,\n Option.match({\n onNone: () => Effect.void,\n onSome: (blocked) => writeStderr(`${blocked.reason}\\n`),\n }),\n );\n\n/** @internal */\nexport const runHookWith =\n <Provided, LayerFailure>({\n serviceName,\n services,\n }: Readonly<{\n serviceName: string;\n services: Layer.Layer<Provided, LayerFailure, Platform>;\n }>): Run<Provided> =>\n (program) => {\n runMainWith({ serviceName, services })(program.pipe(Effect.tapCause(reportBlocked)));\n };\n\n/** @internal */\nexport const runHook = (serviceName: string): Run<never> =>\n runHookWith({ serviceName, services: Layer.empty });\n","import { Array as Arr, Config, Effect, Option, Schema, pipe } from \"effect\";\n\nconst taggedError = Schema.TaggedError;\n\nexport class CacheRootError extends taggedError<\n CacheRootError,\n { readonly brand: unique symbol }\n>()(\"CacheRootError\", { message: Schema.String }) {}\n\nconst SEPARATOR = \"/\";\nexport const CACHE_DIRECTORY_NAME = \".cache\";\n\nconst variable = (name: string): Effect.Effect<Option.Option<string>> =>\n Config.option(Config.NonEmptyString(name)).pipe(Effect.orElseSucceed(Option.none));\n\nconst baseDirectory: Effect.Effect<Option.Option<string>> = Effect.gen(function* baseDirectory() {\n const cacheHome = yield* variable(\"XDG_CACHE_HOME\");\n const home = yield* variable(\"HOME\");\n const profile = yield* variable(\"USERPROFILE\");\n return pipe(\n cacheHome,\n Option.orElse(() =>\n pipe(\n Option.orElse(home, () => profile),\n Option.map((directory) => `${directory}${SEPARATOR}${CACHE_DIRECTORY_NAME}`),\n ),\n ),\n );\n});\n\nexport const cacheRootEffect = (\n segments: readonly string[],\n): Effect.Effect<string, CacheRootError> =>\n baseDirectory.pipe(\n Effect.flatMap(\n Option.match({\n onNone: () => Effect.fail(CacheRootError.make({ message: \"set XDG_CACHE_HOME or HOME\" })),\n onSome: (base) => Effect.succeed(pipe([base, ...segments], Arr.join(SEPARATOR))),\n }),\n ),\n );\n\nexport const cacheRootOf = (segments: readonly string[]): Promise<string> =>\n Effect.runPromise(cacheRootEffect(segments));\n","import type { Option } from \"effect/Option\";\nimport {\n Record as RecordSchema,\n String as StringSchema,\n Unknown,\n decodeOption,\n fromJsonString,\n is,\n} from \"effect/Schema\";\n\nexport const isRecord = is(RecordSchema(StringSchema, Unknown));\n\nexport const parseJson = (text: string): Option<unknown> =>\n decodeOption(fromJsonString(Unknown))(text);\n","import { Array as Arr, Option, Record as Rec, Schema, String as Str, pipe } from \"effect\";\n\nimport type { HistoryEntry, HistoryToolCall, Message, ToolCall } from \"./types.ts\";\n\nconst FIRST = 0;\nconst ONE = 1;\nconst ELLIPSIS = \"…\";\nconst VALUE_CHARS = 200;\nconst COMPACT_INPUT_CHARS = 60;\nconst SPACES = /\\s+/gu;\nconst encodeJson = Schema.encodeOption(Schema.fromJsonString(Schema.Unknown));\n\nexport const jsonOf = (value: unknown): Option.Option<string> => encodeJson(value);\n\nexport const truncate = (text: string, limit: number): string => {\n if (Str.length(text) <= limit) {\n return text;\n }\n return `${Str.slice(FIRST, Math.max(FIRST, limit - ONE))(text)}${ELLIPSIS}`;\n};\n\nexport const isPinned = (index: number, total: number, preserveRecentMessages: number): boolean =>\n index === FIRST || index >= total - preserveRecentMessages;\n\ninterface Found {\n readonly index: number;\n readonly chars: number;\n readonly isError: boolean;\n}\n\nconst resultsOf = (messages: readonly Message[]): ReadonlyMap<string, Found> =>\n new Map(\n pipe(\n messages,\n Arr.flatMap((message, index) =>\n pipe(\n message.toolResults,\n Arr.map(\n (result) =>\n [\n result.tool_use_id,\n { index, chars: Str.length(result.text), isError: result.isError },\n ] as const,\n ),\n ),\n ),\n ),\n );\n\nexport const collectToolCalls = (\n messages: readonly Message[],\n preserveRecentMessages: number,\n): readonly ToolCall[] => {\n const results = resultsOf(messages);\n const pinned = (index: number): boolean =>\n isPinned(index, messages.length, preserveRecentMessages);\n return pipe(\n messages,\n Arr.flatMap((message, callIndex) =>\n pipe(\n message.toolUses,\n Arr.flatMap((tool) =>\n pipe(\n Option.fromUndefinedOr(results.get(tool.tool_use_id)),\n Option.map((found) => ({ tool, callIndex, found })),\n Option.toArray,\n ),\n ),\n ),\n ),\n Arr.map(({ tool, callIndex, found }, index) => ({\n id: `t${String(index + ONE)}`,\n tool_use_id: tool.tool_use_id,\n tool: tool.tool,\n input: tool.input,\n callIndex,\n resultIndex: found.index,\n resultChars: found.chars,\n isError: found.isError,\n pinned: pinned(callIndex) || pinned(found.index),\n })),\n );\n};\n\nexport const inputText = (input: Readonly<Record<string, unknown>>, limit: number): string =>\n truncate(\n Option.getOrElse(jsonOf(input), () => \"[unserializable input]\"),\n limit,\n );\n\nconst outcomeOf = (call: ToolCall): string => {\n if (call.isError) {\n return \"error\";\n }\n return \"ok\";\n};\n\nconst resultNote = (call: ToolCall): string =>\n `${outcomeOf(call)}, ${String(call.resultChars)} chars (omitted)`;\n\nconst valueText = ([key, value]: readonly [string, unknown]): string => {\n const text = pipe(\n Option.liftPredicate(value, (raw): raw is string => typeof raw === \"string\"),\n Option.getOrElse(() => inputText({ [key]: value }, VALUE_CHARS)),\n );\n return `${key}=${Str.replaceAll(SPACES, \" \")(text)}`;\n};\n\nexport const compactCall = (call: ToolCall): string => {\n const input = pipe(Rec.toEntries(call.input), Arr.map(valueText), Arr.join(\" \"));\n return `${call.id} ${call.tool} ${truncate(input, COMPACT_INPUT_CHARS)} → ${outcomeOf(call)} ${String(call.resultChars)}ch`;\n};\n\nexport const callsByMessage = (\n calls: readonly ToolCall[],\n): ReadonlyMap<number, readonly ToolCall[]> =>\n new Map(\n pipe(\n calls,\n Arr.groupBy((call) => String(call.callIndex)),\n Rec.toEntries,\n Arr.map(([index, own]) => [Number(index), own] as const),\n ),\n );\n\nconst historyCallOf =\n (inputChars: number) =>\n (call: ToolCall): HistoryToolCall => ({\n id: call.id,\n tool: call.tool,\n input: inputText(call.input, inputChars),\n result: resultNote(call),\n });\n\nexport const historyEntries = (\n messages: readonly Message[],\n calls: readonly ToolCall[],\n inputChars: number,\n): readonly HistoryEntry[] => {\n const byMessage = callsByMessage(calls);\n return pipe(\n messages,\n Arr.flatMap((message, index): readonly HistoryEntry[] => {\n const own = Option.getOrElse(Option.fromUndefinedOr(byMessage.get(index)), () => []);\n const toolCalls = pipe(own, Arr.map(historyCallOf(inputChars)));\n const entry = { index, role: message.role, text: message.text };\n if (Arr.isReadonlyArrayNonEmpty(toolCalls)) {\n return [{ ...entry, tool_calls: toolCalls }];\n }\n if (Str.isEmpty(Str.trim(message.text))) {\n return [];\n }\n return [entry];\n }),\n );\n};\n","import { Array as Arr, Number as Num, Option, String as Str, pipe } from \"effect\";\n\nconst PIECES = /(?<alpha>[A-Za-z]+)|(?<digits>\\d+)|(?<other>[^\\sA-Za-z\\d])/gu;\nconst DIGITS_PER_TOKEN = 2;\nconst LETTERS_PER_TOKEN = 6;\nconst SYMBOL_TOKENS = 0.9;\nconst ONE = 1;\n\nconst groupOf = (match: RegExpMatchArray, key: string): Option.Option<string> =>\n pipe(\n Option.fromUndefinedOr(match.groups),\n Option.flatMap((groups) => Option.fromUndefinedOr(groups[key])),\n );\n\nconst pieceTokens = (match: RegExpMatchArray): number =>\n pipe(\n groupOf(match, \"digits\"),\n Option.map((digits) => Str.length(digits) / DIGITS_PER_TOKEN),\n Option.orElse(() =>\n Option.map(\n groupOf(match, \"alpha\"),\n (alpha) => ONE + Math.floor((Str.length(alpha) - ONE) / LETTERS_PER_TOKEN),\n ),\n ),\n Option.getOrElse(() => SYMBOL_TOKENS),\n );\n\nconst matchesOf = (pattern: RegExp, text: string): readonly RegExpMatchArray[] =>\n Arr.fromIterable(Str.matchAll(pattern)(text));\n\nexport const estimateTokens = (text: string): number => {\n const pieces = pipe(matchesOf(PIECES, text), Arr.map(pieceTokens));\n return Math.ceil(Num.sumAll(pieces));\n};\n","import { Array as Arr, Number as Num, Option, pipe } from \"effect\";\n\nimport { estimateTokens } from \"#/shared/lib/tokens.ts\";\n\nimport { isPinned, jsonOf } from \"./calls.ts\";\nimport type {\n CompactionState,\n FitOptions,\n FittedState,\n HistoryEntry,\n Message,\n ToolCall,\n} from \"./types.ts\";\n\nconst ONE = 1;\nconst NONE = 0;\n\nexport const entryTokens = (entry: HistoryEntry): number =>\n jsonOf(entry).pipe(\n Option.getOrElse(() => \"\"),\n estimateTokens,\n ) + ONE;\n\nexport interface Fitting {\n readonly history: readonly Option.Option<HistoryEntry>[];\n readonly perEntry: readonly number[];\n readonly tokens: number;\n}\n\nexport interface Plan {\n readonly messages: readonly Message[];\n readonly calls: readonly ToolCall[];\n readonly options: FitOptions;\n readonly stateOf: (history: readonly HistoryEntry[]) => CompactionState;\n readonly baseTokens: number;\n readonly byMessage: ReadonlyMap<number, readonly ToolCall[]>;\n}\n\nexport type Change = (entry: HistoryEntry) => Option.Option<Option.Option<HistoryEntry>>;\n\nexport const fittingOf = (plan: Plan, history: readonly HistoryEntry[]): Fitting => {\n const perEntry = pipe(history, Arr.map(entryTokens));\n return {\n history: pipe(history, Arr.map(Option.some)),\n perEntry,\n tokens: plan.baseTokens + Num.sumAll(perEntry),\n };\n};\n\nexport const kept = (fitting: Fitting): readonly HistoryEntry[] => Arr.getSomes(fitting.history);\n\nexport const fits = (plan: Plan, fitting: Fitting): boolean =>\n fitting.tokens <= plan.options.maxStateTokens;\n\nexport const fitted = (plan: Plan, fitting: Fitting, stage: string): FittedState => ({\n state: plan.stateOf(kept(fitting)),\n tokens: fitting.tokens,\n stage,\n});\n\nexport const pinnedEntry = (plan: Plan, entry: HistoryEntry): boolean =>\n isPinned(entry.index, plan.messages.length, plan.options.preserveRecentMessages);\n\nconst orderOf = (plan: Plan, fitting: Fitting): readonly number[] => {\n const present = pipe(\n fitting.history,\n Arr.flatMap((entry, index) =>\n pipe(\n entry,\n Option.map((value) => [index, pinnedEntry(plan, value)] as const),\n Option.toArray,\n ),\n ),\n );\n const loose = pipe(\n present,\n Arr.filter(([, pinned]) => !pinned),\n );\n const pinned = pipe(\n present,\n Arr.filter(([, isPinnedEntry]) => isPinnedEntry),\n );\n return pipe(\n [...loose, ...pinned],\n Arr.map(([index]) => index),\n );\n};\n\ninterface Step {\n readonly index: number;\n readonly entry: Option.Option<HistoryEntry>;\n readonly tokens: number;\n}\n\nconst stepOf =\n (fitting: Fitting, change: Change) =>\n (index: number): Option.Option<Step> =>\n pipe(\n Option.flatten(Option.fromUndefinedOr(fitting.history[index])),\n Option.flatMap(change),\n Option.map((entry) => ({\n index,\n entry,\n tokens: Option.match(entry, { onNone: () => NONE, onSome: entryTokens }),\n })),\n );\n\nconst applied = (fitting: Fitting, steps: readonly Step[]): Fitting => {\n const byIndex = new Map(\n pipe(\n steps,\n Arr.map((step) => [step.index, step] as const),\n ),\n );\n const pick = <Value>(index: number, value: Value, of: (step: Step) => Value): Value =>\n Option.match(Option.fromUndefinedOr(byIndex.get(index)), { onNone: () => value, onSome: of });\n const history = pipe(\n fitting.history,\n Arr.map((entry, index) => pick(index, entry, (step) => step.entry)),\n );\n const perEntry = pipe(\n fitting.perEntry,\n Arr.map((tokens, index) => pick(index, tokens, (step) => step.tokens)),\n );\n const delta = Num.sumAll(\n pipe(\n steps,\n Arr.map(\n (step) => step.tokens - Option.getOrElse(Arr.get(fitting.perEntry, step.index), () => NONE),\n ),\n ),\n );\n return { history, perEntry, tokens: fitting.tokens + delta };\n};\n\nexport const staged = (\n plan: Plan,\n fitting: Fitting,\n change: Change,\n): readonly [Fitting, boolean] => {\n const steps = pipe(\n orderOf(plan, fitting),\n Arr.flatMap((index) => Option.toArray(stepOf(fitting, change)(index))),\n );\n const totals = pipe(\n steps,\n Arr.scan(\n fitting.tokens,\n (tokens, step) =>\n tokens + step.tokens - Option.getOrElse(Arr.get(fitting.perEntry, step.index), () => NONE),\n ),\n Arr.drop(ONE),\n );\n return Option.match(\n Arr.findFirstIndex(totals, (tokens) => tokens <= plan.options.maxStateTokens),\n {\n onNone: () => [applied(fitting, steps), false] as const,\n onSome: (at) => [applied(fitting, Arr.take(steps, at + ONE)), true] as const,\n },\n );\n};\n","import {\n Array as Arr,\n Effect,\n Option,\n Predicate,\n Result,\n Schema,\n String as Str,\n pipe,\n} from \"effect\";\n\nimport { estimateTokens } from \"#/shared/lib/tokens.ts\";\n\nimport { callsByMessage, compactCall, historyEntries, jsonOf, truncate } from \"./calls.ts\";\nimport { fits, fitted, fittingOf, kept, pinnedEntry, staged } from \"./fitting.ts\";\nimport type { Change, Fitting, Plan } from \"./fitting.ts\";\nimport type {\n CompactionState,\n FitOptions,\n FittedState,\n HistoryEntry,\n HistoryToolCall,\n Message,\n ToolCall,\n} from \"./types.ts\";\n\nexport const STATE_CONTEXT =\n \"A coding assistant conversation is being compacted to free context. `history` is the whole conversation so far, oldest first; tool outputs are replaced by a short `result` note and long texts may be abridged. Each question asks whether one tool call, or the full output of that call, still needs to stay in the history verbatim. Whatever is not kept is deleted permanently, but the assistant can always re-run a tool or re-read a file.\";\n\nconst taggedError = Schema.TaggedError;\n\nexport class HistoryTooLarge extends taggedError<\n HistoryTooLarge,\n { readonly brand: unique symbol }\n>()(\"HistoryTooLarge\", { reason: Schema.String }) {}\n\nconst FULL_INPUT_CHARS = 1000;\nconst SHORT_INPUT_CHARS = 200;\nconst SHORTEST_INPUT_CHARS = 60;\nconst SHORTER_INPUT_CHARS = [SHORT_INPUT_CHARS, SHORTEST_INPUT_CHARS] as const;\nconst TEXT_HEAD = 400;\nconst TEXT_TAIL = 150;\nconst ABRIDGE_MARGIN = 40;\nconst RECENT_GOALS = 3;\nconst GOAL_CHARS = 500;\nconst ONE = 1;\n\nconst abridge = (text: string): string => {\n const omitted = Str.length(text) - TEXT_HEAD - TEXT_TAIL;\n return `${Str.takeLeft(TEXT_HEAD)(text)}\\n[… ${String(omitted)} chars omitted …]\\n${Str.takeRight(TEXT_TAIL)(text)}`;\n};\n\nexport const goalFromMessages = (messages: readonly Message[]): string =>\n pipe(\n messages,\n Arr.filter(\n (message) =>\n message.role === \"user\" &&\n Str.isNonEmpty(Str.trim(message.text)) &&\n Arr.isReadonlyArrayEmpty(message.toolResults),\n ),\n Arr.takeRight(RECENT_GOALS),\n Arr.map((message) => truncate(message.text, GOAL_CHARS)),\n Arr.join(\"\\n\"),\n );\n\nconst abridgeText: Change = (entry: HistoryEntry) =>\n Option.liftPredicate(\n Option.some({ ...entry, text: abridge(entry.text) }),\n () => Str.length(entry.text) > TEXT_HEAD + TEXT_TAIL + ABRIDGE_MARGIN,\n );\n\nconst collapseText =\n (plan: Plan): Change =>\n (entry: HistoryEntry) => {\n const original = pipe(\n Arr.get(plan.messages, entry.index),\n Option.map((message) => Str.length(message.text)),\n Option.getOrElse(() => Str.length(entry.text)),\n );\n return Option.liftPredicate(\n Option.some({ ...entry, text: `[… ${String(original)} chars omitted …]` }),\n () => !pinnedEntry(plan, entry) && Str.isNonEmpty(entry.text),\n );\n };\n\nconst compactCalls =\n (plan: Plan): Change =>\n (entry: HistoryEntry) =>\n pipe(\n Option.fromUndefinedOr(plan.byMessage.get(entry.index)),\n Option.filter(() => !pinnedEntry(plan, entry)),\n Option.map((own) => Option.some({ ...entry, tool_calls: pipe(own, Arr.map(compactCall)) })),\n );\n\nconst leaveOut =\n (plan: Plan): Change =>\n (entry: HistoryEntry) =>\n Option.liftPredicate(\n Option.none<HistoryEntry>(),\n () => !pinnedEntry(plan, entry) && Predicate.isUndefined(entry.tool_calls),\n );\n\nconst callsOf = (entry: HistoryEntry): readonly (HistoryToolCall | string)[] =>\n Option.getOrElse(Option.fromUndefinedOr(entry.tool_calls), () => []);\n\nconst stringCalls = (entry: HistoryEntry): readonly string[] =>\n pipe(callsOf(entry), Arr.filter(Predicate.isString));\n\nconst foldable = (plan: Plan, entry: HistoryEntry): boolean =>\n !pinnedEntry(plan, entry) &&\n Str.isEmpty(entry.text) &&\n pipe(Arr.head(callsOf(entry)), Option.exists(Predicate.isString));\n\nconst mergedRun = (group: Arr.NonEmptyReadonlyArray<HistoryEntry>): HistoryEntry => {\n const first = Arr.headNonEmpty(group);\n if (group.length === ONE) {\n return first;\n }\n return { ...first, tool_calls: pipe(group, Arr.flatMap(stringCalls)) };\n};\n\nconst mergeRuns = (plan: Plan, history: readonly HistoryEntry[]): readonly HistoryEntry[] => {\n if (!Arr.isReadonlyArrayNonEmpty(history)) {\n return [];\n }\n return pipe(\n Arr.groupWith(\n history,\n (left, right) => foldable(plan, left) && foldable(plan, right) && left.role === right.role,\n ),\n Arr.map(mergedRun),\n );\n};\n\ntype Staged = readonly [Fitting, boolean];\n\ntype Stage = readonly [string, (fitting: Fitting) => Staged];\n\nconst rebuilt = (plan: Plan, inputChars: number) => (): readonly [Fitting, boolean] => {\n const fitting = fittingOf(plan, historyEntries(plan.messages, plan.calls, inputChars));\n return [fitting, fits(plan, fitting)];\n};\n\nconst stagesOf = (plan: Plan): readonly Stage[] => [\n ...pipe(\n SHORTER_INPUT_CHARS,\n Arr.map((limit): Stage => [`inputs<=${String(limit)}`, rebuilt(plan, limit)]),\n ),\n [\"texts abridged\", (fitting): Staged => staged(plan, fitting, abridgeText)],\n [\"old messages collapsed\", (fitting): Staged => staged(plan, fitting, collapseText(plan))],\n [\"old calls compacted\", (fitting): Staged => staged(plan, fitting, compactCalls(plan))],\n [\"old messages left out\", (fitting): Staged => staged(plan, fitting, leaveOut(plan))],\n [\n \"old calls merged\",\n (fitting): Staged => {\n const merged = fittingOf(plan, mergeRuns(plan, kept(fitting)));\n return [merged, fits(plan, merged)];\n },\n ],\n];\n\nconst throughStages = (\n plan: Plan,\n fitting: Fitting,\n stages: readonly Stage[],\n): Result.Result<FittedState, Fitting> =>\n Option.match(Arr.head(stages), {\n onNone: () => Result.fail(fitting),\n onSome: ([name, run]) => {\n const [next, done] = run(fitting);\n if (done) {\n return Result.succeed(fitted(plan, next, name));\n }\n return throughStages(plan, next, Arr.drop(stages, ONE));\n },\n });\n\nconst jsonText = (value: unknown): string => Option.getOrElse(jsonOf(value), () => \"\");\n\nconst planOf = (\n messages: readonly Message[],\n calls: readonly ToolCall[],\n options: FitOptions,\n): Plan => {\n const goal = pipe(\n Option.liftPredicate(options.goal, Str.isNonEmpty),\n Option.getOrElse(() => goalFromMessages(messages)),\n );\n const stateOf = (history: readonly HistoryEntry[]): CompactionState => ({\n context: STATE_CONTEXT,\n goal,\n history,\n });\n return {\n messages,\n calls,\n options,\n stateOf,\n baseTokens: estimateTokens(jsonText(stateOf([]))),\n byMessage: callsByMessage(calls),\n };\n};\n\nexport const fitState = (\n messages: readonly Message[],\n calls: readonly ToolCall[],\n options: FitOptions,\n): Effect.Effect<FittedState, HistoryTooLarge> => {\n const plan = planOf(messages, calls, options);\n const full = fittingOf(plan, historyEntries(messages, calls, FULL_INPUT_CHARS));\n if (fits(plan, full)) {\n return Effect.succeed(fitted(plan, full, \"full\"));\n }\n return Result.match(throughStages(plan, full, stagesOf(plan)), {\n onSuccess: Effect.succeed,\n onFailure: (last) =>\n Effect.fail(\n HistoryTooLarge.make({\n reason: `history too large for Jev (~${String(last.tokens)} tokens after truncation, limit ${String(options.maxStateTokens)})`,\n }),\n ),\n });\n};\n","import { Array as Arr, Option, String as Str, pipe } from \"effect\";\n\nconst OWNER_BODIES: readonly RegExp[] = [\n /<message\\b[^>]*\\bfrom=\"human\"[^>]*\\btrust=\"principal\"[^>]*>(?<body>[\\s\\S]*?)<\\/message>/gu,\n /<cited\\b[^>]*\\bauthor=\"user\"[^>]*>(?<body>[\\s\\S]*?)<\\/cited>/gu,\n];\n\nconst bodiesOf = (prompt: string): readonly string[] =>\n pipe(\n OWNER_BODIES,\n Arr.flatMap((pattern) => Arr.fromIterable(pipe(prompt, Str.matchAll(pattern)))),\n Arr.map((found) =>\n pipe(\n Option.fromUndefinedOr(found.groups),\n Option.flatMap((groups) => Option.fromUndefinedOr(groups[\"body\"])),\n ),\n ),\n Arr.getSomes,\n );\n\nconst argumentsAfter =\n (text: string) =>\n (command: string): Option.Option<string> =>\n pipe(\n Option.some(Str.trimStart(text)),\n Option.filter(Str.startsWith(command)),\n Option.map((typed) => Str.slice(command.length)(typed)),\n Option.filter((rest) => Str.isEmpty(rest) || /^\\s/u.test(rest)),\n Option.map(Str.trim),\n );\n\nconst typedIn =\n (commands: readonly string[]) =>\n (text: string): Option.Option<string> =>\n Arr.findFirst(commands, argumentsAfter(text));\n\nconst ownerBody =\n (commands: readonly string[]) =>\n (prompt: string): Option.Option<string> =>\n pipe(bodiesOf(prompt), Arr.map(typedIn(commands)), Arr.getSomes, Arr.last);\n\nexport const ownerCommand = (prompt: string, commands: readonly string[]): Option.Option<string> =>\n Option.orElse(typedIn(commands)(prompt), () => ownerBody(commands)(prompt));\n","import {\n Array as Arr,\n Config,\n Effect,\n FileSystem,\n Option,\n Path,\n Schema,\n String as Str,\n pipe,\n} from \"effect\";\n\nimport { ownerCommand } from \"./owner-command.ts\";\n\nconst OFF = \"disable\";\n\nconst turnsOn = (args: string): boolean =>\n !pipe(\n Str.split(args, /\\s+/u),\n Arr.head,\n Option.exists((word) => word === OFF),\n );\n\nexport const ownerSwitch = (prompt: string, commands: readonly string[]): Option.Option<boolean> =>\n Option.map(ownerCommand(prompt, commands), turnsOn);\n\nconst blank = Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed(\"\")));\n\nexport const OwnerPrompt = Schema.Struct({ prompt: blank, session_id: blank });\n\nconst directoryOf = Effect.fn(\"directoryOf\")(function* directoryOf(name: string) {\n const path = yield* Path.Path;\n const data = yield* Config.NonEmptyString(\"CLAUDE_PLUGIN_DATA\");\n return path.join(data, name);\n});\n\nconst markerOf = Effect.fn(\"markerOf\")(function* markerOf(directory: string, session: string) {\n const path = yield* Path.Path;\n return path.join(directory, path.basename(session));\n});\n\n/** @internal */\nexport const switchSession = Effect.fn(\"switchSession\")(function* switchSession(\n name: string,\n session: string,\n on: boolean,\n) {\n const fs = yield* FileSystem.FileSystem;\n const directory = yield* directoryOf(name);\n const marker = yield* markerOf(directory, session);\n if (!on) {\n return yield* fs.remove(marker, { force: true });\n }\n yield* fs.makeDirectory(directory, { recursive: true });\n return yield* fs.writeFileString(marker, \"\");\n});\n\n/** @internal */\nexport const sessionSwitchedOn = Effect.fn(\"sessionSwitchedOn\")(\n function* sessionSwitchedOn(name: string, session: string) {\n const fs = yield* FileSystem.FileSystem;\n if (Str.isEmpty(session)) {\n return false;\n }\n const directory = yield* directoryOf(name);\n const marker = yield* markerOf(directory, session);\n return yield* fs.exists(marker);\n },\n Effect.orElseSucceed(() => false),\n);\n\n/** @internal */\nexport const followOwnerSwitch = Effect.fn(\"followOwnerSwitch\")(function* followOwnerSwitch(\n input: typeof OwnerPrompt.Type,\n name: string,\n commands: readonly string[],\n) {\n if (Str.isEmpty(input.session_id)) {\n return;\n }\n yield* Option.match(ownerSwitch(input.prompt, commands), {\n onNone: () => Effect.void,\n onSome: (on) => switchSession(name, input.session_id, on),\n });\n});\n","import { Array as Arr, Effect, FileSystem, Path, Record as Rec, Schema, pipe } from \"effect\";\n\nconst InstalledEntry = Schema.Struct({\n installPath: Schema.String,\n version: Schema.Unknown,\n gitCommitSha: Schema.Unknown,\n});\nconst InstalledPlugins = Schema.Struct({\n plugins: Schema.Record(Schema.String, Schema.Array(InstalledEntry)),\n});\nconst decodeInstalled = Schema.decodeUnknownEffect(Schema.fromJsonString(InstalledPlugins));\n\nexport interface InstalledPlugin {\n readonly id: string;\n readonly installPath: string;\n readonly version: unknown;\n readonly sha: unknown;\n}\n\nconst flattened = (installed: typeof InstalledPlugins.Type): readonly InstalledPlugin[] =>\n pipe(\n Rec.toEntries(installed.plugins),\n Arr.flatMap(([id, entries]) =>\n pipe(\n entries,\n Arr.map((entry) => ({\n id,\n installPath: entry.installPath,\n version: entry.version,\n sha: entry.gitCommitSha,\n })),\n ),\n ),\n );\n\n/** @internal */\nexport const installedPlugins = Effect.fn(\"installedPlugins\")(function* installedPlugins(\n home: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const file = path.join(home, \".claude\", \"plugins\", \"installed_plugins.json\");\n return yield* fs.readFileString(file).pipe(\n Effect.flatMap(decodeInstalled),\n Effect.map(flattened),\n Effect.orElseSucceed((): readonly InstalledPlugin[] => []),\n );\n});\n","import {\n Array as Arr,\n Option,\n Predicate,\n Record as Rec,\n Schema,\n String as Str,\n pipe,\n} from \"effect\";\n\nexport type Place = \"ci\" | \"cloud\" | \"local\";\n\nexport interface Origin {\n readonly place: Place;\n readonly project: string;\n readonly hook: string;\n readonly sessionId: string;\n}\n\nexport interface JevSettings {\n readonly openRouterKey: string;\n readonly openRouterModel: string;\n readonly allowTraining: boolean;\n readonly attribution: Readonly<Record<string, string>>;\n}\n\nexport interface JevBackend {\n readonly apiKey: string;\n readonly baseURL: string;\n readonly model: string;\n readonly extra: Readonly<Record<string, unknown>>;\n readonly headers: Readonly<Record<string, string>>;\n readonly textState: boolean;\n}\n\nexport interface PlaceEnv {\n readonly githubActions: string;\n readonly remote: string;\n}\n\nexport type JevState = Readonly<Record<string, string>>;\n\nconst DEFAULT_OPENROUTER_MODEL = \"respan/span-01-lite\";\nconst TEXT_STATE_PREFIX = \"respan/\";\nconst encodeJson = Schema.encodeOption(Schema.fromJsonString(Schema.Unknown));\n\nexport const placeOf = (env: PlaceEnv): Place => {\n if (env.githubActions === \"true\") {\n return \"ci\";\n }\n if (env.remote === \"true\") {\n return \"cloud\";\n }\n return \"local\";\n};\n\nconst dataCollection = (allowTraining: boolean): string => {\n if (allowTraining) {\n return \"allow\";\n }\n return \"deny\";\n};\n\nexport const jevBackend = (settings: JevSettings, origin: Origin): JevBackend => {\n const model = pipe(\n Option.liftPredicate(settings.openRouterModel, Str.isNonEmpty),\n Option.getOrElse(() => DEFAULT_OPENROUTER_MODEL),\n );\n const session = pipe(\n Option.liftPredicate(origin.sessionId, Str.isNonEmpty),\n Option.match({ onNone: () => ({}), onSome: (id) => ({ session_id: id }) }),\n );\n return {\n apiKey: settings.openRouterKey,\n baseURL: \"https://openrouter.ai/api\",\n model,\n extra: {\n provider: { data_collection: dataCollection(settings.allowTraining) },\n user: `${origin.place}:${origin.project}:${origin.hook}`,\n ...session,\n },\n headers: settings.attribution,\n textState: Str.startsWith(TEXT_STATE_PREFIX)(model),\n };\n};\n\nconst sectionOf = ([key, value]: readonly [string, unknown]): string => {\n const text = pipe(\n Option.liftPredicate(value, Predicate.isString),\n Option.orElse(() => encodeJson(value)),\n Option.getOrElse(() => \"\"),\n );\n return `## ${key}\\n${text}`;\n};\n\nexport const stateFor = (backend: JevBackend, state: JevState): JevState | string => {\n if (!backend.textState) {\n return state;\n }\n return pipe(Rec.toEntries(state), Arr.map(sectionOf), Arr.join(\"\\n\\n\"));\n};\n"],"mappings":";;;;AAEA,MAAM,gBAAgB;AAEtB,MAAMA,gBAAc,OAAO;;AAG3B,IAAa,cAAb,cAAiCA,cAA4D,CAAC,CAC5F,eACA,EAAE,QAAQ,OAAO,OAAO,CAC1B,CAAC,CAAC;CACA,CAA0B,QAAQ,iBAAiB;CACnD,CAA0B,QAAQ,iBAAiB;AACrD;;AAGA,MAAa,gBAAgB,OAAO,GAAG,WAAW;;AAGlD,MAAa,aAAa,WACxB,OAAO,KAAK,YAAY,KAAK,EAAE,OAAO,CAAC,CAAC;;AAG1C,MAAa,YAAuD,OAAO,IACzE,UAAU,YAAY;CAEpB,OAAO,QAAO,OADO,MAAM,MAAA,CACP,MAAM,KAAK,OAAO,YAAY,OAAO,UAAU,OAAO,KAAK;AACjF,CACF;;AAGA,MAAa,iBACX,WAEA,OAAO,IAAI,UAAU,OAAO;CAC1B,MAAM,OAAO,OAAO;CACpB,MAAM,OAAO,OAAO,eAAe,MAAM;CACzC,OAAO,OAAO,OAAO,aAAa,IAAI,CAAC,CAAC,IAAI;AAC9C,CAAC;;AAGH,MAAa,eAAe,SAC1B,OAAO,IAAI,UAAU,WAAW;CAC9B,MAAM,QAAQ,OAAO,MAAM;CAC3B,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,KAAK,OAAO,IAAI,MAAM,OAAO,CAAC,GAAG,OAAO,KAAK;AACxE,CAAC;;AAGH,MAAa,eAAe,SAC1B,OAAO,IAAI,UAAU,WAAW;CAC9B,MAAM,QAAQ,OAAO,MAAM;CAC3B,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,KAAK,OAAO,IAAI,MAAM,OAAO,CAAC,GAAG,OAAO,KAAK;AACxE,CAAC;;A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,wBAAwB,CACjD;CACA,MAAM,UAAU,KACd,OAAO,cAAc,OAAO,WAAWA,SAAI,UAAU,GACrD,OAAO,MAAM;EAAE,eAAe,CAAC;EAAI,SAAS,QAAQ,EAAE,YAAY,GAAG;CAAG,CAAC,CAC3E;CACA,OAAO;EACL,QAAQ,SAAS;EACjB,SAAS;EACT;EACA,OAAO;GACL,UAAU,EAAE,iBAAiB,eAAe,SAAS,aAAa,EAAE;GACpE,MAAM,GAAG,OAAO,MAAM,GAAG,OAAO,QAAQ,GAAG,OAAO;GAClD,GAAG;EACL;EACA,SAAS,SAAS;EAClB,WAAWA,SAAI,WAAW,iBAAiB,CAAC,CAAC,KAAK;CACpD;AACF;AAEA,MAAM,aAAa,CAAC,KAAK,WAA+C;CAMtE,OAAO,MAAM,IAAI,IALJ,KACX,OAAO,cAAc,OAAO,UAAU,QAAQ,GAC9C,OAAO,aAAa,WAAW,KAAK,CAAC,GACrC,OAAO,gBAAgB,EAAE,CAEH;AAC1B;AAEA,MAAa,YAAY,SAAqB,UAAuC;CACnF,IAAI,CAAC,QAAQ,WACX,OAAO;CAET,OAAO,KAAKC,OAAI,UAAU,KAAK,GAAGC,MAAI,IAAI,SAAS,GAAGA,MAAI,KAAK,MAAM,CAAC;AACxE"}
|
|
1
|
+
{"version":3,"file":"plugin-kit.mjs","names":["taggedError","RecordSchema","StringSchema","ONE","encodeJson","Str","Arr","Rec","ONE","Str","Arr","Num","ONE","Arr","Num","Str","Arr","Arr","Str","Str","Arr","Rec","Arr","Str","Rec","Arr"],"sources":["../src/features/run-main/model/hook-io.ts","../src/features/run-main/model/run-hook.ts","../src/shared/lib/record.ts","../src/features/fit-history/model/calls.ts","../src/shared/lib/tokens.ts","../src/features/fit-history/model/fitting.ts","../src/features/fit-history/model/state.ts","../src/shared/lib/owner-command.ts","../src/shared/lib/session-switch.ts","../src/shared/lib/installed-plugins.ts","../src/shared/lib/jev-backend.ts"],"sourcesContent":["import { Effect, Runtime, Schema, Stdio, Stream } from \"effect\";\n\nconst EXIT_BLOCKING = 2;\n\nconst taggedError = Schema.TaggedError;\n\n/** @internal */\nexport class HookBlocked extends taggedError<HookBlocked, { readonly brand: unique symbol }>()(\n \"HookBlocked\",\n { reason: Schema.String },\n) {\n public override readonly [Runtime.errorExitCode] = EXIT_BLOCKING;\n public override readonly [Runtime.errorReported] = false;\n}\n\n/** @internal */\nexport const isHookBlocked = Schema.is(HookBlocked);\n\n/** @internal */\nexport const blockHook = (reason: string): Effect.Effect<never, HookBlocked> =>\n Effect.fail(HookBlocked.make({ reason }));\n\n/** @internal */\nexport const readStdin: Effect.Effect<string, never, Stdio.Stdio> = Effect.gen(\n function* readStdin() {\n const stdio = yield* Stdio.Stdio;\n return yield* stdio.stdin.pipe(Stream.decodeText, Stream.mkString, Effect.orDie);\n },\n);\n\n/** @internal */\nexport const readHookInput = <Codec extends Schema.Top>(\n schema: Codec,\n): Effect.Effect<Codec[\"Type\"], Schema.SchemaError, Stdio.Stdio | Codec[\"DecodingServices\"]> =>\n Effect.gen(function* read() {\n const text = yield* readStdin;\n const json = Schema.fromJsonString(schema);\n return yield* Schema.decodeEffect(json)(text);\n });\n\n/** @internal */\nexport const writeStdout = (text: string): Effect.Effect<void, never, Stdio.Stdio> =>\n Effect.gen(function* toStdout() {\n const stdio = yield* Stdio.Stdio;\n yield* Stream.make(text).pipe(Stream.run(stdio.stdout()), Effect.orDie);\n });\n\n/** @internal */\nexport const writeStderr = (text: string): Effect.Effect<void, never, Stdio.Stdio> =>\n Effect.gen(function* toStderr() {\n const stdio = yield* Stdio.Stdio;\n yield* Stream.make(text).pipe(Stream.run(stdio.stderr()), Effect.orDie);\n });\n\n/** @internal */\nexport const writeHookOutput =\n <Codec extends Schema.Top>(schema: Codec) =>\n (value: Codec[\"Type\"]): Effect.Effect<void, never, Stdio.Stdio | Codec[\"EncodingServices\"]> =>\n Schema.encodeEffect(Schema.fromJsonString(schema))(value).pipe(\n Effect.orDie,\n Effect.flatMap(writeStdout),\n );\n","import { Cause, Effect, Layer, Option } from \"effect\";\nimport type { Stdio } from \"effect\";\n\nimport { isHookBlocked, writeStderr } from \"./hook-io.ts\";\nimport type { HookBlocked } from \"./hook-io.ts\";\nimport { runMainWith } from \"./run-main.ts\";\nimport type { Platform, Run } from \"./run-main.ts\";\n\nconst blockedIn = <Failure>(cause: Cause.Cause<Failure>): Option.Option<HookBlocked> =>\n Cause.findErrorOption(cause).pipe(\n Option.filter((error): error is Failure & HookBlocked => isHookBlocked(error)),\n );\n\nconst reportBlocked = <Failure>(\n cause: Cause.Cause<Failure>,\n): Effect.Effect<void, never, Stdio.Stdio> =>\n cause.pipe(\n blockedIn,\n Option.match({\n onNone: () => Effect.void,\n onSome: (blocked) => writeStderr(`${blocked.reason}\\n`),\n }),\n );\n\n/** @internal */\nexport const runHookWith =\n <Provided, LayerFailure>({\n serviceName,\n services,\n }: Readonly<{\n serviceName: string;\n services: Layer.Layer<Provided, LayerFailure, Platform>;\n }>): Run<Provided> =>\n (program) => {\n runMainWith({ serviceName, services })(program.pipe(Effect.tapCause(reportBlocked)));\n };\n\n/** @internal */\nexport const runHook = (serviceName: string): Run<never> =>\n runHookWith({ serviceName, services: Layer.empty });\n","import { Record as RecordSchema, String as StringSchema, Unknown, is } from \"effect/Schema\";\n\nexport const isRecord = is(RecordSchema(StringSchema, Unknown));\n","import { Array as Arr, Option, Record as Rec, Schema, String as Str, pipe } from \"effect\";\n\nimport type { HistoryEntry, HistoryToolCall, Message, ToolCall } from \"./types.ts\";\n\nconst FIRST = 0;\nconst ONE = 1;\nconst ELLIPSIS = \"…\";\nconst VALUE_CHARS = 200;\nconst COMPACT_INPUT_CHARS = 60;\nconst SPACES = /\\s+/gu;\nconst encodeJson = Schema.encodeOption(Schema.fromJsonString(Schema.Unknown));\n\nexport const jsonOf = (value: unknown): Option.Option<string> => encodeJson(value);\n\nexport const truncate = (text: string, limit: number): string => {\n if (Str.length(text) <= limit) {\n return text;\n }\n return `${Str.slice(FIRST, Math.max(FIRST, limit - ONE))(text)}${ELLIPSIS}`;\n};\n\nexport const isPinned = (index: number, total: number, preserveRecentMessages: number): boolean =>\n index === FIRST || index >= total - preserveRecentMessages;\n\ninterface Found {\n readonly index: number;\n readonly chars: number;\n readonly isError: boolean;\n}\n\nconst resultsOf = (messages: readonly Message[]): ReadonlyMap<string, Found> =>\n new Map(\n pipe(\n messages,\n Arr.flatMap((message, index) =>\n pipe(\n message.toolResults,\n Arr.map(\n (result) =>\n [\n result.tool_use_id,\n { index, chars: Str.length(result.text), isError: result.isError },\n ] as const,\n ),\n ),\n ),\n ),\n );\n\nexport const collectToolCalls = (\n messages: readonly Message[],\n preserveRecentMessages: number,\n): readonly ToolCall[] => {\n const results = resultsOf(messages);\n const pinned = (index: number): boolean =>\n isPinned(index, messages.length, preserveRecentMessages);\n return pipe(\n messages,\n Arr.flatMap((message, callIndex) =>\n pipe(\n message.toolUses,\n Arr.flatMap((tool) =>\n pipe(\n Option.fromUndefinedOr(results.get(tool.tool_use_id)),\n Option.map((found) => ({ tool, callIndex, found })),\n Option.toArray,\n ),\n ),\n ),\n ),\n Arr.map(({ tool, callIndex, found }, index) => ({\n id: `t${String(index + ONE)}`,\n tool_use_id: tool.tool_use_id,\n tool: tool.tool,\n input: tool.input,\n callIndex,\n resultIndex: found.index,\n resultChars: found.chars,\n isError: found.isError,\n pinned: pinned(callIndex) || pinned(found.index),\n })),\n );\n};\n\nexport const inputText = (input: Readonly<Record<string, unknown>>, limit: number): string =>\n truncate(\n Option.getOrElse(jsonOf(input), () => \"[unserializable input]\"),\n limit,\n );\n\nconst outcomeOf = (call: ToolCall): string => {\n if (call.isError) {\n return \"error\";\n }\n return \"ok\";\n};\n\nconst resultNote = (call: ToolCall): string =>\n `${outcomeOf(call)}, ${String(call.resultChars)} chars (omitted)`;\n\nconst valueText = ([key, value]: readonly [string, unknown]): string => {\n const text = pipe(\n Option.liftPredicate(value, (raw): raw is string => typeof raw === \"string\"),\n Option.getOrElse(() => inputText({ [key]: value }, VALUE_CHARS)),\n );\n return `${key}=${Str.replaceAll(SPACES, \" \")(text)}`;\n};\n\nexport const compactCall = (call: ToolCall): string => {\n const input = pipe(Rec.toEntries(call.input), Arr.map(valueText), Arr.join(\" \"));\n return `${call.id} ${call.tool} ${truncate(input, COMPACT_INPUT_CHARS)} → ${outcomeOf(call)} ${String(call.resultChars)}ch`;\n};\n\nexport const callsByMessage = (\n calls: readonly ToolCall[],\n): ReadonlyMap<number, readonly ToolCall[]> =>\n new Map(\n pipe(\n calls,\n Arr.groupBy((call) => String(call.callIndex)),\n Rec.toEntries,\n Arr.map(([index, own]) => [Number(index), own] as const),\n ),\n );\n\nconst historyCallOf =\n (inputChars: number) =>\n (call: ToolCall): HistoryToolCall => ({\n id: call.id,\n tool: call.tool,\n input: inputText(call.input, inputChars),\n result: resultNote(call),\n });\n\nexport const historyEntries = (\n messages: readonly Message[],\n calls: readonly ToolCall[],\n inputChars: number,\n): readonly HistoryEntry[] => {\n const byMessage = callsByMessage(calls);\n return pipe(\n messages,\n Arr.flatMap((message, index): readonly HistoryEntry[] => {\n const own = Option.getOrElse(Option.fromUndefinedOr(byMessage.get(index)), () => []);\n const toolCalls = pipe(own, Arr.map(historyCallOf(inputChars)));\n const entry = { index, role: message.role, text: message.text };\n if (Arr.isReadonlyArrayNonEmpty(toolCalls)) {\n return [{ ...entry, tool_calls: toolCalls }];\n }\n if (Str.isEmpty(Str.trim(message.text))) {\n return [];\n }\n return [entry];\n }),\n );\n};\n","import { Array as Arr, Number as Num, Option, String as Str, pipe } from \"effect\";\n\nimport { groupOf } from \"./match-groups.ts\";\n\nconst PIECES = /(?<alpha>[A-Za-z]+)|(?<digits>\\d+)|(?<other>[^\\sA-Za-z\\d])/gu;\nconst DIGITS_PER_TOKEN = 2;\nconst LETTERS_PER_TOKEN = 6;\nconst SYMBOL_TOKENS = 0.9;\nconst ONE = 1;\n\nconst pieceTokens = (match: RegExpMatchArray): number =>\n pipe(\n groupOf(\"digits\")(match),\n Option.map((digits) => Str.length(digits) / DIGITS_PER_TOKEN),\n Option.orElse(() =>\n Option.map(\n groupOf(\"alpha\")(match),\n (alpha) => ONE + Math.floor((Str.length(alpha) - ONE) / LETTERS_PER_TOKEN),\n ),\n ),\n Option.getOrElse(() => SYMBOL_TOKENS),\n );\n\nconst matchesOf = (pattern: RegExp, text: string): readonly RegExpMatchArray[] =>\n Arr.fromIterable(Str.matchAll(pattern)(text));\n\nexport const estimateTokens = (text: string): number => {\n const pieces = pipe(matchesOf(PIECES, text), Arr.map(pieceTokens));\n return Math.ceil(Num.sumAll(pieces));\n};\n","import { Array as Arr, Number as Num, Option, pipe } from \"effect\";\n\nimport { estimateTokens } from \"#/shared/lib/tokens.ts\";\n\nimport { isPinned, jsonOf } from \"./calls.ts\";\nimport type {\n CompactionState,\n FitOptions,\n FittedState,\n HistoryEntry,\n Message,\n ToolCall,\n} from \"./types.ts\";\n\nconst ONE = 1;\nconst NONE = 0;\n\nexport const entryTokens = (entry: HistoryEntry): number =>\n jsonOf(entry).pipe(\n Option.getOrElse(() => \"\"),\n estimateTokens,\n ) + ONE;\n\nexport interface Fitting {\n readonly history: readonly Option.Option<HistoryEntry>[];\n readonly perEntry: readonly number[];\n readonly tokens: number;\n}\n\nexport interface Plan {\n readonly messages: readonly Message[];\n readonly calls: readonly ToolCall[];\n readonly options: FitOptions;\n readonly stateOf: (history: readonly HistoryEntry[]) => CompactionState;\n readonly baseTokens: number;\n readonly byMessage: ReadonlyMap<number, readonly ToolCall[]>;\n}\n\nexport type Change = (entry: HistoryEntry) => Option.Option<Option.Option<HistoryEntry>>;\n\nexport const fittingOf = (plan: Plan, history: readonly HistoryEntry[]): Fitting => {\n const perEntry = pipe(history, Arr.map(entryTokens));\n return {\n history: pipe(history, Arr.map(Option.some)),\n perEntry,\n tokens: plan.baseTokens + Num.sumAll(perEntry),\n };\n};\n\nexport const kept = (fitting: Fitting): readonly HistoryEntry[] => Arr.getSomes(fitting.history);\n\nexport const fits = (plan: Plan, fitting: Fitting): boolean =>\n fitting.tokens <= plan.options.maxStateTokens;\n\nexport const fitted = (plan: Plan, fitting: Fitting, stage: string): FittedState => ({\n state: plan.stateOf(kept(fitting)),\n tokens: fitting.tokens,\n stage,\n});\n\nexport const pinnedEntry = (plan: Plan, entry: HistoryEntry): boolean =>\n isPinned(entry.index, plan.messages.length, plan.options.preserveRecentMessages);\n\nconst orderOf = (plan: Plan, fitting: Fitting): readonly number[] => {\n const present = pipe(\n fitting.history,\n Arr.flatMap((entry, index) =>\n pipe(\n entry,\n Option.map((value) => [index, pinnedEntry(plan, value)] as const),\n Option.toArray,\n ),\n ),\n );\n const loose = pipe(\n present,\n Arr.filter(([, pinned]) => !pinned),\n );\n const pinned = pipe(\n present,\n Arr.filter(([, isPinnedEntry]) => isPinnedEntry),\n );\n return pipe(\n [...loose, ...pinned],\n Arr.map(([index]) => index),\n );\n};\n\ninterface Step {\n readonly index: number;\n readonly entry: Option.Option<HistoryEntry>;\n readonly tokens: number;\n}\n\nconst stepOf =\n (fitting: Fitting, change: Change) =>\n (index: number): Option.Option<Step> =>\n pipe(\n Option.flatten(Option.fromUndefinedOr(fitting.history[index])),\n Option.flatMap(change),\n Option.map((entry) => ({\n index,\n entry,\n tokens: Option.match(entry, { onNone: () => NONE, onSome: entryTokens }),\n })),\n );\n\nconst applied = (fitting: Fitting, steps: readonly Step[]): Fitting => {\n const byIndex = new Map(\n pipe(\n steps,\n Arr.map((step) => [step.index, step] as const),\n ),\n );\n const pick = <Value>(index: number, value: Value, of: (step: Step) => Value): Value =>\n Option.match(Option.fromUndefinedOr(byIndex.get(index)), { onNone: () => value, onSome: of });\n const history = pipe(\n fitting.history,\n Arr.map((entry, index) => pick(index, entry, (step) => step.entry)),\n );\n const perEntry = pipe(\n fitting.perEntry,\n Arr.map((tokens, index) => pick(index, tokens, (step) => step.tokens)),\n );\n const delta = Num.sumAll(\n pipe(\n steps,\n Arr.map(\n (step) => step.tokens - Option.getOrElse(Arr.get(fitting.perEntry, step.index), () => NONE),\n ),\n ),\n );\n return { history, perEntry, tokens: fitting.tokens + delta };\n};\n\nexport const staged = (\n plan: Plan,\n fitting: Fitting,\n change: Change,\n): readonly [Fitting, boolean] => {\n const steps = pipe(\n orderOf(plan, fitting),\n Arr.flatMap((index) => Option.toArray(stepOf(fitting, change)(index))),\n );\n const totals = pipe(\n steps,\n Arr.scan(\n fitting.tokens,\n (tokens, step) =>\n tokens + step.tokens - Option.getOrElse(Arr.get(fitting.perEntry, step.index), () => NONE),\n ),\n Arr.drop(ONE),\n );\n return Option.match(\n Arr.findFirstIndex(totals, (tokens) => tokens <= plan.options.maxStateTokens),\n {\n onNone: () => [applied(fitting, steps), false] as const,\n onSome: (at) => [applied(fitting, Arr.take(steps, at + ONE)), true] as const,\n },\n );\n};\n","import {\n Array as Arr,\n Effect,\n Option,\n Predicate,\n Result,\n Schema,\n String as Str,\n pipe,\n} from \"effect\";\n\nimport { estimateTokens } from \"#/shared/lib/tokens.ts\";\n\nimport { callsByMessage, compactCall, historyEntries, jsonOf, truncate } from \"./calls.ts\";\nimport { fits, fitted, fittingOf, kept, pinnedEntry, staged } from \"./fitting.ts\";\nimport type { Change, Fitting, Plan } from \"./fitting.ts\";\nimport type {\n CompactionState,\n FitOptions,\n FittedState,\n HistoryEntry,\n HistoryToolCall,\n Message,\n ToolCall,\n} from \"./types.ts\";\n\nexport const STATE_CONTEXT =\n \"A coding assistant conversation is being compacted to free context. `history` is the whole conversation so far, oldest first; tool outputs are replaced by a short `result` note and long texts may be abridged. Each question asks whether one tool call, or the full output of that call, still needs to stay in the history verbatim. Whatever is not kept is deleted permanently, but the assistant can always re-run a tool or re-read a file.\";\n\nconst taggedError = Schema.TaggedError;\n\nexport class HistoryTooLarge extends taggedError<\n HistoryTooLarge,\n { readonly brand: unique symbol }\n>()(\"HistoryTooLarge\", { reason: Schema.String }) {}\n\nconst FULL_INPUT_CHARS = 1000;\nconst SHORT_INPUT_CHARS = 200;\nconst SHORTEST_INPUT_CHARS = 60;\nconst SHORTER_INPUT_CHARS = [SHORT_INPUT_CHARS, SHORTEST_INPUT_CHARS] as const;\nconst TEXT_HEAD = 400;\nconst TEXT_TAIL = 150;\nconst ABRIDGE_MARGIN = 40;\nconst RECENT_GOALS = 3;\nconst GOAL_CHARS = 500;\nconst ONE = 1;\n\nconst abridge = (text: string): string => {\n const omitted = Str.length(text) - TEXT_HEAD - TEXT_TAIL;\n return `${Str.takeLeft(TEXT_HEAD)(text)}\\n[… ${String(omitted)} chars omitted …]\\n${Str.takeRight(TEXT_TAIL)(text)}`;\n};\n\nexport const goalFromMessages = (messages: readonly Message[]): string =>\n pipe(\n messages,\n Arr.filter(\n (message) =>\n message.role === \"user\" &&\n Str.isNonEmpty(Str.trim(message.text)) &&\n Arr.isReadonlyArrayEmpty(message.toolResults),\n ),\n Arr.takeRight(RECENT_GOALS),\n Arr.map((message) => truncate(message.text, GOAL_CHARS)),\n Arr.join(\"\\n\"),\n );\n\nconst abridgeText: Change = (entry: HistoryEntry) =>\n Option.liftPredicate(\n Option.some({ ...entry, text: abridge(entry.text) }),\n () => Str.length(entry.text) > TEXT_HEAD + TEXT_TAIL + ABRIDGE_MARGIN,\n );\n\nconst collapseText =\n (plan: Plan): Change =>\n (entry: HistoryEntry) => {\n const original = pipe(\n Arr.get(plan.messages, entry.index),\n Option.map((message) => Str.length(message.text)),\n Option.getOrElse(() => Str.length(entry.text)),\n );\n return Option.liftPredicate(\n Option.some({ ...entry, text: `[… ${String(original)} chars omitted …]` }),\n () => !pinnedEntry(plan, entry) && Str.isNonEmpty(entry.text),\n );\n };\n\nconst compactCalls =\n (plan: Plan): Change =>\n (entry: HistoryEntry) =>\n pipe(\n Option.fromUndefinedOr(plan.byMessage.get(entry.index)),\n Option.filter(() => !pinnedEntry(plan, entry)),\n Option.map((own) => Option.some({ ...entry, tool_calls: pipe(own, Arr.map(compactCall)) })),\n );\n\nconst leaveOut =\n (plan: Plan): Change =>\n (entry: HistoryEntry) =>\n Option.liftPredicate(\n Option.none<HistoryEntry>(),\n () => !pinnedEntry(plan, entry) && Predicate.isUndefined(entry.tool_calls),\n );\n\nconst callsOf = (entry: HistoryEntry): readonly (HistoryToolCall | string)[] =>\n Option.getOrElse(Option.fromUndefinedOr(entry.tool_calls), () => []);\n\nconst stringCalls = (entry: HistoryEntry): readonly string[] =>\n pipe(callsOf(entry), Arr.filter(Predicate.isString));\n\nconst foldable = (plan: Plan, entry: HistoryEntry): boolean =>\n !pinnedEntry(plan, entry) &&\n Str.isEmpty(entry.text) &&\n pipe(Arr.head(callsOf(entry)), Option.exists(Predicate.isString));\n\nconst mergedRun = (group: Arr.NonEmptyReadonlyArray<HistoryEntry>): HistoryEntry => {\n const first = Arr.headNonEmpty(group);\n if (group.length === ONE) {\n return first;\n }\n return { ...first, tool_calls: pipe(group, Arr.flatMap(stringCalls)) };\n};\n\nconst mergeRuns = (plan: Plan, history: readonly HistoryEntry[]): readonly HistoryEntry[] => {\n if (!Arr.isReadonlyArrayNonEmpty(history)) {\n return [];\n }\n return pipe(\n Arr.groupWith(\n history,\n (left, right) => foldable(plan, left) && foldable(plan, right) && left.role === right.role,\n ),\n Arr.map(mergedRun),\n );\n};\n\ntype Staged = readonly [Fitting, boolean];\n\ntype Stage = readonly [string, (fitting: Fitting) => Staged];\n\nconst rebuilt = (plan: Plan, inputChars: number) => (): readonly [Fitting, boolean] => {\n const fitting = fittingOf(plan, historyEntries(plan.messages, plan.calls, inputChars));\n return [fitting, fits(plan, fitting)];\n};\n\nconst stagesOf = (plan: Plan): readonly Stage[] => [\n ...pipe(\n SHORTER_INPUT_CHARS,\n Arr.map((limit): Stage => [`inputs<=${String(limit)}`, rebuilt(plan, limit)]),\n ),\n [\"texts abridged\", (fitting): Staged => staged(plan, fitting, abridgeText)],\n [\"old messages collapsed\", (fitting): Staged => staged(plan, fitting, collapseText(plan))],\n [\"old calls compacted\", (fitting): Staged => staged(plan, fitting, compactCalls(plan))],\n [\"old messages left out\", (fitting): Staged => staged(plan, fitting, leaveOut(plan))],\n [\n \"old calls merged\",\n (fitting): Staged => {\n const merged = fittingOf(plan, mergeRuns(plan, kept(fitting)));\n return [merged, fits(plan, merged)];\n },\n ],\n];\n\nconst throughStages = (\n plan: Plan,\n fitting: Fitting,\n stages: readonly Stage[],\n): Result.Result<FittedState, Fitting> =>\n Option.match(Arr.head(stages), {\n onNone: () => Result.fail(fitting),\n onSome: ([name, run]) => {\n const [next, done] = run(fitting);\n if (done) {\n return Result.succeed(fitted(plan, next, name));\n }\n return throughStages(plan, next, Arr.drop(stages, ONE));\n },\n });\n\nconst jsonText = (value: unknown): string => Option.getOrElse(jsonOf(value), () => \"\");\n\nconst planOf = (\n messages: readonly Message[],\n calls: readonly ToolCall[],\n options: FitOptions,\n): Plan => {\n const goal = pipe(\n Option.liftPredicate(options.goal, Str.isNonEmpty),\n Option.getOrElse(() => goalFromMessages(messages)),\n );\n const stateOf = (history: readonly HistoryEntry[]): CompactionState => ({\n context: STATE_CONTEXT,\n goal,\n history,\n });\n return {\n messages,\n calls,\n options,\n stateOf,\n baseTokens: estimateTokens(jsonText(stateOf([]))),\n byMessage: callsByMessage(calls),\n };\n};\n\nexport const fitState = (\n messages: readonly Message[],\n calls: readonly ToolCall[],\n options: FitOptions,\n): Effect.Effect<FittedState, HistoryTooLarge> => {\n const plan = planOf(messages, calls, options);\n const full = fittingOf(plan, historyEntries(messages, calls, FULL_INPUT_CHARS));\n if (fits(plan, full)) {\n return Effect.succeed(fitted(plan, full, \"full\"));\n }\n return Result.match(throughStages(plan, full, stagesOf(plan)), {\n onSuccess: Effect.succeed,\n onFailure: (last) =>\n Effect.fail(\n HistoryTooLarge.make({\n reason: `history too large for Jev (~${String(last.tokens)} tokens after truncation, limit ${String(options.maxStateTokens)})`,\n }),\n ),\n });\n};\n","import { Array as Arr, Option, String as Str, pipe } from \"effect\";\n\nconst OWNER_BODIES: readonly RegExp[] = [\n /<message\\b[^>]*\\bfrom=\"human\"[^>]*\\btrust=\"principal\"[^>]*>(?<body>[\\s\\S]*?)<\\/message>/gu,\n /<cited\\b[^>]*\\bauthor=\"user\"[^>]*>(?<body>[\\s\\S]*?)<\\/cited>/gu,\n];\n\nconst bodiesOf = (prompt: string): readonly string[] =>\n pipe(\n OWNER_BODIES,\n Arr.flatMap((pattern) => Arr.fromIterable(pipe(prompt, Str.matchAll(pattern)))),\n Arr.map((found) =>\n pipe(\n Option.fromUndefinedOr(found.groups),\n Option.flatMap((groups) => Option.fromUndefinedOr(groups[\"body\"])),\n ),\n ),\n Arr.getSomes,\n );\n\nconst argumentsAfter =\n (text: string) =>\n (command: string): Option.Option<string> =>\n pipe(\n Option.some(Str.trimStart(text)),\n Option.filter(Str.startsWith(command)),\n Option.map((typed) => Str.slice(command.length)(typed)),\n Option.filter((rest) => Str.isEmpty(rest) || /^\\s/u.test(rest)),\n Option.map(Str.trim),\n );\n\nconst typedIn =\n (commands: readonly string[]) =>\n (text: string): Option.Option<string> =>\n Arr.findFirst(commands, argumentsAfter(text));\n\nconst ownerBody =\n (commands: readonly string[]) =>\n (prompt: string): Option.Option<string> =>\n pipe(bodiesOf(prompt), Arr.map(typedIn(commands)), Arr.getSomes, Arr.last);\n\nexport const ownerCommand = (prompt: string, commands: readonly string[]): Option.Option<string> =>\n Option.orElse(typedIn(commands)(prompt), () => ownerBody(commands)(prompt));\n","import {\n Array as Arr,\n Config,\n Effect,\n FileSystem,\n Option,\n Path,\n Schema,\n String as Str,\n pipe,\n} from \"effect\";\n\nimport { ownerCommand } from \"./owner-command.ts\";\n\nconst OFF = \"disable\";\n\nconst turnsOn = (args: string): boolean =>\n !pipe(\n Str.split(args, /\\s+/u),\n Arr.head,\n Option.exists((word) => word === OFF),\n );\n\nexport const ownerSwitch = (prompt: string, commands: readonly string[]): Option.Option<boolean> =>\n Option.map(ownerCommand(prompt, commands), turnsOn);\n\nconst blank = Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed(\"\")));\n\nexport const OwnerPrompt = Schema.Struct({ prompt: blank, session_id: blank });\n\nconst directoryOf = Effect.fn(\"directoryOf\")(function* directoryOf(name: string) {\n const path = yield* Path.Path;\n const data = yield* Config.NonEmptyString(\"CLAUDE_PLUGIN_DATA\");\n return path.join(data, name);\n});\n\nconst markerOf = Effect.fn(\"markerOf\")(function* markerOf(directory: string, session: string) {\n const path = yield* Path.Path;\n return path.join(directory, path.basename(session));\n});\n\n/** @internal */\nexport const switchSession = Effect.fn(\"switchSession\")(function* switchSession(\n name: string,\n session: string,\n on: boolean,\n) {\n const fs = yield* FileSystem.FileSystem;\n const directory = yield* directoryOf(name);\n const marker = yield* markerOf(directory, session);\n if (!on) {\n return yield* fs.remove(marker, { force: true });\n }\n yield* fs.makeDirectory(directory, { recursive: true });\n return yield* fs.writeFileString(marker, \"\");\n});\n\n/** @internal */\nexport const sessionSwitchedOn = Effect.fn(\"sessionSwitchedOn\")(\n function* sessionSwitchedOn(name: string, session: string) {\n const fs = yield* FileSystem.FileSystem;\n if (Str.isEmpty(session)) {\n return false;\n }\n const directory = yield* directoryOf(name);\n const marker = yield* markerOf(directory, session);\n return yield* fs.exists(marker);\n },\n Effect.orElseSucceed(() => false),\n);\n\n/** @internal */\nexport const followOwnerSwitch = Effect.fn(\"followOwnerSwitch\")(function* followOwnerSwitch(\n input: typeof OwnerPrompt.Type,\n name: string,\n commands: readonly string[],\n) {\n if (Str.isEmpty(input.session_id)) {\n return;\n }\n yield* Option.match(ownerSwitch(input.prompt, commands), {\n onNone: () => Effect.void,\n onSome: (on) => switchSession(name, input.session_id, on),\n });\n});\n","import { Array as Arr, Effect, FileSystem, Path, Record as Rec, Schema, pipe } from \"effect\";\n\nconst InstalledEntry = Schema.Struct({\n installPath: Schema.String,\n version: Schema.Unknown,\n gitCommitSha: Schema.Unknown,\n});\nconst InstalledPlugins = Schema.Struct({\n plugins: Schema.Record(Schema.String, Schema.Array(InstalledEntry)),\n});\nconst decodeInstalled = Schema.decodeUnknownEffect(Schema.fromJsonString(InstalledPlugins));\n\nexport interface InstalledPlugin {\n readonly id: string;\n readonly installPath: string;\n readonly version: unknown;\n readonly sha: unknown;\n}\n\nconst flattened = (installed: typeof InstalledPlugins.Type): readonly InstalledPlugin[] =>\n pipe(\n Rec.toEntries(installed.plugins),\n Arr.flatMap(([id, entries]) =>\n pipe(\n entries,\n Arr.map((entry) => ({\n id,\n installPath: entry.installPath,\n version: entry.version,\n sha: entry.gitCommitSha,\n })),\n ),\n ),\n );\n\n/** @internal */\nexport const installedPlugins = Effect.fn(\"installedPlugins\")(function* installedPlugins(\n home: string,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const file = path.join(home, \".claude\", \"plugins\", \"installed_plugins.json\");\n return yield* fs.readFileString(file).pipe(\n Effect.flatMap(decodeInstalled),\n Effect.map(flattened),\n Effect.orElseSucceed((): readonly InstalledPlugin[] => []),\n );\n});\n","import {\n Array as Arr,\n Option,\n Predicate,\n Record as Rec,\n Schema,\n String as Str,\n pipe,\n} from \"effect\";\n\nexport type Place = \"ci\" | \"cloud\" | \"local\";\n\nexport interface Origin {\n readonly place: Place;\n readonly project: string;\n readonly hook: string;\n readonly sessionId: string;\n}\n\nexport interface JevSettings {\n readonly openRouterKey: string;\n readonly openRouterModel: string;\n readonly allowTraining: boolean;\n readonly attribution: Readonly<Record<string, string>>;\n}\n\nexport interface JevBackend {\n readonly apiKey: string;\n readonly baseURL: string;\n readonly model: string;\n readonly extra: Readonly<Record<string, unknown>>;\n readonly headers: Readonly<Record<string, string>>;\n readonly textState: boolean;\n}\n\nexport interface PlaceEnv {\n readonly githubActions: string;\n readonly remote: string;\n}\n\nexport type JevState = Readonly<Record<string, string>>;\n\nconst DEFAULT_OPENROUTER_MODEL = \"respan/span-01-lite\";\nconst TEXT_STATE_PREFIX = \"respan/\";\nconst encodeJson = Schema.encodeOption(Schema.fromJsonString(Schema.Unknown));\n\nexport const placeOf = (env: PlaceEnv): Place => {\n if (env.githubActions === \"true\") {\n return \"ci\";\n }\n if (env.remote === \"true\") {\n return \"cloud\";\n }\n return \"local\";\n};\n\nconst dataCollection = (allowTraining: boolean): string => {\n if (allowTraining) {\n return \"allow\";\n }\n return \"deny\";\n};\n\nexport const jevBackend = (settings: JevSettings, origin: Origin): JevBackend => {\n const model = pipe(\n Option.liftPredicate(settings.openRouterModel, Str.isNonEmpty),\n Option.getOrElse(() => DEFAULT_OPENROUTER_MODEL),\n );\n const session = pipe(\n Option.liftPredicate(origin.sessionId, Str.isNonEmpty),\n Option.match({ onNone: () => ({}), onSome: (id) => ({ session_id: id }) }),\n );\n return {\n apiKey: settings.openRouterKey,\n baseURL: \"https://openrouter.ai/api\",\n model,\n extra: {\n provider: { data_collection: dataCollection(settings.allowTraining) },\n user: `${origin.place}:${origin.project}:${origin.hook}`,\n ...session,\n },\n headers: settings.attribution,\n textState: Str.startsWith(TEXT_STATE_PREFIX)(model),\n };\n};\n\nconst sectionOf = ([key, value]: readonly [string, unknown]): string => {\n const text = pipe(\n Option.liftPredicate(value, Predicate.isString),\n Option.orElse(() => encodeJson(value)),\n Option.getOrElse(() => \"\"),\n );\n return `## ${key}\\n${text}`;\n};\n\nexport const stateFor = (backend: JevBackend, state: JevState): JevState | string => {\n if (!backend.textState) {\n return state;\n }\n return pipe(Rec.toEntries(state), Arr.map(sectionOf), Arr.join(\"\\n\\n\"));\n};\n"],"mappings":";;;;;;AAEA,MAAM,gBAAgB;AAEtB,MAAMA,gBAAc,OAAO;;AAG3B,IAAa,cAAb,cAAiCA,cAA4D,CAAC,CAC5F,eACA,EAAE,QAAQ,OAAO,OAAO,CAC1B,CAAC,CAAC;CACA,CAA0B,QAAQ,iBAAiB;CACnD,CAA0B,QAAQ,iBAAiB;AACrD;;AAGA,MAAa,gBAAgB,OAAO,GAAG,WAAW;;AAGlD,MAAa,aAAa,WACxB,OAAO,KAAK,YAAY,KAAK,EAAE,OAAO,CAAC,CAAC;;AAG1C,MAAa,YAAuD,OAAO,IACzE,UAAU,YAAY;CAEpB,OAAO,QAAO,OADO,MAAM,MAAA,CACP,MAAM,KAAK,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,CAAC,KAAK,WAA+C;CAMtE,OAAO,MAAM,IAAI,IALJ,KACX,OAAO,cAAc,OAAO,UAAU,QAAQ,GAC9C,OAAO,aAAa,WAAW,KAAK,CAAC,GACrC,OAAO,gBAAgB,EAAE,CAEH;AAC1B;AAEA,MAAa,YAAY,SAAqB,UAAuC;CACnF,IAAI,CAAC,QAAQ,WACX,OAAO;CAET,OAAO,KAAKC,SAAI,UAAU,KAAK,GAAGC,MAAI,IAAI,SAAS,GAAGA,MAAI,KAAK,MAAM,CAAC;AACxE"}
|
|
@@ -35,6 +35,22 @@ const collected = Effect.fn("collected")(function* collected({ command, args, en
|
|
|
35
35
|
};
|
|
36
36
|
});
|
|
37
37
|
const outputWith = (command) => collected(command).pipe(Effect.scoped, Effect.filterOrFail(({ code }) => code === SUCCESS, () => failed(command)), Effect.map(({ output }) => String.trim(output)));
|
|
38
|
+
const capturedWith = ({ command, args, env, cwd, forceKillAfter = FORCE_KILL_AFTER, output = "all" }) => Effect.gen(function* captured() {
|
|
39
|
+
const handle = yield* ChildProcess.make(command, args, {
|
|
40
|
+
cwd,
|
|
41
|
+
env,
|
|
42
|
+
extendEnv: true,
|
|
43
|
+
stdin: "ignore",
|
|
44
|
+
forceKillAfter
|
|
45
|
+
});
|
|
46
|
+
const [text, code] = yield* Effect.all([handle[output].pipe(Stream.decodeText(), Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
|
|
47
|
+
return {
|
|
48
|
+
valid: code === SUCCESS,
|
|
49
|
+
output: text
|
|
50
|
+
};
|
|
51
|
+
}).pipe(Effect.scoped);
|
|
52
|
+
/** @internal */
|
|
53
|
+
const captured = capturedWith;
|
|
38
54
|
/** @internal */
|
|
39
55
|
const succeeds = succeedsWith;
|
|
40
56
|
/** @internal */
|
|
@@ -44,6 +60,6 @@ const finishedWith = (command) => Effect.scoped(collected(command));
|
|
|
44
60
|
const outputOf = outputWith;
|
|
45
61
|
/** @internal */
|
|
46
62
|
const finished = finishedWith;
|
|
47
|
-
export {
|
|
63
|
+
export { outputOf as a, mustSucceed as i, captured as n, succeeds as o, finished as r, CommandFailed as t };
|
|
48
64
|
|
|
49
|
-
//# sourceMappingURL=process-
|
|
65
|
+
//# sourceMappingURL=process-DTCkAoL_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-DTCkAoL_.mjs","names":["Arr","Str"],"sources":["../src/shared/lib/process.ts"],"sourcesContent":["import { Array as Arr, Duration, Effect, Schema, Stream, String as Str } from \"effect\";\nimport type { PlatformError } from \"effect\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\n\nconst SUCCESS = 0;\nconst FORCE_KILL_AFTER_SECONDS = 10;\nconst FORCE_KILL_AFTER = Duration.seconds(FORCE_KILL_AFTER_SECONDS);\n\nconst taggedError = Schema.TaggedError;\n\nexport class CommandFailed extends taggedError<CommandFailed, { readonly brand: unique symbol }>()(\n \"CommandFailed\",\n { message: Schema.String },\n) {}\n\nexport interface Command {\n readonly command: string;\n readonly args: readonly string[];\n readonly env?: Readonly<Record<string, string>>;\n readonly cwd?: string;\n readonly forceKillAfter?: Duration.Input;\n}\n\n/** @internal */\nexport type Spawned<Success> = Effect.Effect<\n Success,\n CommandFailed | PlatformError.PlatformError,\n ChildProcessSpawner.ChildProcessSpawner\n>;\n\nconst failed = ({ command, args }: Command): CommandFailed =>\n CommandFailed.make({ message: `${command} ${Arr.join(args, \" \")} failed` });\n\nconst exitCodeOf = Effect.fn(\"exitCodeOf\")(function* exitCodeOf({\n command,\n args,\n env,\n cwd,\n forceKillAfter = FORCE_KILL_AFTER,\n}: Command) {\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n return yield* spawner.exitCode(\n ChildProcess.make(command, args, {\n cwd,\n env,\n extendEnv: true,\n stdin: \"ignore\",\n stdout: \"inherit\",\n stderr: \"inherit\",\n forceKillAfter,\n }),\n );\n});\n\nconst succeedsWith = (command: Command): Spawned<boolean> =>\n exitCodeOf(command).pipe(Effect.map((code) => code === SUCCESS));\n\nconst mustSucceedWith = (command: Command): Spawned<void> =>\n succeedsWith(command).pipe(\n Effect.filterOrFail(\n (passed) => passed,\n () => failed(command),\n ),\n Effect.asVoid,\n );\n\nconst collected = Effect.fn(\"collected\")(function* collected({\n command,\n args,\n env,\n cwd,\n forceKillAfter = FORCE_KILL_AFTER,\n}: Command) {\n const handle = yield* ChildProcess.make(command, args, {\n cwd,\n env,\n extendEnv: true,\n stdin: \"ignore\",\n stderr: \"inherit\",\n forceKillAfter,\n });\n const [output, code] = yield* Effect.all(\n [handle.stdout.pipe(Stream.decodeText(), Stream.mkString), handle.exitCode],\n { concurrency: \"unbounded\" },\n );\n return { output, code };\n});\n\nconst outputWith = (command: Command): Spawned<string> =>\n collected(command).pipe(\n Effect.scoped,\n Effect.filterOrFail(\n ({ code }) => code === SUCCESS,\n () => failed(command),\n ),\n Effect.map(({ output }) => Str.trim(output)),\n );\n\nexport interface Captured {\n readonly valid: boolean;\n readonly output: string;\n}\n\nexport type CapturedCommand = Command & Readonly<{ output?: \"all\" | \"stdout\" }>;\n\nconst capturedWith = ({\n command,\n args,\n env,\n cwd,\n forceKillAfter = FORCE_KILL_AFTER,\n output = \"all\",\n}: CapturedCommand): Effect.Effect<\n Captured,\n PlatformError.PlatformError,\n ChildProcessSpawner.ChildProcessSpawner\n> =>\n Effect.gen(function* captured() {\n const handle = yield* ChildProcess.make(command, args, {\n cwd,\n env,\n extendEnv: true,\n stdin: \"ignore\",\n forceKillAfter,\n });\n const [text, code] = yield* Effect.all(\n [handle[output].pipe(Stream.decodeText(), Stream.mkString), handle.exitCode],\n { concurrency: \"unbounded\" },\n );\n return { valid: code === SUCCESS, output: text };\n }).pipe(Effect.scoped);\n\n/** @internal */\nexport const captured = capturedWith;\n\n/** @internal */\nexport const succeeds = succeedsWith;\n\n/** @internal */\nexport const mustSucceed = mustSucceedWith;\n\nconst finishedWith = (command: Command): Spawned<Readonly<{ output: string; code: number }>> =>\n Effect.scoped(collected(command));\n\n/** @internal */\nexport const outputOf = outputWith;\n\n/** @internal */\nexport const finished = finishedWith;\n"],"mappings":";;;AAIA,MAAM,UAAU;AAEhB,MAAM,mBAAmB,SAAS,QAAQ,EAAwB;AAElE,MAAM,cAAc,OAAO;AAE3B,IAAa,gBAAb,cAAmC,YAA8D,CAAC,CAChG,iBACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;AAiBH,MAAM,UAAU,EAAE,SAAS,WACzB,cAAc,KAAK,EAAE,SAAS,GAAG,QAAQ,GAAGA,MAAI,KAAK,MAAM,GAAG,EAAE,SAAS,CAAC;AAE5E,MAAM,aAAa,OAAO,GAAG,YAAY,CAAC,CAAC,UAAU,WAAW,EAC9D,SACA,MACA,KACA,KACA,iBAAiB,oBACP;CAEV,OAAO,QAAO,OADS,oBAAoB,oBAAA,CACrB,SACpB,aAAa,KAAK,SAAS,MAAM;EAC/B;EACA;EACA,WAAW;EACX,OAAO;EACP,QAAQ;EACR,QAAQ;EACR;CACF,CAAC,CACH;AACF,CAAC;AAED,MAAM,gBAAgB,YACpB,WAAW,OAAO,CAAC,CAAC,KAAK,OAAO,KAAK,SAAS,SAAS,OAAO,CAAC;AAEjE,MAAM,mBAAmB,YACvB,aAAa,OAAO,CAAC,CAAC,KACpB,OAAO,cACJ,WAAW,cACN,OAAO,OAAO,CACtB,GACA,OAAO,MACT;AAEF,MAAM,YAAY,OAAO,GAAG,WAAW,CAAC,CAAC,UAAU,UAAU,EAC3D,SACA,MACA,KACA,KACA,iBAAiB,oBACP;CACV,MAAM,SAAS,OAAO,aAAa,KAAK,SAAS,MAAM;EACrD;EACA;EACA,WAAW;EACX,OAAO;EACP,QAAQ;EACR;CACF,CAAC;CACD,MAAM,CAAC,QAAQ,QAAQ,OAAO,OAAO,IACnC,CAAC,OAAO,OAAO,KAAK,OAAO,WAAW,GAAG,OAAO,QAAQ,GAAG,OAAO,QAAQ,GAC1E,EAAE,aAAa,YAAY,CAC7B;CACA,OAAO;EAAE;EAAQ;CAAK;AACxB,CAAC;AAED,MAAM,cAAc,YAClB,UAAU,OAAO,CAAC,CAAC,KACjB,OAAO,QACP,OAAO,cACJ,EAAE,WAAW,SAAS,eACjB,OAAO,OAAO,CACtB,GACA,OAAO,KAAK,EAAE,aAAaC,OAAI,KAAK,MAAM,CAAC,CAC7C;AASF,MAAM,gBAAgB,EACpB,SACA,MACA,KACA,KACA,iBAAiB,kBACjB,SAAS,YAMT,OAAO,IAAI,UAAU,WAAW;CAC9B,MAAM,SAAS,OAAO,aAAa,KAAK,SAAS,MAAM;EACrD;EACA;EACA,WAAW;EACX,OAAO;EACP;CACF,CAAC;CACD,MAAM,CAAC,MAAM,QAAQ,OAAO,OAAO,IACjC,CAAC,OAAO,OAAO,CAAC,KAAK,OAAO,WAAW,GAAG,OAAO,QAAQ,GAAG,OAAO,QAAQ,GAC3E,EAAE,aAAa,YAAY,CAC7B;CACA,OAAO;EAAE,OAAO,SAAS;EAAS,QAAQ;CAAK;AACjD,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM;;AAGvB,MAAa,WAAW;;AAGxB,MAAa,WAAW;;AAGxB,MAAa,cAAc;AAE3B,MAAM,gBAAgB,YACpB,OAAO,OAAO,UAAU,OAAO,CAAC;;AAGlC,MAAa,WAAW;;AAGxB,MAAa,WAAW"}
|
|
@@ -18,6 +18,16 @@ type Spawned<Success> = Effect.Effect<Success, CommandFailed | PlatformError.Pla
|
|
|
18
18
|
declare const succeedsWith: (command: Command) => Spawned<boolean>;
|
|
19
19
|
declare const mustSucceedWith: (command: Command) => Spawned<void>;
|
|
20
20
|
declare const outputWith: (command: Command) => Spawned<string>;
|
|
21
|
+
interface Captured {
|
|
22
|
+
readonly valid: boolean;
|
|
23
|
+
readonly output: string;
|
|
24
|
+
}
|
|
25
|
+
type CapturedCommand = Command & Readonly<{
|
|
26
|
+
output?: "all" | "stdout";
|
|
27
|
+
}>;
|
|
28
|
+
declare const capturedWith: ({ command, args, env, cwd, forceKillAfter, output }: CapturedCommand) => Effect.Effect<Captured, PlatformError.PlatformError, ChildProcessSpawner.ChildProcessSpawner>;
|
|
29
|
+
/** @internal */
|
|
30
|
+
declare const captured: typeof capturedWith;
|
|
21
31
|
/** @internal */
|
|
22
32
|
declare const succeeds: typeof succeedsWith;
|
|
23
33
|
/** @internal */
|
|
@@ -30,4 +40,4 @@ declare const finishedWith: (command: Command) => Spawned<Readonly<{
|
|
|
30
40
|
declare const outputOf: typeof outputWith;
|
|
31
41
|
/** @internal */
|
|
32
42
|
declare const finished: typeof finishedWith;
|
|
33
|
-
export {
|
|
43
|
+
export { captured as a, outputOf as c, CommandFailed as i, succeeds as l, CapturedCommand as n, finished as o, Command as r, mustSucceed as s, Captured as t };
|
package/dist/process.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { type Command, CommandFailed,
|
|
1
|
+
import { a as captured, c as outputOf, i as CommandFailed, l as succeeds, n as CapturedCommand, r as Command, s as mustSucceed, t as Captured } from "./process-z7u_XWgI.mjs";
|
|
2
|
+
export { type Captured, type CapturedCommand, type Command, CommandFailed, captured, mustSucceed, outputOf, succeeds };
|
package/dist/process.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as CommandFailed, n as
|
|
1
|
+
export { t as CommandFailed, n as captured, i as mustSucceed, a as outputOf, o as succeeds } from "./process-DTCkAoL_.mjs";
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { HttpRouter, HttpServerResponse } from "effect/http";
|
|
3
|
-
import {
|
|
3
|
+
import { n as PageSources } from "../headers-DVWS82Vk.mjs";
|
|
4
4
|
/** @stability experimental */
|
|
5
5
|
export declare const isHtml: (response: HttpServerResponse.HttpServerResponse) => boolean;
|
|
6
6
|
/** @stability experimental */
|
|
7
|
-
export declare const securityHeadersFor: (sources: PageSources) => Layer.Layer<never, never, HttpRouter.HttpRouter>;
|
|
8
|
-
/** @stability experimental */
|
|
9
|
-
export declare const securityHeaders: Layer.Layer<never, never, HttpRouter.HttpRouter>;
|
|
7
|
+
export declare const securityHeadersFor: (sources: PageSources) => Layer.Layer<never, never, HttpRouter.HttpRouter>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Option, Record, String, pipe } from "effect";
|
|
2
2
|
import { Headers, HttpEffect, HttpRouter, HttpServerResponse } from "effect/http";
|
|
3
|
-
import {
|
|
3
|
+
import { a as SERVER_RESPONSE_HEADERS, u as serverPageHeaders } from "../headers-DSqz93yF.mjs";
|
|
4
4
|
// src/features/secure-http/model/security-headers.ts
|
|
5
5
|
const CONTENT_TYPE = "content-type";
|
|
6
6
|
const HTML = "text/html";
|
|
@@ -18,8 +18,6 @@ const securityHeadersFor = (sources) => {
|
|
|
18
18
|
const secured = withSecurityHeaders(serverPageHeaders(sources));
|
|
19
19
|
return HttpRouter.middleware((effect) => HttpEffect.withPreResponseHandler(effect, (_request, response) => response.pipe(secured, Effect.succeed)), { global: true });
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
const securityHeaders = securityHeadersFor({});
|
|
23
|
-
export { isHtml, securityHeaders, securityHeadersFor };
|
|
21
|
+
export { isHtml, securityHeadersFor };
|
|
24
22
|
|
|
25
23
|
//# sourceMappingURL=http.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.mjs","names":["Str","Rec"],"sources":["../../src/features/secure-http/model/security-headers.ts"],"sourcesContent":["import { Effect, Option, Record as Rec, String as Str, pipe } from \"effect\";\nimport type { Layer } from \"effect\";\nimport { Headers, HttpEffect, HttpRouter, HttpServerResponse } from \"effect/http\";\nimport type { HttpBody } from \"effect/http\";\n\nimport { SERVER_RESPONSE_HEADERS, serverPageHeaders } from \"#/entities/policy/index.ts\";\nimport type { PageSources } from \"#/entities/policy/index.ts\";\n\nconst CONTENT_TYPE = \"content-type\";\n\nconst HTML = \"text/html\";\n\nconst declaredType = (body: HttpBody.HttpBody.Proto): Option.Option<string> =>\n Option.fromNullishOr(body.contentType);\n\nconst contentTypeOf = (response: HttpServerResponse.HttpServerResponse): Option.Option<string> =>\n pipe(\n declaredType(response.body),\n Option.orElse(() => Headers.get(response.headers, CONTENT_TYPE)),\n );\n\n/** @stability experimental */\nexport const isHtml = (response: HttpServerResponse.HttpServerResponse): boolean =>\n pipe(contentTypeOf(response), Option.exists(Str.startsWith(HTML)));\n\nconst policyOf = (\n page: Readonly<Record<string, string>>,\n response: HttpServerResponse.HttpServerResponse,\n): Readonly<Record<string, string>> => {\n if (isHtml(response)) {\n return page;\n }\n return SERVER_RESPONSE_HEADERS;\n};\n\nconst withSecurityHeaders =\n (page: Readonly<Record<string, string>>) =>\n (response: HttpServerResponse.HttpServerResponse): HttpServerResponse.HttpServerResponse =>\n HttpServerResponse.setHeaders(\n response,\n pipe(\n policyOf(page, response),\n Rec.filter((_value, name) => !Headers.has(response.headers, name)),\n ),\n );\n\n/** @stability experimental */\nexport const securityHeadersFor = (\n sources: PageSources,\n): Layer.Layer<never, never, HttpRouter.HttpRouter> => {\n const secured = withSecurityHeaders(serverPageHeaders(sources));\n return HttpRouter.middleware(\n (effect) =>\n HttpEffect.withPreResponseHandler(effect, (_request, response) =>\n response.pipe(secured, Effect.succeed),\n ),\n { global: true },\n );\n};\n
|
|
1
|
+
{"version":3,"file":"http.mjs","names":["Str","Rec"],"sources":["../../src/features/secure-http/model/security-headers.ts"],"sourcesContent":["import { Effect, Option, Record as Rec, String as Str, pipe } from \"effect\";\nimport type { Layer } from \"effect\";\nimport { Headers, HttpEffect, HttpRouter, HttpServerResponse } from \"effect/http\";\nimport type { HttpBody } from \"effect/http\";\n\nimport { SERVER_RESPONSE_HEADERS, serverPageHeaders } from \"#/entities/policy/index.ts\";\nimport type { PageSources } from \"#/entities/policy/index.ts\";\n\nconst CONTENT_TYPE = \"content-type\";\n\nconst HTML = \"text/html\";\n\nconst declaredType = (body: HttpBody.HttpBody.Proto): Option.Option<string> =>\n Option.fromNullishOr(body.contentType);\n\nconst contentTypeOf = (response: HttpServerResponse.HttpServerResponse): Option.Option<string> =>\n pipe(\n declaredType(response.body),\n Option.orElse(() => Headers.get(response.headers, CONTENT_TYPE)),\n );\n\n/** @stability experimental */\nexport const isHtml = (response: HttpServerResponse.HttpServerResponse): boolean =>\n pipe(contentTypeOf(response), Option.exists(Str.startsWith(HTML)));\n\nconst policyOf = (\n page: Readonly<Record<string, string>>,\n response: HttpServerResponse.HttpServerResponse,\n): Readonly<Record<string, string>> => {\n if (isHtml(response)) {\n return page;\n }\n return SERVER_RESPONSE_HEADERS;\n};\n\nconst withSecurityHeaders =\n (page: Readonly<Record<string, string>>) =>\n (response: HttpServerResponse.HttpServerResponse): HttpServerResponse.HttpServerResponse =>\n HttpServerResponse.setHeaders(\n response,\n pipe(\n policyOf(page, response),\n Rec.filter((_value, name) => !Headers.has(response.headers, name)),\n ),\n );\n\n/** @stability experimental */\nexport const securityHeadersFor = (\n sources: PageSources,\n): Layer.Layer<never, never, HttpRouter.HttpRouter> => {\n const secured = withSecurityHeaders(serverPageHeaders(sources));\n return HttpRouter.middleware(\n (effect) =>\n HttpEffect.withPreResponseHandler(effect, (_request, response) =>\n response.pipe(secured, Effect.succeed),\n ),\n { global: true },\n );\n};\n"],"mappings":";;;;AAQA,MAAM,eAAe;AAErB,MAAM,OAAO;AAEb,MAAM,gBAAgB,SACpB,OAAO,cAAc,KAAK,WAAW;AAEvC,MAAM,iBAAiB,aACrB,KACE,aAAa,SAAS,IAAI,GAC1B,OAAO,aAAa,QAAQ,IAAI,SAAS,SAAS,YAAY,CAAC,CACjE;;AAGF,MAAa,UAAU,aACrB,KAAK,cAAc,QAAQ,GAAG,OAAO,OAAOA,OAAI,WAAW,IAAI,CAAC,CAAC;AAEnE,MAAM,YACJ,MACA,aACqC;CACrC,IAAI,OAAO,QAAQ,GACjB,OAAO;CAET,OAAO;AACT;AAEA,MAAM,uBACH,UACA,aACC,mBAAmB,WACjB,UACA,KACE,SAAS,MAAM,QAAQ,GACvBC,OAAI,QAAQ,QAAQ,SAAS,CAAC,QAAQ,IAAI,SAAS,SAAS,IAAI,CAAC,CACnE,CACF;;AAGJ,MAAa,sBACX,YACqD;CACrD,MAAM,UAAU,oBAAoB,kBAAkB,OAAO,CAAC;CAC9D,OAAO,WAAW,YACf,WACC,WAAW,uBAAuB,SAAS,UAAU,aACnD,SAAS,KAAK,SAAS,OAAO,OAAO,CACvC,GACF,EAAE,QAAQ,KAAK,CACjB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Array, Effect, Option, Record, pipe } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { a as SERVER_RESPONSE_HEADERS } from "../headers-DSqz93yF.mjs";
|
|
3
3
|
// src/features/secure-response/model/response.ts
|
|
4
4
|
const addMissingHeaders = (response) => {
|
|
5
5
|
const missing = pipe(Record.toEntries(SERVER_RESPONSE_HEADERS), Array.filter(([name]) => !response.headers.has(name)));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as headersFileFor, c as pageHashes, i as headerLines, l as pageSlug, n as PageHashes, o as inlineScriptHashes, r as PageHeaders, s as inlineStyleHashes, t as staticPageHeaders, u as sourceHash } from "../index-
|
|
1
|
+
import { a as headersFileFor, c as pageHashes, i as headerLines, l as pageSlug, n as PageHashes, o as inlineScriptHashes, r as PageHeaders, s as inlineStyleHashes, t as staticPageHeaders, u as sourceHash } from "../index-MqLQZR1B.mjs";
|
|
2
2
|
export { type PageHashes, type PageHeaders, headerLines, headersFileFor, inlineScriptHashes, inlineStyleHashes, pageHashes, pageSlug, sourceHash, staticPageHeaders };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as headerLines, r as headersFileFor, i as inlineScriptHashes, a as inlineStyleHashes, o as pageHashes, s as pageSlug, c as sourceHash, t as staticPageHeaders } from "../static-page-headers-
|
|
1
|
+
export { n as headerLines, r as headersFileFor, i as inlineScriptHashes, a as inlineStyleHashes, o as pageHashes, s as pageSlug, c as sourceHash, t as staticPageHeaders } from "../static-page-headers-C7w-AabA.mjs";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as staticPageHeaders } from "../index-
|
|
1
|
+
import { t as staticPageHeaders } from "../index-MqLQZR1B.mjs";
|
|
2
2
|
export { staticPageHeaders };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as staticPageHeaders } from "../static-page-headers-
|
|
1
|
+
export { t as staticPageHeaders } from "../static-page-headers-C7w-AabA.mjs";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export { ASSET_CACHE_CONTROL, EMBEDDED_VIDEO_SOURCES, type PageSources, SECURITY_HEADERS, SECURITY_HEADERS_CREDENTIALLESS, SECURITY_HEADERS_EMBEDDING, SERVER_PAGE_HEADERS, SERVER_RESPONSE_HEADERS, SPECULATION_RULES_FILE, STATIC_PAGE_HEADERS, WEB_ANALYTICS_REPORT_ORIGIN, WEB_ANALYTICS_SCRIPT_ORIGIN, assetHeaders, contentSecurityPolicy, serverPageHeaders };
|
|
1
|
+
import { a as SPECULATION_RULES_FILE, c as contentSecurityPolicy, i as SECURITY_HEADERS_CREDENTIALLESS, l as serverPageHeaders, n as PageSources, o as STATIC_PAGE_HEADERS, r as SECURITY_HEADERS, s as assetHeaders, t as EMBEDDED_VIDEO_SOURCES } from "./headers-DVWS82Vk.mjs";
|
|
2
|
+
import { n as WEB_ANALYTICS_SCRIPT_ORIGIN, t as WEB_ANALYTICS_REPORT_ORIGIN } from "./index-B995c2b6.mjs";
|
|
3
|
+
export { EMBEDDED_VIDEO_SOURCES, type PageSources, SECURITY_HEADERS, SECURITY_HEADERS_CREDENTIALLESS, SPECULATION_RULES_FILE, STATIC_PAGE_HEADERS, WEB_ANALYTICS_REPORT_ORIGIN, WEB_ANALYTICS_SCRIPT_ORIGIN, assetHeaders, contentSecurityPolicy, serverPageHeaders };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as assetHeaders, i as SECURITY_HEADERS_CREDENTIALLESS, l as contentSecurityPolicy, n as EMBEDDED_VIDEO_SOURCES, o as SPECULATION_RULES_FILE, r as SECURITY_HEADERS, s as STATIC_PAGE_HEADERS, u as serverPageHeaders } from "./headers-DSqz93yF.mjs";
|
|
2
2
|
import { n as WEB_ANALYTICS_SCRIPT_ORIGIN, t as WEB_ANALYTICS_REPORT_ORIGIN } from "./web-analytics-CondjbtC.mjs";
|
|
3
|
-
export {
|
|
3
|
+
export { EMBEDDED_VIDEO_SOURCES, SECURITY_HEADERS, SECURITY_HEADERS_CREDENTIALLESS, SPECULATION_RULES_FILE, STATIC_PAGE_HEADERS, WEB_ANALYTICS_REPORT_ORIGIN, WEB_ANALYTICS_SCRIPT_ORIGIN, assetHeaders, contentSecurityPolicy, serverPageHeaders };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Array, Effect, Option, Record, String, pipe } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { i as SECURITY_HEADERS_CREDENTIALLESS, l as contentSecurityPolicy, r as SECURITY_HEADERS, t as ASSET_CACHE_CONTROL } from "./headers-DSqz93yF.mjs";
|
|
3
3
|
import { Base64 } from "effect/encoding";
|
|
4
4
|
// src/features/write-static-headers/model/static.ts
|
|
5
5
|
const encoder = new TextEncoder();
|
|
@@ -91,6 +91,7 @@ const pageRule = ({ home = "", ...options }) => ({ page, hashes }) => [
|
|
|
91
91
|
script: scriptSourcesOf(options.scriptSources)(page),
|
|
92
92
|
style: hashes,
|
|
93
93
|
image: ["blob:"],
|
|
94
|
+
connect: options.connectSources ?? [],
|
|
94
95
|
styleAttr: true
|
|
95
96
|
})}`
|
|
96
97
|
];
|
|
@@ -130,4 +131,4 @@ const staticPageHeaders = (options) => ({
|
|
|
130
131
|
});
|
|
131
132
|
export { inlineStyleHashes as a, sourceHash as c, inlineScriptHashes as i, headerLines as n, pageHashes as o, headersFileFor as r, pageSlug as s, staticPageHeaders as t };
|
|
132
133
|
|
|
133
|
-
//# sourceMappingURL=static-page-headers-
|
|
134
|
+
//# sourceMappingURL=static-page-headers-C7w-AabA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-page-headers-C7w-AabA.mjs","names":["Rec","Arr","pageRule","Str","Rec","Arr","Str"],"sources":["../src/features/write-static-headers/model/static.ts","../src/features/write-static-headers/api/static-page-headers.ts"],"sourcesContent":["import { Array as Arr, Effect, Option, Record as Rec, String as Str, pipe } from \"effect\";\nimport { Base64 } from \"effect/encoding\";\n\nimport { ASSET_CACHE_CONTROL, SECURITY_HEADERS } from \"#/entities/policy/index.ts\";\n\nexport type PageHeaders = Readonly<{ path: string; headers: Readonly<Record<string, string>> }>;\n\nexport type PageHashes = Readonly<{ page: string; hashes: readonly string[] }>;\n\nconst encoder = new TextEncoder();\nconst INDEX_PAGE = /(?<=^|\\/)index\\.html$/u;\nconst HTML_EXTENSION = /\\.html$/u;\nconst INLINE_SCRIPT = /<script(?<attributes>[^>]*)>(?<body>[\\s\\S]*?)<\\/script>/gu;\nconst INLINE_STYLE = /<style(?<attributes>[^>]*)>(?<body>[\\s\\S]*?)<\\/style>/gu;\nconst EXTERNAL = /\\ssrc=/u;\nconst SCRIPT_TYPE = /\\stype=[\"']?(?<type>[^\"'\\s>]+)/u;\nconst EXECUTED_TYPES: ReadonlySet<string> = new Set([\n \"module\",\n \"importmap\",\n \"text/javascript\",\n \"application/javascript\",\n]);\nconst MAX_RULES = 100;\nconst MAX_LINE_LENGTH = 2000;\nconst PREVIEW_START = 0;\nconst PREVIEW_LENGTH = 60;\n\nexport const headerLines = (headers: Readonly<Record<string, string>>): readonly string[] =>\n pipe(\n Rec.toEntries(headers),\n Arr.map(([name, value]) => ` ${name}: ${value}`),\n );\n\nconst detachLines = (headers: Readonly<Record<string, string>>): readonly string[] =>\n pipe(\n Rec.keys(headers),\n Arr.map((name) => ` ! ${name}`),\n );\n\nconst pageRule = ({ path, headers }: PageHeaders): readonly string[] => [\n path,\n ...detachLines(headers),\n ...headerLines(headers),\n];\n\nconst immutableRule = (path: string): readonly string[] => [\n path,\n ` Cache-Control: ${ASSET_CACHE_CONTROL}`,\n];\n\nexport const renderHeadersFile = (rules: readonly (readonly string[])[]): string => {\n if (rules.length > MAX_RULES) {\n throw new RangeError(`_headers は ${MAX_RULES} 個までのルールしか持てない: ${rules.length}`);\n }\n const lines = Arr.flatten(rules);\n const overlong = Arr.findFirst(lines, (line) => line.length > MAX_LINE_LENGTH);\n if (Option.isSome(overlong)) {\n const { value } = overlong;\n const preview = Str.slice(PREVIEW_START, PREVIEW_LENGTH)(value);\n throw new RangeError(\n `_headers は 1 行 ${MAX_LINE_LENGTH} 文字までしか持てない(超えた行は Cloudflare に捨てられ、ヘッダーが付かない): ${preview}… ${value.length} 文字`,\n );\n }\n return pipe(lines, Arr.append(\"\"), Arr.join(\"\\n\"));\n};\n\nexport const headersFileFor =\n (immutablePaths: readonly string[]) =>\n ({\n documentHeaders,\n pages,\n }: Readonly<{\n documentHeaders: Readonly<Record<string, string>>;\n pages: readonly PageHeaders[];\n }>): string => {\n const rules = [\n [\"/*\", ...headerLines(SECURITY_HEADERS), ...headerLines(documentHeaders)],\n ...pipe(pages, Arr.map(pageRule)),\n ...pipe(immutablePaths, Arr.map(immutableRule)),\n ];\n return renderHeadersFile(rules);\n };\n\nexport const sourceHash = (body: string): Effect.Effect<string> =>\n Effect.promise(() => crypto.subtle.digest(\"SHA-256\", encoder.encode(body))).pipe(\n Effect.map((digest) => `'sha256-${Base64.encode(new Uint8Array(digest))}'`),\n );\n\ntype Inline = Readonly<{ attributes: string; body: string }>;\n\nconst groupOf = (groups: Readonly<Record<string, string>> | undefined, name: string): string =>\n pipe(\n Option.fromNullishOr(groups),\n Option.flatMap(Rec.get(name)),\n Option.getOrElse(() => \"\"),\n );\n\nconst inlineElements =\n (pattern: RegExp) =>\n (html: string): readonly Inline[] =>\n pipe(\n html,\n Str.matchAll(pattern),\n Arr.fromIterable,\n Arr.map(({ groups }) => ({\n attributes: groupOf(groups, \"attributes\"),\n body: groupOf(groups, \"body\"),\n })),\n );\n\nconst isExecutedScript = ({ attributes }: Inline): boolean =>\n !EXTERNAL.test(attributes) &&\n pipe(\n Str.match(SCRIPT_TYPE)(attributes),\n Option.match({\n onNone: () => true,\n onSome: ({ groups }) => EXECUTED_TYPES.has(Str.toLowerCase(groupOf(groups, \"type\"))),\n }),\n );\n\nconst inlineHashes =\n (pattern: RegExp, keep: (inline: Inline) => boolean) =>\n (html: string): Effect.Effect<readonly string[]> =>\n pipe(\n inlineElements(pattern)(html),\n Arr.filter(keep),\n Arr.map(({ body }) => body),\n Arr.dedupe,\n (items) => Effect.forEach(items, sourceHash, { concurrency: 1 }),\n );\n\nexport const inlineScriptHashes = inlineHashes(INLINE_SCRIPT, isExecutedScript);\n\nexport const inlineStyleHashes = inlineHashes(INLINE_STYLE, () => true);\n\nexport const pageSlug = (page: string): string =>\n pipe(page, Str.replace(INDEX_PAGE, \"\"), Str.replace(HTML_EXTENSION, \"\"));\n\nexport const pageHashes = <Failure, Requirements>({\n entries,\n read,\n}: Readonly<{\n entries: readonly string[];\n read: (page: string) => Effect.Effect<string, Failure, Requirements>;\n}>): Effect.Effect<readonly PageHashes[], Failure, Requirements> =>\n pipe(entries, Arr.filter(Str.endsWith(\".html\")), (items) =>\n Effect.forEach(\n items,\n (page) =>\n read(page).pipe(\n Effect.flatMap(inlineScriptHashes),\n Effect.map((hashes): PageHashes => ({ page, hashes })),\n ),\n { concurrency: 1 },\n ),\n );\n","import { Array as Arr, Effect, Option, Record as Rec, String as Str, pipe } from \"effect\";\nimport type { HtmlTagDescriptor, Plugin, Rolldown } from \"vite-plus\";\n\nimport {\n ASSET_CACHE_CONTROL,\n SECURITY_HEADERS_CREDENTIALLESS,\n contentSecurityPolicy,\n} from \"#/entities/policy/index.ts\";\nimport {\n headerLines,\n inlineStyleHashes,\n renderHeadersFile,\n} from \"#/features/write-static-headers/model/static.ts\";\n\nconst HEADERS_FILE = \"_headers\";\nconst PAGE_HTML = /^(?:(?<page>.+)\\/)?index\\.html$/u;\n\nexport type StaticPageHeadersOptions = Readonly<{\n assetsDir: string;\n home?: string;\n scriptSources: Readonly<Record<string, readonly string[]>>;\n connectSources?: readonly string[];\n permissions: Readonly<Record<string, string>>;\n headTags: readonly HtmlTagDescriptor[];\n}>;\n\ntype PageStyles = Readonly<{ page: string; hashes: readonly string[] }>;\n\nexport type HtmlFile = Readonly<{ fileName: string; html: string }>;\n\nconst scriptSourcesOf =\n (scriptSources: StaticPageHeadersOptions[\"scriptSources\"]) =>\n (page: string): readonly string[] =>\n pipe(\n Rec.toEntries(scriptSources),\n Arr.filter(([scope]) => page === scope || Str.startsWith(`${scope}/`)(page)),\n Arr.flatMap(([, sources]) => sources),\n );\n\nconst homePattern = (home: string): string =>\n pipe([home], Arr.filter(Str.isNonEmpty), Arr.prepend(\"\"), Arr.append(\"\"), Arr.join(\"/\"));\n\nconst pagePattern =\n (home: string) =>\n (page: string): string =>\n Option.match(\n Option.liftPredicate(page, (name) => name !== home),\n {\n onNone: () => homePattern(home),\n onSome: (name) => `/${name}/*`,\n },\n );\n\nconst headersOf =\n (permissions: StaticPageHeadersOptions[\"permissions\"]) =>\n (page: string): Readonly<Record<string, string>> =>\n Option.match(Rec.get(permissions, page), {\n onNone: () => SECURITY_HEADERS_CREDENTIALLESS,\n onSome: (policy) => ({ ...SECURITY_HEADERS_CREDENTIALLESS, \"Permissions-Policy\": policy }),\n });\n\nconst pageRule =\n ({ home = \"\", ...options }: StaticPageHeadersOptions) =>\n ({ page, hashes }: PageStyles): readonly string[] => [\n pagePattern(home)(page),\n ...headerLines(headersOf(options.permissions)(page)),\n ` Content-Security-Policy: ${contentSecurityPolicy({\n script: scriptSourcesOf(options.scriptSources)(page),\n style: hashes,\n image: [\"blob:\"],\n connect: options.connectSources ?? [],\n styleAttr: true,\n })}`,\n ];\n\nconst assetsRule = (assetsDir: string): readonly string[] => [\n `/${assetsDir}/*`,\n ...headerLines(SECURITY_HEADERS_CREDENTIALLESS),\n ` Cache-Control: ${ASSET_CACHE_CONTROL}`,\n];\n\nconst headersFile = (options: StaticPageHeadersOptions, pages: readonly PageStyles[]): string => {\n const rules = pipe(pages, Arr.map(pageRule(options)));\n return renderHeadersFile([...rules, assetsRule(options.assetsDir)]);\n};\n\nconst pageOf = (fileName: string): Option.Option<string> =>\n pipe(\n Option.fromNullishOr(PAGE_HTML.exec(fileName)),\n Option.map(({ groups }) =>\n pipe(\n Option.fromNullishOr(groups),\n Option.flatMap(Rec.get(\"page\")),\n Option.flatMap(Option.fromNullishOr),\n Option.getOrElse(() => \"\"),\n ),\n ),\n );\n\nconst pageStyles = ({ fileName, html }: HtmlFile): Option.Option<Effect.Effect<PageStyles>> =>\n pipe(\n pageOf(fileName),\n Option.map((page) =>\n pipe(\n inlineStyleHashes(html),\n Effect.map((hashes) => ({ page, hashes })),\n ),\n ),\n );\n\nexport const bundleHeaders =\n (options: StaticPageHeadersOptions) =>\n (files: readonly HtmlFile[]): Effect.Effect<string> =>\n pipe(\n files,\n Arr.flatMap((file) => Option.toArray(pageStyles(file))),\n (styles) => Effect.all(styles, { concurrency: 1 }),\n Effect.map((pages) => headersFile(options, pages)),\n );\n\nexport const staticPageHeaders = (options: StaticPageHeadersOptions): Plugin => ({\n name: \"static-page-headers\",\n apply: \"build\",\n transformIndexHtml: () => [...options.headTags],\n generateBundle: {\n order: \"post\",\n handler(_options, bundle): Promise<void> {\n const files = pipe(\n Rec.values(bundle),\n Arr.filter((output): output is Rolldown.OutputAsset => output.type === \"asset\"),\n Arr.flatMap(({ fileName, source }) =>\n pipe(\n Option.liftPredicate(source, Str.isString),\n Option.map((html) => ({ fileName, html })),\n Option.toArray,\n ),\n ),\n );\n return Effect.runPromise(\n bundleHeaders(options)(files).pipe(\n Effect.flatMap((source) =>\n Effect.sync(() => this.emitFile({ type: \"asset\", fileName: HEADERS_FILE, source })),\n ),\n Effect.asVoid,\n ),\n );\n },\n },\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,MAAI,QAAQ,WAA2C,OAAO,SAAS,OAAO,GAC9EA,MAAI,SAAS,EAAE,UAAU,aACvB,KACE,OAAO,cAAc,QAAQC,OAAI,QAAQ,GACzC,OAAO,KAAK,UAAU;IAAE;IAAU;GAAK,EAAE,GACzC,OAAO,OACT,CACF,CACF;GACA,OAAO,OAAO,WACZ,cAAc,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAC5B,OAAO,SAAS,WACd,OAAO,WAAW,KAAK,SAAS;IAAE,MAAM;IAAS,UAAU;IAAc;GAAO,CAAC,CAAC,CACpF,GACA,OAAO,MACT,CACF;EACF;CACF;AACF"}
|
package/dist/text.d.mts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
export declare const toJson: (value: unknown) => string;
|
|
3
|
+
export declare const groupsOf: (pattern: RegExp) => (text: string) => Option.Option<Readonly<Partial<Record<string, string>>>>;
|
|
4
|
+
export declare const groupOf: (name: string) => (match: RegExpMatchArray | null | undefined) => Option.Option<string>;
|
package/dist/text.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
import { n as groupsOf, t as groupOf } from "./match-groups-MH1j-WE-.mjs";
|
|
3
|
+
// src/shared/lib/json-text.ts
|
|
4
|
+
const encodeJson = Schema.encodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
|
5
|
+
const toJson = (value) => Option.getOrElse(encodeJson(value), () => String(value));
|
|
6
|
+
export { groupOf, groupsOf, toJson };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=text.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.mjs","names":[],"sources":["../src/shared/lib/json-text.ts"],"sourcesContent":["import { Option, Schema } from \"effect\";\n\nconst encodeJson = Schema.encodeUnknownOption(Schema.fromJsonString(Schema.Unknown));\n\nexport const toJson = (value: unknown): string =>\n Option.getOrElse(encodeJson(value), () => String(value));\n"],"mappings":";;;AAEA,MAAM,aAAa,OAAO,oBAAoB,OAAO,eAAe,OAAO,OAAO,CAAC;AAEnF,MAAa,UAAU,UACrB,OAAO,UAAU,WAAW,KAAK,SAAS,OAAO,KAAK,CAAC"}
|
package/dist/ui/portfolio.d.mts
CHANGED
package/dist/ui/portfolio.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as portfolio, n as sectionUrl
|
|
1
|
+
export { t as portfolio, n as sectionUrl } from "../portfolio-VMbxOrAS.mjs";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { n as WEB_ANALYTICS_SCRIPT_ORIGIN, t as WEB_ANALYTICS_REPORT_ORIGIN } from "../
|
|
2
|
-
import "../index-Cz3K0tg_.mjs";
|
|
1
|
+
import { n as WEB_ANALYTICS_SCRIPT_ORIGIN, t as WEB_ANALYTICS_REPORT_ORIGIN } from "../index-B995c2b6.mjs";
|
|
3
2
|
export declare const WEB_ANALYTICS_BEACON: {
|
|
4
3
|
readonly src: "https://static.cloudflareinsights.com/beacon.min.js/v8c78df7c7c0f484497ecbca7046644da1771523124516";
|
|
5
4
|
readonly integrity: "sha512-8DS7rgIrAmghBFwoOTujcf6D9rXvH8xm8JQ1Ja01h9QX8EzXldiszufYa4IFfKdLUKTTrnSFXLDkUEOTrZQ8Qg==";
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
declare const TallyFields: Schema.Struct<{
|
|
3
|
+
readonly library: Schema.String;
|
|
4
|
+
readonly version: Schema.String;
|
|
5
|
+
readonly kind: Schema.String;
|
|
6
|
+
readonly name: Schema.String;
|
|
7
|
+
readonly calls: Schema.Finite;
|
|
8
|
+
}>;
|
|
9
|
+
type Tally = typeof TallyFields.Type;
|
|
10
|
+
export declare const TallyList: Schema.$Array<Schema.Struct<{
|
|
11
|
+
readonly library: Schema.String;
|
|
12
|
+
readonly version: Schema.String;
|
|
13
|
+
readonly kind: Schema.String;
|
|
14
|
+
readonly name: Schema.String;
|
|
15
|
+
readonly calls: Schema.Finite;
|
|
16
|
+
}>>;
|
|
17
|
+
export declare const CALLS_METRIC = "code.usage.calls";
|
|
2
18
|
interface Attribute {
|
|
3
19
|
readonly key: string;
|
|
4
20
|
readonly value: {
|
|
@@ -40,4 +56,4 @@ interface UsageWindow {
|
|
|
40
56
|
export declare const talliesIn: (text: string) => readonly Tally[];
|
|
41
57
|
export declare const mergeTallies: (tallies: readonly Tally[]) => readonly Tally[];
|
|
42
58
|
export declare const usageMetricsOf: (window: UsageWindow) => (tallies: readonly Tally[]) => UsageMetrics;
|
|
43
|
-
export {
|
|
59
|
+
export type { Attribute, DataPoint, Tally, UsageMetrics, UsageWindow };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Array, Option, Record, Schema, pipe } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { r as TallyList, t as CALLS_METRIC } from "../usage-tally-BD3f41V8.mjs";
|
|
3
3
|
// src/shared/lib/usage-report.ts
|
|
4
4
|
const DELTA = 1;
|
|
5
5
|
const SCOPE = "usage-meter";
|
|
@@ -46,6 +46,6 @@ const usageMetricsOf = (window) => (tallies) => ({ resourceMetrics: [{
|
|
|
46
46
|
}]
|
|
47
47
|
}]
|
|
48
48
|
}] });
|
|
49
|
-
export { CALLS_METRIC,
|
|
49
|
+
export { CALLS_METRIC, TallyList, mergeTallies, talliesIn, usageMetricsOf };
|
|
50
50
|
|
|
51
51
|
//# sourceMappingURL=report.mjs.map
|
package/dist/usage-meter.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { n as SPOOL_ENV } from "./usage-tally-BBhBouif.mjs";
|
|
2
1
|
import "effect";
|
|
3
2
|
interface UsageMeter {
|
|
4
3
|
readonly rules: <Name extends string, Rule>(rules: Readonly<Record<Name, Rule>>) => Readonly<Record<Name, Rule>>;
|
|
@@ -10,4 +9,4 @@ interface RulePlugin {
|
|
|
10
9
|
readonly rules?: Readonly<Record<string, unknown>> | undefined;
|
|
11
10
|
}
|
|
12
11
|
export declare const usageMeter: (moduleUrl: string) => UsageMeter;
|
|
13
|
-
export {
|
|
12
|
+
export type { RulePlugin, UsageMeter };
|
package/dist/usage-meter.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Layer
|
|
1
|
+
import { Layer } from "effect";
|
|
2
2
|
import { n as Runner, t as Run } from "../run-C1nPjDih.mjs";
|
|
3
|
-
export declare const inSpanContext: <Message>(logger: Logger.Logger<Message, void>) => Logger.Logger<Message, void>;
|
|
4
3
|
export declare const layer: Layer.Layer<never>;
|
|
5
4
|
export declare const runner: Runner;
|
|
6
5
|
export declare const run: Run<never>;
|
|
@@ -63,6 +63,6 @@ const consoleLogger = Logger.formatStructured.pipe(Logger.withLeveledConsole, in
|
|
|
63
63
|
const layer = Layer.mergeAll(Layer.succeed(Tracer.Tracer, workersTracer), Logger.layer([consoleLogger]));
|
|
64
64
|
const runner = runnerWith(layer);
|
|
65
65
|
const run = runner(Layer.empty);
|
|
66
|
-
export {
|
|
66
|
+
export { layer, run, runner };
|
|
67
67
|
|
|
68
68
|
//# sourceMappingURL=effect.mjs.map
|