@gitgov/core 1.11.0 → 1.13.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/src/index.js CHANGED
@@ -7543,8 +7543,8 @@ var ProjectAdapter = class {
7543
7543
  /**
7544
7544
  * [EARS-2] Validates environment for GitGovernance initialization
7545
7545
  */
7546
- async validateEnvironment(path10) {
7547
- const targetPath = path10 || process.env["GITGOV_ORIGINAL_DIR"] || process.cwd();
7546
+ async validateEnvironment(path12) {
7547
+ const targetPath = path12 || process.env["GITGOV_ORIGINAL_DIR"] || process.cwd();
7548
7548
  const warnings = [];
7549
7549
  const suggestions = [];
7550
7550
  try {
@@ -9957,22 +9957,22 @@ var LintModule = class {
9957
9957
  );
9958
9958
  }
9959
9959
  this.fileSystem = dependencies.fileSystem ?? {
9960
- readFile: async (path10, encoding) => {
9961
- return promises.readFile(path10, encoding);
9960
+ readFile: async (path12, encoding) => {
9961
+ return promises.readFile(path12, encoding);
9962
9962
  },
9963
- writeFile: async (path10, content) => {
9964
- await promises.writeFile(path10, content, "utf-8");
9963
+ writeFile: async (path12, content) => {
9964
+ await promises.writeFile(path12, content, "utf-8");
9965
9965
  },
9966
- exists: async (path10) => {
9966
+ exists: async (path12) => {
9967
9967
  try {
9968
- await promises.access(path10);
9968
+ await promises.access(path12);
9969
9969
  return true;
9970
9970
  } catch {
9971
9971
  return false;
9972
9972
  }
9973
9973
  },
9974
- unlink: async (path10) => {
9975
- await promises.unlink(path10);
9974
+ unlink: async (path12) => {
9975
+ await promises.unlink(path12);
9976
9976
  }
9977
9977
  };
9978
9978
  }
@@ -10480,8 +10480,8 @@ var LintModule = class {
10480
10480
  * This ensures we know the correct type for each record based on its directory.
10481
10481
  * @private
10482
10482
  */
10483
- async discoverAllRecordsWithTypes(path10) {
10484
- const projectRoot2 = ConfigManager.findProjectRoot() || path10 || ".gitgov/";
10483
+ async discoverAllRecordsWithTypes(path12) {
10484
+ const projectRoot2 = ConfigManager.findProjectRoot() || path12 || ".gitgov/";
10485
10485
  const recordTypes = [
10486
10486
  "actor",
10487
10487
  "agent",
@@ -14053,10 +14053,10 @@ var RelationshipAnalyzer = class {
14053
14053
  }
14054
14054
  const visited = /* @__PURE__ */ new Set();
14055
14055
  const recursionStack = /* @__PURE__ */ new Set();
14056
- const path10 = [];
14056
+ const path12 = [];
14057
14057
  for (const node of graph.keys()) {
14058
14058
  if (!visited.has(node)) {
14059
- const cyclePath = this.findCycleDFS(node, graph, visited, recursionStack, path10);
14059
+ const cyclePath = this.findCycleDFS(node, graph, visited, recursionStack, path12);
14060
14060
  if (cyclePath.length > 0) {
14061
14061
  const cycleDescription = this.formatCycleError(cyclePath);
14062
14062
  throw new CircularDependencyError(cycleDescription);
@@ -14067,24 +14067,24 @@ var RelationshipAnalyzer = class {
14067
14067
  /**
14068
14068
  * DFS helper for circular dependency detection with path tracking
14069
14069
  */
14070
- findCycleDFS(node, graph, visited, recursionStack, path10) {
14070
+ findCycleDFS(node, graph, visited, recursionStack, path12) {
14071
14071
  visited.add(node);
14072
14072
  recursionStack.add(node);
14073
- path10.push(node);
14073
+ path12.push(node);
14074
14074
  const neighbors = graph.get(node) || [];
14075
14075
  for (const neighbor of neighbors) {
14076
14076
  if (!visited.has(neighbor)) {
14077
- const cyclePath = this.findCycleDFS(neighbor, graph, visited, recursionStack, path10);
14077
+ const cyclePath = this.findCycleDFS(neighbor, graph, visited, recursionStack, path12);
14078
14078
  if (cyclePath.length > 0) {
14079
14079
  return cyclePath;
14080
14080
  }
14081
14081
  } else if (recursionStack.has(neighbor)) {
14082
- const cycleStartIndex = path10.indexOf(neighbor);
14083
- return path10.slice(cycleStartIndex).concat([neighbor]);
14082
+ const cycleStartIndex = path12.indexOf(neighbor);
14083
+ return path12.slice(cycleStartIndex).concat([neighbor]);
14084
14084
  }
14085
14085
  }
14086
14086
  recursionStack.delete(node);
14087
- path10.pop();
14087
+ path12.pop();
14088
14088
  return [];
14089
14089
  }
14090
14090
  /**
@@ -15618,6 +15618,352 @@ var WaiverWriter = class {
15618
15618
  }
15619
15619
  };
15620
15620
 
15621
- export { adapters_exports as Adapters, backlog_adapter_exports as BacklogAdapter, changelog_adapter_exports as ChangelogAdapter, config_manager_exports as Config, crypto_exports as Crypto, diagram_generator_exports as DiagramGenerator, event_bus_exports as EventBus, execution_adapter_exports as ExecutionAdapter, factories_exports as Factories, feedback_adapter_exports as FeedbackAdapter, git_exports as Git, identity_adapter_exports as IdentityAdapter, indexer_adapter_exports as IndexerAdapter, lint_exports as Lint, logger_exports as Logger, metrics_adapter_exports as MetricsAdapter, pii_detector_exports as PiiDetector, project_adapter_exports as ProjectAdapter, types_exports as Records, schemas_exports as Schemas, source_auditor_exports as SourceAuditor, store_exports as Store, sync_exports as Sync, validation_exports as Validation, workflow_methodology_adapter_exports as WorkflowMethodologyAdapter };
15621
+ // src/runner/index.ts
15622
+ var runner_exports = {};
15623
+ __export(runner_exports, {
15624
+ AgentNotFoundError: () => AgentNotFoundError,
15625
+ AgentRunnerModule: () => AgentRunnerModule,
15626
+ EngineConfigError: () => EngineConfigError,
15627
+ FunctionNotExportedError: () => FunctionNotExportedError,
15628
+ LocalBackend: () => LocalBackend,
15629
+ LocalEngineConfigError: () => LocalEngineConfigError,
15630
+ MissingDependencyError: () => MissingDependencyError,
15631
+ RunnerError: () => RunnerError,
15632
+ RuntimeNotFoundError: () => RuntimeNotFoundError,
15633
+ UnsupportedEngineTypeError: () => UnsupportedEngineTypeError
15634
+ });
15635
+
15636
+ // src/runner/errors.ts
15637
+ var RunnerError = class _RunnerError extends Error {
15638
+ constructor(message) {
15639
+ super(message);
15640
+ this.name = "RunnerError";
15641
+ Object.setPrototypeOf(this, _RunnerError.prototype);
15642
+ }
15643
+ };
15644
+ var AgentNotFoundError = class _AgentNotFoundError extends RunnerError {
15645
+ agentId;
15646
+ constructor(agentId) {
15647
+ super(`AgentNotFound: ${agentId}`);
15648
+ this.name = "AgentNotFoundError";
15649
+ this.agentId = agentId;
15650
+ Object.setPrototypeOf(this, _AgentNotFoundError.prototype);
15651
+ }
15652
+ };
15653
+ var FunctionNotExportedError = class _FunctionNotExportedError extends RunnerError {
15654
+ functionName;
15655
+ entrypoint;
15656
+ constructor(functionName, entrypoint) {
15657
+ super(`FunctionNotExported: ${functionName} not found in ${entrypoint}`);
15658
+ this.name = "FunctionNotExportedError";
15659
+ this.functionName = functionName;
15660
+ this.entrypoint = entrypoint;
15661
+ Object.setPrototypeOf(this, _FunctionNotExportedError.prototype);
15662
+ }
15663
+ };
15664
+ var LocalEngineConfigError = class _LocalEngineConfigError extends RunnerError {
15665
+ constructor() {
15666
+ super("LocalEngineConfigError: entrypoint or runtime required for execution");
15667
+ this.name = "LocalEngineConfigError";
15668
+ Object.setPrototypeOf(this, _LocalEngineConfigError.prototype);
15669
+ }
15670
+ };
15671
+ var UnsupportedEngineTypeError = class _UnsupportedEngineTypeError extends RunnerError {
15672
+ engineType;
15673
+ constructor(engineType) {
15674
+ super(`UnsupportedEngineType: ${engineType}`);
15675
+ this.name = "UnsupportedEngineTypeError";
15676
+ this.engineType = engineType;
15677
+ Object.setPrototypeOf(this, _UnsupportedEngineTypeError.prototype);
15678
+ }
15679
+ };
15680
+ var EngineConfigError = class _EngineConfigError extends RunnerError {
15681
+ engineType;
15682
+ missingField;
15683
+ constructor(engineType, missingField) {
15684
+ super(`EngineConfigError: ${missingField} required for ${engineType}`);
15685
+ this.name = "EngineConfigError";
15686
+ this.engineType = engineType;
15687
+ this.missingField = missingField;
15688
+ Object.setPrototypeOf(this, _EngineConfigError.prototype);
15689
+ }
15690
+ };
15691
+ var MissingDependencyError = class _MissingDependencyError extends RunnerError {
15692
+ dependency;
15693
+ reason;
15694
+ constructor(dependency, reason) {
15695
+ super(`MissingDependency: ${dependency} ${reason}`);
15696
+ this.name = "MissingDependencyError";
15697
+ this.dependency = dependency;
15698
+ this.reason = reason;
15699
+ Object.setPrototypeOf(this, _MissingDependencyError.prototype);
15700
+ }
15701
+ };
15702
+ var RuntimeNotFoundError = class _RuntimeNotFoundError extends RunnerError {
15703
+ runtime;
15704
+ constructor(runtime) {
15705
+ super(`RuntimeNotFound: ${runtime}`);
15706
+ this.name = "RuntimeNotFoundError";
15707
+ this.runtime = runtime;
15708
+ Object.setPrototypeOf(this, _RuntimeNotFoundError.prototype);
15709
+ }
15710
+ };
15711
+
15712
+ // src/runner/backends/local_backend.ts
15713
+ var LocalBackend = class {
15714
+ constructor(projectRoot2, runtimeRegistry) {
15715
+ this.projectRoot = projectRoot2;
15716
+ this.runtimeRegistry = runtimeRegistry;
15717
+ }
15718
+ /**
15719
+ * Executes a local agent and captures its output.
15720
+ */
15721
+ async execute(engine, ctx) {
15722
+ if (!engine.entrypoint && !engine.runtime) {
15723
+ throw new LocalEngineConfigError();
15724
+ }
15725
+ if (engine.runtime) {
15726
+ return this.executeRuntime(engine, ctx);
15727
+ }
15728
+ return this.executeEntrypoint(engine, ctx);
15729
+ }
15730
+ /**
15731
+ * Executes via entrypoint (dynamic import) and captures output.
15732
+ */
15733
+ async executeEntrypoint(engine, ctx) {
15734
+ const absolutePath = path6__default.join(this.projectRoot, engine.entrypoint);
15735
+ const mod = await import(absolutePath);
15736
+ const fnName = engine.function || "runAgent";
15737
+ const fn = mod[fnName];
15738
+ if (typeof fn !== "function") {
15739
+ throw new FunctionNotExportedError(fnName, engine.entrypoint);
15740
+ }
15741
+ const result = await fn(ctx);
15742
+ return this.normalizeOutput(result);
15743
+ }
15744
+ /**
15745
+ * Executes via runtime handler.
15746
+ */
15747
+ async executeRuntime(engine, ctx) {
15748
+ if (!this.runtimeRegistry) {
15749
+ throw new RuntimeNotFoundError(engine.runtime);
15750
+ }
15751
+ const handler = this.runtimeRegistry.get(engine.runtime);
15752
+ if (!handler) {
15753
+ throw new RuntimeNotFoundError(engine.runtime);
15754
+ }
15755
+ return handler(engine, ctx);
15756
+ }
15757
+ /**
15758
+ * Normalizes any result to AgentOutput.
15759
+ * If agent returns void/undefined, uses empty object.
15760
+ * If returns object with known fields, extracts them.
15761
+ */
15762
+ normalizeOutput(result) {
15763
+ if (result === void 0 || result === null) {
15764
+ return {};
15765
+ }
15766
+ if (typeof result === "object") {
15767
+ const obj = result;
15768
+ const output = {};
15769
+ if (obj["data"] !== void 0) {
15770
+ output.data = obj["data"];
15771
+ }
15772
+ const message = obj["message"];
15773
+ if (typeof message === "string") {
15774
+ output.message = message;
15775
+ }
15776
+ const artifacts = obj["artifacts"];
15777
+ if (Array.isArray(artifacts)) {
15778
+ output.artifacts = artifacts;
15779
+ }
15780
+ const metadata = obj["metadata"];
15781
+ if (typeof metadata === "object" && metadata !== null) {
15782
+ output.metadata = metadata;
15783
+ }
15784
+ return output;
15785
+ }
15786
+ return { data: result };
15787
+ }
15788
+ };
15789
+
15790
+ // src/runner/agent_runner_module.ts
15791
+ var VALID_ENGINE_TYPES = ["local", "api", "mcp", "custom"];
15792
+ var AgentRunnerModule = class {
15793
+ gitgovPath;
15794
+ projectRoot;
15795
+ identityAdapter;
15796
+ executionAdapter;
15797
+ eventBus;
15798
+ /** Fase 2: Protocol handlers for CustomBackend */
15799
+ protocolHandlers;
15800
+ runtimeHandlers;
15801
+ localBackend;
15802
+ constructor(deps) {
15803
+ if (!deps.executionAdapter) {
15804
+ throw new MissingDependencyError("ExecutionAdapter", "required");
15805
+ }
15806
+ this.gitgovPath = deps.gitgovPath ?? path6__default.join(ConfigManager.findProjectRoot(), ".gitgov");
15807
+ this.projectRoot = deps.projectRoot ?? ConfigManager.findProjectRoot();
15808
+ this.identityAdapter = deps.identityAdapter ?? void 0;
15809
+ this.executionAdapter = deps.executionAdapter;
15810
+ this.eventBus = deps.eventBus ?? void 0;
15811
+ this.protocolHandlers = deps.protocolHandlers ?? void 0;
15812
+ this.runtimeHandlers = deps.runtimeHandlers ?? void 0;
15813
+ this.localBackend = new LocalBackend(this.projectRoot, this.runtimeHandlers);
15814
+ }
15815
+ /**
15816
+ * Executes an agent once and returns the response.
15817
+ * TaskRecord must exist before calling this method.
15818
+ */
15819
+ async runOnce(opts) {
15820
+ const startedAt = (/* @__PURE__ */ new Date()).toISOString();
15821
+ const runId = randomUUID();
15822
+ let output;
15823
+ let error;
15824
+ let status = "success";
15825
+ const agent = await this.loadAgent(opts.agentId);
15826
+ const engine = agent.engine;
15827
+ const engineType = engine.type;
15828
+ if (!VALID_ENGINE_TYPES.includes(engineType)) {
15829
+ throw new UnsupportedEngineTypeError(engineType);
15830
+ }
15831
+ if ((engineType === "api" || engineType === "mcp") && !("url" in engine)) {
15832
+ throw new EngineConfigError(engineType, "url");
15833
+ }
15834
+ if (engineType === "api" || engineType === "mcp") {
15835
+ const engineWithAuth = engine;
15836
+ if (engineWithAuth.auth?.type === "actor-signature" && !this.identityAdapter) {
15837
+ throw new MissingDependencyError(
15838
+ "IdentityAdapter",
15839
+ "required for actor-signature auth"
15840
+ );
15841
+ }
15842
+ }
15843
+ const ctx = {
15844
+ agentId: opts.agentId,
15845
+ actorId: opts.actorId ?? opts.agentId,
15846
+ // [EARS-C2]
15847
+ taskId: opts.taskId,
15848
+ runId,
15849
+ input: opts.input
15850
+ };
15851
+ this.emitEvent({
15852
+ type: "agent:started",
15853
+ payload: { runId, agentId: opts.agentId, taskId: opts.taskId, startedAt }
15854
+ });
15855
+ try {
15856
+ switch (engineType) {
15857
+ case "local":
15858
+ output = await this.localBackend.execute(engine, ctx);
15859
+ break;
15860
+ case "api":
15861
+ throw new Error("ApiBackend not implemented (Fase 2)");
15862
+ case "mcp":
15863
+ throw new Error("McpBackend not implemented (Fase 2)");
15864
+ case "custom":
15865
+ throw new Error("CustomBackend not implemented (Fase 2)");
15866
+ }
15867
+ } catch (err) {
15868
+ status = "error";
15869
+ error = err.message;
15870
+ }
15871
+ const completedAt = (/* @__PURE__ */ new Date()).toISOString();
15872
+ const durationMs = new Date(completedAt).getTime() - new Date(startedAt).getTime();
15873
+ const resultMessage = status === "success" ? output?.message || `Agent ${opts.agentId} completed successfully` : `Agent ${opts.agentId} failed: ${error || "Unknown error"}`;
15874
+ const executionRecord = await this.executionAdapter.create(
15875
+ {
15876
+ taskId: opts.taskId,
15877
+ type: status === "success" ? "completion" : "blocker",
15878
+ title: `Agent execution: ${opts.agentId}`,
15879
+ result: resultMessage.length >= 10 ? resultMessage : resultMessage.padEnd(10, "."),
15880
+ metadata: {
15881
+ agentId: opts.agentId,
15882
+ runId,
15883
+ status,
15884
+ output: status === "success" ? output : void 0,
15885
+ error: status === "error" ? error : void 0,
15886
+ startedAt,
15887
+ completedAt,
15888
+ durationMs
15889
+ }
15890
+ },
15891
+ ctx.actorId
15892
+ );
15893
+ const executionRecordId = executionRecord.id;
15894
+ if (status === "success") {
15895
+ this.emitEvent({
15896
+ type: "agent:completed",
15897
+ payload: {
15898
+ runId,
15899
+ agentId: opts.agentId,
15900
+ taskId: opts.taskId,
15901
+ status,
15902
+ durationMs,
15903
+ executionRecordId
15904
+ }
15905
+ });
15906
+ } else {
15907
+ this.emitEvent({
15908
+ type: "agent:error",
15909
+ payload: {
15910
+ runId,
15911
+ agentId: opts.agentId,
15912
+ taskId: opts.taskId,
15913
+ status,
15914
+ error,
15915
+ durationMs,
15916
+ executionRecordId
15917
+ }
15918
+ });
15919
+ }
15920
+ const response = {
15921
+ runId,
15922
+ agentId: opts.agentId,
15923
+ status,
15924
+ executionRecordId,
15925
+ startedAt,
15926
+ completedAt,
15927
+ durationMs
15928
+ };
15929
+ if (status === "success" && output) {
15930
+ response.output = output;
15931
+ }
15932
+ if (status === "error" && error) {
15933
+ response.error = error;
15934
+ }
15935
+ return response;
15936
+ }
15937
+ /**
15938
+ * [EARS-A1, A2] Loads AgentRecord from .gitgov/agents/agent-{id}.json
15939
+ */
15940
+ async loadAgent(agentId) {
15941
+ const id = agentId.startsWith("agent:") ? agentId.slice(6) : agentId;
15942
+ const agentPath = path6__default.join(this.gitgovPath, "agents", `agent-${id}.json`);
15943
+ try {
15944
+ const content = await promises.readFile(agentPath, "utf-8");
15945
+ const record = JSON.parse(content);
15946
+ return record.payload ?? record;
15947
+ } catch {
15948
+ throw new AgentNotFoundError(agentId);
15949
+ }
15950
+ }
15951
+ /**
15952
+ * [EARS-I4] Emits event via EventBus if available.
15953
+ * Works silently without EventBus.
15954
+ */
15955
+ emitEvent(event) {
15956
+ if (this.eventBus) {
15957
+ this.eventBus.publish({
15958
+ type: event.type,
15959
+ timestamp: Date.now(),
15960
+ source: "agent_runner_module",
15961
+ payload: event.payload
15962
+ });
15963
+ }
15964
+ }
15965
+ };
15966
+
15967
+ export { adapters_exports as Adapters, backlog_adapter_exports as BacklogAdapter, changelog_adapter_exports as ChangelogAdapter, config_manager_exports as Config, crypto_exports as Crypto, diagram_generator_exports as DiagramGenerator, event_bus_exports as EventBus, execution_adapter_exports as ExecutionAdapter, factories_exports as Factories, feedback_adapter_exports as FeedbackAdapter, git_exports as Git, identity_adapter_exports as IdentityAdapter, indexer_adapter_exports as IndexerAdapter, lint_exports as Lint, logger_exports as Logger, metrics_adapter_exports as MetricsAdapter, pii_detector_exports as PiiDetector, project_adapter_exports as ProjectAdapter, types_exports as Records, runner_exports as Runner, schemas_exports as Schemas, source_auditor_exports as SourceAuditor, store_exports as Store, sync_exports as Sync, validation_exports as Validation, workflow_methodology_adapter_exports as WorkflowMethodologyAdapter };
15622
15968
  //# sourceMappingURL=index.js.map
15623
15969
  //# sourceMappingURL=index.js.map