This commit is contained in:
ZacharyZhang-NY committed 2026-03-16 00:22:21 -04:00
1 parent d067589276
commit 41eafc7c44
6 files changed
+555 -85

No files matched your search

+26
View File
@@ -759,6 +759,32 @@ export class AgentApiServer {
detail: input.payloadSummary,
});
// Auto-approve hire requests if company has auto_approve_hires enabled
const snapshot = this.db.listSnapshot();
const company = snapshot.companies.find((c) => c.id === companyId);
if (company?.autoApproveHires && (input.type === "hire_agent" || input.type === "approve_ceo_strategy")) {
this.db.decideApproval({ approvalId: id, state: "approved", decisionNote: "Auto-approved by company policy" });
this.db.addActivity({
companyId,
actor: "board",
action: "approval.approved",
entityType: "approval",
entityId: id,
detail: "Auto-approved by company policy",
});
// Wake the requesting agent so they know the hire was approved
this.onWakeAgent(token.agentId, companyId, "approval_resolved");
// Wake the newly hired agent
try {
const fullApproval = this.db.getApprovalRecord(id);
const payload = JSON.parse(fullApproval.payloadJson || "{}") as { agentId?: string };
if (payload.agentId) {
this.onWakeAgent(payload.agentId, companyId, "assignment");
}
} catch { /* ignore if payload is malformed */ }
log.info(`[auto-approve] Auto-approved hire request: ${input.payloadSummary}`);
}
this.onDomainChanged();
this.json(res, 201, { id });
});
+14 -7
View File
@@ -423,8 +423,8 @@ export class AppDatabase {
secretBackend: this.vault.getBackendLabel(),
},
companies: this.readAll<CompanyRecord>(
"select id, name, description, status, created_at as createdAt, updated_at as updatedAt from companies order by created_at asc",
),
"select id, name, description, status, auto_approve_hires as autoApproveHires, created_at as createdAt, updated_at as updatedAt from companies order by created_at asc",
).map((record) => ({ ...record, autoApproveHires: toBoolean(record.autoApproveHires) })) as CompanyRecord[],
connectors,
workspaces: this.readAll<WorkspaceRecord>(
"select id, company_id as companyId, name, local_path as localPath, repo_url as repoUrl, repo_ref as repoRef, project_id as projectId, state, is_primary as isPrimary, created_at as createdAt, updated_at as updatedAt from workspaces order by created_at desc",
@@ -462,18 +462,19 @@ export class AppDatabase {
};
}
saveCompany(input: { id?: string | null; name: string; description: string; status: string }) {
saveCompany(input: { id?: string | null; name: string; description: string; status: string; autoApproveHires?: boolean }) {
const id = ensureId(input.id ?? null);
const ts = nowIso();
const autoApprove = input.autoApproveHires ? 1 : 0;
const existing = this.db.prepare("select id from companies where id = ?").get(id) as { id: string } | undefined;
if (existing) {
this.db
.prepare("update companies set name = ?, description = ?, status = ?, updated_at = ? where id = ?")
.run(input.name, input.description, input.status, ts, id);
.prepare("update companies set name = ?, description = ?, status = ?, auto_approve_hires = ?, updated_at = ? where id = ?")
.run(input.name, input.description, input.status, autoApprove, ts, id);
} else {
this.db
.prepare("insert into companies (id, name, description, status, created_at, updated_at) values (?, ?, ?, ?, ?, ?)")
.run(id, input.name, input.description, input.status, ts, ts);
.prepare("insert into companies (id, name, description, status, auto_approve_hires, created_at, updated_at) values (?, ?, ?, ?, ?, ?, ?)")
.run(id, input.name, input.description, input.status, autoApprove, ts, ts);
if (!this.getCurrentCompanyId()) {
this.setCurrentCompany(id);
}
@@ -1439,6 +1440,12 @@ export class AppDatabase {
// Column already exists.
}
}
// Auto-approve column on companies
try {
this.db.prepare("alter table companies add column auto_approve_hires integer not null default 0").run();
} catch {
// Column already exists.
}
// Comments table
this.db.exec(`
create table if not exists task_comments (