@makinbakin/sdk 0.0.0-bootstrap.0 → 0.0.1-rc.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.
package/routing/index.js CHANGED
@@ -13696,6 +13696,333 @@ var errorEnvelope = exports_external.object({
13696
13696
  error: exports_external.string(),
13697
13697
  issues: exports_external.array(exports_external.unknown()).optional()
13698
13698
  });
13699
+
13700
+ // packages/core/src/logger.ts
13701
+ import { createWriteStream, existsSync, mkdirSync, renameSync, statSync } from "fs";
13702
+ import { join as join2 } from "path";
13703
+
13704
+ // packages/core/src/content-dir.ts
13705
+ import { join } from "path";
13706
+ import { homedir } from "os";
13707
+ // packages/core/src/constants.ts
13708
+ var APP_SLUG = "bakin";
13709
+
13710
+ // packages/core/src/content-dir.ts
13711
+ function bakinHomeDefault() {
13712
+ return join(homedir(), `.${APP_SLUG}`);
13713
+ }
13714
+ var resolvedContentDir = null;
13715
+ function isTestEnv() {
13716
+ return process.env.VITEST === "true" || !!process.env.VITEST;
13717
+ }
13718
+ function realBakinHome() {
13719
+ const realHome = process.env.HOME || process.env.USERPROFILE || "";
13720
+ if (!realHome)
13721
+ return "";
13722
+ return join(realHome, `.${APP_SLUG}`);
13723
+ }
13724
+ function assertSafeForTest(path) {
13725
+ if (!isTestEnv())
13726
+ return;
13727
+ const real = realBakinHome();
13728
+ if (real && path === real) {
13729
+ throw new Error(`[bakin] getContentDir() resolved to the real Bakin home (${real}) ` + `during a test run. This would write test data to your production instance. ` + `Fix: mock src/core/content-dir in this test, or set BAKIN_HOME to a temp ` + `directory before importing any Bakin module. See CLAUDE.md \xA7 Testing Rules.`);
13730
+ }
13731
+ }
13732
+ function getContentDir() {
13733
+ if (resolvedContentDir)
13734
+ return resolvedContentDir;
13735
+ const resolved = resolveContentDirInner();
13736
+ assertSafeForTest(resolved);
13737
+ resolvedContentDir = resolved;
13738
+ return resolvedContentDir;
13739
+ }
13740
+ function resolveContentDirInner() {
13741
+ if (process.env.BAKIN_HOME)
13742
+ return process.env.BAKIN_HOME;
13743
+ return bakinHomeDefault();
13744
+ }
13745
+ function getBakinPaths() {
13746
+ const home = getContentDir();
13747
+ const assets = join(home, "assets");
13748
+ return {
13749
+ home,
13750
+ memoryLog: join(home, "MEMORY-LOG.md"),
13751
+ audit: join(home, "audit.jsonl"),
13752
+ assets,
13753
+ "assets.store": join(assets, "store"),
13754
+ "assets.inbox": join(assets, "inbox"),
13755
+ "assets.trash": join(assets, ".trash"),
13756
+ agents: join(home, "agents"),
13757
+ personas: join(home, "team", "personas"),
13758
+ team: join(home, "team"),
13759
+ heartbeats: join(home, "heartbeats"),
13760
+ inbox: join(home, "inbox"),
13761
+ tasks: join(home, "tasks"),
13762
+ workflows: join(home, "workflows"),
13763
+ settings: join(home, "settings.json"),
13764
+ logs: join(home, "logs")
13765
+ };
13766
+ }
13767
+
13768
+ // packages/core/src/logger.ts
13769
+ var MAX_LOG_BYTES = 10 * 1024 * 1024;
13770
+ var LEVEL_RANK = {
13771
+ debug: 10,
13772
+ info: 20,
13773
+ warn: 30,
13774
+ error: 40
13775
+ };
13776
+ var COLOR_RESET = "\x1B[0m";
13777
+ var COLORS = {
13778
+ dim: "\x1B[2m",
13779
+ blue: "\x1B[34m",
13780
+ cyan: "\x1B[36m",
13781
+ green: "\x1B[32m",
13782
+ magenta: "\x1B[35m",
13783
+ red: "\x1B[31m",
13784
+ yellow: "\x1B[33m"
13785
+ };
13786
+ var fileStream = null;
13787
+ var fileTransportInitialized = false;
13788
+ var fileTransportDisabled = false;
13789
+ function fileTransportEnabled() {
13790
+ if (fileTransportDisabled)
13791
+ return false;
13792
+ if (false)
13793
+ ;
13794
+ if (process.env.VITEST)
13795
+ return false;
13796
+ if (process.env.BAKIN_DISABLE_FILE_LOG === "1")
13797
+ return false;
13798
+ return true;
13799
+ }
13800
+ function ensureFileStream() {
13801
+ if (fileTransportInitialized)
13802
+ return fileStream;
13803
+ fileTransportInitialized = true;
13804
+ if (!fileTransportEnabled())
13805
+ return null;
13806
+ try {
13807
+ const logsDir = getBakinPaths().logs;
13808
+ if (!existsSync(logsDir))
13809
+ mkdirSync(logsDir, { recursive: true });
13810
+ const logPath = join2(logsDir, "server.log");
13811
+ if (existsSync(logPath)) {
13812
+ try {
13813
+ const size = statSync(logPath).size;
13814
+ if (size > MAX_LOG_BYTES) {
13815
+ const rotated = join2(logsDir, "server.log.1");
13816
+ renameSync(logPath, rotated);
13817
+ }
13818
+ } catch {}
13819
+ }
13820
+ fileStream = createWriteStream(logPath, { flags: "a" });
13821
+ fileStream.on("error", () => {
13822
+ fileTransportDisabled = true;
13823
+ fileStream = null;
13824
+ });
13825
+ } catch {
13826
+ fileTransportDisabled = true;
13827
+ fileStream = null;
13828
+ }
13829
+ return fileStream;
13830
+ }
13831
+ function formatEntry(entry) {
13832
+ const parts = [`[${entry.ts}] [${entry.level.toUpperCase()}] [${entry.module}] ${entry.message}`];
13833
+ if (entry.error)
13834
+ parts.push(` error: ${entry.error}`);
13835
+ if (entry.data)
13836
+ parts.push(` data: ${JSON.stringify(entry.data)}`);
13837
+ return parts.join(`
13838
+ `);
13839
+ }
13840
+ function consoleFormat() {
13841
+ const configured = process.env.BAKIN_CONSOLE_FORMAT;
13842
+ if (configured === "pretty" || configured === "verbose" || configured === "plain" || configured === "silent") {
13843
+ return configured;
13844
+ }
13845
+ return process.stdout.isTTY === true ? "pretty" : "plain";
13846
+ }
13847
+ function consoleMinLevel(format) {
13848
+ const configured = process.env.BAKIN_LOG_LEVEL;
13849
+ if (configured === "debug" || configured === "info" || configured === "warn" || configured === "error") {
13850
+ return configured;
13851
+ }
13852
+ if (format === "verbose")
13853
+ return "debug";
13854
+ if (format === "silent")
13855
+ return "error";
13856
+ if (format === "pretty")
13857
+ return "info";
13858
+ return "debug";
13859
+ }
13860
+ function colorEnabled(format) {
13861
+ if (format === "plain")
13862
+ return false;
13863
+ if (process.env.NO_COLOR || process.env.BAKIN_NO_COLOR === "1")
13864
+ return false;
13865
+ return process.stdout.isTTY === true;
13866
+ }
13867
+ function colorize(text, color, enabled) {
13868
+ return enabled ? `${COLORS[color]}${text}${COLOR_RESET}` : text;
13869
+ }
13870
+ function sourceLabel(entry) {
13871
+ const data = entry.data;
13872
+ const explicitSource = typeof data?.source === "string" ? data.source : undefined;
13873
+ const pluginId = typeof data?.pluginId === "string" ? data.pluginId : undefined;
13874
+ if (explicitSource === "antfly")
13875
+ return "antfly";
13876
+ if (explicitSource === "dev")
13877
+ return "dev";
13878
+ if (explicitSource === "plugin" && pluginId)
13879
+ return `plugin:${pluginId}`;
13880
+ if (entry.module === "plugin-registry" && pluginId)
13881
+ return `plugin:${pluginId}`;
13882
+ if (entry.module.startsWith("api:"))
13883
+ return "api";
13884
+ return entry.module;
13885
+ }
13886
+ function sourceColor(source) {
13887
+ if (source === "dev")
13888
+ return "cyan";
13889
+ if (source === "server")
13890
+ return "blue";
13891
+ if (source === "antfly")
13892
+ return "magenta";
13893
+ if (source.startsWith("plugin:"))
13894
+ return "green";
13895
+ if (source.includes("search"))
13896
+ return "cyan";
13897
+ if (source.includes("runtime"))
13898
+ return "magenta";
13899
+ return "dim";
13900
+ }
13901
+ function levelColor(level) {
13902
+ if (level === "debug")
13903
+ return "dim";
13904
+ if (level === "warn")
13905
+ return "yellow";
13906
+ if (level === "error")
13907
+ return "red";
13908
+ return "blue";
13909
+ }
13910
+ function isImportantAntflyInfo(entry) {
13911
+ return [
13912
+ "Metadata API server is ready",
13913
+ "Store HTTP server is ready",
13914
+ "Swarm mode: all servers are ready",
13915
+ "Termite's api server starting"
13916
+ ].some((message) => entry.message.includes(message));
13917
+ }
13918
+ function suppressPrettyInfo(entry) {
13919
+ if (entry.level !== "info")
13920
+ return false;
13921
+ if (entry.data?.source === "antfly")
13922
+ return !isImportantAntflyInfo(entry);
13923
+ if (entry.module === "plugin-registry") {
13924
+ return entry.message === "plugin activated" || entry.message.startsWith("Auto-registered ") || entry.message.startsWith("Plugin activation order:");
13925
+ }
13926
+ return [
13927
+ "search-registry",
13928
+ "search-reconcile",
13929
+ "search-cleanup",
13930
+ "hot-reload-coordinator",
13931
+ "mcporter",
13932
+ "dispatch",
13933
+ "watchdog",
13934
+ "doctor",
13935
+ "lifecycle"
13936
+ ].includes(entry.module);
13937
+ }
13938
+ function shouldWriteConsole(entry, format) {
13939
+ if (format === "silent")
13940
+ return false;
13941
+ const minLevel = consoleMinLevel(format);
13942
+ if (LEVEL_RANK[entry.level] < LEVEL_RANK[minLevel])
13943
+ return false;
13944
+ if (format === "pretty" && suppressPrettyInfo(entry))
13945
+ return false;
13946
+ return true;
13947
+ }
13948
+ function formatPrettyEntry(entry, format) {
13949
+ const colors = colorEnabled(format);
13950
+ const time3 = new Date(entry.ts).toTimeString().slice(0, 8);
13951
+ const level = entry.level.padEnd(5);
13952
+ const source = sourceLabel(entry);
13953
+ const label = source.padEnd(18);
13954
+ const levelPart = colorize(level, levelColor(entry.level), colors);
13955
+ const sourcePart = colorize(label, sourceColor(source), colors);
13956
+ const messagePart = entry.level === "error" ? colorize(entry.message, "red", colors) : entry.message;
13957
+ const parts = [`${colorize(time3, "dim", colors)} ${levelPart} ${sourcePart} ${messagePart}`];
13958
+ if (entry.error)
13959
+ parts[0] += ` - ${entry.error}`;
13960
+ if (format === "verbose" && entry.data) {
13961
+ parts.push(` data: ${JSON.stringify(entry.data)}`);
13962
+ }
13963
+ return parts.join(`
13964
+ `);
13965
+ }
13966
+ function formatConsoleEntry(entry) {
13967
+ const format = consoleFormat();
13968
+ if (format === "plain")
13969
+ return formatEntry(entry);
13970
+ if (format === "silent")
13971
+ return "";
13972
+ return formatPrettyEntry(entry, format);
13973
+ }
13974
+ function writeToFile(entry) {
13975
+ const stream = ensureFileStream();
13976
+ if (!stream)
13977
+ return;
13978
+ try {
13979
+ stream.write(JSON.stringify(entry) + `
13980
+ `);
13981
+ } catch {
13982
+ fileTransportDisabled = true;
13983
+ fileStream = null;
13984
+ }
13985
+ }
13986
+ function createLogger(module) {
13987
+ function log(level, message, errorOrData, data) {
13988
+ const entry = {
13989
+ ts: new Date().toISOString(),
13990
+ level,
13991
+ module,
13992
+ message
13993
+ };
13994
+ if (errorOrData instanceof Error) {
13995
+ entry.error = errorOrData.message;
13996
+ entry.data = data ? { ...data, stack: errorOrData.stack } : { stack: errorOrData.stack };
13997
+ } else if (typeof errorOrData === "string") {
13998
+ entry.error = errorOrData;
13999
+ entry.data = data;
14000
+ } else if (errorOrData && typeof errorOrData === "object") {
14001
+ entry.data = errorOrData;
14002
+ }
14003
+ const format = consoleFormat();
14004
+ if (shouldWriteConsole(entry, format)) {
14005
+ const formatted = formatConsoleEntry(entry);
14006
+ if (level === "error") {
14007
+ console.error(formatted);
14008
+ } else if (level === "warn") {
14009
+ console.warn(formatted);
14010
+ } else {
14011
+ console.log(formatted);
14012
+ }
14013
+ }
14014
+ writeToFile(entry);
14015
+ }
14016
+ return {
14017
+ debug: (message, data) => log("debug", message, data),
14018
+ info: (message, data) => log("info", message, data),
14019
+ warn: (message, errorOrData, data) => log("warn", message, errorOrData, data),
14020
+ error: (message, errorOrData, data) => log("error", message, errorOrData, data)
14021
+ };
14022
+ }
14023
+
14024
+ // packages/core/src/routing/dispatcher.ts
14025
+ var log = createLogger("dispatcher");
13699
14026
  // packages/core/src/routing/search-route.ts
