@sixb/agent 0.2.4 → 0.2.5

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 (90) hide show
  1. package/README.md +2 -2
  2. package/dist/agent-prompt.d.ts.map +1 -1
  3. package/dist/artifacts/layout-check/layout-check.d.ts +21 -24
  4. package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
  5. package/dist/artifacts/publish-tool.d.ts.map +1 -1
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +10590 -8888
  9. package/dist/index.js.map +30 -26
  10. package/dist/run-agent-turn.d.ts +3 -14
  11. package/dist/run-agent-turn.d.ts.map +1 -1
  12. package/dist/run-environment.d.ts.map +1 -1
  13. package/dist/run-subagent.d.ts.map +1 -1
  14. package/dist/sandbox-api-context.d.ts.map +1 -1
  15. package/dist/search-script.d.ts +7 -0
  16. package/dist/search-script.d.ts.map +1 -0
  17. package/dist/skills/built-in.d.ts.map +1 -1
  18. package/dist/tools/glob.d.ts +41 -0
  19. package/dist/tools/glob.d.ts.map +1 -0
  20. package/dist/tools/grep.d.ts +64 -0
  21. package/dist/tools/grep.d.ts.map +1 -0
  22. package/dist/tools/model-spec.d.ts.map +1 -1
  23. package/dist/tools/sandbox-search.d.ts +26 -0
  24. package/dist/tools/sandbox-search.d.ts.map +1 -0
  25. package/dist/tools/search/command.d.ts +15 -0
  26. package/dist/tools/search/command.d.ts.map +1 -0
  27. package/dist/tools/search/gitignore.d.ts +28 -0
  28. package/dist/tools/search/gitignore.d.ts.map +1 -0
  29. package/dist/tools/search/glob.d.ts +15 -0
  30. package/dist/tools/search/glob.d.ts.map +1 -0
  31. package/dist/tools/search/main.d.ts +2 -0
  32. package/dist/tools/search/main.d.ts.map +1 -0
  33. package/dist/tools/search/match.d.ts +30 -0
  34. package/dist/tools/search/match.d.ts.map +1 -0
  35. package/dist/tools/search/pattern.d.ts +19 -0
  36. package/dist/tools/search/pattern.d.ts.map +1 -0
  37. package/dist/tools/search/read.d.ts +62 -0
  38. package/dist/tools/search/read.d.ts.map +1 -0
  39. package/dist/tools/search/request.d.ts +80 -0
  40. package/dist/tools/search/request.d.ts.map +1 -0
  41. package/dist/tools/search/search.d.ts +4 -0
  42. package/dist/tools/search/search.d.ts.map +1 -0
  43. package/dist/tools/search/walk.d.ts +43 -0
  44. package/dist/tools/search/walk.d.ts.map +1 -0
  45. package/dist/tools/tool-outputs.d.ts.map +1 -1
  46. package/dist/turn-inbox.d.ts +75 -0
  47. package/dist/turn-inbox.d.ts.map +1 -0
  48. package/package.json +6 -4
  49. package/src/agent-prompt.ts +1 -0
  50. package/src/agent-runtime/preflight.ts +1 -0
  51. package/src/artifacts/layout-check/check.cjs +176 -95
  52. package/src/artifacts/layout-check/layout-check.ts +118 -76
  53. package/src/artifacts/publish-tool.ts +48 -99
  54. package/src/generated/search.mjs +985 -0
  55. package/src/index.ts +0 -1
  56. package/src/run-agent-turn.ts +85 -129
  57. package/src/run-conversation-turn.ts +4 -4
  58. package/src/run-environment.ts +4 -0
  59. package/src/run-subagent.ts +1 -1
  60. package/src/sandbox-api-context.ts +3 -0
  61. package/src/search-script-assets.d.ts +5 -0
  62. package/src/search-script.ts +9 -0
  63. package/src/skills/built-in.ts +16 -0
  64. package/src/skills/sixb-artifacts/SKILL.md +7 -7
  65. package/src/skills/sixb-artifacts/canvas.md +3 -2
  66. package/src/skills/sixb-artifacts/document.md +92 -5
  67. package/src/skills/sixb-artifacts/examples/document/service-proposal/design.css +114 -0
  68. package/src/skills/sixb-artifacts/examples/document/service-proposal/document.html +159 -0
  69. package/src/skills/sixb-artifacts/examples/document/service-proposal/images/fieldwise.svg +1 -0
  70. package/src/skills/sixb-artifacts/examples/document/service-proposal/images/harbor-pine.svg +1 -0
  71. package/src/skills/sixb-artifacts/queries.md +2 -1
  72. package/src/tools/glob.ts +124 -0
  73. package/src/tools/grep.ts +190 -0
  74. package/src/tools/model-spec.ts +4 -0
  75. package/src/tools/sandbox-search.ts +219 -0
  76. package/src/tools/search/command.ts +116 -0
  77. package/src/tools/search/gitignore.ts +101 -0
  78. package/src/tools/search/glob.ts +90 -0
  79. package/src/tools/search/main.ts +9 -0
  80. package/src/tools/search/match.ts +278 -0
  81. package/src/tools/search/pattern.ts +178 -0
  82. package/src/tools/search/read.ts +237 -0
  83. package/src/tools/search/request.ts +101 -0
  84. package/src/tools/search/search.ts +297 -0
  85. package/src/tools/search/walk.ts +145 -0
  86. package/src/tools/tool-outputs.ts +7 -2
  87. package/src/turn-inbox.ts +283 -0
  88. package/dist/artifacts/board-previews.d.ts +0 -41
  89. package/dist/artifacts/board-previews.d.ts.map +0 -1
  90. package/src/artifacts/board-previews.ts +0 -218
