import { randomUUID } from "node:crypto"; import { initShadow, repoOf } from "../hub/snapshots.ts"; import { PROFILE_NAMES, profileName, projectProfile, resolveProfile, mergeProfileOverrides, type ProfileName } from "../hub/profiles.ts"; import { canonicalJson, loadPacks, packOverrides, type DomainPack } from "../hub/packs.ts"; import { JCODE_MCP_FILE } from "./jcode-mcp.ts"; import { closeSync, constants, fstatSync, openSync, readSync, existsSync, lstatSync, mkdirSync, mkdtempSync, rmSync, readFileSync, statSync, unlinkSync, writeFileSync, renameSync } from "node:fs"; import { tmpdir } from "node:os"; import { dirname, isAbsolute, join, resolve } from "node:path"; import { spawnSync } from "node:child_process"; import type { Stats } from "node:fs"; import { realPath } from "../hub/project.ts"; import { hubGitArgv, hubGitEnv, hubGitSync } from "../hub/git.ts"; import { KIMI_MCP_FILE } from "./kimi-mcp.ts"; import { AGY_PLUGIN_FILES } from "./agy-mcp.ts"; import { DEFAULT_CONFIG, loadConfig } from "../hub/daemon.ts"; import { ALL_MACHINE_LOCAL } from "../hub/config-trust.ts"; import { requiredChecksFor } from "../hub/sdlc-merge.ts"; import { githubOriginRepository } from "../hub/task-repository.ts"; import { loadSdlc, sdlcConfig } from "../hub/sdlc.ts"; import { VERSION } from "../version.ts"; import { roleSummaryLines } from "./init-roles.ts"; import { planInitSettings, TRACK_CONFIG, type InitSettingFile, type InitSettingRow, type InitSettingsRequest } from "./init-settings.ts"; const TEMPLATES = join(import.meta.dir, "..", "..", "templates"); const BEGIN = ""; const END = ""; /** Insert or replace the managed block. Idempotent: text outside the markers is never touched. */ export function upsertBlock(existing: string, block: string): string { const managed = `${BEGIN}\n${block.trim()}\n${END}`; const start = existing.indexOf(""; const RELEASE_END = ""; const HOOK_MARKER = "# agent-hub managed release pre-push guard"; const shellQuote = (value: string) => "'" + value.replace(/'/g, "'\"'\"'") + "'"; function releaseBlock(existing: string): string { const block = `${RELEASE_BEGIN}\n${readFileSync(join(TEMPLATES, "release-guard.block.md"), "utf8").trim()}\n${RELEASE_END}`; const start = existing.indexOf(""; const SPECS_END = ""; /** * #1064 T3: the design-specs instruction block, placed the way the release guard's is. On: insert it (at the end of the file) or replace it in place. Off: drop it and the blank * lines around it, and nothing else. Text outside the markers is never touched, and incomplete markers are refused (nothing is guessed about where a half block ends). */ export function specsBlock(existing: string, enabled: boolean): string { const start = existing.indexOf("