ework-daemon 0.4.59 → 0.4.61

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/opencode.ts +24 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ework-daemon",
3
- "version": "0.4.59",
3
+ "version": "0.4.61",
4
4
  "description": "Issue-driven AI development daemon. Spawns opencode subprocesses to resolve Gitea issues.",
5
5
  "module": "src/index.ts",
6
6
  "type": "module",
package/src/opencode.ts CHANGED
@@ -316,6 +316,20 @@ function createBackendFor(cfg: Config, runtime: string): RuntimeBackend {
316
316
  return new OpencodeBackend(cfg.opencode.binary, cfg.opencode.dbPath, cfg.childEnvDeny);
317
317
  }
318
318
 
319
+ // Wake policy shared by issue_opened and comment_created: blacklist wins,
320
+ // then an explicit login whitelist (which replaces the kind check), then
321
+ // author kind. Issue openers carry no kind and default to human.
322
+ export function wakePolicySkips(
323
+ d: { nonWakingAuthors: string[]; noWakeLogins: string[]; wakeLogins: string[]; wakeKinds: string[] },
324
+ author: string,
325
+ authorKind: string,
326
+ ): string | null {
327
+ if ([...d.nonWakingAuthors, ...d.noWakeLogins].includes(author)) return `non-waking author ${author}`;
328
+ if (d.wakeLogins.length > 0 && !d.wakeLogins.includes(author)) return `author ${author} not in wakeLogins`;
329
+ if (!d.wakeKinds.includes(authorKind)) return `author kind ${authorKind} not in wakeKinds [${d.wakeKinds.join(",")}]`;
330
+ return null;
331
+ }
332
+
319
333
  export class Engine {
320
334
  private cfg: Config;
321
335
  private store: Store;
@@ -393,13 +407,16 @@ export class Engine {
393
407
  // An existing session must keep the backend that owns it: opencode session
394
408
  // ids are "ses_..." while pi ids are bare uuids, so the prefix outvotes the
395
409
  // per-issue override. New sessions follow the issue's runtime setting.
410
+ // k is the session key "tracker:scope#issue@sessionName"; the runtime map is
411
+ // keyed by the issue part, so strip the "@sessionName" suffix.
396
412
  private backendFor(k: string, opencodeSessionId?: string): RuntimeBackend {
413
+ const issueKey = k.slice(0, k.lastIndexOf("@"));
397
414
  if (opencodeSessionId) {
398
415
  const wants = opencodeSessionId.startsWith("ses_") ? "opencode" : "pi";
399
416
  if (wants !== this.cfg.runtime) return this.altBackendFor(wants);
400
417
  return this.backend;
401
418
  }
402
- const runtime = this.issueRuntimes.get(k);
419
+ const runtime = this.issueRuntimes.get(issueKey);
403
420
  if (!runtime || runtime === this.cfg.runtime) return this.backend;
404
421
  return this.altBackendFor(runtime);
405
422
  }
@@ -748,21 +765,12 @@ export class Engine {
748
765
  return;
749
766
  }
750
767
 
751
- if (event.type === "comment_created" && event.comment?.author) {
752
- const author = event.comment.author;
753
- const authorKind = event.comment.authorKind ?? "human";
754
- const d = this.cfg.daemon;
755
- const noWake = [...d.nonWakingAuthors, ...d.noWakeLogins];
756
- if (noWake.includes(author)) {
757
- log.info(`engine: non-waking author ${author} — skipping comment_created for ${ref.trackerType}:${scopeKey}#${ref.issueId}`);
758
- return;
759
- }
760
- if (d.wakeLogins.length > 0 && !d.wakeLogins.includes(author)) {
761
- log.info(`engine: author ${author} not in wakeLogins — skipping comment_created for ${ref.trackerType}:${scopeKey}#${ref.issueId}`);
762
- return;
763
- }
764
- if (!d.wakeKinds.includes(authorKind)) {
765
- log.info(`engine: author kind ${authorKind} not in wakeKinds [${d.wakeKinds.join(",")}] — skipping comment_created for ${ref.trackerType}:${scopeKey}#${ref.issueId}`);
768
+ const wakeAuthor = event.type === "comment_created" ? event.comment?.author : event.type === "issue_opened" ? event.issue?.author : undefined;
769
+ const wakeKind = event.type === "comment_created" ? event.comment?.authorKind ?? "human" : "human";
770
+ if (wakeAuthor) {
771
+ const skip = wakePolicySkips(this.cfg.daemon, wakeAuthor, wakeKind);
772
+ if (skip) {
773
+ log.info(`engine: ${skip} — skipping ${event.type} for ${ref.trackerType}:${scopeKey}#${ref.issueId}`);
766
774
  return;
767
775
  }
768
776
  }