@h-rig/server 0.0.6-alpha.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 (60) hide show
  1. package/README.md +14 -0
  2. package/dist/src/bootstrap.js +161 -0
  3. package/dist/src/index.js +13153 -0
  4. package/dist/src/inspector/agent-runtime.js +1077 -0
  5. package/dist/src/inspector/analysis.js +41 -0
  6. package/dist/src/inspector/discovery.js +137 -0
  7. package/dist/src/inspector/journal.js +518 -0
  8. package/dist/src/inspector/mission.js +562 -0
  9. package/dist/src/inspector/prompt.js +97 -0
  10. package/dist/src/inspector/provider-session.js +65 -0
  11. package/dist/src/inspector/reconcile.js +118 -0
  12. package/dist/src/inspector/review.js +13 -0
  13. package/dist/src/inspector/service.js +1759 -0
  14. package/dist/src/inspector/skills.js +155 -0
  15. package/dist/src/inspector/tools.js +1592 -0
  16. package/dist/src/inspector/types.js +1 -0
  17. package/dist/src/inspector/upstream-sync.js +479 -0
  18. package/dist/src/orchestration.js +402 -0
  19. package/dist/src/remote.js +123 -0
  20. package/dist/src/scheduler.js +84 -0
  21. package/dist/src/server-helpers/broadcasters.js +161 -0
  22. package/dist/src/server-helpers/conversation-snapshot.js +382 -0
  23. package/dist/src/server-helpers/event-emitter.js +41 -0
  24. package/dist/src/server-helpers/github-auth-store.js +155 -0
  25. package/dist/src/server-helpers/github-credentials.js +38 -0
  26. package/dist/src/server-helpers/github-project-status-sync.js +196 -0
  27. package/dist/src/server-helpers/github-projects.js +147 -0
  28. package/dist/src/server-helpers/github-reconciler.js +89 -0
  29. package/dist/src/server-helpers/http-router.js +3781 -0
  30. package/dist/src/server-helpers/http-utils.js +135 -0
  31. package/dist/src/server-helpers/inspector-agent-lifecycle.js +104 -0
  32. package/dist/src/server-helpers/inspector-jobs.js +4145 -0
  33. package/dist/src/server-helpers/issue-analysis.js +362 -0
  34. package/dist/src/server-helpers/normalizers.js +31 -0
  35. package/dist/src/server-helpers/notifications.js +96 -0
  36. package/dist/src/server-helpers/orchestration-ops.js +287 -0
  37. package/dist/src/server-helpers/orchestration.js +39 -0
  38. package/dist/src/server-helpers/plugin-host-cache.js +86 -0
  39. package/dist/src/server-helpers/project-fs-ops.js +194 -0
  40. package/dist/src/server-helpers/project-registry.js +124 -0
  41. package/dist/src/server-helpers/queue-state.js +78 -0
  42. package/dist/src/server-helpers/remote-checkout.js +140 -0
  43. package/dist/src/server-helpers/remote-snapshots.js +119 -0
  44. package/dist/src/server-helpers/run-io.js +262 -0
  45. package/dist/src/server-helpers/run-mutations.js +1784 -0
  46. package/dist/src/server-helpers/run-steering.js +176 -0
  47. package/dist/src/server-helpers/run-writers.js +75 -0
  48. package/dist/src/server-helpers/server-paths.js +27 -0
  49. package/dist/src/server-helpers/snapshot-orchestrator.js +832 -0
  50. package/dist/src/server-helpers/snapshot-service.js +1143 -0
  51. package/dist/src/server-helpers/summaries.js +126 -0
  52. package/dist/src/server-helpers/task-config.js +50 -0
  53. package/dist/src/server-helpers/task-projection.js +98 -0
  54. package/dist/src/server-helpers/terminal-runtime.js +156 -0
  55. package/dist/src/server-helpers/terminal-sessions.js +22 -0
  56. package/dist/src/server-helpers/validation-failure.js +31 -0
  57. package/dist/src/server-helpers/ws-router.js +1308 -0
  58. package/dist/src/server.js +12628 -0
  59. package/dist/src/websocket.js +63 -0
  60. package/package.json +33 -0
