@theokit/sdk-tools 0.15.0 → 0.16.0

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/dist/index.d.cts CHANGED
@@ -75,6 +75,27 @@ interface SessionArtifactStore {
75
75
  */
76
76
  declare function createSessionArtifactStore(options: SessionArtifactStoreOptions): SessionArtifactStore;
77
77
 
78
+ /**
79
+ * `current_time` — built-in tool for coding agents.
80
+ *
81
+ * Returns the current date-time. Codex-faithful at the core (its `clock`/`curr_time` tool returns UTC
82
+ * as `YYYY-MM-DD HH:MM:SS UTC`); this built-in keeps that default and adds an optional IANA `timezone`
83
+ * (additive superset — omitted ⇒ UTC, exactly Codex's behavior) plus an unambiguous `iso` instant.
84
+ *
85
+ * The clock is injectable so the tool is deterministic under test (testing.md §6: never read the real
86
+ * wall clock in a unit test).
87
+ *
88
+ * Result shape (always a JSON string):
89
+ * - `{ ok: true, current_time: "YYYY-MM-DD HH:MM:SS <tz>", iso: string, timezone: string }`
90
+ * - `{ ok: false, error: "invalid_timezone", timezone }`
91
+ */
92
+
93
+ interface CreateCurrentTimeToolOptions {
94
+ /** Injectable clock — defaults to `() => new Date()`. Pass a fixed clock for deterministic tests. */
95
+ clock?: () => Date;
96
+ }
97
+ declare function createCurrentTimeTool(opts?: CreateCurrentTimeToolOptions): CustomTool;
98
+
78
99
  /**
79
100
  * `edit_file` — built-in tool for coding agents.
80
101
  *
@@ -1052,4 +1073,4 @@ interface CreateWriteFileToolOptions {
1052
1073
  }
1053
1074
  declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
1054
1075
 
1055
- export { CatastrophicCommandError, type CommandPolicy, ContextMatchError, type ContextMatchReason, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGenericHttpSearchAdapterOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateInteractiveShellToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type EnvContextOptions, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, ReadTracker, ReasoningTools, RedirectBlockedError, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
1076
+ export { CatastrophicCommandError, type CommandPolicy, ContextMatchError, type ContextMatchReason, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateCurrentTimeToolOptions, type CreateEditFileToolOptions, type CreateGenericHttpSearchAdapterOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateInteractiveShellToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type EnvContextOptions, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, ReadTracker, ReasoningTools, RedirectBlockedError, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createCurrentTimeTool, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
package/dist/index.d.ts CHANGED
@@ -75,6 +75,27 @@ interface SessionArtifactStore {
75
75
  */
76
76
  declare function createSessionArtifactStore(options: SessionArtifactStoreOptions): SessionArtifactStore;
77
77
 
78
+ /**
79
+ * `current_time` — built-in tool for coding agents.
80
+ *
81
+ * Returns the current date-time. Codex-faithful at the core (its `clock`/`curr_time` tool returns UTC
82
+ * as `YYYY-MM-DD HH:MM:SS UTC`); this built-in keeps that default and adds an optional IANA `timezone`
83
+ * (additive superset — omitted ⇒ UTC, exactly Codex's behavior) plus an unambiguous `iso` instant.
84
+ *
85
+ * The clock is injectable so the tool is deterministic under test (testing.md §6: never read the real
86
+ * wall clock in a unit test).
87
+ *
88
+ * Result shape (always a JSON string):
89
+ * - `{ ok: true, current_time: "YYYY-MM-DD HH:MM:SS <tz>", iso: string, timezone: string }`
90
+ * - `{ ok: false, error: "invalid_timezone", timezone }`
91
+ */
92
+
93
+ interface CreateCurrentTimeToolOptions {
94
+ /** Injectable clock — defaults to `() => new Date()`. Pass a fixed clock for deterministic tests. */
95
+ clock?: () => Date;
96
+ }
97
+ declare function createCurrentTimeTool(opts?: CreateCurrentTimeToolOptions): CustomTool;
98
+
78
99
  /**
79
100
  * `edit_file` — built-in tool for coding agents.
80
101
  *
@@ -1052,4 +1073,4 @@ interface CreateWriteFileToolOptions {
1052
1073
  }
1053
1074
  declare function createWriteFileTool(opts: CreateWriteFileToolOptions): CustomTool;
1054
1075
 
1055
- export { CatastrophicCommandError, type CommandPolicy, ContextMatchError, type ContextMatchReason, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateEditFileToolOptions, type CreateGenericHttpSearchAdapterOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateInteractiveShellToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type EnvContextOptions, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, ReadTracker, ReasoningTools, RedirectBlockedError, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
1076
+ export { CatastrophicCommandError, type CommandPolicy, ContextMatchError, type ContextMatchReason, type CreateApplyPatchToolOptions, type CreateBraveWebSearchAdapterOptions, type CreateCurrentTimeToolOptions, type CreateEditFileToolOptions, type CreateGenericHttpSearchAdapterOptions, type CreateGitDiffToolOptions, type CreateGlobToolOptions, type CreateInteractiveShellToolOptions, type CreateListDirToolOptions, type CreateReadFileToolOptions, type CreateRunVitestToolOptions, type CreateSearchTextToolOptions, type CreateShellToolOptions, type CreateWebFetchToolOptions, type CreateWebSearchToolOptions, type CreateWriteFileToolOptions, DEFAULT_TOOL_GUIDANCE, type EnvContextOptions, type PlanModeTool, type PlanModeToolOptions, type PlanModeToolWithStore, type PlanNode, type QuestionTool, type QuestionToolOptions, ReadTracker, ReasoningTools, RedirectBlockedError, type RepoMapOptions, type ResolveAndScreenOptions, type ScreenedFetchOptions, type SessionArtifactStore, type SessionArtifactStoreOptions, SsrfBlockedError, type TodoItem, type TodolistTool, type ToolGuidanceMap, type TruncationOptions, type TruncationResult, type VitestSummary, type WebSearchCallback, type WebSearchResult, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createCurrentTimeTool, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
package/dist/index.js CHANGED
@@ -265,6 +265,46 @@ function createSessionArtifactStore(options) {
265
265
  }
266
266
  return { write, read, has, list, path };
267
267
  }
268
+ function formatInTimezone(now, tz) {
269
+ const parts = new Intl.DateTimeFormat("en-US", {
270
+ timeZone: tz,
271
+ year: "numeric",
272
+ month: "2-digit",
273
+ day: "2-digit",
274
+ hour: "2-digit",
275
+ minute: "2-digit",
276
+ second: "2-digit",
277
+ hour12: false
278
+ }).formatToParts(now);
279
+ const p = {};
280
+ for (const { type, value } of parts) p[type] = value;
281
+ const hour = p.hour === "24" ? "00" : p.hour;
282
+ return `${p.year}-${p.month}-${p.day} ${hour}:${p.minute}:${p.second} ${tz}`;
283
+ }
284
+ function createCurrentTimeTool(opts = {}) {
285
+ const clock = opts.clock ?? (() => /* @__PURE__ */ new Date());
286
+ return Tool.create({
287
+ name: "current_time",
288
+ description: "Get the current date and time. Returns { current_time, iso, timezone } as a JSON string, where current_time is 'YYYY-MM-DD HH:MM:SS <timezone>' and iso is the ISO-8601 instant. Pass an optional IANA timezone (e.g. 'America/Sao_Paulo', 'Europe/Lisbon'); defaults to UTC. Never state the date or time from memory \u2014 always call this. Returns { ok: false, error: 'invalid_timezone' } for an unknown timezone.",
289
+ inputSchema: z.object({
290
+ timezone: z.string().optional().describe("IANA timezone, e.g. 'America/Sao_Paulo' or 'Europe/Lisbon'. Defaults to UTC.")
291
+ }),
292
+ handler: ({ timezone }) => {
293
+ const tz = timezone ?? "UTC";
294
+ const now = clock();
295
+ try {
296
+ return JSON.stringify({
297
+ ok: true,
298
+ current_time: formatInTimezone(now, tz),
299
+ iso: now.toISOString(),
300
+ timezone: tz
301
+ });
302
+ } catch {
303
+ return JSON.stringify({ ok: false, error: "invalid_timezone", timezone: tz });
304
+ }
305
+ }
306
+ });
307
+ }
268
308
 
