@krisada-m/ksd-intelligence 0.0.0-stage → 1.1.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.
Files changed (119) hide show
  1. package/.antigravity-plugin/plugin.json +20 -0
  2. package/LICENSE +21 -0
  3. package/README.md +195 -2
  4. package/agy-skills/erosiano-review/SKILL.md +17 -0
  5. package/dist/adapters/agy/skills.js +252 -0
  6. package/dist/adapters/cli/check-changed.js +3 -0
  7. package/dist/adapters/cli/main.js +1013 -0
  8. package/dist/adapters/cli/policy-bin.js +10 -0
  9. package/dist/adapters/cli/review-verdict.js +3 -0
  10. package/dist/adapters/omp/extension.js +884 -0
  11. package/dist/adapters/omp/skills.js +130 -0
  12. package/dist/adapters/ui/hud.js +389 -0
  13. package/dist/adapters/ui/tree.js +471 -0
  14. package/dist/core/audit/index.js +2 -0
  15. package/dist/core/audit/log.js +505 -0
  16. package/dist/core/audit/summary.js +188 -0
  17. package/dist/core/changes/changes.js +591 -0
  18. package/dist/core/changes/git.js +266 -0
  19. package/dist/core/changes/plan.js +109 -0
  20. package/dist/core/changes/render.js +356 -0
  21. package/dist/core/engine/build.js +178 -0
  22. package/dist/core/engine/child.js +389 -0
  23. package/dist/core/engine/host.js +206 -0
  24. package/dist/core/engine/lock.js +133 -0
  25. package/dist/core/engine/protocol.js +43 -0
  26. package/dist/core/engine/runtime.js +44 -0
  27. package/dist/core/engine/status.js +452 -0
  28. package/dist/core/engine/typescript.js +194 -0
  29. package/dist/core/engine/workspace.js +72 -0
  30. package/dist/core/graph/graph.js +127 -0
  31. package/dist/core/graph/limits.js +16 -0
  32. package/dist/core/impact/query.js +1292 -0
  33. package/dist/core/impact/render.js +590 -0
  34. package/dist/core/impact/session.js +694 -0
  35. package/dist/core/indexing/declarations.js +455 -0
  36. package/dist/core/indexing/differential.js +345 -0
  37. package/dist/core/indexing/doctor.js +120 -0
  38. package/dist/core/indexing/indexer.js +811 -0
  39. package/dist/core/indexing/keys.js +451 -0
  40. package/dist/core/indexing/lexical.js +212 -0
  41. package/dist/core/indexing/packages.js +57 -0
  42. package/dist/core/indexing/program.js +171 -0
  43. package/dist/core/indexing/resolve.js +1004 -0
  44. package/dist/core/indexing/stamp.js +52 -0
  45. package/dist/core/indexing/surface.js +335 -0
  46. package/dist/core/indexing/ui-progress.js +37 -0
  47. package/dist/core/indexing/verify.js +76 -0
  48. package/dist/core/kernel/config.js +383 -0
  49. package/dist/core/kernel/glob.js +105 -0
  50. package/dist/core/kernel/guards.js +4 -0
  51. package/dist/core/kernel/types.js +3 -0
  52. package/dist/core/kernel/verdict.js +142 -0
  53. package/dist/core/knowledge/anchors.js +139 -0
  54. package/dist/core/knowledge/knowledge.js +95 -0
  55. package/dist/core/knowledge/learning.js +102 -0
  56. package/dist/core/knowledge/render.js +76 -0
  57. package/dist/core/knowledge/store.js +109 -0
  58. package/dist/core/knowledge/yaml.js +87 -0
  59. package/dist/core/search/lexical.js +382 -0
  60. package/dist/core/search/render.js +98 -0
  61. package/dist/core/search/segments.js +118 -0
  62. package/dist/core/verify/parse.js +127 -0
  63. package/dist/core/verify/render.js +67 -0
  64. package/dist/core/verify/report.js +40 -0
  65. package/dist/core/verify/revision.js +79 -0
  66. package/dist/core/verify/run.js +117 -0
  67. package/dist/core/verify/store.js +66 -0
  68. package/dist/core/verify/verify.js +173 -0
  69. package/dist/core/workspace/init.js +267 -0
  70. package/dist/core/workspace/probe.js +56 -0
  71. package/dist/core/workspace/scan.js +420 -0
  72. package/dist/engineering/baseline.js +337 -0
  73. package/dist/engineering/change-scope.js +500 -0
  74. package/dist/engineering/check-changed.js +40 -0
  75. package/dist/engineering/config.js +129 -0
  76. package/dist/engineering/dist/policy.d.ts +17 -0
  77. package/dist/engineering/dist/policy.js +150 -0
  78. package/dist/engineering/dist/runtime.d.ts +40 -0
  79. package/dist/engineering/dist/runtime.js +77 -0
  80. package/dist/engineering/dist/sdlc.d.ts +7 -0
  81. package/dist/engineering/dist/sdlc.js +27 -0
  82. package/dist/engineering/eslint-rules/index.js +107 -0
  83. package/dist/engineering/index.d.ts +7 -0
  84. package/dist/engineering/index.js +319 -0
  85. package/dist/engineering/intelligence.js +44 -0
  86. package/dist/engineering/package.json +36 -0
  87. package/dist/engineering/policy.js +2 -0
  88. package/dist/engineering/practice-tool.js +72 -0
  89. package/dist/engineering/practices.js +283 -0
  90. package/dist/engineering/practices.json +2453 -0
  91. package/dist/engineering/review-verdict.js +262 -0
  92. package/dist/engineering/sdlc.js +2 -0
  93. package/dist/index.js +20 -0
  94. package/dist/storage/records.js +245 -0
  95. package/dist/storage/sqlite.js +314 -0
  96. package/dist/workflow/catalog.js +69 -0
  97. package/dist/workflow/classify.js +55 -0
  98. package/dist/workflow/loader.js +140 -0
  99. package/dist/workflow/packs.js +469 -0
  100. package/dist/workflow/registry.js +359 -0
  101. package/dist/workflow/render.js +61 -0
  102. package/dist/workflow/router.js +141 -0
  103. package/dist/workflow/sources.js +229 -0
  104. package/dist/workflow/types.js +44 -0
  105. package/dist/workflow/updates.js +532 -0
  106. package/engineering.lock.json +94 -0
  107. package/package.json +81 -4
  108. package/rules/engineering.md +20 -0
  109. package/scripts/agy-mcp.mjs +27 -0
  110. package/scripts/mcp/engineering.mjs +91 -0
  111. package/scripts/mcp/stdio.mjs +304 -0
  112. package/scripts/mcp/tools.mjs +491 -0
  113. package/skills/ksd-intelligence/SKILL.md +54 -0
  114. package/skills/matt-sdlc/SKILL.md +42 -0
  115. package/skills/osmani-quality/SKILL.md +38 -0
  116. package/skills/poteto-mode/SKILL.md +40 -0
  117. package/skills/pstack-analysis/SKILL.md +36 -0
  118. package/skills.lock.json +71 -0
  119. package/skills.registry.json +181 -0
