@leitwerk-dev/process-sdk 0.1.8 → 0.2.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.
- package/dist/{chunk-TRQJ5PRM.js → chunk-TA4KO53Q.js} +1 -5
- package/dist/chunk-TA4KO53Q.js.map +1 -0
- package/dist/{chunk-5RJZ2E7D.js → chunk-WFY2WWZE.js} +2 -6
- package/dist/{chunk-5RJZ2E7D.js.map → chunk-WFY2WWZE.js.map} +1 -1
- package/dist/core-capabilities.d.ts +76 -34
- package/dist/core-capabilities.d.ts.map +1 -1
- package/dist/define-process.d.ts +36 -55
- package/dist/define-process.d.ts.map +1 -1
- package/dist/{extension-api-CqPGRqc9.d.ts → extension-api-CcqZCYJx.d.ts} +160 -74
- package/dist/extension-api.d.ts +120 -5
- package/dist/extension-api.d.ts.map +1 -1
- package/dist/external-action-source.d.ts +7 -0
- package/dist/external-action-source.d.ts.map +1 -0
- package/dist/external-source-poll.d.ts +15 -0
- package/dist/external-source-poll.d.ts.map +1 -0
- package/dist/flow.d.ts +92 -110
- package/dist/flow.d.ts.map +1 -1
- package/dist/fs-utils.d.ts +2 -0
- package/dist/fs-utils.d.ts.map +1 -1
- package/dist/git-binary.js +25 -33
- package/dist/git-binary.js.map +1 -1
- package/dist/index.d.ts +21 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4694 -29
- package/dist/index.js.map +1 -1
- package/dist/integration-http.d.ts +21 -0
- package/dist/integration-http.d.ts.map +1 -0
- package/dist/json-data.d.ts +3 -0
- package/dist/json-data.d.ts.map +1 -0
- package/dist/leaf-outcome-renderer.js +74 -64
- package/dist/leaf-outcome-renderer.js.map +1 -1
- package/dist/leaf-outcomes.d.ts.map +1 -1
- package/dist/model-provider.d.ts.map +1 -1
- package/dist/pi-config.d.ts +1 -5
- package/dist/pi-config.d.ts.map +1 -1
- package/dist/pi-config.js +20 -180
- package/dist/pi-config.js.map +1 -1
- package/dist/process-flow-view.d.ts.map +1 -1
- package/dist/process-graph.d.ts +1 -2
- package/dist/process-graph.d.ts.map +1 -1
- package/dist/process-watcher-source.d.ts +3 -1
- package/dist/process-watcher-source.d.ts.map +1 -1
- package/dist/project-binding.d.ts +9 -0
- package/dist/project-binding.d.ts.map +1 -0
- package/dist/registry-utils.d.ts.map +1 -1
- package/dist/repository-feedback.d.ts +29 -0
- package/dist/repository-feedback.d.ts.map +1 -0
- package/dist/repository-git-env.d.ts +2 -0
- package/dist/repository-git-env.d.ts.map +1 -1
- package/dist/repository-http.d.ts +19 -0
- package/dist/repository-http.d.ts.map +1 -0
- package/dist/repository-https.d.ts +3 -0
- package/dist/repository-https.d.ts.map +1 -0
- package/dist/repository-issue-watcher.d.ts +31 -0
- package/dist/repository-issue-watcher.d.ts.map +1 -0
- package/dist/repository-source-config.d.ts +32 -0
- package/dist/repository-source-config.d.ts.map +1 -0
- package/dist/repository-types.d.ts +36 -0
- package/dist/repository-types.d.ts.map +1 -0
- package/dist/review-flow.js +12 -43
- package/dist/review-flow.js.map +1 -1
- package/dist/runtime-internals.js +18 -2
- package/dist/runtime-internals.js.map +1 -1
- package/dist/state-helpers.d.ts +3 -2
- package/dist/state-helpers.d.ts.map +1 -1
- package/dist/subprocess-env.d.ts +1 -0
- package/dist/subprocess-env.d.ts.map +1 -1
- package/dist/tool-arguments.d.ts +7 -0
- package/dist/tool-arguments.d.ts.map +1 -0
- package/dist/turn-semantics.d.ts +5 -6
- package/dist/turn-semantics.d.ts.map +1 -1
- package/dist/types.d.ts +5 -15
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/core-capabilities.ts +90 -37
- package/src/define-process.ts +231 -277
- package/src/extension-api.ts +148 -4
- package/src/external-action-source.ts +12 -0
- package/src/external-source-poll.ts +49 -0
- package/src/flow.ts +427 -646
- package/src/fs-utils.ts +17 -2
- package/src/index.ts +56 -13
- package/src/integration-http.ts +58 -0
- package/src/json-data.ts +25 -0
- package/src/leaf-outcomes.ts +1 -9
- package/src/model-provider.ts +10 -23
- package/src/pi-config.ts +1 -6
- package/src/process-flow-view.ts +32 -88
- package/src/process-graph.ts +25 -54
- package/src/process-watcher-source.ts +13 -8
- package/src/project-binding.ts +36 -0
- package/src/registry-utils.ts +1 -5
- package/src/repository-feedback.ts +59 -0
- package/src/repository-git-env.ts +34 -0
- package/src/repository-http.ts +71 -0
- package/src/repository-https.ts +22 -0
- package/src/repository-issue-watcher.ts +92 -0
- package/src/repository-source-config.ts +60 -0
- package/src/repository-types.ts +25 -0
- package/src/state-helpers.ts +8 -9
- package/src/subprocess-env.ts +6 -0
- package/src/tool-arguments.ts +37 -0
- package/src/turn-semantics.ts +31 -75
- package/src/types.ts +5 -15
- package/dist/browser-ui-extension.js +0 -2
- package/dist/browser-ui-extension.js.map +0 -1
- package/dist/capabilities.js +0 -7
- package/dist/capabilities.js.map +0 -1
- package/dist/chunk-TRQJ5PRM.js.map +0 -1
- package/dist/codecs.js +0 -9
- package/dist/codecs.js.map +0 -1
- package/dist/commit-message.js +0 -3
- package/dist/commit-message.js.map +0 -1
- package/dist/core-capabilities.js +0 -6
- package/dist/core-capabilities.js.map +0 -1
- package/dist/define-process.js +0 -1040
- package/dist/define-process.js.map +0 -1
- package/dist/event-bus.js +0 -31
- package/dist/event-bus.js.map +0 -1
- package/dist/extension-api.js +0 -5
- package/dist/extension-api.js.map +0 -1
- package/dist/flow.js +0 -1565
- package/dist/flow.js.map +0 -1
- package/dist/form-contract.js +0 -2
- package/dist/form-contract.js.map +0 -1
- package/dist/fs-utils.js +0 -23
- package/dist/fs-utils.js.map +0 -1
- package/dist/graph-fragments.js +0 -57
- package/dist/graph-fragments.js.map +0 -1
- package/dist/host-capabilities.js +0 -42
- package/dist/host-capabilities.js.map +0 -1
- package/dist/launcher-contract.js +0 -2
- package/dist/launcher-contract.js.map +0 -1
- package/dist/leaf-outcomes.js +0 -52
- package/dist/leaf-outcomes.js.map +0 -1
- package/dist/model-provider.js +0 -171
- package/dist/model-provider.js.map +0 -1
- package/dist/process-definition-internals.js +0 -25
- package/dist/process-definition-internals.js.map +0 -1
- package/dist/process-flow-view.js +0 -418
- package/dist/process-flow-view.js.map +0 -1
- package/dist/process-graph.js +0 -213
- package/dist/process-graph.js.map +0 -1
- package/dist/process-launcher-builder.js +0 -43
- package/dist/process-launcher-builder.js.map +0 -1
- package/dist/process-watcher-builder.js +0 -40
- package/dist/process-watcher-builder.js.map +0 -1
- package/dist/process-watcher-source.js +0 -45
- package/dist/process-watcher-source.js.map +0 -1
- package/dist/registry-utils.js +0 -18
- package/dist/registry-utils.js.map +0 -1
- package/dist/repository-git-env.js +0 -26
- package/dist/repository-git-env.js.map +0 -1
- package/dist/server-events.js +0 -2
- package/dist/server-events.js.map +0 -1
- package/dist/server-process-builder.js +0 -52
- package/dist/server-process-builder.js.map +0 -1
- package/dist/state-helpers.js +0 -20
- package/dist/state-helpers.js.map +0 -1
- package/dist/subprocess-env.js +0 -34
- package/dist/subprocess-env.js.map +0 -1
- package/dist/tool-renderers.js +0 -63
- package/dist/tool-renderers.js.map +0 -1
- package/dist/turn-semantics.js +0 -365
- package/dist/turn-semantics.js.map +0 -1
- package/dist/types.js +0 -23
- package/dist/types.js.map +0 -1
- package/dist/ui-process-builder.js +0 -30
- package/dist/ui-process-builder.js.map +0 -1
- package/dist/worker-process-builder.js +0 -22
- package/dist/worker-process-builder.js.map +0 -1
package/src/process-graph.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type {
|
|
|
2
2
|
ProcessSemanticEntryRefKey,
|
|
3
3
|
ProcessTurnTransition,
|
|
4
4
|
ProcessTurnType,
|
|
5
|
-
ReviewSubject,
|
|
6
5
|
SerializedProcessGraph,
|
|
7
6
|
TurnId,
|
|
8
7
|
} from "@leitwerk-dev/domain";
|
|
@@ -18,7 +17,6 @@ export interface ProcessGraphTurnView {
|
|
|
18
17
|
turnType: ProcessTurnType;
|
|
19
18
|
description: string;
|
|
20
19
|
transitions: readonly ProcessTurnTransition[];
|
|
21
|
-
reviewSubject?: ReviewSubject;
|
|
22
20
|
reviewProduct?: string;
|
|
23
21
|
resultSemanticRef?: ProcessSemanticEntryRefKey;
|
|
24
22
|
publishedProduct?: string;
|
|
@@ -38,71 +36,44 @@ export interface ProcessGraphView {
|
|
|
38
36
|
turns: ReadonlyMap<TurnId, ProcessGraphTurnView>;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (definition.kind !== "human") {
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
const products: string[] = [];
|
|
57
|
-
for (const action of Object.values(definition.actions)) {
|
|
58
|
-
for (const field of action.form?.fields ?? []) {
|
|
59
|
-
if (!field.publish) {
|
|
60
|
-
continue;
|
|
39
|
+
function turnPublishedProducts(definition: TurnDefinition<unknown, unknown>): string[] {
|
|
40
|
+
const products = new Set<string>();
|
|
41
|
+
if (definition.kind === "human") {
|
|
42
|
+
for (const action of Object.values(definition.actions)) {
|
|
43
|
+
for (const field of action.form?.fields ?? []) {
|
|
44
|
+
if (field.publish) {
|
|
45
|
+
products.add(
|
|
46
|
+
typeof field.publish === "object" && field.publish.product
|
|
47
|
+
? field.publish.product
|
|
48
|
+
: field.id,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
61
51
|
}
|
|
62
|
-
products.push(
|
|
63
|
-
typeof field.publish === "object" && field.publish.product
|
|
64
|
-
? field.publish.product
|
|
65
|
-
: field.id,
|
|
66
|
-
);
|
|
67
52
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
for (const action of Object.values(definition.externalActions ?? {})) {
|
|
54
|
+
if (action.publishInput) {
|
|
55
|
+
products.add(action.publishInput.productName);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} else if (definition.kind === "llm" || definition.kind === "automatic") {
|
|
59
|
+
for (const outcome of Object.values(definition.outcomes ?? {})) {
|
|
60
|
+
if (typeof outcome?.publishedProduct === "string") {
|
|
61
|
+
products.add(outcome.publishedProduct);
|
|
62
|
+
}
|
|
72
63
|
}
|
|
73
64
|
}
|
|
74
|
-
return [...
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function outcomePublishedProducts(definition: TurnDefinition<unknown, unknown>): string[] {
|
|
78
|
-
if (
|
|
79
|
-
definition.kind !== "llm" &&
|
|
80
|
-
definition.kind !== "automatic" &&
|
|
81
|
-
definition.kind !== "server_automatic"
|
|
82
|
-
) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
return [
|
|
86
|
-
...new Set(
|
|
87
|
-
Object.values(definition.outcomes ?? {})
|
|
88
|
-
.map((outcome) => outcome?.publishedProduct)
|
|
89
|
-
.filter((productName): productName is string => typeof productName === "string"),
|
|
90
|
-
),
|
|
91
|
-
];
|
|
65
|
+
return [...products];
|
|
92
66
|
}
|
|
93
67
|
|
|
94
68
|
function toTurnView(
|
|
95
69
|
binding: ProcessTurnBinding<TurnDefinition<unknown, unknown>>,
|
|
96
70
|
): ProcessGraphTurnView {
|
|
97
71
|
const definition = binding.definition;
|
|
98
|
-
const publishedProducts =
|
|
99
|
-
...new Set([...humanPublishedProducts(definition), ...outcomePublishedProducts(definition)]),
|
|
100
|
-
];
|
|
72
|
+
const publishedProducts = turnPublishedProducts(definition);
|
|
101
73
|
return {
|
|
102
|
-
turnType:
|
|
74
|
+
turnType: definition.kind,
|
|
103
75
|
description: definition.description,
|
|
104
76
|
transitions: getProcessTurnTransitions(binding),
|
|
105
|
-
...(definition.reviewSubject ? { reviewSubject: { ...definition.reviewSubject } } : {}),
|
|
106
77
|
...(definition.kind === "human" && definition.reviewProduct
|
|
107
78
|
? { reviewProduct: definition.reviewProduct }
|
|
108
79
|
: {}),
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { LaunchModelConfigInput } from "@leitwerk-dev/domain";
|
|
2
2
|
import type { ProcessWatcherSource } from "./extension-api.js";
|
|
3
|
+
import { objectArg } from "./tool-arguments.js";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
throw new Error(`${subject} must be an object`);
|
|
7
|
-
}
|
|
8
|
-
return value as Record<string, unknown>;
|
|
9
|
-
}
|
|
5
|
+
const record = (value: unknown, subject: string) =>
|
|
6
|
+
objectArg(value, `${subject} must be an object`);
|
|
10
7
|
|
|
11
8
|
function nonEmptyString(value: unknown, path: string): string {
|
|
12
9
|
if (typeof value !== "string" || value.trim() === "") {
|
|
@@ -16,9 +13,16 @@ function nonEmptyString(value: unknown, path: string): string {
|
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
/** Parse the shared launch-model fragment nested inside extension-owned watcher config. */
|
|
19
|
-
export function parseProcessWatcherLaunchModelConfig(
|
|
20
|
-
|
|
16
|
+
export function parseProcessWatcherLaunchModelConfig(
|
|
17
|
+
value: unknown,
|
|
18
|
+
): LaunchModelConfigInput & { skillIds: string[] } {
|
|
19
|
+
if (value === undefined) return { defaultModelProfileId: null, turnConfigs: {}, skillIds: [] };
|
|
21
20
|
const launch = record(value, "launch");
|
|
21
|
+
const rawSkills = launch.skills === undefined ? [] : launch.skills;
|
|
22
|
+
if (!Array.isArray(rawSkills)) throw new Error("launch.skills must be an array");
|
|
23
|
+
const skillIds = rawSkills.map((skill, index) => nonEmptyString(skill, `launch.skills.${index}`));
|
|
24
|
+
if (new Set(skillIds).size !== skillIds.length)
|
|
25
|
+
throw new Error("launch.skills contains duplicates");
|
|
22
26
|
const rawTurns =
|
|
23
27
|
launch.turn_configs === undefined ? {} : record(launch.turn_configs, "launch.turn_configs");
|
|
24
28
|
return {
|
|
@@ -40,6 +44,7 @@ export function parseProcessWatcherLaunchModelConfig(value: unknown): LaunchMode
|
|
|
40
44
|
];
|
|
41
45
|
}),
|
|
42
46
|
),
|
|
47
|
+
skillIds,
|
|
43
48
|
};
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IntegrationToolExecutionContext } from "./extension-api.js";
|
|
2
|
+
import { objectArg } from "./tool-arguments.js";
|
|
3
|
+
|
|
4
|
+
export interface RepositoryProjectBinding {
|
|
5
|
+
owner: string;
|
|
6
|
+
repo: string;
|
|
7
|
+
profile: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Validate an authorized project's binding, retaining extension-selected legacy metadata. */
|
|
11
|
+
export function resolveRepositoryProjectBinding(
|
|
12
|
+
ctx: Pick<IntegrationToolExecutionContext, "project" | "process">,
|
|
13
|
+
provider: string,
|
|
14
|
+
legacyMetadataKey?: string,
|
|
15
|
+
): RepositoryProjectBinding {
|
|
16
|
+
const object = (value: unknown) => objectArg(value, `Invalid ${provider} project binding`);
|
|
17
|
+
function text(value: unknown, key: string): string {
|
|
18
|
+
if (typeof value !== "string" || !value.trim())
|
|
19
|
+
throw new Error(`${provider} binding ${key} must be a non-empty string`);
|
|
20
|
+
return value.trim();
|
|
21
|
+
}
|
|
22
|
+
if (!ctx.project || ctx.project.instanceId !== ctx.process.id)
|
|
23
|
+
throw new Error("An authorized process project is required");
|
|
24
|
+
const metadata = object(ctx.project.metadata ?? {});
|
|
25
|
+
const useLegacy = legacyMetadataKey !== undefined && metadata[provider] === undefined;
|
|
26
|
+
const binding = object(metadata[useLegacy ? legacyMetadataKey : provider]);
|
|
27
|
+
const profile =
|
|
28
|
+
useLegacy || (legacyMetadataKey === undefined && binding.profile === undefined)
|
|
29
|
+
? object(JSON.parse(ctx.process.paramsJson ?? "{}"))[`${provider}Profile`]
|
|
30
|
+
: binding.profile;
|
|
31
|
+
return {
|
|
32
|
+
owner: text(binding.owner, "owner"),
|
|
33
|
+
repo: text(binding.repo, "repo"),
|
|
34
|
+
profile: text(profile, "profile"),
|
|
35
|
+
};
|
|
36
|
+
}
|
package/src/registry-utils.ts
CHANGED
|
@@ -23,9 +23,5 @@ export function cloneMap<TKey, TValue>(registry: ReadonlyMap<TKey, TValue>): Map
|
|
|
23
23
|
export function cloneArrayValueMap<TKey, TValue>(
|
|
24
24
|
registry: ReadonlyMap<TKey, readonly TValue[]>,
|
|
25
25
|
): Map<TKey, readonly TValue[]> {
|
|
26
|
-
|
|
27
|
-
for (const [key, values] of registry) {
|
|
28
|
-
cloned.set(key, [...values]);
|
|
29
|
-
}
|
|
30
|
-
return cloned;
|
|
26
|
+
return new Map(Array.from(registry, ([key, values]) => [key, [...values]]));
|
|
31
27
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
2
|
+
|
|
3
|
+
export interface RepositoryFeedbackItem {
|
|
4
|
+
kind: "conversation" | "review" | "inline";
|
|
5
|
+
id: number;
|
|
6
|
+
body: string;
|
|
7
|
+
createdAt: string;
|
|
8
|
+
author: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
line?: number | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Batch already-authorized, unseen feedback after its quiet period. */
|
|
14
|
+
export function repositoryFeedbackBatch(
|
|
15
|
+
unseen: readonly RepositoryFeedbackItem[],
|
|
16
|
+
config: Record<`${RepositoryFeedbackItem["kind"]}Cursor`, number> & { quietPeriodMs: number },
|
|
17
|
+
now: number,
|
|
18
|
+
) {
|
|
19
|
+
if (!unseen.length) return null;
|
|
20
|
+
const latest = Math.max(...unseen.map((item) => Date.parse(item.createdAt) || 0));
|
|
21
|
+
if (now - latest < config.quietPeriodMs) return null;
|
|
22
|
+
const cursors = {
|
|
23
|
+
conversationCursor: config.conversationCursor,
|
|
24
|
+
reviewCursor: config.reviewCursor,
|
|
25
|
+
inlineCursor: config.inlineCursor,
|
|
26
|
+
};
|
|
27
|
+
for (const item of unseen) {
|
|
28
|
+
const key = `${item.kind}Cursor` as const;
|
|
29
|
+
cursors[key] = Math.max(cursors[key], item.id);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
event: { feedbackIds: unseen.map(({ kind, id }) => ({ kind, id })), cursors },
|
|
33
|
+
mergeKey: `${cursors.conversationCursor}:${cursors.reviewCursor}:${cursors.inlineCursor}`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Normalize common forge feedback fields; reject empty bodies and missing identities. */
|
|
38
|
+
export function normalizeRepositoryFeedback(
|
|
39
|
+
kind: RepositoryFeedbackItem["kind"],
|
|
40
|
+
item: Record<string, unknown>,
|
|
41
|
+
): RepositoryFeedbackItem | null {
|
|
42
|
+
const body = typeof item.body === "string" ? item.body.trim() : "";
|
|
43
|
+
const user = asUnknownRecord(item.user) ?? {};
|
|
44
|
+
if (!body || typeof item.id !== "number" || typeof user.login !== "string") return null;
|
|
45
|
+
return {
|
|
46
|
+
kind,
|
|
47
|
+
id: item.id,
|
|
48
|
+
body,
|
|
49
|
+
createdAt:
|
|
50
|
+
typeof item.submitted_at === "string"
|
|
51
|
+
? item.submitted_at
|
|
52
|
+
: typeof item.created_at === "string"
|
|
53
|
+
? item.created_at
|
|
54
|
+
: new Date(0).toISOString(),
|
|
55
|
+
author: user.login,
|
|
56
|
+
...(typeof item.path === "string" ? { path: item.path } : {}),
|
|
57
|
+
...(typeof item.line === "number" ? { line: item.line } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX,
|
|
2
3
|
INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX,
|
|
3
4
|
type SubprocessEnvInput,
|
|
4
5
|
sanitizeWorkerSubprocessEnv,
|
|
@@ -19,6 +20,17 @@ export function clearRepositoryGitSshWrappers(): void {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
export function setRepositoryGitHttpsHelper(projectKey: string, helperPath: string): void {
|
|
24
|
+
process.env[`${INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX}${encodeURIComponent(projectKey)}`] =
|
|
25
|
+
helperPath;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function clearRepositoryGitHttpsHelpers(): void {
|
|
29
|
+
for (const key of Object.keys(process.env)) {
|
|
30
|
+
if (key.startsWith(INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX)) delete process.env[key];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
/** Safe environment for a trusted Git invocation for one process project. */
|
|
23
35
|
export function repositoryGitSubprocessEnv(
|
|
24
36
|
projectKey: string,
|
|
@@ -27,9 +39,31 @@ export function repositoryGitSubprocessEnv(
|
|
|
27
39
|
const env = sanitizeWorkerSubprocessEnv(process.env, overrides);
|
|
28
40
|
const wrapper = process.env[wrapperKey(projectKey)];
|
|
29
41
|
if (wrapper) env.GIT_SSH = wrapper;
|
|
42
|
+
const helper =
|
|
43
|
+
process.env[`${INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX}${encodeURIComponent(projectKey)}`];
|
|
44
|
+
if (helper) {
|
|
45
|
+
const config = [
|
|
46
|
+
["credential.helper", ""],
|
|
47
|
+
["credential.helper", `!${shellQuote(process.execPath)} ${shellQuote(helper)}`],
|
|
48
|
+
["credential.useHttpPath", "true"],
|
|
49
|
+
["http.followRedirects", "false"],
|
|
50
|
+
["protocol.allow", "never"],
|
|
51
|
+
["protocol.https.allow", "always"],
|
|
52
|
+
];
|
|
53
|
+
env.GIT_CONFIG_COUNT = String(config.length);
|
|
54
|
+
config.forEach(([key, value], index) => {
|
|
55
|
+
env[`GIT_CONFIG_KEY_${index}`] = key;
|
|
56
|
+
env[`GIT_CONFIG_VALUE_${index}`] = value;
|
|
57
|
+
});
|
|
58
|
+
env.GIT_TERMINAL_PROMPT = "0";
|
|
59
|
+
}
|
|
30
60
|
return env;
|
|
31
61
|
}
|
|
32
62
|
|
|
33
63
|
export function repositoryGitArgs(args: readonly string[]): string[] {
|
|
34
64
|
return ["-c", "core.hooksPath=/dev/null", ...args];
|
|
35
65
|
}
|
|
66
|
+
|
|
67
|
+
function shellQuote(value: string): string {
|
|
68
|
+
return "'" + value.replaceAll("'", "'\"'\"'") + "'";
|
|
69
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { IntegrationHttpClient } from "./integration-http.js";
|
|
2
|
+
import type { RepositoryIssue, RepositoryPullRequest } from "./repository-types.js";
|
|
3
|
+
|
|
4
|
+
/** Common forge endpoints; extensions retain authentication and specialized operations. */
|
|
5
|
+
export class RepositoryHttpClient<Comment = Record<string, unknown>> extends IntegrationHttpClient {
|
|
6
|
+
protected repositoryPath(owner: string, repo: string): string {
|
|
7
|
+
return `/repos/${owner}/${repo}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
getIssue(owner: string, repo: string, number: number, signal?: AbortSignal) {
|
|
11
|
+
return this.request<RepositoryIssue>(`${this.repositoryPath(owner, repo)}/issues/${number}`, {
|
|
12
|
+
signal,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
listIssueComments(owner: string, repo: string, number: number, signal?: AbortSignal) {
|
|
17
|
+
return this.pages<Comment>(
|
|
18
|
+
`${this.repositoryPath(owner, repo)}/issues/${number}/comments`,
|
|
19
|
+
signal,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
addIssueComment(owner: string, repo: string, number: number, body: string, signal?: AbortSignal) {
|
|
24
|
+
return this.writeJson(
|
|
25
|
+
`${this.repositoryPath(owner, repo)}/issues/${number}/comments`,
|
|
26
|
+
"POST",
|
|
27
|
+
{ body },
|
|
28
|
+
signal,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
createPullRequest(
|
|
33
|
+
owner: string,
|
|
34
|
+
repo: string,
|
|
35
|
+
input: { title: string; body: string; head: string; base: string },
|
|
36
|
+
) {
|
|
37
|
+
return this.writeJson<RepositoryPullRequest>(
|
|
38
|
+
`${this.repositoryPath(owner, repo)}/pulls`,
|
|
39
|
+
"POST",
|
|
40
|
+
input,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getPullRequest(owner: string, repo: string, number: number, signal?: AbortSignal) {
|
|
45
|
+
return this.request<RepositoryPullRequest>(
|
|
46
|
+
`${this.repositoryPath(owner, repo)}/pulls/${number}`,
|
|
47
|
+
{ signal },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
listPullRequests(owner: string, repo: string, state = "open") {
|
|
52
|
+
return this.pages<RepositoryPullRequest>(
|
|
53
|
+
`${this.repositoryPath(owner, repo)}/pulls?state=${encodeURIComponent(state)}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
updatePullRequest(
|
|
58
|
+
owner: string,
|
|
59
|
+
repo: string,
|
|
60
|
+
number: number,
|
|
61
|
+
patch: Record<string, unknown>,
|
|
62
|
+
signal?: AbortSignal,
|
|
63
|
+
) {
|
|
64
|
+
return this.writeJson<RepositoryPullRequest>(
|
|
65
|
+
`${this.repositoryPath(owner, repo)}/pulls/${number}`,
|
|
66
|
+
"PATCH",
|
|
67
|
+
patch,
|
|
68
|
+
signal,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Canonical, credential-free HTTPS repository URL. Reject ambiguous Git credential paths. */
|
|
2
|
+
export function repositoryHttpsUrl(value: string): URL {
|
|
3
|
+
let url: URL;
|
|
4
|
+
try {
|
|
5
|
+
url = new URL(value);
|
|
6
|
+
} catch {
|
|
7
|
+
throw new Error("Repository authentication requires a valid HTTPS URL");
|
|
8
|
+
}
|
|
9
|
+
if (
|
|
10
|
+
url.protocol !== "https:" ||
|
|
11
|
+
url.username ||
|
|
12
|
+
url.password ||
|
|
13
|
+
url.search ||
|
|
14
|
+
url.hash ||
|
|
15
|
+
!url.pathname.slice(1) ||
|
|
16
|
+
/[%\\\s]/.test(url.pathname) ||
|
|
17
|
+
url.pathname.split("/").some((part) => part === "." || part === "..") ||
|
|
18
|
+
url.href !== value
|
|
19
|
+
)
|
|
20
|
+
throw new Error("Repository authentication requires a canonical credential-free HTTPS URL");
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { parseDurationMs } from "@leitwerk-dev/watcher-utils";
|
|
2
|
+
import { parseProcessWatcherLaunchModelConfig } from "./process-watcher-source.js";
|
|
3
|
+
import { objectArg } from "./tool-arguments.js";
|
|
4
|
+
|
|
5
|
+
export interface RepositoryIssueWatcherConfig {
|
|
6
|
+
profile: string;
|
|
7
|
+
pollInterval: string;
|
|
8
|
+
repositories: { include: readonly string[]; exclude: readonly string[] };
|
|
9
|
+
labels: { trigger: string; done: string };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function matchesRepository(
|
|
13
|
+
config: Pick<RepositoryIssueWatcherConfig, "repositories">,
|
|
14
|
+
repository: { full_name: string },
|
|
15
|
+
): boolean {
|
|
16
|
+
const { include = [], exclude = [] } = config.repositories ?? {};
|
|
17
|
+
return (
|
|
18
|
+
!exclude.includes(repository.full_name) &&
|
|
19
|
+
(include.length === 0 || include.includes(repository.full_name))
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const record = (value: unknown, subject: string) =>
|
|
24
|
+
objectArg(value, `${subject} must be an object`);
|
|
25
|
+
|
|
26
|
+
function nonEmptyString(value: unknown, path: string): string {
|
|
27
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
28
|
+
throw new Error(`${path} must be a non-empty string`);
|
|
29
|
+
return value.trim();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function repositoryNames(value: unknown, path: string): readonly string[] {
|
|
33
|
+
if (value === undefined) return [];
|
|
34
|
+
if (!Array.isArray(value)) throw new Error(`${path} must be an array`);
|
|
35
|
+
return value.map((candidate, index) => {
|
|
36
|
+
const name = nonEmptyString(candidate, `${path}[${index}]`);
|
|
37
|
+
if (!/^[^/\s]+\/[^/\s]+$/.test(name))
|
|
38
|
+
throw new Error(`${path}[${index}] must use owner/name format`);
|
|
39
|
+
return name;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Parse shared issue watcher fields; extensions choose the legacy type and label policy. */
|
|
44
|
+
export function parseRepositoryIssueWatcherConfig(
|
|
45
|
+
raw: unknown,
|
|
46
|
+
legacyType: string,
|
|
47
|
+
distinctLabels = false,
|
|
48
|
+
) {
|
|
49
|
+
const config = record(raw, "watcher config");
|
|
50
|
+
if (config.type !== undefined && config.type !== legacyType)
|
|
51
|
+
throw new Error(`type must be '${legacyType}' when specified`);
|
|
52
|
+
if (typeof config.enabled !== "boolean") throw new Error("enabled must be a boolean");
|
|
53
|
+
const pollInterval = nonEmptyString(config.poll_interval, "poll_interval");
|
|
54
|
+
if (parseDurationMs(pollInterval, -1, { allowHours: true }) <= 0)
|
|
55
|
+
throw new Error("poll_interval must be a positive duration");
|
|
56
|
+
const labels = record(config.labels, "labels");
|
|
57
|
+
const repositories =
|
|
58
|
+
config.repositories === undefined ? {} : record(config.repositories, "repositories");
|
|
59
|
+
const parsed: RepositoryIssueWatcherConfig = {
|
|
60
|
+
profile: nonEmptyString(config.profile, "profile"),
|
|
61
|
+
pollInterval,
|
|
62
|
+
repositories: {
|
|
63
|
+
include: repositoryNames(repositories.include, "repositories.include"),
|
|
64
|
+
exclude: repositoryNames(repositories.exclude, "repositories.exclude"),
|
|
65
|
+
},
|
|
66
|
+
labels: {
|
|
67
|
+
trigger: nonEmptyString(labels.trigger, "labels.trigger"),
|
|
68
|
+
done: nonEmptyString(labels.done, "labels.done"),
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
if (distinctLabels && parsed.labels.trigger === parsed.labels.done)
|
|
72
|
+
throw new Error("Trigger and done labels must differ");
|
|
73
|
+
return {
|
|
74
|
+
config: parsed,
|
|
75
|
+
enabled: config.enabled,
|
|
76
|
+
launchModelConfig: parseProcessWatcherLaunchModelConfig(config.launch),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function presentRepositoryIssueWatcherConfig(config: RepositoryIssueWatcherConfig) {
|
|
81
|
+
return {
|
|
82
|
+
targetSummary: `Profile ${config.profile} · trigger ${config.labels.trigger}`,
|
|
83
|
+
details: [
|
|
84
|
+
{ label: "Profile", value: config.profile },
|
|
85
|
+
{ label: "Included repositories", value: config.repositories.include.join(", ") || "all" },
|
|
86
|
+
{ label: "Excluded repositories", value: config.repositories.exclude.join(", ") || "none" },
|
|
87
|
+
{ label: "Trigger label", value: config.labels.trigger },
|
|
88
|
+
{ label: "Done label", value: config.labels.done },
|
|
89
|
+
{ label: "Poll interval", value: config.pollInterval },
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
2
|
+
|
|
3
|
+
/** Parse common forge source fields, preserving polling defaults and permissive string handling. */
|
|
4
|
+
export function parseRepositoryPullRequestConfig(value: unknown) {
|
|
5
|
+
const config = asUnknownRecord(value) ?? {};
|
|
6
|
+
if (
|
|
7
|
+
typeof config.profile !== "string" ||
|
|
8
|
+
typeof config.owner !== "string" ||
|
|
9
|
+
typeof config.repo !== "string" ||
|
|
10
|
+
typeof config.prNumber !== "number"
|
|
11
|
+
)
|
|
12
|
+
return null;
|
|
13
|
+
const terminalOutcome: "merged" | "closed" | undefined =
|
|
14
|
+
config.terminalOutcome === "merged" || config.terminalOutcome === "closed"
|
|
15
|
+
? config.terminalOutcome
|
|
16
|
+
: undefined;
|
|
17
|
+
return {
|
|
18
|
+
profile: config.profile,
|
|
19
|
+
owner: config.owner,
|
|
20
|
+
repo: config.repo,
|
|
21
|
+
prNumber: config.prNumber,
|
|
22
|
+
pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
|
|
23
|
+
terminalOutcome,
|
|
24
|
+
disabled: config.disabled === true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function parseRepositoryFeedbackConfig(value: unknown) {
|
|
29
|
+
const base = parseRepositoryPullRequestConfig(value);
|
|
30
|
+
const config = asUnknownRecord(value) ?? {};
|
|
31
|
+
if (!base) return null;
|
|
32
|
+
return {
|
|
33
|
+
...base,
|
|
34
|
+
conversationCursor:
|
|
35
|
+
typeof config.conversationCursor === "number" ? config.conversationCursor : 0,
|
|
36
|
+
reviewCursor: typeof config.reviewCursor === "number" ? config.reviewCursor : 0,
|
|
37
|
+
inlineCursor: typeof config.inlineCursor === "number" ? config.inlineCursor : 0,
|
|
38
|
+
quietPeriodMs: typeof config.quietPeriodMs === "number" ? config.quietPeriodMs : 120_000,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function parseRepositoryIssueCancelledConfig(value: unknown) {
|
|
43
|
+
const config = asUnknownRecord(value) ?? {};
|
|
44
|
+
if (
|
|
45
|
+
typeof config.profile !== "string" ||
|
|
46
|
+
typeof config.owner !== "string" ||
|
|
47
|
+
typeof config.repo !== "string" ||
|
|
48
|
+
typeof config.issueNumber !== "number" ||
|
|
49
|
+
typeof config.triggerLabel !== "string"
|
|
50
|
+
)
|
|
51
|
+
return null;
|
|
52
|
+
return {
|
|
53
|
+
profile: config.profile,
|
|
54
|
+
owner: config.owner,
|
|
55
|
+
repo: config.repo,
|
|
56
|
+
issueNumber: config.issueNumber,
|
|
57
|
+
triggerLabel: config.triggerLabel,
|
|
58
|
+
pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Common issue and pull-request response fields used by repository integrations. */
|
|
2
|
+
export interface RepositoryIssue {
|
|
3
|
+
number: number;
|
|
4
|
+
title: string;
|
|
5
|
+
body: string | null;
|
|
6
|
+
state: string;
|
|
7
|
+
html_url: string;
|
|
8
|
+
updated_at: string;
|
|
9
|
+
user: { login: string };
|
|
10
|
+
labels: Array<{ id: number; name: string }>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface RepositoryPullRequest {
|
|
14
|
+
number: number;
|
|
15
|
+
title: string;
|
|
16
|
+
body: string | null;
|
|
17
|
+
state: string;
|
|
18
|
+
merged: boolean;
|
|
19
|
+
mergeable?: boolean | null;
|
|
20
|
+
mergeable_state?: string | null;
|
|
21
|
+
merge_commit_sha: string | null;
|
|
22
|
+
html_url: string;
|
|
23
|
+
head: { ref: string; sha: string };
|
|
24
|
+
base: { ref: string; sha: string };
|
|
25
|
+
}
|
package/src/state-helpers.ts
CHANGED
|
@@ -1,36 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
|
+
asUnknownRecord,
|
|
2
3
|
createEmptyProcessProductRefs,
|
|
3
4
|
createEmptyProcessSemanticEntryRefs,
|
|
4
5
|
type ProcessProductRefs,
|
|
5
6
|
type ProcessSemanticEntryRefs,
|
|
6
7
|
parseProcessProductRefs,
|
|
7
8
|
parseProcessSemanticEntryRefs,
|
|
8
|
-
parseReviewSubject,
|
|
9
|
-
type ReviewSubject,
|
|
10
9
|
} from "@leitwerk-dev/domain";
|
|
10
|
+
import type { Codec } from "./extension-api.js";
|
|
11
11
|
|
|
12
12
|
export interface StructuralProcessState {
|
|
13
13
|
semanticEntryRefs: ProcessSemanticEntryRefs;
|
|
14
14
|
productRefs: ProcessProductRefs;
|
|
15
|
-
reviewSubject: ReviewSubject | null;
|
|
16
15
|
}
|
|
17
16
|
|
|
17
|
+
export const structuralStateCodec: Codec<StructuralProcessState> = {
|
|
18
|
+
parse: parseStructuralProcessState,
|
|
19
|
+
serialize: (value) => value,
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
export function createEmptyStructuralProcessState(): StructuralProcessState {
|
|
19
23
|
return {
|
|
20
24
|
semanticEntryRefs: createEmptyProcessSemanticEntryRefs(),
|
|
21
25
|
productRefs: createEmptyProcessProductRefs(),
|
|
22
|
-
reviewSubject: null,
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export function parseStructuralProcessState(value: unknown): StructuralProcessState {
|
|
27
|
-
|
|
28
|
-
return createEmptyStructuralProcessState();
|
|
29
|
-
}
|
|
30
|
-
const record = value as Record<string, unknown>;
|
|
30
|
+
const record = asUnknownRecord(value) ?? {};
|
|
31
31
|
return {
|
|
32
32
|
semanticEntryRefs: parseProcessSemanticEntryRefs(record.semanticEntryRefs),
|
|
33
33
|
productRefs: parseProcessProductRefs(record.productRefs),
|
|
34
|
-
reviewSubject: parseReviewSubject(record.reviewSubject),
|
|
35
34
|
};
|
|
36
35
|
}
|
package/src/subprocess-env.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
export type SubprocessEnvInput = Record<string, string | undefined>;
|
|
8
8
|
|
|
9
9
|
export const INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX = "LEITWERK_INTERNAL_REPOSITORY_GIT_SSH_";
|
|
10
|
+
export const INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX = "LEITWERK_INTERNAL_REPOSITORY_GIT_HTTPS_";
|
|
10
11
|
|
|
11
12
|
export const WORKER_SUBPROCESS_SENSITIVE_ENV_KEYS = [
|
|
12
13
|
WORKER_IPC_CONNECT_TOKEN_ENV,
|
|
@@ -20,6 +21,8 @@ const SENSITIVE_ENV_KEYS = new Set<string>([
|
|
|
20
21
|
"SSH_AGENT_PID",
|
|
21
22
|
"GIT_SSH",
|
|
22
23
|
"GIT_SSH_COMMAND",
|
|
24
|
+
"GIT_ASKPASS",
|
|
25
|
+
"SSH_ASKPASS",
|
|
23
26
|
]);
|
|
24
27
|
|
|
25
28
|
/**
|
|
@@ -38,6 +41,9 @@ export function sanitizeWorkerSubprocessEnv(
|
|
|
38
41
|
if (
|
|
39
42
|
SENSITIVE_ENV_KEYS.has(key) ||
|
|
40
43
|
key.startsWith(INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX) ||
|
|
44
|
+
key.startsWith(INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX) ||
|
|
45
|
+
key.startsWith("GIT_CONFIG_") ||
|
|
46
|
+
/(?:^|_)(?:TOKEN|API_KEY|PASSWORD|SECRET)$/.test(key) ||
|
|
41
47
|
value === undefined
|
|
42
48
|
) {
|
|
43
49
|
continue;
|