@@ -0,0 +1,65 @@
1
+ // @bun
2
+ // packages/server/src/inspector/provider-session.ts
3
+ function uniqueStrings(values) {
4
+ return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
5
+ }
6
+ function withSupport(defaultValue, support, key) {
7
+ return typeof support?.[key] === "boolean" ? Boolean(support[key]) : defaultValue;
8
+ }
9
+ function normalizeProviderSession(run) {
10
+ const sessionLogPaths = uniqueStrings([run.sessionLogPath]);
11
+ const artifactRoots = uniqueStrings([run.artifactRoot]);
12
+ const eventSources = uniqueStrings([run.source, ...run.rawSourceKinds, run.sessionPath ? "session-file" : null]);
13
+ const capabilityHints = uniqueStrings([
14
+ sessionLogPaths.length > 0 ? "logs" : null,
15
+ artifactRoots.length > 0 ? "artifacts" : null,
16
+ run.worktreePath ? "workspace" : null,
17
+ run.conflictState !== "none" ? "conflict" : null,
18
+ run.threadId ? "thread" : null
19
+ ]);
20
+ const observabilityConfidence = sessionLogPaths.length > 0 && artifactRoots.length > 0 && run.threadId ? "high" : sessionLogPaths.length > 0 || artifactRoots.length > 0 || Boolean(run.threadId) ? "medium" : "low";
21
+ return {
22
+ provider: run.provider,
23
+ runId: run.runId,
24
+ taskId: run.taskId,
25
+ workspaceId: run.workspaceId,
26
+ workspaceDir: run.worktreePath,
27
+ runtimeAdapter: run.runtimeAdapter,
28
+ status: run.status,
29
+ startedAt: run.startedAt,
30
+ updatedAt: run.updatedAt,
31
+ completedAt: run.completedAt,
32
+ threadId: run.threadId,
33
+ sessionLogPaths,
34
+ artifactRoots,
35
+ eventSources,
36
+ observabilityConfidence,
37
+ rawSourceKinds: [...run.rawSourceKinds],
38
+ capabilityHints
39
+ };
40
+ }
41
+ function deriveInspectorCapabilitySet(session, support = {}) {
42
+ return {
43
+ discoverRuns: withSupport(true, support, "discoverRuns"),
44
+ inspectRuns: withSupport(true, support, "inspectRuns"),
45
+ readLogs: session.sessionLogPaths.length > 0 && withSupport(true, support, "readLogs"),
46
+ readArtifacts: session.artifactRoots.length > 0 && withSupport(true, support, "readArtifacts"),
47
+ callServerApis: withSupport(true, support, "callServerApis"),
48
+ interruptRuns: withSupport(false, support, "interruptRuns"),
49
+ stopRuns: withSupport(false, support, "stopRuns"),
50
+ resumeRuns: withSupport(false, support, "resumeRuns"),
51
+ relaunchRuns: withSupport(false, support, "relaunchRuns"),
52
+ patchRepo: session.workspaceDir !== null && withSupport(true, support, "patchRepo"),
53
+ patchHarness: session.workspaceDir !== null && withSupport(true, support, "patchHarness"),
54
+ createTasks: withSupport(false, support, "createTasks"),
55
+ runReviewerAgents: withSupport(false, support, "runReviewerAgents"),
56
+ provisionSkills: withSupport(true, support, "provisionSkills"),
57
+ scanUpstream: withSupport(false, support, "scanUpstream"),
58
+ writeJournal: withSupport(true, support, "writeJournal"),
59
+ spawnSpecialists: withSupport(false, support, "spawnSpecialists")
60
+ };
61
+ }
62
+ export {
63
+ normalizeProviderSession,
64
+ deriveInspectorCapabilitySet
65
+ };
@@ -0,0 +1,118 @@
1
+ // @bun
2
+ // packages/server/src/inspector/reconcile.ts
3
+ function decisionTypeForStatus(status) {
4
+ switch (status) {
5
+ case "failed":
6
+ return "investigate-failure";
7
+ case "stopped":
8
+ return "inspect-stop";
9
+ default:
10
+ return null;
11
+ }
12
+ }
13
+ function reconcileInspectorRuns(options) {
14
+ const now = options.now ?? (() => new Date().toISOString());
15
+ let observedCount = 0;
16
+ let decisionCount = 0;
17
+ let actionCount = 0;
18
+ for (const run of options.runs) {
19
+ options.journal.upsertRun({
20
+ runId: run.runId,
21
+ workspaceId: run.workspaceId,
22
+ taskId: run.taskId,
23
+ runtimeAdapter: run.runtimeAdapter,
24
+ provider: run.provider,
25
+ status: run.status,
26
+ conflictState: run.conflictState,
27
+ conflictSummary: run.conflictSummary,
28
+ source: run.source,
29
+ title: run.title,
30
+ startedAt: run.startedAt,
31
+ updatedAt: run.updatedAt,
32
+ completedAt: run.completedAt
33
+ });
34
+ const observation = options.journal.appendObservation({
35
+ id: `observation:${run.runId}:${options.reason}:${run.updatedAt}`,
36
+ runId: run.runId,
37
+ dedupeKey: `run:${run.runId}:status:${run.status}:updated:${run.updatedAt}`,
38
+ kind: "run.observed",
39
+ severity: run.status === "failed" ? "warn" : "info",
40
+ source: run.source,
41
+ summary: `Observed run ${run.title}`,
42
+ details: {
43
+ reason: options.reason,
44
+ status: run.status,
45
+ provider: run.provider,
46
+ runtimeAdapter: run.runtimeAdapter,
47
+ conflictState: run.conflictState,
48
+ rawSourceKinds: run.rawSourceKinds
49
+ },
50
+ createdAt: now()
51
+ });
52
+ if (observation.ok && observation.changed) {
53
+ observedCount += 1;
54
+ }
55
+ const action = options.journal.appendAction({
56
+ id: `action:${run.runId}:${options.reason}:${run.updatedAt}`,
57
+ runId: run.runId,
58
+ dedupeKey: `action:${run.runId}:observe:${run.updatedAt}`,
59
+ actionType: "observe",
60
+ status: "completed",
61
+ target: `run:${run.runId}`,
62
+ input: { reason: options.reason },
63
+ result: { status: run.status },
64
+ startedAt: now(),
65
+ completedAt: now()
66
+ });
67
+ if (action.ok && action.changed) {
68
+ actionCount += 1;
69
+ }
70
+ const decisionType = decisionTypeForStatus(run.status);
71
+ if (decisionType) {
72
+ const decision = options.journal.appendDecision({
73
+ id: `decision:${run.runId}:${decisionType}:${run.updatedAt}`,
74
+ runId: run.runId,
75
+ dedupeKey: `decision:${run.runId}:${decisionType}:${run.updatedAt}`,
76
+ decisionType,
77
+ summary: `Investigate ${run.title}`,
78
+ rationale: `Run status ${run.status} requires inspector attention.`,
79
+ details: {
80
+ reason: options.reason,
81
+ status: run.status
82
+ },
83
+ createdAt: now()
84
+ });
85
+ if (decision.ok && decision.changed) {
86
+ decisionCount += 1;
87
+ }
88
+ }
89
+ if (run.conflictState !== "none") {
90
+ const conflictDecision = options.journal.appendDecision({
91
+ id: `decision:${run.runId}:conflict:${run.updatedAt}`,
92
+ runId: run.runId,
93
+ dedupeKey: `decision:${run.runId}:conflict:${run.updatedAt}`,
94
+ decisionType: "inspect-conflict",
95
+ summary: `Resolve ${run.title} observation conflict`,
96
+ rationale: run.conflictSummary ?? "Observed run surfaces disagree and require inspector review.",
97
+ details: {
98
+ reason: options.reason,
99
+ conflictState: run.conflictState,
100
+ conflictSummary: run.conflictSummary
101
+ },
102
+ createdAt: now()
103
+ });
104
+ if (conflictDecision.ok && conflictDecision.changed) {
105
+ decisionCount += 1;
106
+ }
107
+ }
108
+ }
109
+ return {
110
+ discoveredCount: options.runs.length,
111
+ observedCount,
112
+ decisionCount,
113
+ actionCount
114
+ };
115
+ }
116
+ export {
117
+ reconcileInspectorRuns
118
+ };
@@ -0,0 +1,13 @@
1
+ // @bun
2
+ // packages/server/src/inspector/review.ts
3
+ function buildLocalReviewRequest(options) {
4
+ return {
5
+ reviewerType: "local-reviewer",
6
+ runId: options.runId,
7
+ taskId: options.taskId,
8
+ focus: options.focus
9
+ };
10
+ }
11
+ export {
12
+ buildLocalReviewRequest
13
+ };