@alpacakit/script-hooks 0.1.0-beta.36

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Masahiro Tonomura (codemafia0000)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @alpacakit/script-hooks
2
+
3
+ Validate and resolve registered local script paths, match them by string key,
4
+ and run JSON payloads through `.sh`, `.js`, `.mjs`, or `.py` hooks. The root
5
+ entry exports the schemas, path resolver, registry, result, and observation
6
+ contracts; import the subprocess adapter from `@alpacakit/script-hooks/node`.
7
+
8
+ The Node runner writes one JSON value followed by LF to stdin and returns
9
+ expected script exits and timeouts as result values. Timeout teardown uses a
10
+ POSIX process group and is therefore supported on Linux and macOS. The runner
11
+ does not choose or filter the environment, sandbox scripts, schedule
12
+ concurrency, or retry failures; those policies belong to the host application.
@@ -0,0 +1,6 @@
1
+ export * from "./model.js";
2
+ export * from "./observation.js";
3
+ export * from "./path.js";
4
+ export * from "./registry.js";
5
+ export * from "./schema.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./model.js";
2
+ export * from "./observation.js";
3
+ export * from "./path.js";
4
+ export * from "./registry.js";
5
+ export * from "./schema.js";
@@ -0,0 +1,72 @@
1
+ import type { Brand, JsonValue } from "@alpacakit/core";
2
+ export type ScriptHookPath = Brand<string, "ScriptHookPath">;
3
+ export type ScriptHookAbsolutePath = Brand<string, "ScriptHookAbsolutePath">;
4
+ export type ScriptHookEntry<Key extends string> = {
5
+ readonly path: ScriptHookPath;
6
+ readonly on: readonly Key[];
7
+ };
8
+ export type ResolvedScriptHookEntry<Key extends string> = ScriptHookEntry<Key> & {
9
+ readonly absolutePath: ScriptHookAbsolutePath;
10
+ };
11
+ export interface ScriptHookRegistry<Key extends string, Entry extends ResolvedScriptHookEntry<Key> = ResolvedScriptHookEntry<Key>> {
12
+ list(): readonly Entry[];
13
+ matching(key: Key): readonly Entry[];
14
+ }
15
+ export type ResolveScriptHookPathResult = {
16
+ readonly kind: "resolved";
17
+ readonly absolutePath: ScriptHookAbsolutePath;
18
+ } | {
19
+ readonly kind: "outside_root";
20
+ }
21
+ /** The candidate (or a path component) does not exist: an expected failure
22
+ * for a user-supplied hook path, not a fault. */
23
+ | {
24
+ readonly kind: "missing";
25
+ };
26
+ export type ScriptHookTermination = {
27
+ readonly kind: "exit";
28
+ readonly exitCode: number;
29
+ } | {
30
+ readonly kind: "signal";
31
+ readonly signal: string;
32
+ } | {
33
+ readonly kind: "unknown";
34
+ };
35
+ export type ScriptHookRunResult = {
36
+ readonly kind: "succeeded";
37
+ readonly stderrTail: string | null;
38
+ } | {
39
+ readonly kind: "failed";
40
+ readonly stderrTail: string | null;
41
+ readonly termination: ScriptHookTermination;
42
+ } | {
43
+ readonly kind: "timed_out";
44
+ readonly stderrTail: string | null;
45
+ };
46
+ export type ScriptHookObservedRunResult = {
47
+ readonly kind: "succeeded";
48
+ readonly stderrTail: string;
49
+ } | Exclude<ScriptHookRunResult, {
50
+ readonly kind: "succeeded";
51
+ }>;
52
+ export interface ScriptHookRunner<Payload extends JsonValue = JsonValue> {
53
+ run(input: {
54
+ readonly hookPath: ScriptHookAbsolutePath;
55
+ readonly payload: Payload;
56
+ }): Promise<ScriptHookRunResult>;
57
+ }
58
+ export type ScriptHookObservation<Payload extends JsonValue = JsonValue> = {
59
+ readonly kind: "run";
60
+ readonly payload: Payload;
61
+ readonly hookPath: ScriptHookAbsolutePath;
62
+ readonly result: ScriptHookObservedRunResult;
63
+ } | {
64
+ readonly kind: "runner_failure";
65
+ readonly payload: Payload;
66
+ readonly hookPath: ScriptHookAbsolutePath;
67
+ readonly message: string;
68
+ };
69
+ export interface ScriptHookObserver<Payload extends JsonValue = JsonValue> {
70
+ report(observation: ScriptHookObservation<Payload>): void | Promise<void>;
71
+ }
72
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE7D,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;AAE7E,MAAM,MAAM,eAAe,CAAC,GAAG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AM,CAAC,WAAW,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3E"}
package/dist/model.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/node.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { createAgentsExecScriptHookRunner } from "./runner.js";
2
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC"}
package/dist/node.js ADDED
@@ -0,0 +1 @@
1
+ export { createAgentsExecScriptHookRunner } from "./runner.js";
@@ -0,0 +1,5 @@
1
+ import type { JsonValue } from "@alpacakit/core";
2
+ import type { ScriptHookObservation, ScriptHookObservedRunResult, ScriptHookObserver, ScriptHookRunResult } from "./model.js";
3
+ export declare function isScriptHookRunResultObservable(result: ScriptHookRunResult): result is ScriptHookObservedRunResult;
4
+ export declare function reportScriptHookObservationSafely<Payload extends JsonValue>(observer: ScriptHookObserver<Payload>, observation: ScriptHookObservation<Payload>): Promise<void>;
5
+ //# sourceMappingURL=observation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EACV,qBAAqB,EACrB,2BAA2B,EAC3B,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,mBAAmB,GAC1B,MAAM,IAAI,2BAA2B,CAEvC;AAED,wBAAsB,iCAAiC,CACrD,OAAO,SAAS,SAAS,EAEzB,QAAQ,EAAE,kBAAkB,CAAC,OAAO,CAAC,EACrC,WAAW,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAC1C,OAAO,CAAC,IAAI,CAAC,CAMf"}
@@ -0,0 +1,11 @@
1
+ export function isScriptHookRunResultObservable(result) {
2
+ return result.kind !== "succeeded" || result.stderrTail !== null;
3
+ }
4
+ export async function reportScriptHookObservationSafely(observer, observation) {
5
+ try {
6
+ await observer.report(observation);
7
+ }
8
+ catch {
9
+ // Observation is diagnostic-only and never alters execution flow.
10
+ }
11
+ }
package/dist/path.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { ResolveScriptHookPathResult, ScriptHookPath } from "./model.js";
2
+ export declare function resolveScriptHookPath(root: string, relative: ScriptHookPath): Promise<ResolveScriptHookPathResult>;
3
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,2BAA2B,EAE3B,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,cAAc,GACvB,OAAO,CAAC,2BAA2B,CAAC,CAuBtC"}
package/dist/path.js ADDED
@@ -0,0 +1,31 @@
1
+ import { realpath } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export async function resolveScriptHookPath(root, relative) {
4
+ const canonicalRoot = await realpath(root);
5
+ let canonicalCandidate;
6
+ try {
7
+ canonicalCandidate = await realpath(path.resolve(root, relative));
8
+ }
9
+ catch (error) {
10
+ if (isMissingPathError(error)) {
11
+ return { kind: "missing" };
12
+ }
13
+ throw error;
14
+ }
15
+ const relativeToRoot = path.relative(canonicalRoot, canonicalCandidate);
16
+ if (relativeToRoot === ".." ||
17
+ relativeToRoot.startsWith(`..${path.sep}`) ||
18
+ path.isAbsolute(relativeToRoot)) {
19
+ return { kind: "outside_root" };
20
+ }
21
+ return {
22
+ kind: "resolved",
23
+ absolutePath: canonicalCandidate,
24
+ };
25
+ }
26
+ function isMissingPathError(error) {
27
+ return (error instanceof Error &&
28
+ "code" in error &&
29
+ (error.code === "ENOENT" ||
30
+ error.code === "ENOTDIR"));
31
+ }
@@ -0,0 +1,3 @@
1
+ import type { ResolvedScriptHookEntry, ScriptHookRegistry } from "./model.js";
2
+ export declare function createScriptHookRegistry<Key extends string, Entry extends ResolvedScriptHookEntry<Key>>(entries: readonly Entry[]): ScriptHookRegistry<Key, Entry>;
3
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE9E,wBAAgB,wBAAwB,CACtC,GAAG,SAAS,MAAM,EAClB,KAAK,SAAS,uBAAuB,CAAC,GAAG,CAAC,EAC1C,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAK3D"}
@@ -0,0 +1,6 @@
1
+ export function createScriptHookRegistry(entries) {
2
+ return {
3
+ list: () => [...entries],
4
+ matching: (key) => entries.filter((entry) => entry.on.includes(key)),
5
+ };
6
+ }
@@ -0,0 +1,12 @@
1
+ import { type Clock, type Exec } from "@alpacakit/agents";
2
+ import type { JsonValue } from "@alpacakit/core";
3
+ import type { ScriptHookRunner } from "./model.js";
4
+ export declare function createAgentsExecScriptHookRunner<Payload extends JsonValue>(input: {
5
+ readonly exec: Exec;
6
+ readonly clock: Clock;
7
+ readonly baseEnv: Readonly<Record<string, string>>;
8
+ readonly cwd: string;
9
+ readonly timeoutMs: number;
10
+ readonly killGraceMs: number;
11
+ }): ScriptHookRunner<Payload>;
12
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,KAAK,EACV,KAAK,IAAI,EAEV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AAWpB,wBAAgB,gCAAgC,CAC9C,OAAO,SAAS,SAAS,EACzB,KAAK,EAAE;IACP,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAyE5B"}
package/dist/runner.js ADDED
@@ -0,0 +1,110 @@
1
+ import { extname } from "node:path";
2
+ import { OUTPUT_CHANNEL, PROCESS_SIGNAL, redactSecrets, } from "@alpacakit/agents";
3
+ const STDERR_MAX_CHARS = 4_000;
4
+ const STDERR_COLLECTION_MAX_CHARS = STDERR_MAX_CHARS * 2;
5
+ const RUNNER_BY_EXTENSION = {
6
+ ".sh": "bash",
7
+ ".js": "node",
8
+ ".mjs": "node",
9
+ ".py": "python3",
10
+ };
11
+ export function createAgentsExecScriptHookRunner(input) {
12
+ return {
13
+ run: async ({ hookPath, payload }) => {
14
+ const child = input.exec.spawn({
15
+ command: runnerForPath(hookPath),
16
+ args: [hookPath],
17
+ cwd: input.cwd,
18
+ env: { ...input.baseEnv },
19
+ stdin: `${JSON.stringify(payload)}\n`,
20
+ processGroup: true,
21
+ });
22
+ let stderr = "";
23
+ let timedOut = false;
24
+ let resolveEscalation = () => { };
25
+ let rejectEscalation = () => { };
26
+ const escalation = new Promise((resolve, reject) => {
27
+ resolveEscalation = resolve;
28
+ rejectEscalation = reject;
29
+ });
30
+ void escalation.catch(() => { });
31
+ let rejectSignalFailure = () => { };
32
+ const signalFailure = new Promise((_resolve, reject) => {
33
+ rejectSignalFailure = reject;
34
+ });
35
+ void signalFailure.catch(() => { });
36
+ const cancelTimeout = input.clock.setTimeout(() => {
37
+ timedOut = true;
38
+ try {
39
+ child.kill(PROCESS_SIGNAL.sigterm);
40
+ }
41
+ catch (error) {
42
+ rejectSignalFailure(error);
43
+ }
44
+ input.clock.setTimeout(() => {
45
+ try {
46
+ child.kill(PROCESS_SIGNAL.sigkill);
47
+ resolveEscalation();
48
+ }
49
+ catch (error) {
50
+ rejectEscalation(error);
51
+ rejectSignalFailure(error);
52
+ }
53
+ }, input.killGraceMs);
54
+ }, input.timeoutMs);
55
+ try {
56
+ const collectOutput = (async () => {
57
+ for await (const chunk of child.chunks) {
58
+ if (chunk.channel === OUTPUT_CHANNEL.stderr) {
59
+ stderr = appendTail(stderr, chunk.text);
60
+ }
61
+ }
62
+ })();
63
+ const [exit] = await Promise.race([
64
+ Promise.all([child.exit, collectOutput]),
65
+ signalFailure,
66
+ ]);
67
+ const stderrTail = summarizeStderr(stderr);
68
+ if (timedOut) {
69
+ await escalation;
70
+ return { kind: "timed_out", stderrTail };
71
+ }
72
+ if (exit.code === 0) {
73
+ return { kind: "succeeded", stderrTail };
74
+ }
75
+ return {
76
+ kind: "failed",
77
+ termination: terminationFromExit(exit),
78
+ stderrTail,
79
+ };
80
+ }
81
+ finally {
82
+ cancelTimeout();
83
+ }
84
+ },
85
+ };
86
+ }
87
+ function runnerForPath(filePath) {
88
+ const extension = extname(filePath).toLowerCase();
89
+ const runner = RUNNER_BY_EXTENSION[extension];
90
+ if (runner === undefined) {
91
+ throw new Error(`Unsupported script hook extension: ${extension}`);
92
+ }
93
+ return runner;
94
+ }
95
+ function terminationFromExit(exit) {
96
+ if (exit.code !== null) {
97
+ return { kind: "exit", exitCode: exit.code };
98
+ }
99
+ if (exit.signal !== null) {
100
+ return { kind: "signal", signal: exit.signal };
101
+ }
102
+ return { kind: "unknown" };
103
+ }
104
+ function appendTail(current, chunk) {
105
+ return `${current}${chunk}`.slice(-STDERR_COLLECTION_MAX_CHARS);
106
+ }
107
+ function summarizeStderr(stderr) {
108
+ const summary = redactSecrets(stderr).trim();
109
+ return summary === "" ? null : summary.slice(-STDERR_MAX_CHARS);
110
+ }
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ import type { ScriptHookEntry } from "./model.js";
3
+ export declare const scriptHookPathSchema: z.ZodType<import("@alpacakit/core").Brand<string, "ScriptHookPath">, unknown, z.core.$ZodTypeInternals<import("@alpacakit/core").Brand<string, "ScriptHookPath">, unknown>>;
4
+ export declare function createScriptHookEntrySchema<Key extends string>(keySchema: z.ZodType<Key>): z.ZodType<ScriptHookEntry<Key>>;
5
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAkB,MAAM,YAAY,CAAC;AAMlE,eAAO,MAAM,oBAAoB,6KAEc,CAAC;AAEhD,wBAAgB,2BAA2B,CAAC,GAAG,SAAS,MAAM,EAC5D,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GACxB,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAWjC"}
package/dist/schema.js ADDED
@@ -0,0 +1,24 @@
1
+ import { brandedStringSchema, strictReadonlyObject } from "@alpacakit/core";
2
+ import { posix, win32, extname } from "node:path";
3
+ import { z } from "zod";
4
+ const SUPPORTED_EXTENSIONS = new Set([".sh", ".js", ".mjs", ".py"]);
5
+ const PATH_ERROR = "Expected a non-traversing relative .sh, .js, .mjs, or .py hook path.";
6
+ export const scriptHookPathSchema = brandedStringSchema().refine(isSupportedRelativePath, PATH_ERROR);
7
+ export function createScriptHookEntrySchema(keySchema) {
8
+ return strictReadonlyObject({
9
+ path: scriptHookPathSchema,
10
+ on: z
11
+ .array(keySchema)
12
+ .min(1)
13
+ .refine((keys) => new Set(keys).size === keys.length, {
14
+ message: "Expected each script hook key only once.",
15
+ })
16
+ .readonly(),
17
+ });
18
+ }
19
+ function isSupportedRelativePath(value) {
20
+ return (!posix.isAbsolute(value) &&
21
+ !win32.isAbsolute(value) &&
22
+ !value.split(/[\\/]/u).includes("..") &&
23
+ SUPPORTED_EXTENSIONS.has(extname(value).toLowerCase()));
24
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@alpacakit/script-hooks",
3
+ "version": "0.1.0-beta.36",
4
+ "description": "Validate, register, and run local JSON-fed script hooks.",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public",
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./node": {
17
+ "types": "./dist/node.d.ts",
18
+ "import": "./dist/node.js"
19
+ }
20
+ },
21
+ "types": "./dist/index.d.ts",
22
+ "files": [
23
+ "dist",
24
+ "README*.md",
25
+ "LICENSE"
26
+ ],
27
+ "dependencies": {
28
+ "@alpacakit/core": "0.1.0-beta.36",
29
+ "@alpacakit/agents": "0.1.0-beta.36"
30
+ },
31
+ "peerDependencies": {
32
+ "zod": "^4.3.6"
33
+ },
34
+ "devDependencies": {
35
+ "typescript": "^5.9.3",
36
+ "vitest": "^4.0.18",
37
+ "zod": "4.3.6"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc -p tsconfig.build.json",
41
+ "typecheck": "tsc -p tsconfig.json --noEmit",
42
+ "test": "vitest run"
43
+ }
44
+ }