@@ -0,0 +1,150 @@
1
+ import { KSD_MODES } from "./sdlc.js";
2
+ // Keep this policy orthogonal to Ponytail's simplicity and over-engineering guidance.
3
+ export const SECTION_KEY = "erosiano-dev";
4
+ export const POLICY_MARKER = "[erosiano-dev Policy]";
5
+ export const POLICY_END = "[End erosiano-dev Policy]";
6
+ /** A complete line consisting only of a policy marker: the stable marker or a numbered legacy version. */
7
+ const COMPLETE_MARKER_LINE = /^\[(?:Engineering Proxy|erosiano-dev) Policy(?: v\d+(?:\.\d+)*)?\]\r?$/;
8
+ /** An array element is owned when it BEGINS with the stable or a numbered legacy marker (existing array contract). */
9
+ const LEADING_MARKER = /^\[(?:Engineering Proxy|erosiano-dev) Policy(?: v\d+(?:\.\d+)*)?\]/;
10
+ const changed = (next, base) => next !== base;
11
+ /**
12
+ * Locate complete owned blocks in a string prompt: each runs from a dedicated marker line to the next
13
+ * end-marker line. A marker line that is never closed, or one that is met again before its end, leaves the
14
+ * block unterminated and the whole correction denied (never guess its end or drop unrelated content).
15
+ */
16
+ function findStringBlocks(base) {
17
+ const lines = [];
18
+ let position = 0;
19
+ while (position < base.length) {
20
+ const newlineAt = base.indexOf("\n", position);
21
+ const end = newlineAt === -1 ? base.length : newlineAt + 1;
22
+ lines.push({ text: base.slice(position, newlineAt === -1 ? base.length : newlineAt), start: position, end });
23
+ if (newlineAt === -1)
24
+ break;
25
+ position = end;
26
+ }
27
+ const blocks = [];
28
+ let unterminated = false;
29
+ let index = 0;
30
+ while (index < lines.length) {
31
+ const line = lines[index];
32
+ if (!COMPLETE_MARKER_LINE.test(line.text)) {
33
+ index += 1;
34
+ continue;
35
+ }
36
+ const expectedEnd = line.text.startsWith("[Engineering Proxy Policy") ? "[End Engineering Proxy Policy]" : POLICY_END;
37
+ let blockEnd = -1;
38
+ for (let probe = index + 1; probe < lines.length; probe++) {
39
+ const candidate = lines[probe];
40
+ if (candidate.text.replace(/\r$/, "") === expectedEnd) {
41
+ blockEnd = candidate.start + expectedEnd.length;
42
+ index = probe + 1;
43
+ break;
44
+ }
45
+ if (COMPLETE_MARKER_LINE.test(candidate.text) || candidate.text.replace(/\r$/, "") === POLICY_END || candidate.text.replace(/\r$/, "") === "[End Engineering Proxy Policy]") {
46
+ unterminated = true;
47
+ break;
48
+ }
49
+ }
50
+ if (blockEnd < 0) {
51
+ unterminated = true;
52
+ break;
53
+ }
54
+ blocks.push({ start: line.start, end: blockEnd });
55
+ }
56
+ return { blocks, unterminated };
57
+ }
58
+ /** Remove every complete owned block, preserving unrelated bytes, and insert at most one policy where the first block stood. */
59
+ function reconcileString(base, policy, warn) {
60
+ const { blocks, unterminated } = findStringBlocks(base);
61
+ if (unterminated) {
62
+ warn?.("erosiano-dev could not replace/remove an unterminated legacy policy; restart the session.");
63
+ return undefined;
64
+ }
65
+ if (blocks.length === 0) {
66
+ if (policy === undefined)
67
+ return undefined; // Nothing owned to remove; keep the prompt as-is.
68
+ if (base === "")
69
+ return policy;
70
+ const next = `${base}\n\n${policy}`;
71
+ return changed(next, base) ? next : undefined;
72
+ }
73
+ const strippedParts = [];
74
+ let cursor = 0;
75
+ for (const block of blocks) {
76
+ strippedParts.push(base.slice(cursor, block.start));
77
+ cursor = block.end;
78
+ }
79
+ strippedParts.push(base.slice(cursor));
80
+ const stripped = strippedParts.join("");
81
+ const next = policy === undefined ? stripped : base.slice(0, blocks[0].start) + policy + stripped.slice(blocks[0].start);
82
+ return changed(next, base) ? next : undefined;
83
+ }
84
+ export function buildPolicy({ enforcement = "balanced" } = {}) {
85
+ if (!KSD_MODES.includes(enforcement))
86
+ throw new Error("Unsupported KSD enforcement mode");
87
+ const cleanCode = enforcement === "adaptive"
88
+ ? "Adaptive Clean Code: flat by default. Guard clauses/early returns; no else after return or nesting avoidable by guards or combined conditions. Changed-code review: FIX REQUIRED for behavior-preserving fixes; WARN if behavior-sensitive. Never weaken security, transactions or error handling."
89
+ : "Balanced Clean Code: prefer behavior-preserving guards/early returns; nesting findings are advisory.";
90
+ return `${POLICY_MARKER}
91
+ erosiano-dev personal style. Explicit user requirements and current repo conventions take precedence.
92
+ ${cleanCode}
93
+ - No nested ternaries; use if, named helper or lookup map.
94
+ - One blank before return after 2+ preceding statements in the same block; optional after one, none for first-statement return. One blank between adjacent implementations, not TS overloads.
95
+ - Prefer typed domain results (discriminated unions); throw IO/infrastructure errors, catch at boundary. Preserve project error contracts and causes.
96
+ - No any, \`as\` casts except \`as const\`, or non-null \`!\`; type guards, explicit exported return types.
97
+ - Extract helpers for reuse or clearer callers, not length. Comments: one line explaining why, not what.
98
+ - Before substantial changes, establish a scoped project baseline: instructions, native gates, maintained code/tests. Distinguish current, legacy and unknown; refresh stale evidence. Preserve architecture, contracts, validation, accessibility; no unrelated refactors. Never copy insecure legacy behavior.
99
+ - Select applicable practices after baseline via permitted resolver/catalog; never inject entire catalog.
100
+ - Ponytail owns YAGNI/simplification and /ponytail-review; don't duplicate or invoke it.
101
+ - Risky auth/authorization, payments, DB schema/queries/RLS, destructive data, secrets, concurrency: prove normal-user denial (cross-tenant/other owner/unauthenticated); preserve idempotency/replay protection, check constraints/locks/transactions/migration compatibility. Never run real payments or destructive shared-DB checks.
102
+ - Validate runtime boundaries, handle promise rejection/exhaustive states. Never weaken types, security or tests, invent APIs or fake production success.
103
+ - Never claim a check passed without running it.
104
+ Enforcement=${enforcement}: native gates authoritative; deterministic only if adopted. SDLC: /erosiano-dev review.
105
+ ${POLICY_END}`;
106
+ }
107
+ /** Reconcile a string or array fallback prompt: remove owned guidance, or replace it with exactly one policy. */
108
+ function reconcileFallback(base, policy, warn) {
109
+ if (typeof base === "string") {
110
+ const next = reconcileString(base, policy, warn);
111
+ return next === undefined ? undefined : { systemPrompt: next };
112
+ }
113
+ const owned = base
114
+ .map((part, index) => (typeof part === "string" && LEADING_MARKER.test(part) ? index : -1))
115
+ .filter(index => index >= 0);
116
+ if (owned.length === 0) {
117
+ return policy === undefined ? undefined : { systemPrompt: [...base, policy] };
118
+ }
119
+ if (owned.length === 1 && base[owned[0]] === policy)
120
+ return undefined;
121
+ if (policy === undefined) {
122
+ return { systemPrompt: base.filter((_part, index) => !owned.includes(index)) };
123
+ }
124
+ // Exactly one owned element survives: unrelated order preserved, extra owned elements dropped.
125
+ return { systemPrompt: base.flatMap((part, index) => {
126
+ if (owned.includes(index))
127
+ return index === owned[0] ? [policy] : [];
128
+ return [part];
129
+ }) };
130
+ }
131
+ export function augmentSystemPrompt(event, policy, warn) {
132
+ const sections = event?.systemPromptOptions?.sections;
133
+ // Do not add a structured policy if an unterminated fallback cannot be removed.
134
+ if (sections && typeof sections === "object") {
135
+ let failed = false;
136
+ const fallback = event?.systemPrompt === undefined ? undefined : reconcileFallback(event.systemPrompt, undefined, message => {
137
+ failed = true;
138
+ warn?.(message);
139
+ });
140
+ delete sections["engineering-proxy"];
141
+ if (policy === undefined || failed)
142
+ delete sections[SECTION_KEY];
143
+ else
144
+ sections[SECTION_KEY] = policy;
145
+ return fallback;
146
+ }
147
+ return event?.systemPrompt === undefined
148
+ ? (policy === undefined ? undefined : { systemPrompt: policy })
149
+ : reconcileFallback(event.systemPrompt, policy, warn);
150
+ }
@@ -0,0 +1,40 @@
1
+ /** In-process hot-path engine. No native processes, filesystem access or LLM calls. */
2
+ import type { KsdMode } from "./sdlc.js";
3
+ export interface KsdConfig {
4
+ readonly enabled: boolean;
5
+ readonly enforcement: "balanced" | "adaptive";
6
+ readonly configError?: string;
7
+ readonly root?: string;
8
+ readonly configPresent?: boolean;
9
+ }
10
+ export interface KsdTheme {
11
+ fg?(style: string, text: string): string;
12
+ }
13
+ export interface KsdUi {
14
+ setStatus?(key: string, value: string | undefined): void;
15
+ readonly theme?: KsdTheme;
16
+ }
17
+ export interface KsdContext {
18
+ readonly cwd?: string;
19
+ readonly ui?: KsdUi;
20
+ }
21
+ type LoadConfig = (cwd: string) => KsdConfig;
22
+ type BuildPolicy = (config: {
23
+ enforcement: KsdMode;
24
+ }) => string;
25
+ type IsDisabled = () => boolean;
26
+ export declare class KsdRuntime {
27
+ private readonly loadConfig;
28
+ private readonly buildPolicy;
29
+ private readonly isDisabled;
30
+ private readonly configs;
31
+ private readonly policies;
32
+ private readonly statuses;
33
+ constructor(loadConfig: LoadConfig, buildPolicy: BuildPolicy, isDisabled: IsDisabled);
34
+ getConfig(cwd: string, refresh?: boolean): KsdConfig;
35
+ getPolicy(mode: KsdMode): string;
36
+ /** Redraw after session/UI resets even if status text is unchanged. */
37
+ invalidateStatus(ui?: KsdUi): void;
38
+ syncStatus(ctx: KsdContext | undefined, isActive: boolean, mode: KsdConfig["enforcement"], notice?: string): void;
39
+ }
40
+ export {};
@@ -0,0 +1,77 @@
1
+ export class KsdRuntime {
2
+ loadConfig;
3
+ buildPolicy;
4
+ isDisabled;
5
+ configs = new Map();
6
+ policies = new Map();
7
+ statuses = new WeakMap();
8
+ constructor(loadConfig, buildPolicy, isDisabled) {
9
+ this.loadConfig = loadConfig;
10
+ this.buildPolicy = buildPolicy;
11
+ this.isDisabled = isDisabled;
12
+ }
13
+ getConfig(cwd, refresh = false) {
14
+ const known = this.configs.get(cwd);
15
+ if (!refresh && known)
16
+ return known;
17
+ const next = this.loadConfig(cwd);
18
+ this.configs.set(cwd, next);
19
+ return next;
20
+ }
21
+ getPolicy(mode) {
22
+ const existing = this.policies.get(mode);
23
+ if (existing !== undefined)
24
+ return existing;
25
+ // The single-field config object is allocated only on a two-mode cache miss.
26
+ const policy = this.buildPolicy({ enforcement: mode });
27
+ this.policies.set(mode, policy);
28
+ return policy;
29
+ }
30
+ /** Redraw after session/UI resets even if status text is unchanged. */
31
+ invalidateStatus(ui) {
32
+ if (ui)
33
+ this.statuses.delete(ui);
34
+ }
35
+ syncStatus(ctx, isActive, mode, notice) {
36
+ const ui = ctx?.ui;
37
+ if (typeof ui?.setStatus !== "function" || !ctx?.cwd)
38
+ return;
39
+ try {
40
+ const config = this.getConfig(ctx.cwd);
41
+ const enabled = config.enabled && !this.isDisabled();
42
+ let theme;
43
+ try {
44
+ theme = ui.theme;
45
+ }
46
+ catch {
47
+ // Missing theme must never break headless/early-start UIs.
48
+ }
49
+ let status;
50
+ if (enabled) {
51
+ const dot = isActive ? "●" : "○";
52
+ let colored = dot;
53
+ try {
54
+ if (typeof theme?.fg === "function") {
55
+ colored = theme.fg(isActive ? "accent" : "dim", dot);
56
+ }
57
+ }
58
+ catch {
59
+ // Theme rendering is optional.
60
+ }
61
+ status = `${colored} 🛡 EROSIANO: ${mode.toUpperCase()}`;
62
+ if (notice)
63
+ status += `; ${notice}`;
64
+ }
65
+ else if (notice)
66
+ status = `⚠ EROSIANO: ${notice}`;
67
+ const before = this.statuses.get(ui);
68
+ if (before && before.value === status && before.theme === theme)
69
+ return;
70
+ ui.setStatus("erosiano-dev", status);
71
+ this.statuses.set(ui, { value: status, theme, notice });
72
+ }
73
+ catch {
74
+ // Decorative UI must never cause a coding session to fail.
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,7 @@
1
+ /** Lightweight SDLC guidance; not an automatic release gate. */
2
+ export declare const KSD_MODES: readonly ["balanced", "adaptive"];
3
+ export type KsdMode = (typeof KSD_MODES)[number];
4
+ export declare const SDLC_PHASES: readonly string[];
5
+ export declare function buildSdlcPolicy({ mode }?: {
6
+ mode?: KsdMode;
7
+ }): string;
@@ -0,0 +1,27 @@
1
+ /** Lightweight SDLC guidance; not an automatic release gate. */
2
+ export const KSD_MODES = Object.freeze(["balanced", "adaptive"]);
3
+ export const SDLC_PHASES = Object.freeze([
4
+ "Requirements",
5
+ "Design",
6
+ "Implementation",
7
+ "Verification",
8
+ "Delivery",
9
+ ]);
10
+ const REVIEW_GUIDANCE = "Review ownership/authorization by testing normal-user denial (cross-tenant, another owner's record, unauthenticated); a service-role or admin success alone never proves isolation. Where payments are affected, preserve confirmation, idempotency and replay protection and never execute real provider transactions. Where databases are affected, check constraints, locks and transaction boundaries, and migration compatibility with existing data; review deletion scope, cascades and recovery paths. Never invent TTL, provider, or retention semantics, and never run real payment or destructive shared-database checks.";
11
+ export function buildSdlcPolicy({ mode = "balanced" } = {}) {
12
+ if (!KSD_MODES.includes(mode))
13
+ throw new Error("Invalid SDLC policy mode");
14
+ return [
15
+ "SDLC workflow (proportional to the actual change; never fabricate evidence or create unnecessary documents):",
16
+ "1. Requirements: identify intent, acceptance criteria, affected users/contracts and unknowns before changing behavior. State a short acceptance note for UI/cosmetic work and focused checks instead of document ceremony.",
17
+ "2. Design: inspect existing callers, architecture, data flow and invariants. Compare only relevant alternatives; avoid speculative abstraction or redesign.",
18
+ "3. Implementation: smallest behavior-preserving change, guard clauses where clearer, no unrelated churn. Apply repo conventions and Ponytail simplification without duplicating it.",
19
+ "4. Verification: select tests by impact; verify negative/error cases, contracts, types and security when relevant. Distinguish skipped, missing, and actually executed gates.",
20
+ "5. Delivery: summarize changed files, test commands/results, remaining risks, rollback impact and explicit approval blockers. Never automatically push, merge or deploy.",
21
+ "Escalate on behavior in either mode, not filenames: Auth, Payments, Database/schema/query changes, row-level security/authorization, destructive data operations, secrets and concurrency require stronger design and security evidence. " + REVIEW_GUIDANCE,
22
+ "When a requirement is unclear, ask or mark it UNKNOWN instead of inventing policy, TTL, database state or provider behavior.",
23
+ mode === "adaptive"
24
+ ? "Adaptive emphasis: use the lightest sufficient SDLC evidence for each change, but escalate on risky contracts or behavior. Keep control flow flat where semantics allow."
25
+ : "Balanced emphasis: preserve the repository's established checkpoints, with explicit evidence for all applicable gates.",
26
+ ].join("\n");
27
+ }
@@ -0,0 +1,107 @@
1
+ // Optional ESLint flat-config rules. ESLint supplies the AST, so OMP needs no parser dependency.
2
+ // Enable in each repository deliberately; this module is not auto-run by the OMP extension.
3
+
4
+ // A return after a single statement may hug it (`const x = f();` then `return x;`); from two statements on it needs air.
5
+ const MIN_PRECEDING_FOR_BLANK = 2;
6
+
7
+ function getTextAndGap(context, previous, next) {
8
+ const source = context.sourceCode ?? context.getSourceCode();
9
+ const begin = previous.loc.end.line;
10
+ const end = next.loc.start.line;
11
+ const between = source.lines.slice(begin, Math.max(begin, end - 1));
12
+ const blankCount = between.filter(line => line.trim() === "").length;
13
+ const containsOtherContent = between.some(line => line.trim() !== "");
14
+
15
+ return { blankCount, containsOtherContent };
16
+ }
17
+
18
+ function adjacentImplementations(body) {
19
+ return Array.isArray(body) ? body.filter(Boolean) : [];
20
+ }
21
+
22
+ function isFunction(node) {
23
+ if (node?.type === "ExportNamedDeclaration" || node?.type === "ExportDefaultDeclaration") {
24
+ return isFunction(node.declaration);
25
+ }
26
+ if (node?.type === "FunctionDeclaration") return Boolean(node.body); // excludes TS overload signatures
27
+ if (node?.type !== "VariableDeclaration") return false;
28
+
29
+ return node.declarations?.length === 1 &&
30
+ ["ArrowFunctionExpression", "FunctionExpression"].includes(node.declarations[0]?.init?.type);
31
+ }
32
+
33
+ export const rules = {
34
+ "blank-before-return": {
35
+ meta: {
36
+ type: "layout",
37
+ docs: { description: "One empty line before a return preceded by two or more statements; never more than one" },
38
+ schema: [],
39
+ messages: { missing: "Leave exactly one blank line before this return.", extra: "Leave only one blank line before this return." },
40
+ },
41
+ create(context) {
42
+ return {
43
+ ReturnStatement(node) {
44
+ const siblings = node.parent?.body;
45
+ if (!Array.isArray(siblings)) return;
46
+ const index = siblings.indexOf(node);
47
+ if (index <= 0) return;
48
+ const { blankCount, containsOtherContent } = getTextAndGap(context, siblings[index - 1], node);
49
+ if (containsOtherContent) return; // comments/preprocessor matter; avoid false positives
50
+ if (blankCount > 1) {
51
+ context.report({ node, messageId: "extra" });
52
+
53
+ return;
54
+ }
55
+ if (blankCount === 0 && index >= MIN_PRECEDING_FOR_BLANK) context.report({ node, messageId: "missing" });
56
+ },
57
+ };
58
+ },
59
+ },
60
+ "blank-between-functions": {
61
+ meta: {
62
+ type: "layout",
63
+ docs: { description: "Exactly one blank line between adjacent function implementations" },
64
+ schema: [],
65
+ messages: { missing: "Leave exactly one blank line between function implementations.", extra: "Leave only one blank line between function implementations." },
66
+ },
67
+ create(context) {
68
+ function inspect(body) {
69
+ const statements = adjacentImplementations(body);
70
+ for (let i = 1; i < statements.length; i++) {
71
+ const before = statements[i - 1];
72
+ const after = statements[i];
73
+ if (!isFunction(before) || !isFunction(after)) continue;
74
+ const { blankCount, containsOtherContent } = getTextAndGap(context, before, after);
75
+ if (containsOtherContent) continue;
76
+ if (blankCount !== 1) context.report({ node: after, messageId: blankCount === 0 ? "missing" : "extra" });
77
+ }
78
+ }
79
+
80
+ return {
81
+ Program(node) { inspect(node.body); },
82
+ BlockStatement(node) { inspect(node.body); },
83
+ };
84
+ },
85
+ },
86
+ "prefer-guard-clauses": {
87
+ meta: {
88
+ type: "suggestion",
89
+ docs: { description: "Warn on avoidable directly nested if blocks; no unsafe auto-fix" },
90
+ schema: [],
91
+ messages: { nested: "Consider a guard clause instead of a nested if, if behavior remains equivalent." },
92
+ },
93
+ create(context) {
94
+ return {
95
+ IfStatement(node) {
96
+ if (node.alternate) return;
97
+ const only = node.consequent?.type === "BlockStatement" ? node.consequent.body : [];
98
+ if (only.length === 1 && only[0]?.type === "IfStatement") {
99
+ context.report({ node: only[0], messageId: "nested" });
100
+ }
101
+ },
102
+ };
103
+ },
104
+ },
105
+ };
106
+
107
+ export default { rules };
@@ -0,0 +1,7 @@
1
+ export interface EngineeringExtensionOptions {
2
+ globalConfigPath?: string;
3
+ defaultIntelligenceMode?: "off" | "native" | "mcp" | "cli";
4
+ label?: string;
5
+ }
6
+ export declare function createExtension(pi: unknown, options?: EngineeringExtensionOptions): void;
7
+ export default createExtension;