@grwnd/pi-governance 3.0.0 → 3.0.2

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.
@@ -2981,8 +2981,9 @@ var piGovernance = (pi) => {
2981
2981
  }
2982
2982
  const rulesFileCfg = config.policy?.yaml?.rules_file ?? "./governance-rules.yaml";
2983
2983
  paths.add(resolve(rulesFileCfg));
2984
- paths.add(resolve(ctx.workingDirectory, ".pi/governance.yaml"));
2985
- paths.add(resolve(ctx.workingDirectory, "governance-rules.yaml"));
2984
+ const cwd = ctx.workingDirectory ?? process.cwd();
2985
+ paths.add(resolve(cwd, ".pi/governance.yaml"));
2986
+ paths.add(resolve(cwd, "governance-rules.yaml"));
2986
2987
  protectedPaths = paths;
2987
2988
  const chain = createIdentityChain(config.auth);
2988
2989
  identity = await chain.resolve();
@@ -3103,6 +3104,7 @@ var piGovernance = (pi) => {
3103
3104
  );
3104
3105
  });
3105
3106
  pi.on("tool_call", async (event, _ctx) => {
3107
+ if (!audit || !policyEngine || !identity) return void 0;
3106
3108
  const { toolName, input } = event;
3107
3109
  const params = summarizeParams(toolName, input);
3108
3110
  const baseRecord = {
@@ -3319,6 +3321,7 @@ var piGovernance = (pi) => {
3319
3321
  return void 0;
3320
3322
  });
3321
3323
  pi.on("tool_result", async (event, _ctx) => {
3324
+ if (!audit || !identity) return;
3322
3325
  if (dlpScanner && dlpMasker && event.output) {
3323
3326
  const result = dlpScanner.scan(event.output);
3324
3327
  if (result.hasMatches) {
@@ -3370,15 +3373,16 @@ var piGovernance = (pi) => {
3370
3373
  });
3371
3374
  pi.on("session_shutdown", async (_event, _ctx) => {
3372
3375
  configWatcher?.stop();
3376
+ if (!audit) return;
3373
3377
  await audit.log({
3374
3378
  sessionId,
3375
3379
  event: "session_end",
3376
- userId: identity.userId,
3377
- role: identity.role,
3378
- orgUnit: identity.orgUnit,
3380
+ userId: identity?.userId,
3381
+ role: identity?.role,
3382
+ orgUnit: identity?.orgUnit,
3379
3383
  metadata: {
3380
3384
  stats: { ...stats },
3381
- budget: { used: budgetTracker.used(), remaining: budgetTracker.remaining() },
3385
+ budget: budgetTracker ? { used: budgetTracker.used(), remaining: budgetTracker.remaining() } : void 0,
3382
3386
  summary: Object.fromEntries(audit.getSummary())
3383
3387
  }
3384
3388
  });