@leitwerk-dev/process-sdk 0.2.1 → 0.3.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 (41) hide show
  1. package/README.md +12 -0
  2. package/dist/core-capabilities.d.ts +2 -0
  3. package/dist/core-capabilities.d.ts.map +1 -1
  4. package/dist/{extension-api-B4gG5w1K.d.ts → extension-api-3Vr3RE8S.d.ts} +5 -5
  5. package/dist/extension-api.d.ts +5 -5
  6. package/dist/extension-api.d.ts.map +1 -1
  7. package/dist/external-source-poll.d.ts +18 -12
  8. package/dist/external-source-poll.d.ts.map +1 -1
  9. package/dist/index.d.ts +2 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +45 -38
  12. package/dist/index.js.map +1 -1
  13. package/dist/integration-http.d.ts +4 -4
  14. package/dist/integration-http.d.ts.map +1 -1
  15. package/dist/json-data.d.ts +1 -1
  16. package/dist/json-data.d.ts.map +1 -1
  17. package/dist/repository-feedback.d.ts +32 -26
  18. package/dist/repository-feedback.d.ts.map +1 -1
  19. package/dist/repository-https.d.ts +1 -1
  20. package/dist/repository-https.d.ts.map +1 -1
  21. package/dist/repository-issue-watcher.d.ts +30 -25
  22. package/dist/repository-issue-watcher.d.ts.map +1 -1
  23. package/dist/repository-source-config.d.ts +29 -44
  24. package/dist/repository-source-config.d.ts.map +1 -1
  25. package/dist/subprocess-env.d.ts +1 -1
  26. package/dist/subprocess-env.d.ts.map +1 -1
  27. package/dist/tool-arguments.d.ts +3 -3
  28. package/dist/tool-arguments.d.ts.map +1 -1
  29. package/package.json +6 -6
  30. package/src/core-capabilities.ts +2 -0
  31. package/src/extension-api.ts +5 -5
  32. package/src/external-source-poll.ts +65 -11
  33. package/src/index.ts +9 -1
  34. package/src/integration-http.ts +3 -3
  35. package/src/json-data.ts +1 -1
  36. package/src/repository-feedback.ts +48 -20
  37. package/src/repository-https.ts +1 -1
  38. package/src/repository-issue-watcher.ts +48 -21
  39. package/src/repository-source-config.ts +66 -23
  40. package/src/subprocess-env.ts +1 -1
  41. package/src/tool-arguments.ts +3 -3
@@ -4,38 +4,35 @@ import { asUnknownRecord } from "@leitwerk-dev/domain";
4
4
  export interface RepositoryFeedbackItem {
5
5
  /** @public */
6
6
  kind: "conversation" | "review" | "inline";
7
- /** @internal */
7
+ /** @public */
8
8
  id: number;
9
9
  /** @public */
10
10
  body: string;
11
- /** @internal */
11
+ /** @public */
12
12
  createdAt: string;
13
13
  /** @public */
14
14
  author: string;
15
- /** @internal */
15
+ /** @public */
16
16
  path?: string;
17
- /** @internal */
17
+ /** @public */
18
18
  line?: number | null;
19
19
  }
20
20
 
