@webpieces/hook-runtime 0.4.925 → 0.4.927

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/hook-runtime",
3
- "version": "0.4.925",
3
+ "version": "0.4.927",
4
4
  "description": "Agent hook protocol, normalized events, and fail-closed application boundary.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -22,16 +22,16 @@
22
22
  "dependencies": {
23
23
  "inversify": "7.10.4",
24
24
  "reflect-metadata": "0.2.2",
25
- "@webpieces/rules-config": "0.4.925",
26
- "@webpieces/tooling-common": "0.4.925",
25
+ "@webpieces/rules-config": "0.4.927",
26
+ "@webpieces/tooling-common": "0.4.927",
27
27
  "tslib": "2.8.1",
28
- "@webpieces/rules-sdk": "0.4.925"
28
+ "@webpieces/rules-sdk": "0.4.927"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
33
  "devDependencies": {
34
- "@webpieces/tooling-testkit": "0.4.925"
34
+ "@webpieces/tooling-testkit": "0.4.927"
35
35
  },
36
36
  "types": "./src/index.d.ts"
37
37
  }
package/src/hook-app.js CHANGED
@@ -3,12 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HookBootFailure = exports.HookApp = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const inversify_1 = require("inversify");
6
+ const tooling_common_1 = require("@webpieces/tooling-common");
6
7
  const hook_evaluator_1 = require("./hook-evaluator");
7
8
  const outcome_1 = require("./outcome");
8
9
  const hook_ports_1 = require("./hook-ports");
9
10
  const response_1 = require("./response");
10
11
  const to_error_1 = require("./to-error");
11
12
  const CRASH_PREFIX = '[ai-hooks] hook crashed unexpectedly — failing closed: ';
13
+ /**
14
+ * The deny reason for anything that escaped the evaluator. An InformAiError (a config or policy-file
15
+ * problem) is a NORMAL deny carrying its own repair instructions — never a crash (#1273). Only a genuine
16
+ * bug gets the crash prefix.
17
+ */
18
+ // webpieces-disable no-function-outside-class -- sibling of the two protocol boundaries below, shared by both
19
+ function denyReason(error) {
20
+ return error instanceof tooling_common_1.InformAiError ? error.message : `${CRASH_PREFIX}${error.message}`;
21
+ }
12
22
  let HookApp = class HookApp {
13
23
  stdin;
14
24
  stdout;
@@ -33,7 +43,7 @@ let HookApp = class HookApp {
33
43
  }
34
44
  catch (err) {
35
45
  const error = (0, to_error_1.toError)(err);
36
- return new outcome_1.HookOutcome(`${(0, response_1.denyJson)(null, `${CRASH_PREFIX}${error.message}`)}\n`, 0);
46
+ return new outcome_1.HookOutcome(`${(0, response_1.denyJson)(null, denyReason(error))}\n`, 0);
37
47
  }
38
48
  }
39
49
  };
