@sourcegraph/amp-sdk 0.1.0-20251029183144-g02378e6 → 0.1.0-20251210022310-g15793ed
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/LICENSE.md +1 -1
- package/README.md +542 -4
- package/dist/index.js +11 -4
- package/dist/types.d.ts +6 -3
- package/package.json +6 -5
package/LICENSE.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
© Sourcegraph Inc. All rights reserved. Use of Amp is subject to Amp's [Terms of Service](https://ampcode.com/terms).
|
|
1
|
+
© Sourcegraph Inc. All rights reserved. Use of Amp is subject to Amp's [Terms of Service](https://ampcode.com/terms), or separate Amp terms that you have signed with Sourcegraph Inc.
|
package/README.md
CHANGED
|
@@ -36,13 +36,11 @@ The Amp SDK enables a wide range of AI-powered applications:
|
|
|
36
36
|
|
|
37
37
|
### Installation
|
|
38
38
|
|
|
39
|
-
Install the Amp SDK using `npm` or `yarn`:
|
|
40
|
-
|
|
41
39
|
```bash
|
|
42
|
-
# npm
|
|
40
|
+
# Install the Amp SDK using npm
|
|
43
41
|
npm install @sourcegraph/amp-sdk
|
|
44
42
|
|
|
45
|
-
# yarn
|
|
43
|
+
# or yarn
|
|
46
44
|
yarn add @sourcegraph/amp-sdk
|
|
47
45
|
```
|
|
48
46
|
|
|
@@ -191,6 +189,27 @@ for await (const message of execute({
|
|
|
191
189
|
}
|
|
192
190
|
```
|
|
193
191
|
|
|
192
|
+
### Agent Mode
|
|
193
|
+
|
|
194
|
+
Select which agent mode to use. The mode controls the model, system prompt, and tool selection:
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
for await (const message of execute({
|
|
198
|
+
prompt: 'Quickly fix this typo',
|
|
199
|
+
options: {
|
|
200
|
+
mode: 'rush', // Use rush mode for faster responses
|
|
201
|
+
},
|
|
202
|
+
})) {
|
|
203
|
+
// Process messages
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Available modes:
|
|
208
|
+
|
|
209
|
+
- **smart** (default): Balanced mode with full capabilities
|
|
210
|
+
- **rush**: Faster responses with streamlined tool usage
|
|
211
|
+
- **large**: Extended context for complex tasks
|
|
212
|
+
|
|
194
213
|
### Tool Permissions
|
|
195
214
|
|
|
196
215
|
Control which tools Amp can use with fine-grained permissions:
|
|
@@ -397,3 +416,522 @@ for await (const message of execute({
|
|
|
397
416
|
```
|
|
398
417
|
|
|
399
418
|
To find out more about Amp Toolboxes, see the [Toolboxes](https://ampcode.com/manual#toolboxes) section of the Amp documentation.
|
|
419
|
+
|
|
420
|
+
## Functions
|
|
421
|
+
|
|
422
|
+
### execute()
|
|
423
|
+
|
|
424
|
+
The main function for executing Amp CLI commands programmatically.
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
function execute(options: ExecuteOptions): AsyncIterable<StreamMessage>
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
#### Parameters
|
|
431
|
+
|
|
432
|
+
- `options` ([`ExecuteOptions`](#executeoptions)) - Configuration for the execution
|
|
433
|
+
|
|
434
|
+
#### Returns
|
|
435
|
+
|
|
436
|
+
- `AsyncIterable<StreamMessage>` - Stream of messages from the Amp CLI
|
|
437
|
+
|
|
438
|
+
#### Example
|
|
439
|
+
|
|
440
|
+
```typescript
|
|
441
|
+
import { execute } from '@sourcegraph/amp-sdk'
|
|
442
|
+
|
|
443
|
+
for await (const message of execute({
|
|
444
|
+
prompt: 'Analyze this codebase',
|
|
445
|
+
options: {
|
|
446
|
+
cwd: './my-project',
|
|
447
|
+
dangerouslyAllowAll: true,
|
|
448
|
+
},
|
|
449
|
+
})) {
|
|
450
|
+
if (message.type === 'assistant') {
|
|
451
|
+
console.log('Assistant:', message.message.content)
|
|
452
|
+
} else if (message.type === 'result') {
|
|
453
|
+
console.log('Final result:', message.result)
|
|
454
|
+
break
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### createUserMessage()
|
|
460
|
+
|
|
461
|
+
Helper function to create properly formatted user input messages for streaming conversations.
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
function createUserMessage(text: string): UserInputMessage
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
#### Parameters
|
|
468
|
+
|
|
469
|
+
- `text` (`string`) - The text content for the user message
|
|
470
|
+
|
|
471
|
+
#### Returns
|
|
472
|
+
|
|
473
|
+
- [`UserInputMessage`](#userinputmessage) - A formatted user input message
|
|
474
|
+
|
|
475
|
+
#### Example
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
import { createUserMessage } from '@sourcegraph/amp-sdk'
|
|
479
|
+
|
|
480
|
+
const message = createUserMessage('Analyze this code')
|
|
481
|
+
console.log(message)
|
|
482
|
+
// Output: { type: 'user', message: { role: 'user', content: [{ type: 'text', text: 'Analyze this code' }] } }
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### createPermission()
|
|
486
|
+
|
|
487
|
+
Helper function to create permission objects for controlling tool usage.
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
function createPermission(
|
|
491
|
+
tool: string,
|
|
492
|
+
action: 'allow' | 'reject' | 'ask' | 'delegate',
|
|
493
|
+
options?: {
|
|
494
|
+
matches?: Record<string, PermissionMatchCondition>
|
|
495
|
+
context?: 'thread' | 'subagent'
|
|
496
|
+
to?: string
|
|
497
|
+
},
|
|
498
|
+
): Permission
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
#### Parameters
|
|
502
|
+
|
|
503
|
+
- `tool` (`string`) - The name of the tool to which this permission applies (supports glob patterns)
|
|
504
|
+
- `action` (`'allow' | 'reject' | 'ask' | 'delegate'`) - How Amp should proceed when matched
|
|
505
|
+
- `options` (`object`, optional) - Additional configuration for the permission
|
|
506
|
+
- `matches` ([`Record<string, PermissionMatchCondition>`](#permissionmatchcondition)) - Match conditions for tool arguments
|
|
507
|
+
- `context` (`'thread' | 'subagent'`) - Only apply this rule in specific context
|
|
508
|
+
- `to` (`string`) - Command to delegate to (required when action is `'delegate'`)
|
|
509
|
+
|
|
510
|
+
#### Returns
|
|
511
|
+
|
|
512
|
+
- [`Permission`](#permission) - A permission object that can be used in the permissions array
|
|
513
|
+
|
|
514
|
+
#### Examples
|
|
515
|
+
|
|
516
|
+
```typescript
|
|
517
|
+
import { createPermission } from '@sourcegraph/amp-sdk'
|
|
518
|
+
|
|
519
|
+
// Allow all Bash commands
|
|
520
|
+
createPermission('Bash', 'allow')
|
|
521
|
+
|
|
522
|
+
// Allow specific git commands
|
|
523
|
+
createPermission('Bash', 'allow', {
|
|
524
|
+
matches: { cmd: 'git *' },
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
// Ask before allowing Read operations on sensitive paths
|
|
528
|
+
createPermission('Read', 'ask', {
|
|
529
|
+
matches: { path: '/etc/*' },
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
// Delegate web browsing to a custom command
|
|
533
|
+
createPermission('mcp__playwright__*', 'delegate', {
|
|
534
|
+
to: 'node browse.js',
|
|
535
|
+
})
|
|
536
|
+
|
|
537
|
+
// Only apply in subagent context
|
|
538
|
+
createPermission('Bash', 'reject', {
|
|
539
|
+
context: 'subagent',
|
|
540
|
+
})
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
## Types
|
|
544
|
+
|
|
545
|
+
### ExecuteOptions
|
|
546
|
+
|
|
547
|
+
Configuration options for the `execute()` function.
|
|
548
|
+
|
|
549
|
+
```typescript
|
|
550
|
+
interface ExecuteOptions {
|
|
551
|
+
prompt: string | AsyncIterable<UserInputMessage>
|
|
552
|
+
options?: AmpOptions
|
|
553
|
+
signal?: AbortSignal
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
#### Properties
|
|
558
|
+
|
|
559
|
+
| Property | Type | Required | Description |
|
|
560
|
+
| --------- | ------------------------------------------- | -------- | -------------------------------------------------------------------------------------------- |
|
|
561
|
+
| `prompt` | `string \| AsyncIterable<UserInputMessage>` | Yes | The input prompt as a string or async iterable of user messages for multi-turn conversations |
|
|
562
|
+
| `options` | [`AmpOptions`](#ampoptions) | No | CLI configuration options |
|
|
563
|
+
| `signal` | `AbortSignal` | No | Signal for cancellation support |
|
|
564
|
+
|
|
565
|
+
### AmpOptions
|
|
566
|
+
|
|
567
|
+
Configuration options that map to Amp CLI flags.
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
interface AmpOptions {
|
|
571
|
+
cwd?: string
|
|
572
|
+
mode?: 'smart' | 'rush' | 'large'
|
|
573
|
+
dangerouslyAllowAll?: boolean
|
|
574
|
+
visibility?: 'public' | 'private' | 'workspace' | 'group'
|
|
575
|
+
settingsFile?: string
|
|
576
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'audit'
|
|
577
|
+
logFile?: string
|
|
578
|
+
mcpConfig?: string | MCPConfig
|
|
579
|
+
env?: Record<string, string>
|
|
580
|
+
continue?: boolean | string
|
|
581
|
+
toolbox?: string
|
|
582
|
+
permissions?: Permission[]
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
#### Properties
|
|
587
|
+
|
|
588
|
+
| Property | Type | Default | Description |
|
|
589
|
+
| --------------------- | --------------------------------------------------- | --------------- | ------------------------------------------------------------------------ |
|
|
590
|
+
| `cwd` | `string` | `process.cwd()` | Current working directory for execution |
|
|
591
|
+
| `mode` | `'smart' \| 'rush' \| 'large'` | `'smart'` | Agent mode - controls model, system prompt, and tool selection |
|
|
592
|
+
| `dangerouslyAllowAll` | `boolean` | `false` | Allow all tool usage without permission prompts |
|
|
593
|
+
| `visibility` | `'public' \| 'private' \| 'workspace' \| 'group'` | `'workspace'` | Thread visibility level |
|
|
594
|
+
| `settingsFile` | `string` | - | Path to custom settings file |
|
|
595
|
+
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error' \| 'audit'` | `'info'` | Logging verbosity level |
|
|
596
|
+
| `logFile` | `string` | - | Path to write logs |
|
|
597
|
+
| `continue` | `boolean \| string` | `false` | Continue most recent thread (`true`) or specific thread by ID (`string`) |
|
|
598
|
+
| `mcpConfig` | `string \| MCPConfig` | - | MCP server configuration as JSON string, or config object |
|
|
599
|
+
| `env` | `Record<string, string>` | - | Additional environment variables |
|
|
600
|
+
| `toolbox` | `string` | - | Folder path with toolbox scripts |
|
|
601
|
+
| `permissions` | [`Permission[]`](#permission) | - | Permission rules for tool usage |
|
|
602
|
+
|
|
603
|
+
## Message Types
|
|
604
|
+
|
|
605
|
+
The SDK streams various message types during execution. All messages implement the base `StreamMessage` type.
|
|
606
|
+
|
|
607
|
+
### SystemMessage
|
|
608
|
+
|
|
609
|
+
Initial message containing session information and available tools.
|
|
610
|
+
|
|
611
|
+
```typescript
|
|
612
|
+
interface SystemMessage {
|
|
613
|
+
type: 'system'
|
|
614
|
+
subtype: 'init'
|
|
615
|
+
session_id: string
|
|
616
|
+
cwd: string
|
|
617
|
+
tools: string[]
|
|
618
|
+
mcp_servers: Array<{
|
|
619
|
+
name: string
|
|
620
|
+
status: 'connected' | 'connecting' | 'connection-failed' | 'disabled'
|
|
621
|
+
}>
|
|
622
|
+
}
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
#### Properties
|
|
626
|
+
|
|
627
|
+
| Property | Type | Description |
|
|
628
|
+
| ------------- | --------------------------------------- | -------------------------------------------- |
|
|
629
|
+
| `session_id` | `string` | Unique identifier for this execution session |
|
|
630
|
+
| `cwd` | `string` | Current working directory |
|
|
631
|
+
| `tools` | `string[]` | List of available tool names |
|
|
632
|
+
| `mcp_servers` | `Array<{name: string, status: string}>` | Status of MCP servers |
|
|
633
|
+
|
|
634
|
+
### AssistantMessage
|
|
635
|
+
|
|
636
|
+
AI assistant responses with text content and tool usage.
|
|
637
|
+
|
|
638
|
+
```typescript
|
|
639
|
+
interface AssistantMessage {
|
|
640
|
+
type: 'assistant'
|
|
641
|
+
session_id: string
|
|
642
|
+
message: {
|
|
643
|
+
id: string
|
|
644
|
+
type: 'message'
|
|
645
|
+
role: 'assistant'
|
|
646
|
+
model: string
|
|
647
|
+
content: Array<TextContent | ToolUseContent>
|
|
648
|
+
stop_reason: 'end_turn' | 'tool_use' | 'max_tokens' | null
|
|
649
|
+
stop_sequence: string | null
|
|
650
|
+
usage?: Usage
|
|
651
|
+
}
|
|
652
|
+
parent_tool_use_id: string | null
|
|
653
|
+
}
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
#### Properties
|
|
657
|
+
|
|
658
|
+
| Property | Type | Description |
|
|
659
|
+
| -------------------- | ---------------- | ------------------------------------------------ |
|
|
660
|
+
| `session_id` | `string` | Unique identifier for this execution session |
|
|
661
|
+
| `message` | `object` | The assistant's message content |
|
|
662
|
+
| `parent_tool_use_id` | `string \| null` | ID of parent tool use if this is a tool response |
|
|
663
|
+
|
|
664
|
+
### UserMessage
|
|
665
|
+
|
|
666
|
+
User input and tool results.
|
|
667
|
+
|
|
668
|
+
```typescript
|
|
669
|
+
interface UserMessage {
|
|
670
|
+
type: 'user'
|
|
671
|
+
session_id: string
|
|
672
|
+
message: {
|
|
673
|
+
role: 'user'
|
|
674
|
+
content: Array<TextContent | ToolResultContent>
|
|
675
|
+
}
|
|
676
|
+
parent_tool_use_id: string | null
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
#### Properties
|
|
681
|
+
|
|
682
|
+
| Property | Type | Description |
|
|
683
|
+
| -------------------- | ---------------- | ------------------------------------------------ |
|
|
684
|
+
| `session_id` | `string` | Unique identifier for this execution session |
|
|
685
|
+
| `message` | `object` | The user's message content |
|
|
686
|
+
| `parent_tool_use_id` | `string \| null` | ID of parent tool use if this is a tool response |
|
|
687
|
+
|
|
688
|
+
### ResultMessage
|
|
689
|
+
|
|
690
|
+
Final successful execution result.
|
|
691
|
+
|
|
692
|
+
```typescript
|
|
693
|
+
interface ResultMessage {
|
|
694
|
+
type: 'result'
|
|
695
|
+
subtype: 'success'
|
|
696
|
+
session_id: string
|
|
697
|
+
is_error: false
|
|
698
|
+
result: string
|
|
699
|
+
duration_ms: number
|
|
700
|
+
num_turns: number
|
|
701
|
+
usage?: Usage
|
|
702
|
+
permission_denials?: string[]
|
|
703
|
+
}
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
#### Properties
|
|
707
|
+
|
|
708
|
+
| Property | Type | Description |
|
|
709
|
+
| -------------------- | ----------------- | -------------------------------------------- |
|
|
710
|
+
| `session_id` | `string` | Unique identifier for this execution session |
|
|
711
|
+
| `result` | `string` | The final result from the assistant |
|
|
712
|
+
| `duration_ms` | `number` | Total execution time in milliseconds |
|
|
713
|
+
| `num_turns` | `number` | Number of conversation turns |
|
|
714
|
+
| `usage` | [`Usage`](#usage) | Token usage information |
|
|
715
|
+
| `permission_denials` | `string[]` | List of permissions that were denied |
|
|
716
|
+
|
|
717
|
+
### ErrorResultMessage
|
|
718
|
+
|
|
719
|
+
Final error result indicating execution failure.
|
|
720
|
+
|
|
721
|
+
```typescript
|
|
722
|
+
interface ErrorResultMessage {
|
|
723
|
+
type: 'result'
|
|
724
|
+
subtype: 'error_during_execution' | 'error_max_turns'
|
|
725
|
+
session_id: string
|
|
726
|
+
is_error: true
|
|
727
|
+
error: string
|
|
728
|
+
duration_ms: number
|
|
729
|
+
num_turns: number
|
|
730
|
+
usage?: Usage
|
|
731
|
+
permission_denials?: string[]
|
|
732
|
+
}
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
#### Properties
|
|
736
|
+
|
|
737
|
+
| Property | Type | Description |
|
|
738
|
+
| -------------------- | ----------------- | -------------------------------------------- |
|
|
739
|
+
| `session_id` | `string` | Unique identifier for this execution session |
|
|
740
|
+
| `error` | `string` | Error message describing what went wrong |
|
|
741
|
+
| `duration_ms` | `number` | Total execution time in milliseconds |
|
|
742
|
+
| `num_turns` | `number` | Number of conversation turns |
|
|
743
|
+
| `usage` | [`Usage`](#usage) | Token usage information |
|
|
744
|
+
| `permission_denials` | `string[]` | List of permissions that were denied |
|
|
745
|
+
|
|
746
|
+
### TextContent
|
|
747
|
+
|
|
748
|
+
Plain text content block.
|
|
749
|
+
|
|
750
|
+
```typescript
|
|
751
|
+
interface TextContent {
|
|
752
|
+
type: 'text'
|
|
753
|
+
text: string
|
|
754
|
+
}
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
### ToolUseContent
|
|
758
|
+
|
|
759
|
+
Tool execution request.
|
|
760
|
+
|
|
761
|
+
```typescript
|
|
762
|
+
interface ToolUseContent {
|
|
763
|
+
type: 'tool_use'
|
|
764
|
+
id: string
|
|
765
|
+
name: string
|
|
766
|
+
input: Record<string, unknown>
|
|
767
|
+
}
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
### ToolResultContent
|
|
771
|
+
|
|
772
|
+
Result from tool execution.
|
|
773
|
+
|
|
774
|
+
```typescript
|
|
775
|
+
interface ToolResultContent {
|
|
776
|
+
type: 'tool_result'
|
|
777
|
+
tool_use_id: string
|
|
778
|
+
content: string
|
|
779
|
+
is_error: boolean
|
|
780
|
+
}
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
### Usage
|
|
784
|
+
|
|
785
|
+
Token usage and billing information from API calls.
|
|
786
|
+
|
|
787
|
+
```typescript
|
|
788
|
+
interface Usage {
|
|
789
|
+
input_tokens: number
|
|
790
|
+
cache_creation_input_tokens?: number
|
|
791
|
+
cache_read_input_tokens?: number
|
|
792
|
+
output_tokens: number
|
|
793
|
+
service_tier?: string
|
|
794
|
+
}
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
#### Properties
|
|
798
|
+
|
|
799
|
+
| Property | Type | Description |
|
|
800
|
+
| ----------------------------- | -------- | ---------------------------------- |
|
|
801
|
+
| `input_tokens` | `number` | Number of input tokens used |
|
|
802
|
+
| `cache_creation_input_tokens` | `number` | Tokens used for cache creation |
|
|
803
|
+
| `cache_read_input_tokens` | `number` | Tokens read from cache |
|
|
804
|
+
| `output_tokens` | `number` | Number of output tokens generated |
|
|
805
|
+
| `service_tier` | `string` | Service tier used for this request |
|
|
806
|
+
|
|
807
|
+
## Input Types
|
|
808
|
+
|
|
809
|
+
### UserInputMessage
|
|
810
|
+
|
|
811
|
+
Formatted user input message for streaming conversations.
|
|
812
|
+
|
|
813
|
+
```typescript
|
|
814
|
+
interface UserInputMessage {
|
|
815
|
+
type: 'user'
|
|
816
|
+
message: {
|
|
817
|
+
role: 'user'
|
|
818
|
+
content: Array<{
|
|
819
|
+
type: 'text'
|
|
820
|
+
text: string
|
|
821
|
+
}>
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
```
|
|
825
|
+
|
|
826
|
+
### MCPConfig
|
|
827
|
+
|
|
828
|
+
Configuration for MCP (Model Context Protocol) servers.
|
|
829
|
+
|
|
830
|
+
```typescript
|
|
831
|
+
type MCPConfig = Record<string, MCPServer>
|
|
832
|
+
|
|
833
|
+
interface MCPServer {
|
|
834
|
+
command: string
|
|
835
|
+
args?: string[]
|
|
836
|
+
env?: Record<string, string>
|
|
837
|
+
disabled?: boolean
|
|
838
|
+
}
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
#### Properties
|
|
842
|
+
|
|
843
|
+
| Property | Type | Required | Description |
|
|
844
|
+
| ---------- | ------------------------ | -------- | ------------------------------------ |
|
|
845
|
+
| `command` | `string` | Yes | Command to start the MCP server |
|
|
846
|
+
| `args` | `string[]` | No | Command line arguments |
|
|
847
|
+
| `env` | `Record<string, string>` | No | Environment variables for the server |
|
|
848
|
+
| `disabled` | `boolean` | No | Whether this server is disabled |
|
|
849
|
+
|
|
850
|
+
### Permission
|
|
851
|
+
|
|
852
|
+
Individual permission rule for controlling tool usage.
|
|
853
|
+
|
|
854
|
+
```typescript
|
|
855
|
+
interface Permission {
|
|
856
|
+
tool: string
|
|
857
|
+
matches?: Record<string, PermissionMatchCondition>
|
|
858
|
+
action: 'allow' | 'reject' | 'ask' | 'delegate'
|
|
859
|
+
context?: 'thread' | 'subagent'
|
|
860
|
+
to?: string
|
|
861
|
+
}
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
#### Properties
|
|
865
|
+
|
|
866
|
+
| Property | Type | Required | Description |
|
|
867
|
+
| --------- | -------------------------------------------- | -------- | ----------------------------------------------------------- |
|
|
868
|
+
| `tool` | `string` | Yes | Tool name (supports glob patterns like `Bash` or `mcp__*`) |
|
|
869
|
+
| `matches` | `Record<string, PermissionMatchCondition>` | No | Match conditions for tool arguments |
|
|
870
|
+
| `action` | `'allow' \| 'reject' \| 'ask' \| 'delegate'` | Yes | How Amp should proceed when the rule matches |
|
|
871
|
+
| `context` | `'thread' \| 'subagent'` | No | Apply rule only in main thread or sub-agents |
|
|
872
|
+
| `to` | `string` | No | Command to delegate to (required when action is `delegate`) |
|
|
873
|
+
|
|
874
|
+
#### Example
|
|
875
|
+
|
|
876
|
+
```typescript
|
|
877
|
+
import { execute, createPermission } from '@sourcegraph/amp-sdk'
|
|
878
|
+
|
|
879
|
+
for await (const message of execute({
|
|
880
|
+
prompt: 'Deploy the application',
|
|
881
|
+
options: {
|
|
882
|
+
permissions: [
|
|
883
|
+
// Allow git commands
|
|
884
|
+
createPermission('Bash', 'allow', { matches: { cmd: 'git *' } }),
|
|
885
|
+
// Allow reading files
|
|
886
|
+
createPermission('Read', 'allow'),
|
|
887
|
+
],
|
|
888
|
+
},
|
|
889
|
+
})) {
|
|
890
|
+
// Handle messages
|
|
891
|
+
}
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
### PermissionMatchCondition
|
|
895
|
+
|
|
896
|
+
Match condition for tool arguments. Supports strings (with glob patterns or regex), arrays (OR logic), booleans, numbers, null, undefined, and nested objects.
|
|
897
|
+
|
|
898
|
+
```typescript
|
|
899
|
+
type PermissionMatchCondition =
|
|
900
|
+
| string
|
|
901
|
+
| PermissionMatchCondition[]
|
|
902
|
+
| { [key: string]: PermissionMatchCondition }
|
|
903
|
+
| boolean
|
|
904
|
+
| number
|
|
905
|
+
| null
|
|
906
|
+
| undefined
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
#### Examples
|
|
910
|
+
|
|
911
|
+
```typescript
|
|
912
|
+
// String pattern with wildcard
|
|
913
|
+
{
|
|
914
|
+
cmd: 'npm *'
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// Array for OR logic
|
|
918
|
+
{
|
|
919
|
+
cmd: ['npm install', 'npm test', 'npm run build']
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// Regex pattern
|
|
923
|
+
{
|
|
924
|
+
cmd: '/^git (status|log|diff)$/'
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// Nested object matching
|
|
928
|
+
{
|
|
929
|
+
env: {
|
|
930
|
+
NODE_ENV: 'production'
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
```
|
|
934
|
+
|
|
935
|
+
## Requirements
|
|
936
|
+
|
|
937
|
+
- Node.js 18 or higher
|
package/dist/index.js
CHANGED
|
@@ -4041,8 +4041,9 @@ var MCPServerSchema = exports_external.object({
|
|
|
4041
4041
|
var MCPConfigSchema = exports_external.record(exports_external.string(), MCPServerSchema).describe("MCP server configurations keyed by server name");
|
|
4042
4042
|
var AmpOptionsSchema = exports_external.object({
|
|
4043
4043
|
cwd: exports_external.string().describe("Current working directory").optional(),
|
|
4044
|
+
mode: exports_external.enum(["smart", "rush", "large"]).describe("Agent mode - controls the model, system prompt, and tool selection").default("smart").optional(),
|
|
4044
4045
|
dangerouslyAllowAll: exports_external.boolean().describe("Allow all tool usage without asking for permission").optional(),
|
|
4045
|
-
visibility: exports_external.enum(["private", "
|
|
4046
|
+
visibility: exports_external.enum(["private", "public", "workspace", "group"]).describe("Visibility level for new threads").default("workspace").optional(),
|
|
4046
4047
|
settingsFile: exports_external.string().describe("Settings file path").optional(),
|
|
4047
4048
|
logLevel: exports_external.enum(["debug", "info", "warn", "error", "audit"]).describe("Log level").optional(),
|
|
4048
4049
|
logFile: exports_external.string().describe("Log file path").optional(),
|
|
@@ -4112,7 +4113,7 @@ function generateSessionId() {
|
|
|
4112
4113
|
return `sdk-${Date.now()}-${randomHex}`;
|
|
4113
4114
|
}
|
|
4114
4115
|
async function buildSettingsFile(options, sessionId) {
|
|
4115
|
-
if (!options.permissions) {
|
|
4116
|
+
if (!options.permissions && !options.mode) {
|
|
4116
4117
|
return {
|
|
4117
4118
|
settingsFilePath: null,
|
|
4118
4119
|
cleanupTempFile: async () => {}
|
|
@@ -4133,6 +4134,9 @@ async function buildSettingsFile(options, sessionId) {
|
|
|
4133
4134
|
}
|
|
4134
4135
|
}
|
|
4135
4136
|
mergedSettings["amp.permissions"] = options.permissions;
|
|
4137
|
+
if (options.mode === "large") {
|
|
4138
|
+
mergedSettings["amp.internal.visibleModes"] = (mergedSettings["amp.internal.visibleModes"] ?? []).concat("large");
|
|
4139
|
+
}
|
|
4136
4140
|
await mkdir(tempDir, { recursive: true });
|
|
4137
4141
|
await writeFile(tempSettingsPath, JSON.stringify(mergedSettings, null, 2), "utf-8");
|
|
4138
4142
|
return {
|
|
@@ -4154,7 +4158,7 @@ function buildEnvironmentVariables(options) {
|
|
|
4154
4158
|
if (options.env) {
|
|
4155
4159
|
Object.assign(env, options.env);
|
|
4156
4160
|
}
|
|
4157
|
-
env.AMP_SDK_VERSION = "0.1.0-
|
|
4161
|
+
env.AMP_SDK_VERSION = "0.1.0-20251210022310-g15793ed";
|
|
4158
4162
|
return env;
|
|
4159
4163
|
}
|
|
4160
4164
|
function spawnAmpCli(args, options) {
|
|
@@ -4217,6 +4221,9 @@ function buildCliArgs(options) {
|
|
|
4217
4221
|
const mcpConfigValue = typeof options.mcpConfig === "string" ? options.mcpConfig : JSON.stringify(options.mcpConfig);
|
|
4218
4222
|
args.push("--mcp-config", mcpConfigValue);
|
|
4219
4223
|
}
|
|
4224
|
+
if (options.mode) {
|
|
4225
|
+
args.push("--mode", options.mode);
|
|
4226
|
+
}
|
|
4220
4227
|
return args;
|
|
4221
4228
|
}
|
|
4222
4229
|
async function* processOutputStream(stdout) {
|
|
@@ -4355,4 +4362,4 @@ export {
|
|
|
4355
4362
|
AmpOptionsSchema
|
|
4356
4363
|
};
|
|
4357
4364
|
|
|
4358
|
-
//# debugId=
|
|
4365
|
+
//# debugId=69EC9F263B63276764756E2164756E21
|
package/dist/types.d.ts
CHANGED
|
@@ -225,8 +225,9 @@ export type MCPConfig = z.infer<typeof MCPConfigSchema>;
|
|
|
225
225
|
/** Configuration options for Amp execution schema */
|
|
226
226
|
export declare const AmpOptionsSchema: z.ZodObject<{
|
|
227
227
|
cwd: z.ZodOptional<z.ZodString>;
|
|
228
|
+
mode: z.ZodOptional<z.ZodDefault<z.ZodEnum<["smart", "rush", "large"]>>>;
|
|
228
229
|
dangerouslyAllowAll: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
-
visibility: z.ZodOptional<z.ZodDefault<z.ZodEnum<["private", "
|
|
230
|
+
visibility: z.ZodOptional<z.ZodDefault<z.ZodEnum<["private", "public", "workspace", "group"]>>>;
|
|
230
231
|
settingsFile: z.ZodOptional<z.ZodString>;
|
|
231
232
|
logLevel: z.ZodOptional<z.ZodEnum<["debug", "info", "warn", "error", "audit"]>>;
|
|
232
233
|
logFile: z.ZodOptional<z.ZodString>;
|
|
@@ -283,8 +284,9 @@ export declare const AmpOptionsSchema: z.ZodObject<{
|
|
|
283
284
|
}, "strict", z.ZodTypeAny, {
|
|
284
285
|
env?: Record<string, string> | undefined;
|
|
285
286
|
cwd?: string | undefined;
|
|
287
|
+
mode?: "smart" | "rush" | "large" | undefined;
|
|
286
288
|
dangerouslyAllowAll?: boolean | undefined;
|
|
287
|
-
visibility?: "private" | "
|
|
289
|
+
visibility?: "private" | "public" | "workspace" | "group" | undefined;
|
|
288
290
|
settingsFile?: string | undefined;
|
|
289
291
|
logLevel?: "debug" | "info" | "warn" | "error" | "audit" | undefined;
|
|
290
292
|
logFile?: string | undefined;
|
|
@@ -306,8 +308,9 @@ export declare const AmpOptionsSchema: z.ZodObject<{
|
|
|
306
308
|
}, {
|
|
307
309
|
env?: Record<string, string> | undefined;
|
|
308
310
|
cwd?: string | undefined;
|
|
311
|
+
mode?: "smart" | "rush" | "large" | undefined;
|
|
309
312
|
dangerouslyAllowAll?: boolean | undefined;
|
|
310
|
-
visibility?: "private" | "
|
|
313
|
+
visibility?: "private" | "public" | "workspace" | "group" | undefined;
|
|
311
314
|
settingsFile?: string | undefined;
|
|
312
315
|
logLevel?: "debug" | "info" | "warn" | "error" | "audit" | undefined;
|
|
313
316
|
logFile?: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": {
|
|
3
|
-
"name": "The Amp Team
|
|
4
|
-
"email": "amp-devs@
|
|
3
|
+
"name": "The Amp Team",
|
|
4
|
+
"email": "amp-devs@ampcode.com"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@sourcegraph/amp": "latest",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"sdk",
|
|
35
35
|
"automation"
|
|
36
36
|
],
|
|
37
|
-
"license": "
|
|
37
|
+
"license": "Amp Commercial License",
|
|
38
38
|
"main": "dist/index.js",
|
|
39
39
|
"name": "@sourcegraph/amp-sdk",
|
|
40
40
|
"repository": {
|
|
@@ -44,14 +44,15 @@
|
|
|
44
44
|
},
|
|
45
45
|
"type": "module",
|
|
46
46
|
"types": "dist/index.d.ts",
|
|
47
|
-
"version": "0.1.0-
|
|
47
|
+
"version": "0.1.0-20251210022310-g15793ed",
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "bun run scripts/build.ts",
|
|
50
50
|
"dev": "pnpm exec tsc -b --watch",
|
|
51
51
|
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
52
|
-
"examples:basic": "pnpm run build && bun run examples/basic.ts",
|
|
52
|
+
"examples:basic": "pnpm run build && bun run examples/basic.ts --",
|
|
53
53
|
"test": "vitest run",
|
|
54
54
|
"test:watch": "vitest",
|
|
55
|
+
"test:integration": "vitest run --config vitest.integration.config.js",
|
|
55
56
|
"pin-cli-version": "bun run scripts/pin-cli-version.ts"
|
|
56
57
|
}
|
|
57
58
|
}
|