Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/cli/configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
applies_to:
stack: preview
serverless: preview
type: overview

Check notice on line 6 in docs/cli/configuration_reference.md

View workflow job for this annotation

GitHub Actions / build / build

Unknown key 'type'. Valid keys: applies_to, cta, description, layout, listing, mapped_pages, meta_title, navigation_title, noindex, products, sub, title. It is ignored.

Check notice on line 6 in docs/cli/configuration_reference.md

View workflow job for this annotation

GitHub Actions / build / build

Unknown key 'type'. Valid keys: applies_to, cta, description, layout, listing, mapped_pages, meta_title, navigation_title, noindex, products, sub, title. It is ignored.
---

# Configuration file reference
Expand Down Expand Up @@ -80,6 +80,6 @@

| Profile | Description |
| - | - |
| `serverless` | Only commands that work on {{serverless-full}}. Hides `cloud hosted` and exposes `cloud serverless` plus the majority of stack commands. |
| `stack` | Full command surface, including self-managed / hosted-only APIs. Equivalent to having no policy (allow everything). |
| `serverless` | Only commands that work on {{serverless-full}}. Hides `cloud hosted` and exposes `cloud serverless`, `nightshift`, plus the majority of stack commands. |
| `stack` | Full command surface, including self-managed / hosted-only APIs, except `nightshift`, which only applies to {{serverless-short}} Observability projects. |
| `default` | Alias for `serverless`; the most conservative baseline, recommended for agents and LLM-based tooling. |
16 changes: 16 additions & 0 deletions docs/cli/nightshift/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Description

:::{warning}
Nightshift commands are experimental and subject to significant changes before they reach a stable state. Each run prints a warning to stderr; pass `--accept-experimental` to suppress it. The warning is not printed with `--json`.

Check notice on line 4 in docs/cli/nightshift/index.md

View workflow job for this annotation

GitHub Actions / build / vale

Elastic.Semicolons: Use semicolons sparingly. Consider splitting the sentence or using a comma or conjunction.

Check notice on line 4 in docs/cli/nightshift/index.md

View workflow job for this annotation

GitHub Actions / build / vale

Elastic.Semicolons: Use semicolons sparingly. Consider splitting the sentence or using a comma or conjunction.
:::

Ask the Nightshift assistant a question and get its answer back in a single response, without starting an investigation.
This is `elastic kb agent-builder post-chat-message` with the agent fixed to `nightshift.assistant`.

Nightshift is only available on {{serverless-short}} Observability projects, with the `agentBuilder:experimentalFeatures` advanced setting enabled.
The command is hidden when the context's `kibana.version` [hint](../configuration.md#versions) is a {{stack}} version, and the `stack` command profile blocks it.