@@ -49,7 +59,7 @@ class HookBootFailure {
49
59
  // webpieces-disable no-any-unknown -- a process rejection is unknown by construction and is immediately narrowed through toError().
50
60
  report(err) {
51
61
  const error = (0, to_error_1.toError)(err);
52
- process.stdout.write(`${(0, response_1.denyJson)(null, `${CRASH_PREFIX}${error.message}`)}\n`);
62
+ process.stdout.write(`${(0, response_1.denyJson)(null, denyReason(error))}\n`);
53
63
  // webpieces-disable no-process-exit-outside-main -- last-resort protocol boundary before DI exists.
54
64
  process.exit(0);
55
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"hook-app.js","sourceRoot":"","sources":["../../../../../packages/tooling/hook-runtime/src/hook-app.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAE3D,qDAAiD;AACjD,uCAAkD;AAClD,6CAAgF;AAChF,yCAAsC;AACtC,yCAAqC;AAErC,MAAM,YAAY,GAAG,yDAAyD,CAAC;AAGxE,IAAM,OAAO,GAAb,MAAM,OAAO;IAEK;IACA;IACA;IACA;IAJrB,YACqB,KAAsB,EACtB,MAAsB,EACtB,WAA4B,EAC5B,SAAwB;QAHxB,UAAK,GAAL,KAAK,CAAiB;QACtB,WAAM,GAAN,MAAM,CAAgB;QACtB,gBAAW,GAAX,WAAW,CAAi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AC,IAAI,CAAC,CAAC;QAC/E,oGAAoG;QACpG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;CACJ;AARD,0CAQC","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\n\nimport { HookEvaluator } from './hook-evaluator';\nimport { HookArgs, HookOutcome } from './outcome';\nimport { HookProcessExit, HookStdinSource, HookStdoutSink } from './hook-ports';\nimport { denyJson } from './response';\nimport { toError } from './to-error';\n\nconst CRASH_PREFIX = '[ai-hooks] hook crashed unexpectedly — failing closed: ';\n\n@injectable(bindingScopeValues.Singleton)\nexport class HookApp {\n constructor(\n private readonly stdin: HookStdinSource,\n private readonly stdout: HookStdoutSink,\n private readonly processExit: HookProcessExit,\n private readonly evaluator: HookEvaluator,\n ) {}\n\n async run(args: HookArgs): Promise<void> {\n const outcome = await this.decide(args);\n if (outcome.stdout !== '') this.stdout.write(outcome.stdout);\n this.processExit.exit(outcome.exitCode);\n }\n\n private async decide(args: HookArgs): Promise<HookOutcome> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- fail-closed boundary converts port/evaluator faults into an explicit protocol deny.\n try {\n return await this.evaluator.evaluate(await this.stdin.read(), args);\n } catch (err: unknown) {\n const error = toError(err);\n return new HookOutcome(`${denyJson(null, `${CRASH_PREFIX}${error.message}`)}\\n`, 0);\n }\n }\n}\n\nexport class HookBootFailure {\n // webpieces-disable no-any-unknown -- a process rejection is unknown by construction and is immediately narrowed through toError().\n report(err: unknown): void {\n const error = toError(err);\n process.stdout.write(`${denyJson(null, `${CRASH_PREFIX}${error.message}`)}\\n`);\n // webpieces-disable no-process-exit-outside-main -- last-resort protocol boundary before DI exists.\n process.exit(0);\n }\n}\n"]}
1
+ {"version":3,"file":"hook-app.js","sourceRoot":"","sources":["../../../../../packages/tooling/hook-runtime/src/hook-app.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,8DAA0D;AAE1D,qDAAiD;AACjD,uCAAkD;AAClD,6CAAg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K,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;CACJ,CAAA;AAvBY,0BAAO;kBAAP,OAAO;IADnB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGT,4BAAe;QACd,2BAAc;QACT,4BAAe;QACjB,8BAAa;GALpC,OAAO,CAuBnB;AAED,MAAa,eAAe;IACxB,oIAAoI;IACpI,MAAM,CAAC,GAAY;QACf,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,mBAAQ,EAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/D,oGAAoG;QACpG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;CACJ;AARD,0CAQC","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { HookEvaluator } from './hook-evaluator';\nimport { HookArgs, HookOutcome } from './outcome';\nimport { HookProcessExit, HookStdinSource, HookStdoutSink } from './hook-ports';\nimport { denyJson } from './response';\nimport { toError } from './to-error';\n\nconst CRASH_PREFIX = '[ai-hooks] hook crashed unexpectedly — failing closed: ';\n\n/**\n * The deny reason for anything that escaped the evaluator. An InformAiError (a config or policy-file\n * problem) is a NORMAL deny carrying its own repair instructions — never a crash (#1273). Only a genuine\n * bug gets the crash prefix.\n */\n// webpieces-disable no-function-outside-class -- sibling of the two protocol boundaries below, shared by both\nfunction denyReason(error: Error): string {\n return error instanceof InformAiError ? error.message : `${CRASH_PREFIX}${error.message}`;\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class HookApp {\n constructor(\n private readonly stdin: HookStdinSource,\n private readonly stdout: HookStdoutSink,\n private readonly processExit: HookProcessExit,\n private readonly evaluator: HookEvaluator,\n ) {}\n\n async run(args: HookArgs): Promise<void> {\n const outcome = await this.decide(args);\n if (outcome.stdout !== '') this.stdout.write(outcome.stdout);\n this.processExit.exit(outcome.exitCode);\n }\n\n private async decide(args: HookArgs): Promise<HookOutcome> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- fail-closed boundary converts port/evaluator faults into an explicit protocol deny.\n try {\n return await this.evaluator.evaluate(await this.stdin.read(), args);\n } catch (err: unknown) {\n const error = toError(err);\n return new HookOutcome(`${denyJson(null, denyReason(error))}\\n`, 0);\n }\n }\n}\n\nexport class HookBootFailure {\n // webpieces-disable no-any-unknown -- a process rejection is unknown by construction and is immediately narrowed through toError().\n report(err: unknown): void {\n const error = toError(err);\n process.stdout.write(`${denyJson(null, denyReason(error))}\\n`);\n // webpieces-disable no-process-exit-outside-main -- last-resort protocol boundary before DI exists.\n process.exit(0);\n }\n}\n"]}