269
309
  // src/internal/context-match.ts
270
310
  var ContextMatchError = class extends Error {
@@ -379,8 +419,11 @@ async function editViaBackend(filesystem, ctx, path, old_string, new_string) {
379
419
  let content;
380
420
  try {
381
421
  content = await backend.readFile(path);
382
- } catch {
383
- return JSON.stringify({ ok: false, error: "not_found", path });
422
+ } catch (err) {
423
+ if (err instanceof FileNotFoundError) {
424
+ return JSON.stringify({ ok: false, error: "not_found", path });
425
+ }
426
+ throw err;
384
427
  }
385
428
  const outcome = computeEdit(content, old_string, new_string);
386
429
  if (!outcome.ok) return JSON.stringify({ ok: false, error: "no_match", path });
@@ -654,6 +697,7 @@ function runGitProcess(cwd, args, timeoutMs, maxStdoutBytes) {
654
697
  });
655
698
  }
656
699
  var DEFAULT_EXCLUDES = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".theo"]);
700
+ var MAX_BACKEND_WALK_DEPTH = 64;
657
701
  function createGlobTool(opts) {
658
702
  const { projectRoot, filesystem } = opts;
659
703
  return Tool.create({
@@ -671,7 +715,7 @@ function createGlobTool(opts) {
671
715
  const backend = await resolveFilesystem(filesystem, ctx ?? {});
672
716
  const searchRel = cwd ?? "";
673
717
  const found = [];
674
- await walkDirBackend(backend, searchRel, searchRel, regex, found);
718
+ await walkDirBackend(backend, searchRel, searchRel, regex, found, 0);
675
719
  return JSON.stringify({ ok: true, files: found.sort(), count: found.length });
676
720
  }
677
721
  const searchRoot = cwd ? safePathJoin(projectRoot, cwd) : projectRoot;
@@ -712,7 +756,8 @@ async function walkDir(base, dir, pattern, results) {
712
756
  }
713
757
  }
714
758
  }
715
- async function walkDirBackend(backend, base, dir, pattern, results) {
759
+ async function walkDirBackend(backend, base, dir, pattern, results, depth) {
760
+ if (depth > MAX_BACKEND_WALK_DEPTH) return;
716
761
  let names;
717
762
  try {
718
763
  names = await backend.list(dir);
@@ -720,10 +765,10 @@ async function walkDirBackend(backend, base, dir, pattern, results) {
720
765
  return;
721
766
  }
722
767
  for (const name of names) {
723
- await walkBackendEntry(backend, base, dir, name, pattern, results);
768
+ await walkBackendEntry(backend, base, dir, name, pattern, results, depth);
724
769
  }
725
770
  }
726
- async function walkBackendEntry(backend, base, dir, name, pattern, results) {
771
+ async function walkBackendEntry(backend, base, dir, name, pattern, results, depth) {
727
772
  if (DEFAULT_EXCLUDES.has(name)) return;
728
773
  const fullRel = dir === "" ? name : `${dir}/${name}`;
729
774
  const relPath = base === "" ? fullRel : relative(base, fullRel);
@@ -734,7 +779,7 @@ async function walkBackendEntry(backend, base, dir, name, pattern, results) {
734
779
  return;
735
780
  }
736
781
  if (st.isDirectory) {
737
- await walkDirBackend(backend, base, fullRel, pattern, results);
782
+ await walkDirBackend(backend, base, fullRel, pattern, results, depth + 1);
738
783
  } else if (st.isFile && pattern.test(relPath)) {
739
784
  results.push(fullRel);
740
785
  }
@@ -1806,6 +1851,7 @@ var DEFAULT_MAX_MATCHES = 100;
1806
1851
  var DEFAULT_MAX_FILE_SIZE = 1024 * 1024;
1807
1852
  var BINARY_PROBE_BYTES2 = 8 * 1024;
1808
1853
  var PREVIEW_MAX = 200;
1854
+ var MAX_BACKEND_WALK_DEPTH2 = 64;
1809
1855
  function createSearchTextTool(opts) {
1810
1856
  const {
1811
1857
  projectRoot,
@@ -1834,7 +1880,7 @@ function createSearchTextTool(opts) {
1834
1880
  const scopeRel = resolveScopeRel(path, projectRoot);
1835
1881
  if ("error" in scopeRel) return scopeRel.error;
1836
1882
  const backend = await resolveFilesystem(filesystem, ctx ?? {});
1837
- await walkBackend(backend, scopeRel.rel, state);
1883
+ await walkBackend(backend, scopeRel.rel, state, 0);
1838
1884
  return JSON.stringify({
1839
1885
  ok: true,
1840
1886
  matches: state.matches,
@@ -1944,8 +1990,9 @@ function resolveScopeRel(path, projectRoot) {
1944
1990
  throw err;
1945
1991
  }
1946
1992
  }
1947
- async function walkBackend(backend, dirRel, state) {
1993
+ async function walkBackend(backend, dirRel, state, depth) {
1948
1994
  if (state.truncated) return;
1995
+ if (depth > MAX_BACKEND_WALK_DEPTH2) return;
1949
1996
  let names;
1950
1997
  try {
1951
1998
  names = await backend.list(dirRel);
@@ -1954,10 +2001,10 @@ async function walkBackend(backend, dirRel, state) {
1954
2001
  }
1955
2002
  for (const name of names) {
1956
2003
  if (state.truncated) return;
1957
- await handleBackendEntry(backend, dirRel, name, state);
2004
+ await handleBackendEntry(backend, dirRel, name, state, depth);
1958
2005
  }
1959
2006
  }
1960
- async function handleBackendEntry(backend, dirRel, name, state) {
2007
+ async function handleBackendEntry(backend, dirRel, name, state, depth) {
1961
2008
  const entryRel = dirRel === "" ? name : `${dirRel}/${name}`;
1962
2009
  if (isForbiddenPath(entryRel)) return;
1963
2010
  let st;
@@ -1967,7 +2014,7 @@ async function handleBackendEntry(backend, dirRel, name, state) {
1967
2014
  return;
1968
2015
  }
1969
2016
  if (st.isDirectory) {
1970
- await walkBackend(backend, entryRel, state);
2017
+ await walkBackend(backend, entryRel, state, depth + 1);
1971
2018
  } else if (st.isFile) {
1972
2019
  await scanFileBackend(backend, entryRel, st.size, state);
1973
2020
  }
@@ -2550,6 +2597,6 @@ async function isBinaryFile(absolutePath) {
2550
2597
  }
2551
2598
  }
2552
2599
 
2553
- export { CatastrophicCommandError, ContextMatchError, DEFAULT_TOOL_GUIDANCE, ReadTracker, ReasoningTools, RedirectBlockedError, SsrfBlockedError, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
2600
+ export { CatastrophicCommandError, ContextMatchError, DEFAULT_TOOL_GUIDANCE, ReadTracker, ReasoningTools, RedirectBlockedError, SsrfBlockedError, buildEnvContext, buildRepoMap, catastrophicShellReason, commandDenialReason, createApplyPatchTool, createBraveWebSearchAdapter, createCurrentTimeTool, createEditFileTool, createGenericHttpSearchAdapter, createGitDiffTool, createGlobTool, createInteractiveShellTool, createListDirTool, createPlanModeTool, createQuestionTool, createReadFileTool, createRunVitestTool, createSearchTextTool, createSessionArtifactStore, createShellTool, createTodolistTool, createWebFetchTool, createWebSearchTool, createWriteFileTool, createWriteStdinTool, denyCatastrophicCommands, formatCode, formatDiff, formatError, formatFileList, injectGuidance, isBlockedIp, isCommandAllowed, renderToolList, replaceUnique, resolveAndScreen, screenedFetch, todoItemsToPlanNodes, truncateOutput, withDefaultGuidance, withDescription, withName, withShellExitGuidance, withToolResultGuidance };
2554
2601
  //# sourceMappingURL=index.js.map
2555
2602
  //# sourceMappingURL=index.js.map