```bash
elastic nightshift ask "Why did checkout latency spike at 14:00?"
elastic nightshift ask --conversation-id <id> "Which service should I look at first?"
```
74 changes: 72 additions & 2 deletions docs/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -123119,7 +123119,7 @@
"name": "accept-experimental",
"type": "boolean",
"required": false,
"summary": "Acknowledge that this command is experimental and may be removed; suppresses the warning"
"summary": "Acknowledge that this command is experimental and may change or be removed; suppresses the warning"
},
{
"role": "flag",
Expand Down Expand Up @@ -123168,7 +123168,7 @@
"name": "accept-experimental",
"type": "boolean",
"required": false,
"summary": "Acknowledge that this command is experimental and may be removed; suppresses the warning"
"summary": "Acknowledge that this command is experimental and may change or be removed; suppresses the warning"
},
{
"role": "flag",
Expand Down Expand Up @@ -123243,6 +123243,76 @@
}
]
},
{
"segment": "nightshift",
"commands": [
{
"path": [
"nightshift"
],
"name": "ask",
"parameters": [
{
"role": "positional",
"name": "message",
"type": "string",
"required": false,
"summary": "The user message to send to the agent."
}
],
"summary": "Ask the Nightshift assistant a question and get its answer",
"intent": {
"requiresAuth": true
}
}
],
"namespaces": [],
"summary": "Ask the Nightshift assistant",
"options": [
{
"role": "flag",
"name": "accept-experimental",
"type": "boolean",
"required": false,
"summary": "Acknowledge that this command is experimental and may change or be removed; suppresses the warning"
},
{
"role": "flag",
"name": "conversation-id",
"type": "string",
"required": false,
"summary": "The ID of an existing conversation to continue. Omit it to start a new conversation; the response carries the ID to reuse on the next call."
},
{
"role": "flag",
"name": "message",
"type": "string",
"required": true,
"summary": "The user message to send to the agent."
},
{
"role": "flag",
"name": "input-file",
"type": "string",
"required": false,
"summary": "path to a JSON file to use as command input"
},
{
"role": "dryRun",
"name": "dry-run",
"type": "boolean",
"required": false,
"summary": "validate all inputs and exit without performing any action"
},
{
"role": "flag",
"name": "no-validate",
"type": "boolean",
"required": false,
"summary": "skip input validation and send the request as-is"
}
]
},
{
"segment": "config",
"commands": [],
Expand Down
4 changes: 2 additions & 2 deletions src/cli-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ function hoistNamespaceOptions (ns: CliNamespace): void {

function stripFrom (n: CliNamespace): void {
for (const cmd of n.commands) {
cmd.parameters = cmd.parameters.filter(p => !commonNames.has(p.name))
cmd.parameters = cmd.parameters.filter(p => p.role === 'positional' || !commonNames.has(p.name))
}
for (const sub of n.namespaces) stripFrom(sub)
}
Expand Down Expand Up @@ -474,7 +474,7 @@ function promoteToGlobalOptions (
}

for (const cmd of rootCommands) {
cmd.parameters = cmd.parameters.filter(p => !commonNames.has(p.name))
cmd.parameters = cmd.parameters.filter(p => p.role === 'positional' || !commonNames.has(p.name))
}

return promoted
Expand Down
8 changes: 8 additions & 0 deletions src/completion/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ export async function buildCompletionTree (rewrittenWords: readonly string[]): P
root.addCommand(defineGroup({ name: 'docs', description: 'Search, read, and ask questions about Elastic documentation' }))
}

// `nightshift` — deep-load on exact match, stub otherwise.
if (firstWord === 'nightshift') {
const { NAMESPACES } = await import('../namespaces.ts')
root.addCommand(await NAMESPACES.find(ns => ns.name === 'nightshift')!.load())
} else {
root.addCommand(defineGroup({ name: 'nightshift', description: 'Ask the Nightshift assistant' }))
}

// `config` — deep-load on exact match, stub otherwise.
if (firstWord === 'config') {
const { registerConfigCommands } = await import('../config/commands.ts')
Expand Down
17 changes: 11 additions & 6 deletions src/config/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* Built-in profiles:
* - `serverless` — only commands that work on Elastic Serverless. Hides
* `cloud hosted` and exposes `cloud serverless` + all stack commands.
* - `stack` — full surface including self-managed / hosted-only APIs.
* Equivalent to having no policy (allow everything).
* - `stack` — full surface including self-managed / hosted-only APIs,
* minus commands that only apply to Serverless projects.
* - `default` — alias for `serverless`; the most conservative baseline,
* recommended for agents and LLM-based tooling.
*/
Expand All @@ -40,14 +40,17 @@ const STACK_ONLY_ES_NAMESPACES = [
'watcher',
] as const

/** Namespaces that only apply to Serverless projects (Nightshift: observability projects). */
const SERVERLESS_ONLY_NAMESPACES = ['nightshift'] as const

/**
* Resolves a built-in profile to an effective allow/block policy.
*
* Returns `null` for `stack`, which means "no restriction" (allow everything).
* Returns an object with `allowed` and `blocked` patterns for all other profiles.
* `allowed`, when present, is the complete allow-list; without it every command
* not matched by `blocked` is allowed.
*/
export function resolveBuiltinProfile (name: BuiltInProfile): { allowed: readonly string[]; blocked?: readonly string[] } | null {
if (name === 'stack') return null
export function resolveBuiltinProfile (name: BuiltInProfile): { allowed?: readonly string[]; blocked?: readonly string[] } {
if (name === 'stack') return { blocked: SERVERLESS_ONLY_NAMESPACES.map(ns => `${ns}.*`) }

// `default` is an alias for `serverless`
return {
Expand All @@ -65,6 +68,8 @@ export function resolveBuiltinProfile (name: BuiltInProfile): { allowed: readonl
// All stack commands (Elasticsearch + Kibana)
'stack.*',

...SERVERLESS_ONLY_NAMESPACES.map(ns => `${ns}.*`),

// Cloud cross-cutting namespaces (apply to both Hosted and Serverless)
'cloud.trust.*',
'cloud.auth.*',
Expand Down
24 changes: 7 additions & 17 deletions src/docs/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { defineCommand } from '../factory.ts'
import type { OpaqueCommandHandle, JsonValue } from '../factory.ts'
import { docsAskStream, newUuid, type AskStreamEvent } from './client.ts'
import { startSpinner, streamAnswer } from './stream.ts'
import { ACCEPT_EXPERIMENTAL_OPTION, warnIfExperimental } from '../lib/experimental.ts'

export interface AskDeps {
docsAskStream: (message: string, conversationId: string) => AsyncGenerator<AskStreamEvent>
Expand All @@ -27,34 +28,23 @@ const inputSchema: Record<string, unknown> = {
},
}

function experimentalBanner (isTTY: boolean): string {
const text =
'Warning: "docs ask" is experimental and in active development.\n' +
' Not yet suited for scripts or automation. Pass --accept-experimental to suppress this warning.\n\n'
return isTTY ? `\x1b[33m${text}\x1b[0m` : text
}

export function createAskCommand (deps: AskDeps = defaultDeps): OpaqueCommandHandle {
return defineCommand({
name: 'ask',
description: 'Ask a question about Elastic documentation using AI (single answer)',
input: inputSchema,
positionalArg: { name: 'question', description: 'Question to ask', required: false },
options: [
{
long: 'accept-experimental',
type: 'boolean',
description: 'Acknowledge that this command is experimental and may be removed; suppresses the warning',
},
],
options: [ACCEPT_EXPERIMENTAL_OPTION],
handler: async (parsed): Promise<JsonValue> => {
const inp = parsed.input as { question?: string } | undefined
const question = (parsed.arg ?? inp?.question ?? '').trim()
if (question === '') return { error: { code: 'missing_input', message: 'Pass --question <text> (or a positional question).' } }

if (parsed.options['accept-experimental'] !== true && parsed.options['json'] !== true) {
deps.stderr.write(experimentalBanner(process.stderr.isTTY === true))
}
warnIfExperimental(parsed, {
label: 'docs ask',
status: 'in active development',
advice: 'Not yet suited for scripts or automation.',
}, deps.stderr)

const conversationId = newUuid()
const interactive = process.stderr.isTTY === true && parsed.options['json'] !== true
Expand Down
24 changes: 7 additions & 17 deletions src/docs/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { defineCommand } from '../factory.ts'
import type { OpaqueCommandHandle, JsonValue } from '../factory.ts'
import { docsSearch, stripHtmlTags } from './client.ts'
import { ACCEPT_EXPERIMENTAL_OPTION, warnIfExperimental } from '../lib/experimental.ts'

function resultSummary (aiShortSummary: string | undefined, description: string): string {
return (aiShortSummary != null && aiShortSummary !== '') ? aiShortSummary : stripHtmlTags(description)
Expand All @@ -27,30 +28,19 @@ const inputSchema: Record<string, unknown> = {
},
}

function experimentalBanner (command: string, isTTY: boolean): string {
const text =
`Warning: "${command}" is experimental and in active development.\n` +
` Not yet suited for scripts or automation. Pass --accept-experimental to suppress this warning.\n\n`
return isTTY ? `\x1b[33m${text}\x1b[0m` : text
}

export function createSearchCommand (deps: SearchDeps = defaultDeps): OpaqueCommandHandle {
return defineCommand({
name: 'search',
description: 'Search Elastic documentation',
input: inputSchema,
positionalArg: { name: 'query', description: 'Search terms', required: false },
options: [
{
long: 'accept-experimental',
type: 'boolean',
description: 'Acknowledge that this command is experimental and may be removed; suppresses the warning',
},
],
options: [ACCEPT_EXPERIMENTAL_OPTION],
handler: async (parsed): Promise<JsonValue> => {
if (parsed.options['accept-experimental'] !== true && parsed.options['json'] !== true) {
deps.stderr.write(experimentalBanner('docs search', process.stderr.isTTY === true))
}
warnIfExperimental(parsed, {
label: 'docs search',
status: 'in active development',
advice: 'Not yet suited for scripts or automation.',
}, deps.stderr)
const inp = parsed.input as { query?: string; page?: number; size?: number } | undefined
const query = (parsed.arg ?? inp?.query ?? '').trim()
if (query === '') return { error: { code: 'missing_input', message: 'query is required' } }
Expand Down
12 changes: 7 additions & 5 deletions src/factory-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export interface CommandConfig {
name: string
description: string
options?: OptionDefinition[]
positionalArg?: { name: string; description: string; required?: boolean }
/**
* Optional positional argument. With `inputKey`, its value fills that input schema
* field before validation, as an alternative to the field's flag.
*/
positionalArg?: { name: string; description: string; required?: boolean; inputKey?: string }
handler: (parsed: ParsedResult) => HandlerResult | Promise<HandlerResult>
/** JSON Schema object for structured input (properties carry `x-found-in` routing). */
input?: Record<string, unknown>
Expand Down Expand Up @@ -194,10 +198,8 @@ export function isCommandAllowed (commandDotPath: string, policy: CommandPolicy

if (policy.profile != null) {
const profilePolicy = resolveBuiltinProfile(policy.profile)
if (profilePolicy != null) {
if (!profilePolicy.allowed.some(matches)) return false
if (profilePolicy.blocked?.some(matches)) return false
}
if (profilePolicy.allowed != null && !profilePolicy.allowed.some(matches)) return false
if (profilePolicy.blocked?.some(matches)) return false
if (policy.blocked != null) return !policy.blocked.some(matches)
return true
}
Expand Down
17 changes: 15 additions & 2 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ interface MergedInput {
}

/** Merges schema-derived CLI flag values over the JSON input; flags win. */
function mergeFlagsIntoInput (cmd: Command, jsonInput: unknown, schemaArgs: SchemaArgDefinition[], allRaw: OptionValues): MergedInput {
function mergeFlagsIntoInput (
cmd: Command, jsonInput: unknown, schemaArgs: SchemaArgDefinition[], allRaw: OptionValues,
positionalArg?: CommandConfig['positionalArg'],
): MergedInput {
let inputValue = jsonInput
const rawBodyValues: Record<string, RawJsonValue> = {}
const sortParsedKeys = new Set<string>()
Expand Down Expand Up @@ -539,6 +542,16 @@ function mergeFlagsIntoInput (cmd: Command, jsonInput: unknown, schemaArgs: Sche
}
}

const positionalKey = positionalArg?.inputKey
const positionalInput = cmd.processedArgs[0] as string | undefined
if (positionalKey != null && positionalInput !== undefined) {
if (positionalKey in cliInput) {
const flag = schemaArgs.find((a) => a.schemaKey === positionalKey)?.cliFlag ?? positionalKey
return cmd.error(`pass ${positionalArg!.name} either as an argument or as --${flag}, not both`)
}
cliInput[positionalKey] = positionalInput
}

if (Object.keys(cliInput).length > 0) {
inputValue = { ...(inputValue as Record<string, unknown> ?? {}), ...cliInput }
}
Expand Down Expand Up @@ -864,7 +877,7 @@ export function defineCommand (config: CommandConfig): OpaqueCommandHandle {
const jsonFormat = allRaw.json
const options = collectOptions(optDefs, allRaw)
const merged = isJsonSchemaInput(config.input)
? mergeFlagsIntoInput(cmd, readInput(cmd, config), schemaArgs, allRaw)
? mergeFlagsIntoInput(cmd, readInput(cmd, config), schemaArgs, allRaw, config.positionalArg)
: undefined

const positionalValue = config.positionalArg != null
Expand Down
Loading
Loading