13700
14027
  var searchQuery = exports_external.object({
13701
14028
  q: exports_external.string().min(1),
package/slots/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `@bakin/sdk/slots` — client-side slot registry + `<Slot>` primitive.
2
+ * `@makinbakin/sdk/slots` — client-side slot registry + `<Slot>` primitive.
3
3
  *
4
4
  * The slot system lets a plugin render components contributed by other
5
5
  * plugins at a named extension point. Today it's used for:
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Public Bakin plugin contract types.
3
3
  *
4
4
  * This module is intentionally self-contained. External plugins must be able
5
- * to typecheck against `@bakin/sdk/types` without resolving `@bakin/core`,
5
+ * to typecheck against `@makinbakin/sdk/types` without resolving `@bakin/core`,
6
6
  * Bakin source aliases, adapter packages, or another plugin's internals.
7
7
  */
8
8
  import type { ComponentType } from 'react';
@@ -40,6 +40,14 @@ export interface PluginEntryPoints {
40
40
  server: string;
41
41
  client?: string;
42
42
  }
43
+ export interface SecretDeclaration {
44
+ /** Canonical environment variable name, for example `ANTHROPIC_API_KEY`. */
45
+ name: string;
46
+ /** Human-readable setup note. Never include a secret value here. */
47
+ description: string;
48
+ /** Missing required secrets should be reported by setup/health checks. Defaults to true. */
49
+ required: boolean;
50
+ }
43
51
  export interface ApiRouteContribution {
44
52
  method: HttpMethod;
45
53
  /** Plugin-relative path. Exposed as `/api/plugins/{pluginId}{path}`. */
@@ -140,7 +148,7 @@ export interface PluginManifest {
140
148
  description: string;
141
149
  entry: PluginEntryPoints;
142
150
  contentFiles?: string[];
143
- secrets?: string[];
151
+ secrets?: SecretDeclaration[];
144
152
  tests?: string;
145
153
  dependencies?: string[];
146
154
  permissions?: PluginPermission[];
@@ -182,6 +190,12 @@ export interface ActivityAPI {
182
190
  }): void;
183
191
  audit(event: string, agent: string, data?: Record<string, unknown>): void;
184
192
  }
193
+ export interface PluginLogger {
194
+ debug(message: string, data?: Record<string, unknown>): void;
195
+ info(message: string, data?: Record<string, unknown>): void;
196
+ warn(message: string, errorOrData?: unknown, data?: Record<string, unknown>): void;
197
+ error(message: string, errorOrData?: unknown, data?: Record<string, unknown>): void;
198
+ }
185
199
  export interface HookAPI {
186
200
  register(name: string, handler: (data: unknown) => unknown, metadata?: HookRegistrationMetadata): () => void;
187
201
  call<T>(name: string, data: T): Promise<T>;
@@ -248,9 +262,25 @@ export interface RuntimeChannel {
248
262
  capabilities: string[];
249
263
  metadata?: Record<string, unknown>;
250
264
  }
251
- export interface RuntimeMessageArgs {
265
+ export type RuntimeMessageToolsMode = 'auto' | 'none';
266
+ export interface RuntimeMessageToolPolicy {
267
+ /**
268
+ * Controls whether runtime-native tools are available for this agent turn.
269
+ * `none` disables tools. Omit or use `auto` for runtime/provider defaults.
270
+ */
271
+ toolsMode?: RuntimeMessageToolsMode;
272
+ /** Optional runtime-native tool allowlist for this turn. */
273
+ toolsAllow?: string[];
274
+ /** Optional runtime-native tool denylist for this turn. */
275
+ toolsDeny?: string[];
276
+ }
277
+ export interface RuntimeMessageArgs extends RuntimeMessageToolPolicy {
252
278
  agentId: string;
253
279
  content: string;
280
+ /**
281
+ * Adapter-neutral durable conversation key. Runtime adapters should map the
282
+ * same agentId + threadId pair to the same provider/runtime session.
283
+ */
254
284
  threadId?: string;
255
285
  metadata?: Record<string, unknown>;
256
286
  }
@@ -259,10 +289,22 @@ export interface RuntimeMessageResult {
259
289
  content?: string;
260
290
  metadata?: Record<string, unknown>;
261
291
  }
292
+ export interface RuntimeToolActivity {
293
+ phase: 'call' | 'result';
294
+ callId?: string;
295
+ toolName: string;
296
+ status?: 'running' | 'completed' | 'failed' | string;
297
+ summary?: string;
298
+ inputPreview?: string;
299
+ outputPreview?: string;
300
+ durationMs?: number;
301
+ exitCode?: number;
302
+ metadata?: Record<string, unknown>;
303
+ }
262
304
  export interface RuntimeChatChunk {
263
305
  type: 'text' | 'tool' | 'status' | 'done' | 'error';
264
306
  content?: string;
265
- data?: unknown;
307
+ data?: Record<string, unknown> | RuntimeToolActivity;
266
308
  }
267
309
  export interface CronJob {
268
310
  id: string;
@@ -385,10 +427,19 @@ export interface Task {
385
427
  workflowId?: string;
386
428
  scheduleJobId?: string;
387
429
  projectId?: string;
430
+ availableAt?: string;
431
+ dueAt?: string;
432
+ source?: TaskSource;
388
433
  order?: number;
389
434
  createdAt?: string;
390
435
  updatedAt?: string;
391
436
  }
437
+ export interface TaskSource {
438
+ pluginId?: string;
439
+ entityType?: string;
440
+ entityId?: string;
441
+ purpose?: string;
442
+ }
392
443
  export interface TaskColumns {
393
444
  backlog: Task[];
394
445
  inProgress: Task[];
@@ -414,6 +465,9 @@ export interface TaskCreateInput {
414
465
  workflowId?: string;
415
466
  projectId?: string;
416
467
  parentId?: string | null;
468
+ availableAt?: string;
469
+ dueAt?: string;
470
+ source?: TaskSource;
417
471
  skipWorkflowReason?: string;
418
472
  }
419
473
  export interface TaskUpdateInput {
@@ -429,6 +483,9 @@ export interface TaskUpdateInput {
429
483
  scheduleJobId?: string;
430
484
  projectId?: string;
431
485
  parentId?: string | null;
486
+ availableAt?: string | null;
487
+ dueAt?: string | null;
488
+ source?: TaskSource | null;
432
489
  }
433
490
  export interface TaskService {
434
491
  create(input: TaskCreateInput): Promise<Task>;
@@ -667,11 +724,39 @@ export interface HealthCheckResult {
667
724
  message: string;
668
725
  autoFixable: boolean;
669
726
  }
727
+ export type HealthRepairSafety = 'safe' | 'manual' | 'destructive';
728
+ export interface HealthRepairChange {
729
+ kind: 'file' | 'setting' | 'service' | 'runtime' | 'task' | 'other';
730
+ target: string;
731
+ action: 'create' | 'update' | 'delete' | 'install' | 'invoke';
732
+ description: string;
733
+ }
734
+ export interface HealthRepairPlanItem {
735
+ id: string;
736
+ checkId: string;
737
+ title: string;
738
+ reason: string;
739
+ safety: HealthRepairSafety;
740
+ requiresConfirmation: boolean;
741
+ changes: HealthRepairChange[];
742
+ }
743
+ export interface HealthRepairApplyResult {
744
+ id: string;
745
+ checkId: string;
746
+ status: 'applied' | 'skipped' | 'failed';
747
+ message: string;
748
+ changes: HealthRepairChange[];
749
+ }
750
+ export interface HealthRepairHandler {
751
+ plan(rows: HealthCheckResult[]): Promise<HealthRepairPlanItem[]>;
752
+ apply(items: HealthRepairPlanItem[]): Promise<HealthRepairApplyResult[]>;
753
+ }
670
754
  export interface PluginHealthCheckInput {
671
755
  id: string;
672
756
  name: string;
673
757
  run: () => Promise<HealthCheckResult[]>;
674
758
  autoFix?: boolean;
759
+ repair?: HealthRepairHandler;
675
760
  }
676
761
  interface BaseSettingsField {
677
762
  key: string;
@@ -734,6 +819,7 @@ export interface PluginContext {
734
819
  getSettings<T = Record<string, unknown>>(): T;
735
820
  updateSettings(patch: Record<string, unknown>): void;
736
821
  activity: ActivityAPI;
822
+ log?: PluginLogger;
737
823
  hooks: HookAPI;
738
824
  search: SearchAPI;
739
825
  }
package/ui/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * `@bakin/sdk/ui` — shadcn base UI primitives for plugin authors.
2
+ * `@makinbakin/sdk/ui` — shadcn base UI primitives for plugin authors.
3
3
  *
4
4
  * These are re-exports from Bakin's `src/components/ui/*`. At Bakin build time
5
5
  * they resolve to source. At plugin build time (Phase 3) the plugin author
6
- * marks `@bakin/sdk` and `@bakin/sdk/ui` as externals so the plugin bundle
6
+ * marks `@makinbakin/sdk` and `@makinbakin/sdk/ui` as externals so the plugin bundle
7
7
  * doesn't duplicate these. At runtime the browser's import map resolves the
8
8
  * externals to Bakin's bundled copy.
9
9
  */
package/utils/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `@bakin/sdk/utils` — tiny utilities for plugin authors.
2
+ * `@makinbakin/sdk/utils` — tiny utilities for plugin authors.
3
3
  *
4
4
  * `cn(...)` is the Tailwind class merger every shadcn-flavored component
5
5
  * needs. The `format*` helpers are re-exported from `@bakin/core/format`
@@ -7,3 +7,8 @@
7
7
  */
8
8
  export { cn } from '../_internal/app/lib/utils';
9
9
  export { formatAge, formatSize, isStale } from '../_internal/core/format';
10
+ export { brainstormActivityMessageFromCustom, runtimeChunkToBrainstormActivity, toBrainstormTimeline, } from '../_internal/app/components/integrated-brainstorm/activity';
11
+ export { brainstormThreadId, normalizeBrainstormActivityForStorage, normalizeBrainstormActivityMessageForStorage, } from '../_internal/app/components/integrated-brainstorm/session';
12
+ export type { BrainstormActivityInput, BrainstormTimelineActivityInput, BrainstormTimelineMessageInput, } from '../_internal/app/components/integrated-brainstorm/activity';
13
+ export type { BrainstormActivityStorageInput, BrainstormActivityStorageRecord, } from '../_internal/app/components/integrated-brainstorm/session';
14
+ export { readBrainstormSseResponse } from '../_internal/app/components/integrated-brainstorm/sse';