@alint-js/plugin-js 0.4.0 → 0.6.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.
@@ -0,0 +1,8 @@
1
+ import { r as tryImport } from "./index-DoHiaFQM-CRsQPut_.mjs";
2
+ //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.8_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_fc4c9b616e7b9dad1be842cce987659a/node_modules/xsschema/dist/effect-Df2gY8Wx.js
3
+ const getToJsonSchemaFn = async () => {
4
+ const { JSONSchema } = await tryImport(import("./esm-DxmkD6o9.mjs"), "effect");
5
+ return (schema) => JSONSchema.make(schema);
6
+ };
7
+ //#endregion
8
+ export { getToJsonSchemaFn };
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.7_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_2fbd9cf5ae1608dbd5cb0576dee823ee/node_modules/xsschema/dist/index-DoHiaFQM.js
1
+ //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.8_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_fc4c9b616e7b9dad1be842cce987659a/node_modules/xsschema/dist/index-DoHiaFQM.js
2
2
  const strictJsonSchema = (schema) => ({
3
3
  ...schema,
4
4
  additionalProperties: false,
package/dist/index.d.mts CHANGED
@@ -746,7 +746,7 @@ interface Config$1<TIssue extends BaseIssue$1<unknown>> {
746
746
  readonly abortPipeEarly?: boolean | undefined;
747
747
  }
748
748
  //#endregion
749
- //#region ../core/dist/types-deBCDA4_.d.mts
749
+ //#region ../core/dist/types-Cm5Z7Fll.d.mts
750
750
  //#region src/config/types.d.ts
751
751
  type ModelSize = 'large' | 'medium' | 'small';
752
752
  interface RunnerCacheConfig {
@@ -826,6 +826,7 @@ interface AlintConfigItem {
826
826
  files?: readonly (readonly string[] | string)[];
827
827
  ignore?: IgnoreConfig;
828
828
  ignores?: readonly string[];
829
+ integrations?: IntegrationsConfig;
829
830
  language?: string;
830
831
  languageOptions?: Record<string, unknown>;
831
832
  linterOptions?: AlintLinterOptions;
@@ -870,6 +871,9 @@ interface DirectoryTarget {
870
871
  interface IgnoreConfig {
871
872
  gitignore?: boolean;
872
873
  }
874
+ interface IntegrationsConfig {
875
+ stopGate?: StopGateConfig;
876
+ }
873
877
  interface LanguageDefinition {
874
878
  extensions?: readonly string[];
875
879
  extract: (file: SourceFile, context: LanguageContext) => Awaitable<SourceTarget[]>;
@@ -973,8 +977,10 @@ interface RuleInferenceUsageRecord {
973
977
  totalTokens?: number;
974
978
  }
975
979
  /**
976
- * - `'any'` — every registered language, and never a failure. A rule that works from `FunctionInfo`
977
- * alone wants this: a language pack the user installs later is covered without a new release.
980
+ * - `'any'` — every language except `plaintext`, and never a failure. Plain text is what a file
981
+ * falls back to when no language claims it, so a rule asking for any language is asking for a
982
+ * real one. Rules that work from `FunctionInfo` alone want this: install another language pack
983
+ * and they cover it too, unchanged.
978
984
  * - A list of language ids — `LanguageDefinition.name` values such as `go` or `typescript`, never
979
985
  * file extensions. The rule handles exactly these. Files of other languages are skipped
980
986
  * rather than failed, so one plugin can carry rules for several languages behind one `files:`
@@ -1008,6 +1014,12 @@ interface RuleWithHandler {
1008
1014
  onTargetProject?: never;
1009
1015
  onTargetWith: (target: Target) => Awaitable<void>;
1010
1016
  }
1017
+ interface StopGateConfig {
1018
+ enabled?: boolean;
1019
+ target?: StopGateTarget;
1020
+ timeoutMs?: number;
1021
+ }
1022
+ type StopGateTarget = 'all' | 'dirty-files';
1011
1023
  type Target = DirectoryTarget | PlannedSourceTarget | ProjectTarget;
1012
1024
  //#endregion
1013
1025
  //#region ../../node_modules/.pnpm/valibot@1.4.2_typescript@6.0.3/node_modules/valibot/dist/index.d.mts
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as __exportAll, r as __toESM, t as __commonJSMin } from "./rolldown-runtime-DC62tzP2.mjs";
2
- import { n as strictJsonSchema } from "./index-DoHiaFQM-DimeKT70.mjs";
2
+ import { n as strictJsonSchema } from "./index-DoHiaFQM-CRsQPut_.mjs";
3
3
  import { isAbsolute, normalize, relative, resolve, sep } from "node:path";
4
4
  import * as nativeFs from "fs";
5
5
  import { readdir, readdirSync, realpath, realpathSync, stat, statSync } from "fs";
@@ -1347,7 +1347,7 @@ function toStandardJsonSchema(schema) {
1347
1347
  } };
1348
1348
  }
1349
1349
  //#endregion
1350
- //#region ../../node_modules/.pnpm/@xsai+shared@0.5.0-beta.7/node_modules/@xsai/shared/dist/index.js
1350
+ //#region ../../node_modules/.pnpm/@xsai+shared@0.5.0-beta.8/node_modules/@xsai/shared/dist/index.js
1351
1351
  var XSAIError = class extends Error {
1352
1352
  constructor(message, code, options = {}) {
1353
1353
  super(message, { cause: options.cause });
@@ -1394,12 +1394,6 @@ var JSONParseError = class extends XSAIError {
1394
1394
  this.text = options.text;
1395
1395
  }
1396
1396
  };
1397
- var ToolExecutionError = class extends XSAIError {
1398
- constructor(message, options) {
1399
- super(message, "tool_execution_error", options);
1400
- Object.assign(this, options);
1401
- }
1402
- };
1403
1397
  const strCamelToSnake = (str) => str.replace(/[A-Z]/g, (s) => `_${s.toLowerCase()}`);
1404
1398
  const objCamelToSnake = (obj) => Object.fromEntries(Object.entries(obj).map(([k, v]) => [strCamelToSnake(k), v]));
1405
1399
  const clean = (obj) => Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
@@ -1468,7 +1462,7 @@ const trampoline = async (fn) => {
1468
1462
  return result;
1469
1463
  };
1470
1464
  //#endregion
1471
- //#region ../../node_modules/.pnpm/@xsai+shared-chat@0.5.0-beta.7/node_modules/@xsai/shared-chat/dist/index.js
1465
+ //#region ../../node_modules/.pnpm/@xsai+shared-chat@0.5.0-beta.8/node_modules/@xsai/shared-chat/dist/index.js
1472
1466
  const chat = async (options) => postJSON("chat/completions", {
1473
1467
  ...options,
1474
1468
  maxSteps: void 0,
@@ -1493,7 +1487,12 @@ const toToolMessageContent = (result) => {
1493
1487
  }
1494
1488
  return JSON.stringify(result);
1495
1489
  };
1496
- const isAbortError = (error, abortSignal) => abortSignal?.aborted === true && error === abortSignal.reason || error instanceof Error && error.name === "AbortError";
1490
+ const toCompletionToolCall = (toolCall) => ({
1491
+ args: toolCall.function.arguments ?? "",
1492
+ toolCallId: toolCall.id,
1493
+ toolCallType: "function",
1494
+ toolName: toolCall.function.name ?? ""
1495
+ });
1497
1496
  const parseToolInput = async (tool, input) => {
1498
1497
  let result;
1499
1498
  try {
@@ -1516,17 +1515,18 @@ const parseToolInput = async (tool, input) => {
1516
1515
  }
1517
1516
  return result;
1518
1517
  };
1519
- const runTool = async (tool, options) => {
1518
+ const createErrorToolResult = (toolCall, args, cause, abortSignal) => ({
1519
+ args,
1520
+ isError: true,
1521
+ result: `Tool "${toolCall.toolName}" execution failed: ${abortSignal?.aborted === true ? "This operation was aborted" : cause instanceof Error ? cause.message : String(cause)}`,
1522
+ toolCallId: toolCall.toolCallId,
1523
+ toolName: toolCall.toolName
1524
+ });
1525
+ const catchToolError = async (toolCall, abortSignal, callback) => {
1520
1526
  try {
1521
- return await tool.execute(options.args, options.toolExecuteOptions);
1527
+ return await callback(toolCall);
1522
1528
  } catch (cause) {
1523
- if (isAbortError(cause, options.toolExecuteOptions.abortSignal)) throw cause;
1524
- throw new ToolExecutionError(`Tool "${tool.function.name}" execution failed.`, {
1525
- cause,
1526
- toolCallId: options.toolExecuteOptions.toolCallId,
1527
- toolInput: options.args,
1528
- toolName: tool.function.name
1529
- });
1529
+ return createErrorToolResult(toolCall, InvalidToolInputError.isInstance(cause) ? cause.toolInput : toolCall.args, cause, abortSignal);
1530
1530
  }
1531
1531
  };
1532
1532
  const assertSameToolCallId = (source, next, label) => {
@@ -1573,29 +1573,34 @@ const executeTool = async ({ abortSignal, messages, postToolCall, preToolCall, t
1573
1573
  toolName
1574
1574
  };
1575
1575
  let completionToolResult;
1576
- const preToolCallResult = await preToolCall?.(completionToolCall, toolExecuteOptions);
1576
+ let parsedArgs;
1577
+ let shouldPostToolCall = false;
1578
+ const preToolCallResult = await catchToolError(completionToolCall, abortSignal, async (toolCall2) => preToolCall?.(toolCall2, toolExecuteOptions));
1577
1579
  if (preToolCallResult) {
1578
1580
  assertSameToolCallId(completionToolCall.toolCallId, preToolCallResult, "preToolCallResult");
1579
1581
  if ("result" in preToolCallResult) completionToolResult = preToolCallResult;
1580
1582
  else completionToolCall = preToolCallResult;
1581
1583
  }
1582
- if (completionToolResult == null) {
1584
+ completionToolResult ??= await catchToolError(completionToolCall, abortSignal, async () => {
1583
1585
  const tool = findTool(tools, completionToolCall.toolName, completionToolCall);
1584
- const args = await parseToolInput(tool, completionToolCall.args);
1585
- completionToolResult = {
1586
- args,
1587
- result: await runTool(tool, {
1588
- args,
1589
- toolExecuteOptions
1590
- }),
1586
+ parsedArgs = await parseToolInput(tool, completionToolCall.args);
1587
+ if (abortSignal?.aborted === true) return createErrorToolResult(completionToolCall, parsedArgs, abortSignal.reason, abortSignal);
1588
+ shouldPostToolCall = true;
1589
+ const result = await tool.execute(parsedArgs, toolExecuteOptions);
1590
+ return {
1591
+ args: parsedArgs,
1592
+ result,
1591
1593
  toolCallId: completionToolCall.toolCallId,
1592
1594
  toolName: completionToolCall.toolName
1593
1595
  };
1594
- }
1595
- const postToolCallResult = await postToolCall?.(completionToolResult, toolExecuteOptions);
1596
- if (postToolCallResult) {
1597
- assertSameToolCallId(completionToolResult.toolCallId, postToolCallResult, "postToolCallResult");
1598
- completionToolResult = postToolCallResult;
1596
+ });
1597
+ if (shouldPostToolCall) {
1598
+ completionToolResult.args = parsedArgs;
1599
+ const postToolCallResult = await catchToolError(completionToolResult, abortSignal, async (toolResult) => postToolCall?.(toolResult, toolExecuteOptions));
1600
+ if (postToolCallResult) {
1601
+ assertSameToolCallId(completionToolResult.toolCallId, postToolCallResult, "postToolCallResult");
1602
+ completionToolResult = postToolCallResult;
1603
+ }
1599
1604
  }
1600
1605
  return {
1601
1606
  completionToolCall,
@@ -1629,7 +1634,7 @@ const normalizeChatCompletionUsage = (usage) => ({
1629
1634
  totalTokens: usage.total_tokens
1630
1635
  });
1631
1636
  //#endregion
1632
- //#region ../../node_modules/.pnpm/@xsai+generate-text@0.5.0-beta.7/node_modules/@xsai/generate-text/dist/index.js
1637
+ //#region ../../node_modules/.pnpm/@xsai+generate-text@0.5.0-beta.8/node_modules/@xsai/generate-text/dist/index.js
1633
1638
  const rawGenerateText = async (options) => {
1634
1639
  const messages = options.steps == null ? structuredClone(options.messages) : options.messages;
1635
1640
  const steps = options.steps ?? [];
@@ -1660,13 +1665,26 @@ const rawGenerateText = async (options) => {
1660
1665
  responseBody
1661
1666
  });
1662
1667
  }
1663
- const toolCalls = [];
1664
- const toolResults = [];
1665
1668
  const { finish_reason: finishReason, message } = choices[0];
1666
1669
  const msgToolCalls = message?.tool_calls ?? [];
1670
+ const toolCalls = msgToolCalls.map(toCompletionToolCall);
1671
+ const toolResults = [];
1667
1672
  const stopWhen = options.stopWhen ?? stepCountAtLeast(1);
1668
1673
  messages.push(message);
1669
- if (msgToolCalls.length > 0) {
1674
+ const step = {
1675
+ finishReason,
1676
+ text: Array.isArray(message.content) ? message.content.filter((m) => m.type === "text").map((m) => m.text).join("\n") : message.content,
1677
+ toolCalls,
1678
+ toolResults,
1679
+ usage
1680
+ };
1681
+ if (options.abortSignal?.aborted === true) throw options.abortSignal.reason ?? /* @__PURE__ */ new Error("This operation was aborted");
1682
+ const stop = shouldStop(stopWhen, {
1683
+ input: messages,
1684
+ step,
1685
+ steps: [...steps, step]
1686
+ });
1687
+ if (!stop && msgToolCalls.length > 0) {
1670
1688
  const results = await Promise.all(msgToolCalls.map(async (toolCall) => executeTool({
1671
1689
  abortSignal: options.abortSignal,
1672
1690
  messages,
@@ -1675,6 +1693,7 @@ const rawGenerateText = async (options) => {
1675
1693
  toolCall,
1676
1694
  tools: options.tools
1677
1695
  })));
1696
+ toolCalls.length = 0;
1678
1697
  for (const { completionToolCall, completionToolResult, result } of results) {
1679
1698
  toolCalls.push(completionToolCall);
1680
1699
  toolResults.push(completionToolResult);
@@ -1685,19 +1704,7 @@ const rawGenerateText = async (options) => {
1685
1704
  });
1686
1705
  }
1687
1706
  }
1688
- const step = {
1689
- finishReason,
1690
- text: Array.isArray(message.content) ? message.content.filter((m) => m.type === "text").map((m) => m.text).join("\n") : message.content,
1691
- toolCalls,
1692
- toolResults,
1693
- usage
1694
- };
1695
- const stop = shouldStop(stopWhen, {
1696
- input: messages,
1697
- step,
1698
- steps: [...steps, step]
1699
- });
1700
- const willContinue = toolCalls.length > 0 && !stop;
1707
+ const willContinue = toolCalls.length > 0 && !stop && !options.abortSignal?.aborted;
1701
1708
  steps.push(step);
1702
1709
  if (options.onStepFinish) await options.onStepFinish(step);
1703
1710
  if (!willContinue) return {
@@ -1721,7 +1728,7 @@ const rawGenerateText = async (options) => {
1721
1728
  };
1722
1729
  const generateText = async (options) => trampoline(async () => rawGenerateText(options));
1723
1730
  //#endregion
1724
- //#region ../../node_modules/.pnpm/@xsai+tool@0.5.0-beta.7_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3____f38a8212ad071b3d82e34970cca0a89a/node_modules/@xsai/tool/dist/index.js
1731
+ //#region ../../node_modules/.pnpm/@xsai+tool@0.5.0-beta.8_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3____61a066324c36664bceb0a54542d37106/node_modules/@xsai/tool/dist/index.js
1725
1732
  const rawTool = ({ description, execute, name, parameters, strict }) => ({
1726
1733
  execute,
1727
1734
  function: {
@@ -1881,20 +1888,32 @@ function parseStructuredResponse(schema, toolName, response) {
1881
1888
  retriable: true
1882
1889
  };
1883
1890
  const toolResults = response.toolResults.filter((result) => result.toolName === toolName);
1884
- if (toolResults.length === 0) return {
1891
+ const toolCalls = response.toolCalls.filter((call) => call.toolName === toolName);
1892
+ const matches = toolResults.length + toolCalls.length;
1893
+ if (matches === 0) return {
1885
1894
  error: `Missing ${toolName} tool result; finishReason=${response.finishReason}`,
1886
1895
  ok: false,
1887
1896
  retriable: true
1888
1897
  };
1889
- if (toolResults.length > 1) return {
1890
- error: `Expected one ${toolName} tool result, received ${toolResults.length}`,
1898
+ if (matches > 1) return {
1899
+ error: `Expected one ${toolName} tool result, received ${matches}`,
1891
1900
  ok: false,
1892
1901
  retriable: true
1893
1902
  };
1903
+ let value;
1904
+ try {
1905
+ value = toolResults[0] !== void 0 ? toolResults[0].result : JSON.parse(toolCalls[0].args);
1906
+ } catch (error) {
1907
+ return {
1908
+ error: `Tool call failed before validation: ${errorMessageFrom(error) ?? String(error)}`,
1909
+ ok: false,
1910
+ retriable: true
1911
+ };
1912
+ }
1894
1913
  try {
1895
1914
  return {
1896
1915
  ok: true,
1897
- value: parse(schema, toolResults[0].result)
1916
+ value: parse(schema, value)
1898
1917
  };
1899
1918
  } catch (error) {
1900
1919
  return {
@@ -0,0 +1,8 @@
1
+ import { r as tryImport } from "./index-DoHiaFQM-CRsQPut_.mjs";
2
+ //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.8_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_fc4c9b616e7b9dad1be842cce987659a/node_modules/xsschema/dist/sury-BoOvxlMw.js
3
+ const getToJsonSchemaFn = async () => {
4
+ const { toJSONSchema } = await tryImport(import("./S-0EivakUR.mjs"), "sury");
5
+ return (schema) => toJSONSchema(schema);
6
+ };
7
+ //#endregion
8
+ export { getToJsonSchemaFn };
@@ -0,0 +1,8 @@
1
+ import { r as tryImport } from "./index-DoHiaFQM-CRsQPut_.mjs";
2
+ //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.8_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_fc4c9b616e7b9dad1be842cce987659a/node_modules/xsschema/dist/valibot-_ibN3zSD.js
3
+ const getToJsonSchemaFn = async () => {
4
+ const { toJsonSchema } = await tryImport(import("./index.mjs").then((n) => n.t), "@valibot/to-json-schema");
5
+ return (schema) => toJsonSchema(schema);
6
+ };
7
+ //#endregion
8
+ export { getToJsonSchemaFn };
@@ -1,5 +1,5 @@
1
- import { t as missingDependenciesUrl } from "./index-DoHiaFQM-DimeKT70.mjs";
2
- //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.7_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_2fbd9cf5ae1608dbd5cb0576dee823ee/node_modules/xsschema/dist/zod-DjyNjMBF.js
1
+ import { t as missingDependenciesUrl } from "./index-DoHiaFQM-CRsQPut_.mjs";
2
+ //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.8_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_fc4c9b616e7b9dad1be842cce987659a/node_modules/xsschema/dist/zod-DjyNjMBF.js
3
3
  const getToJsonSchemaFn = async () => {
4
4
  let zodV4toJSONSchema = (_schema) => {
5
5
  throw new Error(`xsschema: Missing zod v4 dependencies "zod". see ${missingDependenciesUrl}`);
package/package.json CHANGED
@@ -1,7 +1,23 @@
1
1
  {
2
2
  "name": "@alint-js/plugin-js",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.6.0",
5
+ "description": "Model-backed JavaScript and TypeScript review rules for alint",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/moeru-ai/alint.git",
10
+ "directory": "packages/plugin-js"
11
+ },
12
+ "keywords": [
13
+ "alint",
14
+ "lint",
15
+ "plugin",
16
+ "javascript",
17
+ "typescript",
18
+ "code-analysis",
19
+ "ai"
20
+ ],
5
21
  "exports": {
6
22
  ".": {
7
23
  "types": "./dist/index.d.mts",
@@ -16,9 +32,9 @@
16
32
  "@valibot/to-json-schema": "^1.7.1",
17
33
  "apeira": "^0.0.7",
18
34
  "valibot": "^1.4.2",
19
- "@alint-js/plugin": "0.4.0",
20
- "@alint-js/tools-fs": "0.4.0",
21
- "@alint-js/core": "0.4.0"
35
+ "@alint-js/core": "0.6.0",
36
+ "@alint-js/tools-fs": "0.6.0",
37
+ "@alint-js/plugin": "0.6.0"
22
38
  },
23
39
  "scripts": {
24
40
  "build": "tsdown",
@@ -1,8 +0,0 @@
1
- import { r as tryImport } from "./index-DoHiaFQM-DimeKT70.mjs";
2
- //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.7_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_2fbd9cf5ae1608dbd5cb0576dee823ee/node_modules/xsschema/dist/effect-Df2gY8Wx.js
3
- const getToJsonSchemaFn = async () => {
4
- const { JSONSchema } = await tryImport(import("./esm-DxmkD6o9.mjs"), "effect");
5
- return (schema) => JSONSchema.make(schema);
6
- };
7
- //#endregion
8
- export { getToJsonSchemaFn };
@@ -1,8 +0,0 @@
1
- import { r as tryImport } from "./index-DoHiaFQM-DimeKT70.mjs";
2
- //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.7_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_2fbd9cf5ae1608dbd5cb0576dee823ee/node_modules/xsschema/dist/sury-BoOvxlMw.js
3
- const getToJsonSchemaFn = async () => {
4
- const { toJSONSchema } = await tryImport(import("./S-0EivakUR.mjs"), "sury");
5
- return (schema) => toJSONSchema(schema);
6
- };
7
- //#endregion
8
- export { getToJsonSchemaFn };
@@ -1,8 +0,0 @@
1
- import { r as tryImport } from "./index-DoHiaFQM-DimeKT70.mjs";
2
- //#region ../../node_modules/.pnpm/xsschema@0.5.0-beta.7_@valibot+to-json-schema@1.7.1_valibot@1.4.2_typescript@6.0.3___ef_2fbd9cf5ae1608dbd5cb0576dee823ee/node_modules/xsschema/dist/valibot-_ibN3zSD.js
3
- const getToJsonSchemaFn = async () => {
4
- const { toJsonSchema } = await tryImport(import("./index.mjs").then((n) => n.t), "@valibot/to-json-schema");
5
- return (schema) => toJsonSchema(schema);
6
- };
7
- //#endregion
8
- export { getToJsonSchemaFn };