Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
"marked": "^15.0.12",
"marked-terminal": "^7.3.0",
"nodemailer": "^8.0.5",
"pino": "^10.3.1",
"pino-pretty": "^13.1.3",
"playwright": "^1.50.0",
"postgres": "^3.4.7",
"react": "^19.2.4",
Expand Down
63 changes: 63 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions settings/src/app/api/admin/wiki/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export async function POST() {
try {
// Trigger wiki compilation via daemon gRPC command
const { exec } = await import("node:child_process");
const { promisify } = await import("node:util");
const execAsync = promisify(exec);

// Use the notify-daemon pattern to trigger compilation
const path = await import("node:path");
Expand Down
12 changes: 2 additions & 10 deletions settings/src/app/api/google/oauth/start/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ export async function POST() {
// DB not available
}
const env = await readConfig(
[
"GOOGLE_OAUTH_CLIENT_ID",
"GOOGLE_OAUTH_CLIENT_SECRET",
"GWS_SERVICES",
"GOOGLE_CLOUD_PROJECT",
],
["GOOGLE_OAUTH_CLIENT_ID", "GOOGLE_OAUTH_CLIENT_SECRET", "GOOGLE_CLOUD_PROJECT"],
sql,
);

const clientId = env.GOOGLE_OAUTH_CLIENT_ID;
const clientSecret = env.GOOGLE_OAUTH_CLIENT_SECRET;
const gwsServices = env.GWS_SERVICES;
const gcpProjectId = env.GOOGLE_CLOUD_PROJECT;

if (!clientId || !clientSecret) {
Expand All @@ -53,14 +47,12 @@ export async function POST() {

// Write a valid client_secret.json (with project_id) for the CLI flow.
// Same helper /api/env uses on save, so the two paths can't drift.
const { writeGwsClientSecret, gwsClientSecretPath } =
await import("@/lib/sync-gws-client-secret");
const { writeGwsClientSecret } = await import("@/lib/sync-gws-client-secret");
writeGwsClientSecret({
clientId,
clientSecret,
projectId: gcpProjectId ?? "",
});
const clientSecretPath = gwsClientSecretPath();

// Build args for gws auth login with explicit scopes.
// Using --scopes ensures Gmail/Calendar are included even if the gws CLI
Expand Down
22 changes: 15 additions & 7 deletions src/cate/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import type { PolicyConfig } from "@project-nomos/cate-sdk/types";
import { NomosKeystore } from "./nomos-keystore.ts";
import { NomosTransport } from "./nomos-transport.ts";
import { getDb } from "../db/client.ts";
import { createLogger } from "../lib/logger.ts";

const log = createLogger("cate-integration");

const AGENT_KEY_ID = "nomos-agent";
const USER_KEY_ID = "nomos-user";
Expand Down Expand Up @@ -43,14 +46,14 @@ export async function initCATEIntegration(options?: {
let agentKey = await keystore.getKey(AGENT_KEY_ID);
if (!agentKey) {
agentKey = await keystore.generateKey(AGENT_KEY_ID);
console.log("[cate] Generated new agent key pair");
log.info("Generated new agent key pair");
}

// Create or load user key (for VC issuance)
let userKey = await keystore.getKey(USER_KEY_ID);
if (!userKey) {
userKey = await keystore.generateKey(USER_KEY_ID);
console.log("[cate] Generated new user key pair");
log.info("Generated new user key pair");
}

const agentDid = createDIDKey(agentKey.publicKey);
Expand Down Expand Up @@ -102,18 +105,23 @@ export async function initCATEIntegration(options?: {
identity: { did: agentDid, keystore },
policy: policyConfig,
onMessage: async (envelope, context) => {
console.log(
`[cate] Received envelope from ${context.senderDid} (${context.trustTier}, ${context.policyAction})`,
log.info(
{
senderDid: context.senderDid,
trustTier: context.trustTier,
policyAction: context.policyAction,
},
"Received envelope",
);
await options?.onMessage?.(envelope);
},
onError: (error) => {
console.error(`[cate] Error: ${error.message}`);
log.error({ err: error }, "Error");
},
});

await server.listen({ transport });
console.log(`[cate] Server started on port ${port} (DID: ${agentDid})`);
log.info({ port, agentDid }, "Server started");

return { server, agentDid, agentCard, keystore, transport };
}
Expand Down Expand Up @@ -168,5 +176,5 @@ async function loadPolicyConfig(): Promise<PolicyConfig> {
*/
export async function stopCATEIntegration(integration: CATEIntegration): Promise<void> {
await integration.server.close();
console.log("[cate] Server stopped");
log.info("Server stopped");
}
5 changes: 4 additions & 1 deletion src/cate/nomos-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
type TransportOptions,
type TransportEvents,
} from "@project-nomos/cate-sdk/transport";
import { createLogger } from "../lib/logger.ts";

const log = createLogger("cate-transport");

export class NomosTransport extends Transport {
private server?: { close: () => void };
Expand Down Expand Up @@ -62,7 +65,7 @@ export class NomosTransport extends Transport {

await new Promise<void>((resolve) => {
server.listen(this.port, () => {
console.log(`[cate] Transport listening on port ${this.port}`);
log.info({ port: this.port }, "Transport listening");
resolve();
});
});
Expand Down
18 changes: 8 additions & 10 deletions src/config/file-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import fs from "node:fs";
import path from "node:path";
import { createHash } from "node:crypto";
import { getKysely } from "../db/client.ts";
import { createLogger } from "../lib/logger.ts";

const log = createLogger("file-sync");

// ── Paths ──

Expand Down Expand Up @@ -42,11 +45,9 @@ async function syncOne(file: ManagedFile): Promise<string | null> {

// Check disk (first path that exists wins)
let diskContent: string | null = null;
let diskPath: string | null = null;
for (const p of file.diskPaths) {
if (fs.existsSync(p)) {
diskContent = fs.readFileSync(p, "utf-8");
diskPath = p;
break;
}
}
Expand Down Expand Up @@ -85,7 +86,7 @@ async function syncOne(file: ManagedFile): Promise<string | null> {
const dir = path.dirname(restorePath);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(restorePath, row.content, "utf-8");
console.log(`[file-sync] Restored ${file.dbPath} -> ${restorePath}`);
log.info({ dbPath: file.dbPath, restorePath }, "Restored");
return row.content;
}

Expand All @@ -112,10 +113,7 @@ export async function syncFileToDb(dbPath: string, content: string): Promise<voi
)
.execute();
} catch (err) {
console.warn(
`[file-sync] Failed to sync ${dbPath} to DB:`,
err instanceof Error ? err.message : err,
);
log.warn({ dbPath, err: err instanceof Error ? err.message : err }, "Failed to sync to DB");
}
}

Expand Down Expand Up @@ -246,9 +244,9 @@ export async function syncAllFiles(): Promise<void> {
restored += restoredPersonal;

if (synced > 0 || restored > 0) {
console.log(
`[file-sync] Synced ${synced} file(s) to DB` +
(restored > 0 ? `, restored ${restored} from DB` : ""),
log.info(
{ synced, restored },
`Synced ${synced} file(s) to DB` + (restored > 0 ? `, restored ${restored} from DB` : ""),
);
}
}
7 changes: 5 additions & 2 deletions src/cron/scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { CronExpressionParser } from "cron-parser";
import type { CronJob } from "./types.ts";
import { createLogger } from "../lib/logger.ts";

const log = createLogger("cron-scheduler");

export type CronCallback = (job: CronJob) => Promise<void>;

Expand Down Expand Up @@ -98,7 +101,7 @@ export class CronScheduler {

this.timers.set(job.id, timer);
} catch (error) {
console.error(`Failed to schedule job ${job.id}:`, error);
log.error({ err: error, jobId: job.id }, "Failed to schedule job");
}
}

Expand Down Expand Up @@ -130,7 +133,7 @@ export class CronScheduler {
try {
await this.callback(job);
} catch (error) {
console.error(`Error executing cron job ${job.id}:`, error);
log.error({ err: error, jobId: job.id }, "Error executing cron job");
}
}
}
Expand Down
Loading
Loading