21
- /** Batch already-authorized, unseen feedback after its quiet period. @internal */
21
+ /** Batch already-authorized, unseen feedback after its quiet period. @public */
22
22
  export function repositoryFeedbackBatch(
23
23
  unseen: readonly RepositoryFeedbackItem[],
24
- config: Record<`${RepositoryFeedbackItem["kind"]}Cursor`, number> & {
25
- /** @internal */
26
- quietPeriodMs: number;
27
- },
24
+ config: RepositoryFeedbackBatchConfig,
28
25
  now: number,
29
- ) {
26
+ ): RepositoryFeedbackBatch | null {
30
27
  if (!unseen.length) return null;
31
28
  const latest = Math.max(...unseen.map((item) => Date.parse(item.createdAt) || 0));
32
29
  if (now - latest < config.quietPeriodMs) return null;
33
30
  const cursors = {
34
- /** @internal */
31
+ /** @public */
35
32
  conversationCursor: config.conversationCursor,
36
- /** @internal */
33
+ /** @public */
37
34
  reviewCursor: config.reviewCursor,
38
- /** @internal */
35
+ /** @public */
39
36
  inlineCursor: config.inlineCursor,
40
37
  };
41
38
  for (const item of unseen) {
@@ -43,24 +40,24 @@ export function repositoryFeedbackBatch(
43
40
  cursors[key] = Math.max(cursors[key], item.id);
44
41
  }
45
42
  return {
46
- /** @internal */
43
+ /** @public */
47
44
  event: {
48
- /** @internal */
45
+ /** @public */
49
46
  feedbackIds: unseen.map(({ kind, id }) => ({
50
- /** @internal */
47
+ /** @public */
51
48
  kind,
52
- /** @internal */
49
+ /** @public */
53
50
  id,
54
51
  })),
55
- /** @internal */
52
+ /** @public */
56
53
  cursors,
57
54
  },
58
- /** @internal */
55
+ /** @public */
59
56
  mergeKey: `${cursors.conversationCursor}:${cursors.reviewCursor}:${cursors.inlineCursor}`,
60
57
  };
61
58
  }
62
59
 
63
- /** Normalize common forge feedback fields; reject empty bodies and missing identities. @internal */
60
+ /** Normalize common forge feedback fields; reject empty bodies and missing identities. @public */
64
61
  export function normalizeRepositoryFeedback(
65
62
  kind: RepositoryFeedbackItem["kind"],
66
63
  item: Record<string, unknown>,
@@ -83,3 +80,34 @@ export function normalizeRepositoryFeedback(
83
80
  ...(typeof item.line === "number" ? { line: item.line } : {}),
84
81
  };
85
82
  }
83
+ /** @public */
84
+ export interface RepositoryFeedbackCursors {
85
+ /** @public */
86
+ conversationCursor: number;
87
+ /** @public */
88
+ reviewCursor: number;
89
+ /** @public */
90
+ inlineCursor: number;
91
+ }
92
+ /** @public */
93
+ export interface RepositoryFeedbackBatchConfig extends RepositoryFeedbackCursors {
94
+ /** @public */
95
+ quietPeriodMs: number;
96
+ }
97
+ /** @public */
98
+ export interface RepositoryFeedbackBatch {
99
+ /** @public */
100
+ event: {
101
+ /** @public */
102
+ feedbackIds: {
103
+ /** @public */
104
+ kind: RepositoryFeedbackItem["kind"];
105
+ /** @public */
106
+ id: number;
107
+ }[];
108
+ /** @public */
109
+ cursors: RepositoryFeedbackCursors;
110
+ };
111
+ /** @public */
112
+ mergeKey: string;
113
+ }
@@ -1,4 +1,4 @@
1
- /** Canonical, credential-free HTTPS repository URL. Reject ambiguous Git credential paths. @internal */
1
+ /** Canonical, credential-free HTTPS repository URL. Reject ambiguous Git credential paths. @public */
2
2
  export function repositoryHttpsUrl(value: string): URL {
3
3
  let url: URL;
4
4
  try {
@@ -1,34 +1,35 @@
1
+ import type { LaunchModelConfigInput } from "@leitwerk-dev/domain";
1
2
  import { parseDurationMs } from "@leitwerk-dev/watcher-utils";
2
3
  import { parseProcessWatcherLaunchModelConfig } from "./process-watcher-source.js";
3
4
  import { objectArg } from "./tool-arguments.js";
4
5
 
5
6
  /** @public */
6
7
  export interface RepositoryIssueWatcherConfig {
7
- /** @internal */
8
+ /** @public */
8
9
  profile: string;
9
- /** @internal */
10
+ /** @public */
10
11
  pollInterval: string;
11
- /** @internal */
12
+ /** @public */
12
13
  repositories: {
13
- /** @internal */
14
+ /** @public */
14
15
  include: readonly string[];
15
- /** @internal */
16
+ /** @public */
16
17
  exclude: readonly string[];
17
18
  };
18
- /** @internal */
19
+ /** @public */
19
20
  labels: {
20
- /** @internal */
21
+ /** @public */
21
22
  trigger: string;
22
- /** @internal */
23
+ /** @public */
23
24
  done: string;
24
25
  };
25
26
  }
26
27
 
27
- /** @internal */
28
+ /** @public */
28
29
  export function matchesRepository(
29
30
  config: Pick<RepositoryIssueWatcherConfig, "repositories">,
30
31
  repository: {
31
- /** @internal */
32
+ /** @public */
32
33
  full_name: string;
33
34
  },
34
35
  ): boolean {
@@ -59,12 +60,12 @@ function repositoryNames(value: unknown, path: string): readonly string[] {
59
60
  });
60
61
  }
61
62
 
62
- /** Parse shared issue watcher fields; extensions choose the legacy type and label policy. @internal */
63
+ /** Parse shared issue watcher fields; extensions choose the legacy type and label policy. @public */
63
64
  export function parseRepositoryIssueWatcherConfig(
64
65
  raw: unknown,
65
66
  legacyType: string,
66
67
  distinctLabels = false,
67
- ) {
68
+ ): ParsedRepositoryIssueWatcherConfig {
68
69
  const config = record(raw, "watcher config");
69
70
  if (config.type !== undefined && config.type !== legacyType)
70
71
  throw new Error(`type must be '${legacyType}' when specified`);
@@ -90,26 +91,28 @@ export function parseRepositoryIssueWatcherConfig(
90
91
  if (distinctLabels && parsed.labels.trigger === parsed.labels.done)
91
92
  throw new Error("Trigger and done labels must differ");
92
93
  return {
93
- /** @internal */
94
+ /** @public */
94
95
  config: parsed,
95
- /** @internal */
96
+ /** @public */
96
97
  enabled: config.enabled,
97
- /** @internal */
98
+ /** @public */
98
99
  launchModelConfig: parseProcessWatcherLaunchModelConfig(config.launch),
99
100
  };
100
101
  }
101
102
 
102
- /** @internal */
103
- export function presentRepositoryIssueWatcherConfig(config: RepositoryIssueWatcherConfig) {
103
+ /** @public */
104
+ export function presentRepositoryIssueWatcherConfig(
105
+ config: RepositoryIssueWatcherConfig,
106
+ ): RepositoryIssueWatcherPresentation {
104
107
  return {
105
- /** @internal */
108
+ /** @public */
106
109
  targetSummary: `Profile ${config.profile} · trigger ${config.labels.trigger}`,
107
- /** @internal */
110
+ /** @public */
108
111
  details: [
109
112
  {
110
- /** @internal */
113
+ /** @public */
111
114
  label: "Profile",
112
- /** @internal */
115
+ /** @public */
113
116
  value: config.profile,
114
117
  },
115
118
  { label: "Included repositories", value: config.repositories.include.join(", ") || "all" },
@@ -120,3 +123,27 @@ export function presentRepositoryIssueWatcherConfig(config: RepositoryIssueWatch
120
123
  ],
121
124
  };
122
125
  }
126
+ /** @public */
127
+ export interface ParsedRepositoryIssueWatcherConfig {
128
+ /** @public */
129
+ config: RepositoryIssueWatcherConfig;
130
+ /** @public */
131
+ enabled: boolean;
132
+ /** @public */
133
+ launchModelConfig: LaunchModelConfigInput & {
134
+ /** @public */
135
+ skillIds: string[];
136
+ };
137
+ }
138
+ /** @public */
139
+ export interface RepositoryIssueWatcherPresentation {
140
+ /** @public */
141
+ targetSummary: string;
142
+ /** @public */
143
+ details: {
144
+ /** @public */
145
+ label: string;
146
+ /** @public */
147
+ value: string;
148
+ }[];
149
+ }
@@ -1,7 +1,10 @@
1
1
  import { asUnknownRecord } from "@leitwerk-dev/domain";
2
+ import type { RepositoryFeedbackBatchConfig } from "./repository-feedback.js";
2
3
 
3
- /** Parse common forge source fields, preserving polling defaults and permissive string handling. @internal */
4
- export function parseRepositoryPullRequestConfig(value: unknown) {
4
+ /** Parse common forge source fields, preserving polling defaults and permissive string handling. @public */
5
+ export function parseRepositoryPullRequestConfig(
6
+ value: unknown,
7
+ ): RepositoryPullRequestSourceConfig | null {
5
8
  const config = asUnknownRecord(value) ?? {};
6
9
  if (
7
10
  typeof config.profile !== "string" ||
@@ -15,44 +18,48 @@ export function parseRepositoryPullRequestConfig(value: unknown) {
15
18
  ? config.terminalOutcome
16
19
  : undefined;
17
20
  return {
18
- /** @internal */
21
+ /** @public */
19
22
  profile: config.profile,
20
- /** @internal */
23
+ /** @public */
21
24
  owner: config.owner,
22
- /** @internal */
25
+ /** @public */
23
26
  repo: config.repo,
24
- /** @internal */
27
+ /** @public */
25
28
  prNumber: config.prNumber,
26
- /** @internal */
29
+ /** @public */
27
30
  pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
28
- /** @internal */
31
+ /** @public */
29
32
  terminalOutcome,
30
- /** @internal */
33
+ /** @public */
31
34
  disabled: config.disabled === true,
32
35
  };
33
36
  }
34
37
 
35
- /** @internal */
36
- export function parseRepositoryFeedbackConfig(value: unknown) {
38
+ /** @public */
39
+ export function parseRepositoryFeedbackConfig(
40
+ value: unknown,
41
+ ): RepositoryFeedbackSourceConfig | null {
37
42
  const base = parseRepositoryPullRequestConfig(value);
38
43
  const config = asUnknownRecord(value) ?? {};
39
44
  if (!base) return null;
40
45
  return {
41
46
  ...base,
42
- /** @internal */
47
+ /** @public */
43
48
  conversationCursor:
44
49
  typeof config.conversationCursor === "number" ? config.conversationCursor : 0,
45
- /** @internal */
50
+ /** @public */
46
51
  reviewCursor: typeof config.reviewCursor === "number" ? config.reviewCursor : 0,
47
- /** @internal */
52
+ /** @public */
48
53
  inlineCursor: typeof config.inlineCursor === "number" ? config.inlineCursor : 0,
49
- /** @internal */
54
+ /** @public */
50
55
  quietPeriodMs: typeof config.quietPeriodMs === "number" ? config.quietPeriodMs : 120_000,
51
56
  };
52
57
  }
53
58
 
54
- /** @internal */
55
- export function parseRepositoryIssueCancelledConfig(value: unknown) {
59
+ /** @public */
60
+ export function parseRepositoryIssueCancelledConfig(
61
+ value: unknown,
62
+ ): RepositoryIssueCancelledSourceConfig | null {
56
63
  const config = asUnknownRecord(value) ?? {};
57
64
  if (
58
65
  typeof config.profile !== "string" ||
@@ -63,17 +70,53 @@ export function parseRepositoryIssueCancelledConfig(value: unknown) {
63
70
  )
64
71
  return null;
65
72
  return {
66
- /** @internal */
73
+ /** @public */
67
74
  profile: config.profile,
68
- /** @internal */
75
+ /** @public */
69
76
  owner: config.owner,
70
- /** @internal */
77
+ /** @public */
71
78
  repo: config.repo,
72
- /** @internal */
79
+ /** @public */
73
80
  issueNumber: config.issueNumber,
74
- /** @internal */
81
+ /** @public */
75
82
  triggerLabel: config.triggerLabel,
76
- /** @internal */
83
+ /** @public */
77
84
  pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
78
85
  };
79
86
  }
87
+ /** @public */
88
+ export interface RepositoryPullRequestSourceConfig {
89
+ /** @public */
90
+ profile: string;
91
+ /** @public */
92
+ owner: string;
93
+ /** @public */
94
+ repo: string;
95
+ /** @public */
96
+ prNumber: number;
97
+ /** @public */
98
+ pollInterval: string;
99
+ /** @public */
100
+ terminalOutcome: "merged" | "closed" | undefined;
101
+ /** @public */
102
+ disabled: boolean;
103
+ }
104
+ /** @public */
105
+ export interface RepositoryFeedbackSourceConfig
106
+ extends RepositoryPullRequestSourceConfig,
107
+ RepositoryFeedbackBatchConfig {}
108
+ /** @public */
109
+ export interface RepositoryIssueCancelledSourceConfig {
110
+ /** @public */
111
+ profile: string;
112
+ /** @public */
113
+ owner: string;
114
+ /** @public */
115
+ repo: string;
116
+ /** @public */
117
+ issueNumber: number;
118
+ /** @public */
119
+ triggerLabel: string;
120
+ /** @public */
121
+ pollInterval: string;
122
+ }
@@ -34,7 +34,7 @@ const SENSITIVE_ENV_KEYS = new Set<string>([
34
34
  * process itself. Repository scripts, git hooks, package managers, and other
35
35
  * tool subprocesses must not receive them.
36
36
  */
37
- /** @internal */
37
+ /** @public */
38
38
  export function sanitizeWorkerSubprocessEnv(
39
39
  baseEnv: SubprocessEnvInput = process.env,
40
40
  overrides: SubprocessEnvInput = {},
@@ -13,7 +13,7 @@ export function projectParameters(
13
13
  };
14
14
  }
15
15
 
16
- /** @internal */
16
+ /** @public */
17
17
  export function objectArg(
18
18
  value: unknown,
19
19
  message = "Tool arguments must be an object",
@@ -22,7 +22,7 @@ export function objectArg(
22
22
  return value as Record<string, unknown>;
23
23
  }
24
24
 
25
- /** Read required integration-tool arguments at the runtime boundary. @internal */
25
+ /** Read required integration-tool arguments at the runtime boundary. @public */
26
26
  export function stringArg(args: Record<string, unknown>, name: string): string {
27
27
  const value = args[name];
28
28
  if (typeof value !== "string" || !value.trim())
@@ -30,7 +30,7 @@ export function stringArg(args: Record<string, unknown>, name: string): string {
30
30
  return value.trim();
31
31
  }
32
32
 
33
- /** @internal */
33
+ /** @public */
34
34
  export function numberArg(args: Record<string, unknown>, name: string): number {
35
35
  const value = args[name];
36
36
  if (typeof value !== "number" || !Number.isInteger(value) || value <= 0)