diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-27 22:39:50 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-27 22:39:50 +0200 |
| commit | 1575c64b7d40f4a7b462609242bd72885157a383 (patch) | |
| tree | 31e21bf96769759f16eb4375e27273c824b104c8 /internal/askcli/task_scope.go | |
| parent | 2ddb334fa671b9c425ca43c8c673c6b36c3ad0ab (diff) | |
Diffstat (limited to 'internal/askcli/task_scope.go')
| -rw-r--r-- | internal/askcli/task_scope.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/askcli/task_scope.go b/internal/askcli/task_scope.go new file mode 100644 index 0000000..42dd022 --- /dev/null +++ b/internal/askcli/task_scope.go @@ -0,0 +1,63 @@ +package askcli + +import "context" + +type taskScopeMode int + +const ( + taskScopeAgent taskScopeMode = iota + taskScopeNoAgent +) + +type taskScopeContextKey struct{} + +func contextWithTaskScope(ctx context.Context, scope taskScopeMode) context.Context { + if scope == taskScopeAgent { + return ctx + } + return context.WithValue(ctx, taskScopeContextKey{}, scope) +} + +func taskScopeFromContext(ctx context.Context) taskScopeMode { + if ctx == nil { + return taskScopeAgent + } + scope, ok := ctx.Value(taskScopeContextKey{}).(taskScopeMode) + if !ok { + return taskScopeAgent + } + return scope +} + +func taskScopeFilter(scope taskScopeMode) string { + if scope == taskScopeNoAgent { + return "-agent" + } + return "+agent" +} + +func parseTaskScopePrefix(args []string) (taskScopeMode, []string) { + if len(args) == 0 { + return taskScopeAgent, nil + } + if isTaskScopePrefix(args[0]) { + return taskScopeNoAgent, args[1:] + } + return taskScopeAgent, args +} + +func isTaskScopePrefix(arg string) bool { + switch arg { + case "na", "no-agent": + return true + default: + return false + } +} + +func trimTaskScopePrefix(args []string) []string { + if len(args) == 0 || !isTaskScopePrefix(args[0]) { + return args + } + return args[1:] +} |