@@ -0,0 +1,114 @@
1
+ /* The paper: US Letter with its margins. Pages and the PDF are cut from it. */
2
+ @page { size: letter; margin: 0.72in 0.84in; }
3
+
4
+ :root {
5
+ --accent: #0f766e;
6
+ --ink: #18181b;
7
+ --muted: #71717a;
8
+ --rule: #e4e4e7;
9
+ --wash: #f0fdfa;
10
+ }
11
+
12
+ body {
13
+ color: var(--ink);
14
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
15
+ font-size: 10pt;
16
+ line-height: 1.6;
17
+ }
18
+
19
+ h1, h2, h3 { margin: 0; letter-spacing: -0.02em; break-after: avoid; }
20
+ h2 { margin-bottom: 12px; font-size: 14pt; line-height: 1.25; }
21
+ h3 { margin: 20px 0 6px; font-size: 10.5pt; }
22
+ p { margin: 0 0 10px; }
23
+ ul, ol { margin: 0 0 12px; padding-left: 20px; }
24
+ li + li { margin-top: 4px; }
25
+ strong { font-weight: 700; }
26
+
27
+ .section-number { color: var(--accent); }
28
+ .page { break-before: page; }
29
+
30
+ /* The cover fills its page; the facts sit at its foot. */
31
+ .cover { display: flex; flex-direction: column; min-height: 9.4in; }
32
+ .cover header { display: flex; align-items: flex-start; justify-content: space-between; }
33
+ .logos { display: flex; align-items: center; gap: 18px; }
34
+ .logos img + img { padding-left: 18px; border-left: 1px solid var(--rule); }
35
+ .eyebrow {
36
+ margin: 0;
37
+ color: var(--muted);
38
+ font-size: 7pt;
39
+ font-weight: 700;
40
+ letter-spacing: 0.14em;
41
+ text-transform: uppercase;
42
+ }
43
+ .cover h1 { margin-top: 88px; font-size: 30pt; line-height: 1.1; letter-spacing: -0.03em; }
44
+ .prepared-for { margin-top: 14px; color: #52525b; }
45
+ .summary { margin-top: 44px; padding-top: 22px; border-top: 2px solid var(--accent); }
46
+ .summary .eyebrow { margin-bottom: 10px; color: var(--ink); }
47
+ .facts {
48
+ display: grid;
49
+ grid-template-columns: repeat(3, 1fr);
50
+ gap: 24px;
51
+ margin-top: auto;
52
+ padding-top: 16px;
53
+ border-top: 1px solid var(--rule);
54
+ }
55
+ .facts p { margin: 6px 0 0; font-size: 8.5pt; }
56
+
57
+ .columns { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
58
+ .columns h3 { margin-top: 0; padding-top: 10px; border-top: 1px solid var(--rule); }
59
+ .callout { margin: 18px 0; padding: 14px 16px; border: 1px solid #ccfbf1; background: var(--wash); }
60
+ .callout p:last-child { margin-bottom: 0; }
61
+
62
+ /* A numbered timeline down the page. */
63
+ .timeline { margin: 18px 0; padding: 0; list-style: none; }
64
+ .timeline li { position: relative; margin: 0; padding: 0 0 16px 40px; break-inside: avoid; }
65
+ .timeline li::before {
66
+ content: counter(list-item, decimal-leading-zero);
67
+ position: absolute;
68
+ left: 0;
69
+ top: 0;
70
+ width: 22px;
71
+ height: 22px;
72
+ border: 1px solid #99f6e4;
73
+ border-radius: 50%;
74
+ background: var(--wash);
75
+ color: var(--accent);
76
+ font-size: 6.5pt;
77
+ line-height: 20px;
78
+ text-align: center;
79
+ }
80
+ .timeline li:not(:last-child)::after {
81
+ content: "";
82
+ position: absolute;
83
+ left: 11px;
84
+ top: 26px;
85
+ bottom: 2px;
86
+ border-left: 1px solid var(--rule);
87
+ }
88
+ .timeline strong { display: block; }
89
+ .timeline p { margin: 2px 0 0; color: #52525b; }
90
+
91
+ table { width: 100%; margin: 12px 0 20px; border: 1px solid var(--rule); border-collapse: collapse; }
92
+ thead { display: table-header-group; }
93
+ th, td { padding: 7px 10px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
94
+ th { color: var(--muted); font-size: 6.5pt; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; background: #fafafa; }
95
+ tr { break-inside: avoid; }
96
+ .amount { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
97
+ tfoot td { font-weight: 700; }
98
+
99
+ /* Two parties side by side, a line to sign on each. */
100
+ .signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--rule); break-inside: avoid; }
101
+ .signature-line { height: 44px; border-bottom: 1px solid #a1a1aa; }
102
+ .signatures .name { margin: 8px 0 0; font-weight: 600; }
103
+ .signatures .organization { margin: 0; color: var(--muted); font-size: 8pt; }
104
+ .signatures .dated { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
105
+ .signatures .dated span { display: block; padding-top: 22px; border-bottom: 1px solid #a1a1aa; color: var(--muted); font-size: 6.5pt; letter-spacing: 0.1em; text-transform: uppercase; }
106
+
107
+ /* On a phone the document is one sheet at the screen's width: the grids stack. */
108
+ @media screen and (max-width: 600px) {
109
+ .cover { min-height: 0; }
110
+ .columns, .facts, .signatures { grid-template-columns: 1fr; }
111
+ .cover header { flex-direction: column; gap: 12px; }
112
+ .cover h1 { margin-top: 48px; }
113
+ .logos { flex-wrap: wrap; }
114
+ }
@@ -0,0 +1,159 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Harbor &amp; Pine Landscaping: job flow proposal</title>
6
+ <link rel="stylesheet" href="design.css">
7
+ </head>
8
+ <body>
9
+ <section class="cover">
10
+ <header>
11
+ <div class="logos">
12
+ <img src="images/fieldwise.svg" alt="Fieldwise" width="132" height="32">
13
+ <img src="images/harbor-pine.svg" alt="Harbor &amp; Pine Landscaping" width="150" height="32">
14
+ </div>
15
+ <p class="eyebrow">Service proposal</p>
16
+ </header>
17
+
18
+ <h1>Harbor &amp; Pine Landscaping</h1>
19
+ <p class="prepared-for">Prepared for <strong>Harbor &amp; Pine Landscaping LLC</strong> · Dana Reyes</p>
20
+
21
+ <div class="summary">
22
+ <p class="eyebrow">Executive summary</p>
23
+ <p>Fieldwise will build one system around the way Harbor &amp; Pine already works. It connects
24
+ to QuickBooks, so the books stay where they are, and gives every job one path from first
25
+ call to paid that the whole crew can see.</p>
26
+ <p>The work takes about five weeks for a fixed fee of <strong>$4,000</strong>, with hosting
27
+ and maintenance at <strong>$200 a month</strong> after delivery.</p>
28
+ </div>
29
+
30
+ <div class="facts">
31
+ <div><p class="eyebrow">Prepared by</p><p>Sam Okafor · Fieldwise</p></div>
32
+ <div><p class="eyebrow">Proposal date</p><p>November 5, 2026</p></div>
33
+ <div><p class="eyebrow">Valid until</p><p>December 5, 2026</p></div>
34
+ </div>
35
+ </section>
36
+
37
+ <section class="page">
38
+ <h2><span class="section-number">1.</span> What changes for Harbor &amp; Pine</h2>
39
+ <div class="columns">
40
+ <div>
41
+ <h3>What we heard</h3>
42
+ <p>The business runs through Dana: calls, texts and what she keeps in her head. There is no
43
+ shared schedule, so the crew gets its plan from talking to her.</p>
44
+ <p>The aim is not more work, but the same work running smoothly without everything passing
45
+ through one person.</p>
46
+ </div>
47
+ <div>
48
+ <h3>What we saw in the books</h3>
49
+ <p>Work ranges from large custom projects to recurring maintenance and snow contracts.</p>
50
+ <p>Many estimates stay marked pending, so QuickBooks can't tell which ones are still
51
+ live.</p>
52
+ </div>
53
+ </div>
54
+ <h3>What we propose</h3>
55
+ <p>Keep what already works, walking the site and QuickBooks doing the books, and add one path
56
+ every job follows:</p>
57
+ <p><strong>Call → Site visit → Estimate → Won → Scheduled → In progress → Invoiced → Paid</strong></p>
58
+ <div class="callout">
59
+ <p><strong>The goal</strong></p>
60
+ <p>The same business, running more smoothly, with work moving through the company without
61
+ Dana carrying all of it.</p>
62
+ </div>
63
+ </section>
64
+
65
+ <section class="page">
66
+ <h2><span class="section-number">2.</span> Scope of work</h2>
67
+ <p>Fieldwise builds an app on top of QuickBooks, for the office computer and the crew's
68
+ phones. QuickBooks keeps the books; the app handles everything around each job.</p>
69
+ <h3>What we'll deliver</h3>
70
+ <ol>
71
+ <li><strong>Every job in one place.</strong> From first call to paid, including annual
72
+ contracts.</li>
73
+ <li><strong>Site visits to estimates.</strong> Photos and notes become a draft estimate you
74
+ price and send through QuickBooks.</li>
75
+ <li><strong>One shared schedule.</strong> The crew knows where to go, and customers get
76
+ updates.</li>
77
+ <li><strong>Extras and invoices.</strong> Approved extras carry onto the invoice, and payments
78
+ show on the job.</li>
79
+ </ol>
80
+ <h3>Your part</h3>
81
+ <ul>
82
+ <li>QuickBooks Online admin access</li>
83
+ <li>Your estimate terms and conditions</li>
84
+ <li>A short check-in each week</li>
85
+ </ul>
86
+ <h3>Not included</h3>
87
+ <p>Payroll, time tracking, and a customer login or portal.</p>
88
+ </section>
89
+
90
+ <section class="page">
91
+ <h2><span class="section-number">3.</span> Timeline</h2>
92
+ <p>Delivery is about three weeks from kickoff, with a review as each part comes together.</p>
93
+ <ol class="timeline">
94
+ <li><strong>Week 1: Kickoff and QuickBooks</strong>
95
+ <p>Connect QuickBooks and bring in customers, estimates, invoices and payments.</p></li>
96
+ <li><strong>Weeks 1–2: Jobs and customers</strong>
97
+ <p>Build the Today page, the jobs board and customer pages, then review them with you.</p></li>
98
+ <li><strong>Week 2: Site visits and estimates</strong>
99
+ <p>Build site visit capture and drafted estimates, then try them on a real job.</p></li>
100
+ <li><strong>Weeks 2–3: Schedule, crew and invoices</strong>
101
+ <p>Build the calendar, the crew view, extras and invoices.</p></li>
102
+ <li><strong>Weeks 4–5: Fixes and small changes</strong>
103
+ <p>Fix what comes up as you use it on real jobs.</p></li>
104
+ </ol>
105
+ </section>
106
+
107
+ <section class="page">
108
+ <h2><span class="section-number">4.</span> Pricing and payment terms</h2>
109
+ <p>The full scope is delivered for a <strong>fixed fee of $4,000</strong>.</p>
110
+ <table>
111
+ <thead><tr><th>Item</th><th>Includes</th><th class="amount">Fee</th></tr></thead>
112
+ <tbody>
113
+ <tr><td>Setup</td><td>Kickoff, QuickBooks connection, hosting, sign-in</td><td class="amount">$500</td></tr>
114
+ <tr><td>Jobs and customers</td><td>Today page, jobs board, customer pages</td><td class="amount">$900</td></tr>
115
+ <tr><td>Site visits and estimates</td><td>Photos, notes, drafted estimates in QuickBooks</td><td class="amount">$900</td></tr>
116
+ <tr><td>Schedule and crew</td><td>Shared calendar, crew view</td><td class="amount">$450</td></tr>
117
+ <tr><td>Extras and invoices</td><td>Approved extras, invoices in QuickBooks</td><td class="amount">$500</td></tr>
118
+ <tr><td>Testing and fixes</td><td>Real data testing, walkthrough, fixes</td><td class="amount">$750</td></tr>
119
+ </tbody>
120
+ <tfoot><tr><td colspan="2">Total fixed fee</td><td class="amount">$4,000</td></tr></tfoot>
121
+ </table>
122
+ <h3>Payment schedule</h3>
123
+ <table>
124
+ <thead><tr><th>Payment</th><th>When</th><th class="amount">Amount</th></tr></thead>
125
+ <tbody>
126
+ <tr><td>Kickoff</td><td>When work starts</td><td class="amount">$2,000</td></tr>
127
+ <tr><td>Delivery</td><td>When it is delivered</td><td class="amount">$2,000</td></tr>
128
+ </tbody>
129
+ </table>
130
+ <p>Invoices are due within 30 days.</p>
131
+ <h3>Hosting and maintenance</h3>
132
+ <p><strong>$200 a month</strong> after delivery, covering hosting, updates and fixes. Either
133
+ party can end it with 30 days' notice.</p>
134
+ </section>
135
+
136
+ <section class="page">
137
+ <h2><span class="section-number">5.</span> Acceptance and next steps</h2>
138
+ <p>By signing below, Harbor &amp; Pine Landscaping LLC authorizes Fieldwise to proceed with the
139
+ scope above for a fixed fee of <strong>$4,000</strong>, with hosting and maintenance at
140
+ <strong>$200 a month</strong> after delivery. Once it's signed, we'll schedule the kickoff.</p>
141
+ <div class="signatures">
142
+ <div>
143
+ <p class="eyebrow">For the service provider</p>
144
+ <div class="signature-line"></div>
145
+ <p class="name">Sam Okafor</p>
146
+ <p class="organization">Fieldwise</p>
147
+ <div class="dated"><span>Title</span><span>Date</span></div>
148
+ </div>
149
+ <div>
150
+ <p class="eyebrow">Accepted and agreed</p>
151
+ <div class="signature-line"></div>
152
+ <p class="name">Dana Reyes</p>
153
+ <p class="organization">Harbor &amp; Pine Landscaping LLC</p>
154
+ <div class="dated"><span>Title</span><span>Date</span></div>
155
+ </div>
156
+ </div>
157
+ </section>
158
+ </body>
159
+ </html>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="132" height="32" viewBox="0 0 132 32"><path d="M2 26 L14 4 L26 26 Z" fill="#0f766e"/><path d="M14 4 L26 26 L18 26 Z" fill="#115e59"/><text x="34" y="23" font-family="Helvetica, Arial, sans-serif" font-size="19" font-weight="700" letter-spacing="-0.4" fill="#18181b">Fieldwise</text></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="150" height="32" viewBox="0 0 150 32"><circle cx="14" cy="16" r="12" fill="none" stroke="#3f3f46" stroke-width="2"/><path d="M14 7 L20 19 H8 Z M14 13 L21 25 H7 Z" fill="#3f3f46"/><text x="34" y="15" font-family="Georgia, serif" font-size="12" letter-spacing="1.6" fill="#27272a">HARBOR &amp; PINE</text><text x="34" y="27" font-family="Helvetica, Arial, sans-serif" font-size="7.5" letter-spacing="2.4" fill="#71717a">LANDSCAPING</text></svg>
@@ -3,7 +3,8 @@
3
3
  A query reads the project's objects each time the artifact is opened, as whoever opens it: they see
4
4
  the rows they may view, and a value they are not cleared for shows locked. Data from the project
5
5
  goes in a query, not a copy, so the artifact stays current: a sheet shows its rows (`sheet.md`, Live
6
- rows), and a page, a deck, or a canvas board reads them with `sixb.query` (`page.md`).
6
+ rows), a page, a deck, or a canvas board reads them with `sixb.query` (`page.md`), and a designed
7
+ document shows them in its fields (`document.md`, Live data).
7
8
 
8
9
  ## Write one
9
10
 
@@ -0,0 +1,124 @@
1
+ import type { JsonObject, JsonValue, ModelTool } from "@sixb/core/models"
2
+ import { agentToolErrorText } from "../model-adapters"
3
+ import type { AgentSandboxHandle } from "../sandbox-handle"
4
+ import { objectInput } from "./edit"
5
+ import { publicError } from "./file-writes"
6
+ import {
7
+ INCOMPLETE_SEARCH_FOOTER,
8
+ isRecord,
9
+ optionalPathInput,
10
+ runSandboxSearch,
11
+ searchUnavailable,
12
+ } from "./sandbox-search"
13
+ import type { GlobSearchResult } from "./search/request"
14
+
15
+ export const GLOB_TOOL_SPEC = {
16
+ name: "glob",
17
+ strict: true,
18
+ description:
19
+ "Find files by name. A pattern without / matches at any depth (*.md finds every Markdown file); one with / matches from path (src/**/*.ts). Supports *, **, ?, [abc] and {a,b}. Skips .git and what .gitignore excludes, and hidden files and node_modules unless the pattern names them. Returns at most 100 paths, sorted. Prefer this over bash to find files.",
20
+ inputSchema: {
21
+ type: "object",
22
+ properties: {
23
+ pattern: { type: "string", description: "Glob pattern, relative to path." },
24
+ path: {
25
+ type: "string",
26
+ description:
27
+ "Folder to search: relative to the working directory, or an absolute path in the run's context directory. Default: the working directory.",
28
+ },
29
+ },
30
+ required: ["pattern"],
31
+ additionalProperties: false,
32
+ } satisfies JsonObject,
33
+ } as const
34
+
35
+ export interface GlobToolInput {
36
+ readonly pattern: string
37
+ readonly path?: string
38
+ }
39
+
40
+ export interface GlobToolOutput {
41
+ readonly pattern: string
42
+ /** As the call named it; `.` for the working directory. */
43
+ readonly path: string
44
+ /** Relative to the working directory when under it, absolute otherwise. */
45
+ readonly files: readonly string[]
46
+ /** More files match than the 100 listed. */
47
+ readonly truncated: boolean
48
+ /** The search stopped at its deadline. */
49
+ readonly incomplete?: true
50
+ }
51
+
52
+ export function createGlobTool(
53
+ resolveSandbox: () => Promise<AgentSandboxHandle>
54
+ ): ModelTool<GlobToolInput> {
55
+ return {
56
+ ...GLOB_TOOL_SPEC,
57
+ parseInput: parseGlobInput,
58
+ async execute(input, { signal }): Promise<JsonValue> {
59
+ const handle = await resolveSandbox()
60
+ const result = await runSandboxSearch(handle, { tool: "glob", ...input }, signal)
61
+ if (!isGlobResult(result)) {
62
+ throw searchUnavailable(
63
+ "glob",
64
+ "its output could not be read",
65
+ new Error("Invalid sandbox output.")
66
+ )
67
+ }
68
+
69
+ return {
70
+ pattern: input.pattern,
71
+ path: input.path ?? ".",
72
+ files: result.files,
73
+ truncated: result.truncated,
74
+ ...(result.incomplete ? { incomplete: true } : {}),
75
+ } satisfies GlobToolOutput
76
+ },
77
+ toModelOutput(output) {
78
+ return { type: "text", value: globModelText(output as unknown as GlobToolOutput) }
79
+ },
80
+ errorText: agentToolErrorText,
81
+ }
82
+ }
83
+
84
+ /** One path per line, then what the list leaves out. */
85
+ export function globModelText(output: GlobToolOutput): string {
86
+ const footers = [
87
+ ...(output.truncated
88
+ ? [`(${output.files.length} files shown, more match: narrow the pattern or the path)`]
89
+ : []),
90
+ ...(output.incomplete ? [INCOMPLETE_SEARCH_FOOTER] : []),
91
+ ]
92
+ const list = output.files.length > 0 ? output.files.join("\n") : "No files found"
93
+ return [list, ...footers].join("\n\n")
94
+ }
95
+
96
+ function parseGlobInput(value: unknown): GlobToolInput {
97
+ const input = objectInput(value, "glob", ["pattern", "path"])
98
+ if (typeof input.pattern !== "string" || input.pattern === "") {
99
+ throw publicError("glob", "pattern must be a non-empty glob pattern.")
100
+ }
101
+ // Either would find nothing, and the model would read that nothing matches.
102
+ if (input.pattern.startsWith("/")) {
103
+ throw publicError(
104
+ "glob",
105
+ "pattern is relative to path: pass the folder as path and the rest as pattern."
106
+ )
107
+ }
108
+ if (input.pattern.endsWith("/")) {
109
+ throw publicError("glob", "glob finds files: drop the trailing /, or read the folder.")
110
+ }
111
+
112
+ const path = optionalPathInput(input.path, "glob")
113
+ return { pattern: input.pattern, ...(path === undefined ? {} : { path }) }
114
+ }
115
+
116
+ function isGlobResult(value: unknown): value is GlobSearchResult {
117
+ return (
118
+ isRecord(value) &&
119
+ Array.isArray(value.files) &&
120
+ value.files.every((file) => typeof file === "string") &&
121
+ typeof value.truncated === "boolean" &&
122
+ (value.incomplete === undefined || value.incomplete === true)
123
+ )
124
+ }
@@ -0,0 +1,190 @@
1
+ import type { JsonObject, JsonValue, ModelTool } from "@sixb/core/models"
2
+ import { agentToolErrorText } from "../model-adapters"
3
+ import type { AgentSandboxHandle } from "../sandbox-handle"
4
+ import { objectInput } from "./edit"
5
+ import { publicError } from "./file-writes"
6
+ import {
7
+ INCOMPLETE_SEARCH_FOOTER,
8
+ isLeftOut,
9
+ isRecord,
10
+ optionalPathInput,
11
+ runSandboxSearch,
12
+ searchUnavailable,
13
+ } from "./sandbox-search"
14
+ import type { GrepMatch, GrepSearchResult } from "./search/request"
15
+
16
+ export const GREP_TOOL_SPEC = {
17
+ name: "grep",
18
+ strict: true,
19
+ description:
20
+ "Search file contents with a JavaScript regular expression, or with literal text. Case is ignored unless the pattern has an uppercase letter. Searches hidden files, and skips .git, node_modules, what .gitignore excludes, binary files and files over 10 MiB. Matches the first 4,000 characters of a line. Returns matching lines grouped by file, at most 100 in all and 20 per file, with line numbers that read takes as its offset. Prefer this over bash to search text.",
21
+ inputSchema: {
22
+ type: "object",
23
+ properties: {
24
+ pattern: {
25
+ type: "string",
26
+ description: "Regular expression, or the text itself with literal.",
27
+ },
28
+ path: {
29
+ type: "string",
30
+ description:
31
+ "File or folder to search: relative to the working directory, or an absolute path in the run's context directory. Default: the working directory.",
32
+ },
33
+ include: {
34
+ type: "string",
35
+ description: "Glob pattern the files must match, such as *.ts or *.{ts,tsx}.",
36
+ },
37
+ literal: {
38
+ type: "boolean",
39
+ description: "Search the pattern as written, not as a regular expression. Default: false.",
40
+ },
41
+ },
42
+ required: ["pattern"],
43
+ additionalProperties: false,
44
+ } satisfies JsonObject,
45
+ } as const
46
+
47
+ export interface GrepToolInput {
48
+ readonly pattern: string
49
+ readonly path?: string
50
+ readonly include?: string
51
+ readonly literal?: boolean
52
+ }
53
+
54
+ export interface GrepToolOutput {
55
+ readonly pattern: string
56
+ /** As the call named it; `.` for the working directory. */
57
+ readonly path: string
58
+ /** Paths relative to the working directory when under it, absolute otherwise. */
59
+ readonly matches: readonly GrepMatch[]
60
+ /** How many files the matches are in. */
61
+ readonly files: number
62
+ /** Matching lines past the 20 a file shows, by path. */
63
+ readonly more?: Readonly<Record<string, number>>
64
+ /** Another file matches past the 100 lines shown. */
65
+ readonly truncated: boolean
66
+ /** The search stopped at its deadline. */
67
+ readonly incomplete?: true
68
+ }
69
+
70
+ export function createGrepTool(
71
+ resolveSandbox: () => Promise<AgentSandboxHandle>
72
+ ): ModelTool<GrepToolInput> {
73
+ return {
74
+ ...GREP_TOOL_SPEC,
75
+ parseInput: parseGrepInput,
76
+ async execute(input, { signal }): Promise<JsonValue> {
77
+ const handle = await resolveSandbox()
78
+ const result = await runSandboxSearch(handle, { tool: "grep", ...input }, signal)
79
+ if (!isGrepResult(result)) {
80
+ throw searchUnavailable(
81
+ "grep",
82
+ "its output could not be read",
83
+ new Error("Invalid sandbox output.")
84
+ )
85
+ }
86
+
87
+ return {
88
+ pattern: input.pattern,
89
+ path: input.path ?? ".",
90
+ matches: result.matches.map(({ path, line, text }) => ({ path, line, text })),
91
+ files: result.files,
92
+ ...(result.more ? { more: result.more } : {}),
93
+ truncated: result.truncated,
94
+ ...(result.incomplete ? { incomplete: true } : {}),
95
+ } satisfies GrepToolOutput
96
+ },
97
+ toModelOutput(output) {
98
+ return { type: "text", value: grepModelText(output as unknown as GrepToolOutput) }
99
+ },
100
+ errorText: agentToolErrorText,
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Matches grouped by file, each line with its number, then how many more the file holds:
106
+ *
107
+ * ```
108
+ * src/config.ts
109
+ * 12: const retries = 3
110
+ * … 7 more in this file
111
+ * ```
112
+ */
113
+ export function grepModelText(output: GrepToolOutput): string {
114
+ const groups: string[] = []
115
+ let group: string[] = []
116
+ let path: string | undefined
117
+
118
+ const close = () => {
119
+ if (path === undefined) return
120
+ const more = output.more?.[path]
121
+ if (more) group.push(` … ${more} more in this file`)
122
+ groups.push(group.join("\n"))
123
+ }
124
+
125
+ for (const match of output.matches) {
126
+ if (match.path !== path) {
127
+ close()
128
+ path = match.path
129
+ group = [match.path]
130
+ }
131
+ group.push(` ${match.line}: ${match.text}`)
132
+ }
133
+ close()
134
+
135
+ const footers = [
136
+ ...(output.truncated
137
+ ? [
138
+ `(${output.matches.length} matching lines shown, more match: narrow the pattern, the path or include)`,
139
+ ]
140
+ : []),
141
+ ...(output.incomplete ? [INCOMPLETE_SEARCH_FOOTER] : []),
142
+ ]
143
+ return [groups.length > 0 ? groups.join("\n\n") : "No matches", ...footers].join("\n\n")
144
+ }
145
+
146
+ function parseGrepInput(value: unknown): GrepToolInput {
147
+ const input = objectInput(value, "grep", ["pattern", "path", "include", "literal"])
148
+ if (typeof input.pattern !== "string" || input.pattern === "") {
149
+ throw publicError("grep", "pattern must be a non-empty pattern.")
150
+ }
151
+ if (input.literal !== undefined && input.literal !== null && typeof input.literal !== "boolean") {
152
+ throw publicError("grep", "literal must be true or false.")
153
+ }
154
+
155
+ const path = optionalPathInput(input.path, "grep")
156
+ const include = isLeftOut(input.include) ? undefined : input.include
157
+ if (include !== undefined && typeof include !== "string") {
158
+ throw publicError("grep", "include must be a glob pattern.")
159
+ }
160
+
161
+ return {
162
+ pattern: input.pattern,
163
+ ...(path === undefined ? {} : { path }),
164
+ ...(include === undefined ? {} : { include }),
165
+ ...(input.literal === true ? { literal: true } : {}),
166
+ }
167
+ }
168
+
169
+ function isGrepResult(value: unknown): value is GrepSearchResult {
170
+ return (
171
+ isRecord(value) &&
172
+ Array.isArray(value.matches) &&
173
+ value.matches.every(isGrepMatch) &&
174
+ typeof value.files === "number" &&
175
+ (value.more === undefined ||
176
+ (isRecord(value.more) &&
177
+ Object.values(value.more).every((count) => typeof count === "number"))) &&
178
+ typeof value.truncated === "boolean" &&
179
+ (value.incomplete === undefined || value.incomplete === true)
180
+ )
181
+ }
182
+
183
+ function isGrepMatch(value: unknown): value is GrepMatch {
184
+ return (
185
+ isRecord(value) &&
186
+ typeof value.path === "string" &&
187
+ typeof value.line === "number" &&
188
+ typeof value.text === "string"
189
+ )
190
+ }
@@ -4,6 +4,8 @@ import { OPEN_ARTIFACT_TOOL_SPEC, PUBLISH_ARTIFACT_TOOL_SPEC } from "../artifact
4
4
  import { STOP_TOOL_SPEC, WAIT_TOOL_SPEC } from "./background"
5
5
  import { BASH_TOOL_SPEC } from "./bash"
6
6
  import { EDIT_TOOL_SPEC } from "./edit"
7
+ import { GLOB_TOOL_SPEC } from "./glob"
8
+ import { GREP_TOOL_SPEC } from "./grep"
7
9
  import { READ_TOOL_SPEC } from "./read"
8
10
  import { WEB_FETCH_TOOL_SPEC } from "./web-fetch/tool"
9
11
  import { WEB_SEARCH_TOOL_SPEC } from "./web-search"
@@ -28,6 +30,8 @@ export function agentModelToolSpecs(
28
30
  READ_TOOL_SPEC,
29
31
  EDIT_TOOL_SPEC,
30
32
  WRITE_TOOL_SPEC,
33
+ GLOB_TOOL_SPEC,
34
+ GREP_TOOL_SPEC,
31
35
  BASH_TOOL_SPEC,
32
36
  WAIT_TOOL_SPEC,
33
37
  STOP_TOOL_SPEC,