@leitwerk-dev/process-sdk 0.5.10 → 0.5.12

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
+ /**
2
+ * Best-effort initialization at the checked-out revision. Returns a safe warning
3
+ * when preparation is incomplete, without exposing Git output or credentials.
4
+ * Call after selecting the revision and before using the checkout.
5
+ * @public
6
+ */
7
+ export declare function prepareRepositorySubmodules(projectKey: string, repoPath: string, signal?: AbortSignal): Promise<string | undefined>;
8
+ //# sourceMappingURL=repository-submodules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-submodules.d.ts","sourceRoot":"","sources":["../src/repository-submodules.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAChD,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAmG7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leitwerk-dev/process-sdk",
3
- "version": "0.5.10",
3
+ "version": "0.5.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/leitwerk-dev/leitwerk.git",
@@ -43,14 +43,14 @@
43
43
  "build": "tsup --silent"
44
44
  },
45
45
  "dependencies": {
46
- "@leitwerk-dev/domain": "0.5.10",
47
- "@leitwerk-dev/protocol": "0.5.10",
48
- "@leitwerk-dev/worker-protocol": "0.5.10",
49
- "@leitwerk-dev/watcher-utils": "0.5.10",
46
+ "@leitwerk-dev/domain": "0.5.12",
47
+ "@leitwerk-dev/protocol": "0.5.12",
48
+ "@leitwerk-dev/worker-protocol": "0.5.12",
49
+ "@leitwerk-dev/watcher-utils": "0.5.12",
50
50
  "escape-html": "^1.0.3",
51
51
  "mustache": "^4.2.0",
52
52
  "valibot": "^1.3.1",
53
- "@leitwerk-dev/external-writes": "0.5.10"
53
+ "@leitwerk-dev/external-writes": "0.5.12"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/escape-html": "^1.0.4",
@@ -944,6 +944,8 @@ export interface RepositoryCredentialRegistrar {
944
944
  export interface ProcessRuntimeCapabilities {
945
945
  /** Choose eager clones, on-demand checkout, or no local checkout. @public */
946
946
  readonly repositoryCheckout?: "eager" | "on_demand" | "none";
947
+ /** Initialize pinned submodules before handing over a checkout; warn rather than fail. @public */
948
+ readonly repositorySubmodules?: "best_effort";
947
949
  /** Install repository-declared development tools with mise before accepting work. @internal */
948
950
  readonly developmentTools?: boolean;
949
951
  /** Require a Docker CLI connected to a private or explicitly acknowledged daemon. @public */
package/src/flow.ts CHANGED
@@ -21,7 +21,6 @@ import type {
21
21
  LlmModelPurpose,
22
22
  LlmOutcomeSubmission,
23
23
  LlmTurnDefinition,
24
- LlmTurnPreparationContext,
25
24
  OutcomeParameterContext,
26
25
  ProcessEffectPlan,
27
26
  ProcessHumanTurnActionSpec,
@@ -46,6 +45,7 @@ import type {
46
45
  ProcessActionDefinition,
47
46
  ProcessLauncherAPI,
48
47
  ProcessLauncherDefinition,
48
+ ProcessRuntimeCapabilities,
49
49
  ProcessWatcherAPI,
50
50
  ProcessWatcherDefinition,
51
51
  ServerProcessAPI,
@@ -2630,17 +2630,13 @@ export class FlowProcessBuilder<TParams = unknown, TState = unknown> extends Flo
2630
2630
  }
2631
2631
 
2632
2632
  /** Declare runner-provided process runtime capabilities. @public */
2633
- runtime(capabilities: {
2634
- /** @internal */
2635
- developmentTools?: boolean;
2636
- /** @public */
2637
- docker?: boolean;
2638
- /** @internal */
2639
- repositoryCheckout?: "eager" | "on_demand" | "none";
2640
- }): this {
2633
+ runtime(capabilities: ProcessRuntimeCapabilities): this {
2641
2634
  const runtime = {
2642
2635
  ...(capabilities.developmentTools === true ? { developmentTools: true } : {}),
2643
2636
  ...(capabilities.docker === true ? { docker: true } : {}),
2637
+ ...(capabilities.repositorySubmodules === "best_effort"
2638
+ ? { repositorySubmodules: capabilities.repositorySubmodules }
2639
+ : {}),
2644
2640
  ...(capabilities.repositoryCheckout
2645
2641
  ? { repositoryCheckout: capabilities.repositoryCheckout }
2646
2642
  : {}),
package/src/index.ts CHANGED
@@ -111,6 +111,7 @@ export type {
111
111
  ProcessLaunchPlan,
112
112
  ProcessLaunchProjectConfig,
113
113
  ProcessLeafOutcomeDefinition,
114
+ ProcessRuntimeCapabilities,
114
115
  ProcessTitleSourceField,
115
116
  ProcessTurnBinding,
116
117
  ProcessWatcherDefinition,
@@ -319,6 +320,7 @@ export {
319
320
  parseRepositoryIssueCancelledConfig,
320
321
  parseRepositoryPullRequestConfig,
321
322
  } from "./repository-source-config.js";
323
+ export { prepareRepositorySubmodules } from "./repository-submodules.js";
322
324
  export type { RepositoryIssue, RepositoryPullRequest } from "./repository-types.js";
323
325
  export * from "./scoped-settings.js";
324
326
  export type {
@@ -0,0 +1,121 @@
1
+ import { spawn } from "node:child_process";
2
+ import { resolveGitBinary } from "./git-binary.js";
3
+ import { repositoryGitArgs, repositoryGitSubprocessEnv } from "./repository-git-env.js";
4
+
5
+ const preserveLocalWork = [
6
+ 'status=$(git status --porcelain --ignored=matching --untracked-files=normal --ignore-submodules=dirty) && test -z "$status" || exit 1',
7
+ "head=$(git rev-parse HEAD) || exit 1",
8
+ // Do not move an unpushed detached commit. A named branch retains its HEAD.
9
+ 'test "$head" = "$sha1" || git symbolic-ref -q HEAD >/dev/null || test -n "$(git for-each-ref --contains "$head" refs/remotes --format="%(refname)")"',
10
+ ].join("; ");
11
+
12
+ /**
13
+ * Best-effort initialization at the checked-out revision. Returns a safe warning
14
+ * when preparation is incomplete, without exposing Git output or credentials.
15
+ * Call after selecting the revision and before using the checkout.
16
+ * @public
17
+ */
18
+ export async function prepareRepositorySubmodules(
19
+ projectKey: string,
20
+ repoPath: string,
21
+ signal?: AbortSignal,
22
+ ): Promise<string | undefined> {
23
+ const deadline = AbortSignal.timeout(30_000);
24
+ const stop = signal ? AbortSignal.any([signal, deadline]) : deadline;
25
+ const env = repositoryGitSubprocessEnv(projectKey, { GIT_TERMINAL_PROMPT: "0" });
26
+ env.GIT_CONFIG_NOSYSTEM = "1";
27
+ env.GIT_CONFIG_GLOBAL = "/dev/null";
28
+ // No ambient helpers, transports or redirects. A managed SSH wrapper enforces pinned host keys.
29
+ const config = [
30
+ "-c",
31
+ "protocol.allow=never",
32
+ "-c",
33
+ "protocol.https.allow=always",
34
+ "-c",
35
+ `protocol.ssh.allow=${env.GIT_SSH ? "always" : "never"}`,
36
+ "-c",
37
+ "http.followRedirects=false",
38
+ "-c",
39
+ "http.extraHeader=",
40
+ ...(env.GIT_CONFIG_COUNT ? [] : ["-c", "credential.helper="]),
41
+ ];
42
+
43
+ const run = (args: string[]) =>
44
+ new Promise<{ ok: boolean; output: string }>((resolve) => {
45
+ if (stop.aborted) return resolve({ ok: false, output: "" });
46
+ const child = spawn(resolveGitBinary(), repositoryGitArgs([...config, ...args]), {
47
+ cwd: repoPath,
48
+ env,
49
+ detached: true,
50
+ stdio: ["ignore", "pipe", "ignore"],
51
+ });
52
+ let output = Buffer.alloc(0);
53
+ let stopped = false;
54
+ const terminate = () => {
55
+ stopped = true;
56
+ try {
57
+ if (child.pid) process.kill(-child.pid, "SIGKILL");
58
+ } catch {
59
+ /* The process group already exited. */
60
+ }
61
+ };
62
+ stop.addEventListener("abort", terminate, { once: true });
63
+ child.stdout.on("data", (chunk: Buffer) => {
64
+ if (output.length + chunk.length > 1024 * 1024) terminate();
65
+ else output = Buffer.concat([output, chunk]);
66
+ });
67
+ child.on("error", () => {
68
+ stopped = true;
69
+ });
70
+ child.on("close", (code) => {
71
+ stop.removeEventListener("abort", terminate);
72
+ resolve({ ok: !stopped && code === 0, output: output.toString("utf8") });
73
+ });
74
+ });
75
+
76
+ const manifest = await run(["ls-files", "--stage", "--", ".gitmodules"]);
77
+ if (manifest.ok && !manifest.output) return undefined;
78
+ const safeWarning = (reason: string) => `Submodules in ${projectKey} are incomplete: ${reason}`;
79
+ const unavailable = () =>
80
+ safeWarning(
81
+ deadline.aborted
82
+ ? "preparation timed out."
83
+ : "check repository access or transport and run git submodule status --recursive.",
84
+ );
85
+ if (!manifest.ok) return unavailable();
86
+ const unmerged = await run(["ls-files", "--unmerged", "-z"]);
87
+ if (!unmerged.ok) return unavailable();
88
+ if (unmerged.output) return safeWarning("the checkout has unresolved conflicts.");
89
+
90
+ const staged = await run([
91
+ "diff",
92
+ "--cached",
93
+ "--raw",
94
+ "--ignore-submodules=none",
95
+ "--no-renames",
96
+ "-z",
97
+ ]);
98
+ const configStatus = await run(["status", "--porcelain", "--", ".gitmodules"]);
99
+ if (!staged.ok || !configStatus.ok) return unavailable();
100
+ if (/(?:^|\0):(?:160000 \d{6}|\d{6} 160000) /.test(staged.output) || configStatus.output)
101
+ return safeWarning("existing submodule configuration was left untouched.");
102
+ const before = await run(["submodule", "status", "--recursive"]);
103
+ const incomplete = /^(?:[-+U])/m;
104
+ if (!before.ok) return unavailable();
105
+ if (!incomplete.test(before.output)) return undefined;
106
+ if (!(await run(["submodule", "foreach", "--quiet", "--recursive", preserveLocalWork])).ok)
107
+ return stop.aborted
108
+ ? unavailable()
109
+ : safeWarning("existing submodule work was left untouched.");
110
+ const update = await run([
111
+ "submodule",
112
+ "update",
113
+ "--init",
114
+ "--recursive",
115
+ "--checkout",
116
+ "--jobs=4",
117
+ ]);
118
+ const status = await run(["submodule", "status", "--recursive"]);
119
+ if (!update.ok || !status.ok || incomplete.test(status.output)) return unavailable();
120
+ return undefined;
121
+ }