karajan-code 4.48.0 → 4.48.1
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
package/src/commands/harden.js
CHANGED
|
@@ -186,7 +186,7 @@ export async function hardenCommand({
|
|
|
186
186
|
const cfg = withConfig ? installConfigsForRoots({ projectDir, roots, dryRun }) : null;
|
|
187
187
|
const withCi = ci && profile !== "minimal";
|
|
188
188
|
const wf = withCi
|
|
189
|
-
? installWorkflows({ projectDir, language: roots[0]?.language ?? null, profile, mutation, dryRun })
|
|
189
|
+
? installWorkflows({ projectDir, language: roots[0]?.language ?? null, root: roots[0]?.dir ?? ".", profile, mutation, dryRun })
|
|
190
190
|
: null;
|
|
191
191
|
const withGuidelines = guidelines && profile !== "minimal";
|
|
192
192
|
// KJC-BUG-0199 (issue #1773): the same detected language the workflows and
|
package/src/config/defaults.js
CHANGED
|
@@ -254,7 +254,8 @@ const DEFAULTS = {
|
|
|
254
254
|
// delta re-index before every `kj run`; `onCommit` is consulted by
|
|
255
255
|
// `kj rag install-hooks` to decide whether to install the post-merge
|
|
256
256
|
// hook. Both default ON; flip to false to opt out without uninstalling.
|
|
257
|
-
|
|
257
|
+
// maxFiles (KJC-BUG-0304): past this drift the pre-query refresh answers from the index as it is.
|
|
258
|
+
autoUpdate: { onCommit: true, onRun: true, maxFiles: 25 },
|
|
258
259
|
// KJC-TSK-0682 — sensitivity of the indexed code. Cloud embedders
|
|
259
260
|
// (openai/voyage/cohere/mistral) require an explicit "public"; the
|
|
260
261
|
// safe default blocks them (local ollama/onnx always allowed).
|
|
@@ -1049,7 +1049,11 @@ process.stdin.on("end", () => {
|
|
|
1049
1049
|
// above rules on it) and the ledger only holds in-repo paths.
|
|
1050
1050
|
// KJC-BUG-0190: with nothing indexed, no query can cover anything —
|
|
1051
1051
|
// the gate asks for kj rag index instead of denying the impossible.
|
|
1052
|
-
|
|
1052
|
+
// KJC-BUG-0308: a barrel only re-exports its folder, so the RAG answers with
|
|
1053
|
+
// what it re-exports and never with the barrel: a hit in its own subtree covers it.
|
|
1054
|
+
const BARRELS = ["index.js", "index.ts", "index.mjs", "index.cjs", "index.jsx", "index.tsx", "__init__.py", "mod.rs"];
|
|
1055
|
+
const barrelCovered = dirOf(rel) !== "" && BARRELS.includes(rel.slice(rel.lastIndexOf("/") + 1)) && hits.some((h) => h.startsWith(dirOf(rel) + "/"));
|
|
1056
|
+
const covered = rel.startsWith("..") || hits.includes(rel) || hits.some((h) => dirOf(h) === dirOf(rel)) || barrelCovered || ((rs.rag_queries || []).length > 0 && fresh()) || rs.rag_index_empty === true;
|
|
1053
1057
|
// ADR 0015 (KJC-TSK-0925): no escape. The cases it covered (new file, empty
|
|
1054
1058
|
// index, not indexable) are decided by the gate itself.
|
|
1055
1059
|
if (!covered) {
|
|
@@ -73,10 +73,14 @@ export function installWorkflows({
|
|
|
73
73
|
mutation = false,
|
|
74
74
|
dryRun = false,
|
|
75
75
|
kjVersion = null,
|
|
76
|
+
root = ".",
|
|
76
77
|
} = {}) {
|
|
77
78
|
const dir = join(projectDir, WORKFLOWS_DIR);
|
|
78
79
|
const pm = detectPackageManager(projectDir);
|
|
79
|
-
|
|
80
|
+
// KJC-BUG-0309: the Quality workflow reads the package manager and the lint
|
|
81
|
+
// script where the language root is, and runs its steps there.
|
|
82
|
+
const appDir = join(projectDir, root);
|
|
83
|
+
const quality = qualityWorkflowFor(language, detectPackageManager(appDir), hasLintScript(appDir), root);
|
|
80
84
|
const extras = extraWorkflowsFor({ profile, publishable: isPublishableNpm(projectDir), pm });
|
|
81
85
|
const mut = mutation ? mutationWorkflowFor(language, pm) : null;
|
|
82
86
|
// PL-C: el tier C solo existe donde el proyecto DECLARA policy. Versión a
|
|
@@ -166,13 +166,21 @@ const QUALITY_BY_LANGUAGE = {
|
|
|
166
166
|
* `lint:false` drops the JS lint step entirely (project has no lint script,
|
|
167
167
|
* KJC-BUG-0137) — mirroring the local hook, which also omits it.
|
|
168
168
|
*/
|
|
169
|
-
export function qualityWorkflowFor(language, pm = "npm", lint = true) {
|
|
169
|
+
export function qualityWorkflowFor(language, pm = "npm", lint = true, root = ".") {
|
|
170
170
|
const c = PM_COMMANDS[pm] || PM_COMMANDS.npm;
|
|
171
171
|
const body =
|
|
172
172
|
language === "javascript" || language === "typescript"
|
|
173
173
|
? header([...nodeSetupSteps(pm), ...(lint ? [` - run: ${c.lint}`] : []), ` - run: ${c.test}`])
|
|
174
174
|
: QUALITY_BY_LANGUAGE[language];
|
|
175
|
-
return body ? { file: "kj-quality.yml", blockId: "wf-quality", body } : null;
|
|
175
|
+
return body ? { file: "kj-quality.yml", blockId: "wf-quality", body: inRoot(body, root) } : null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// KJC-BUG-0309 (#2023): a repo whose app lives in a subdirectory runs every step
|
|
179
|
+
// there. The root goes into YAML, so it is a plain relative path or nothing.
|
|
180
|
+
function inRoot(body, root) {
|
|
181
|
+
if (root === "." || root === "") return body;
|
|
182
|
+
if (!/^[\w.-]+(\/[\w.-]+)*$/.test(root) || root.split("/").includes("..")) throw new Error(`kj harden: "${root}" is not a safe directory for the Quality workflow`);
|
|
183
|
+
return body.replace(" runs-on: ubuntu-latest\n", ` runs-on: ubuntu-latest\n defaults:\n run:\n working-directory: ${root}\n`);
|
|
176
184
|
}
|
|
177
185
|
|
|
178
186
|
// Caps the net LOC delta of a PR (strict profile only — it is opinionated).
|
package/src/rag/auto-update.js
CHANGED
|
@@ -12,6 +12,8 @@ import { ragExclude } from "./indexable.js";
|
|
|
12
12
|
import { makeGovernedEmbedder } from "./governed-embedder.js";
|
|
13
13
|
import { openProjectStore } from "./project-store.js";
|
|
14
14
|
|
|
15
|
+
// The pre-query refresh reindexes at most this many changed files (config.rag.autoUpdate.maxFiles).
|
|
16
|
+
export const DEFAULT_MAX_DRIFT_FILES = 25;
|
|
15
17
|
const HOOK_SRC = resolve(fileURLToPath(import.meta.url), "../../../scripts/git-hooks/post-merge");
|
|
16
18
|
|
|
17
19
|
export async function maybeAutoUpdate({ projectDir, config, logger = console, flags = {} } = {}) {
|
|
@@ -26,6 +28,16 @@ export async function maybeAutoUpdate({ projectDir, config, logger = console, fl
|
|
|
26
28
|
try {
|
|
27
29
|
const since = getLastIndexedCommit(db, slug);
|
|
28
30
|
if (!since || since === head) return { skipped: true, head };
|
|
31
|
+
// KJC-BUG-0304: a drift of hundreds of files (an index weeks old) reindexed the
|
|
32
|
+
// repo for half an hour before the query answered. Past the bound the query
|
|
33
|
+
// answers from the index as it is, and says how to bring it up to date.
|
|
34
|
+
const maxFiles = config?.rag?.autoUpdate?.maxFiles ?? DEFAULT_MAX_DRIFT_FILES;
|
|
35
|
+
const { stdout } = await execa("git", ["-C", projectDir, "diff", "--name-only", since, "HEAD"]);
|
|
36
|
+
const changed = stdout.split("\n").filter(Boolean).length;
|
|
37
|
+
if (changed > maxFiles) {
|
|
38
|
+
logger.warn?.(`[rag] ${changed} file(s) changed since the last index (more than ${maxFiles}): answering from the index as it is; bring it up to date with kj rag index --since auto`);
|
|
39
|
+
return { skipped: true, reason: "drift-too-large", changed, head };
|
|
40
|
+
}
|
|
29
41
|
logger.info?.(`[rag] drift detected (${since.slice(0, 7)} → ${head.slice(0, 7)}); running delta update`);
|
|
30
42
|
const totals = await indexProjectDelta(projectDir, { db, embedder: makeGovernedEmbedder(config), since, logger, exclude: ragExclude(config) });
|
|
31
43
|
if (totals.head) setLastIndexedCommit(db, slug, totals.head);
|