Skip to content

feat: pursue a goal autonomously #270

Open
chengluyu wants to merge 62 commits into
MoonshotAI:mainfrom
chengluyu:feat/goal-impl/1
Open

feat: pursue a goal autonomously #270
chengluyu wants to merge 62 commits into
MoonshotAI:mainfrom
chengluyu:feat/goal-impl/1

Conversation

@chengluyu
Copy link
Copy Markdown
Collaborator

This PR implements the “goal” feature, which has been highly requested for many times.

Related Issue

TBA.

Problem

TBA.

What changed

TBA.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

chengluyu added 30 commits May 30, 2026 02:54
@wbxl2000 wbxl2000 marked this pull request as ready for review June 2, 2026 06:54
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf46229fbc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/agent/turn/index.ts
Comment thread apps/kimi-code/src/cli/run-prompt.ts
Comment thread packages/agent-core/src/agent/turn/index.ts
Comment thread packages/agent-core/src/session/index.ts
Comment thread packages/agent-core/src/session/rpc.ts
Comment thread packages/agent-core/src/tools/builtin/goal/create-goal.ts
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e68378e8ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core/src/agent/turn/index.ts Outdated
Comment thread packages/agent-core/src/agent/turn/index.ts
Comment thread apps/kimi-code/src/tui/commands/registry.ts Outdated
Comment thread apps/kimi-code/src/tui/commands/goal.ts
Comment thread apps/kimi-code/src/tui/commands/goal.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0815f5ea1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core/src/agent/turn/index.ts
Comment thread packages/agent-core/src/agent/turn/index.ts Outdated
Comment thread packages/agent-core/src/agent/injection/goal.ts Outdated
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 2, 2026

pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@e7e6879
npx https://pkg.pr.new/@moonshot-ai/kimi-code@e7e6879

commit: e7e6879

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7f34e153d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/kimi-code/src/cli/run-prompt.ts
Comment thread packages/agent-core/src/loop/turn-step.ts Outdated
Comment thread apps/kimi-code/src/tui/kimi-tui.ts Outdated
Comment thread packages/agent-core/src/tools/builtin/goal/update-goal.ts
Comment thread packages/agent-core/src/session/goal.ts
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 734b1d438d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +605 to +607
if (!stopHookContinuationUsed) {
const stopBlock = await this.agent.hooks?.triggerBlock('Stop', {
signal,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Block Stop-hook continuations after budget exhaustion

When an active goal hits its token budget, afterStep returns stopTurn, but runTurn still invokes this shouldContinueAfterStop hook before the goal driver can mark the goal blocked. In sessions with a Stop hook that returns a block/continuation, this branch appends the hook prompt and returns continue: true, causing another model step after the hard budget has already been reached. Check stopForGoalBudget before allowing steer/Stop-hook continuations so configured token ceilings remain deterministic.

Useful? React with 👍 / 👎.

Comment on lines +64 to +66
const reservedGoal = this.session.metadata.custom?.['goal'];
const patchCustom = (payload.metadata as Partial<SessionMeta> | undefined)?.custom;
if (patchCustom !== undefined && 'goal' in patchCustom) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reserve goal metadata on create and fork

This guard only protects updateSessionMetadata, but the public create/fork session metadata path is copied directly into Session.metadata.custom, where goal is now reserved. An SDK caller that creates or forks a session with custom metadata { goal: ... } can still seed arbitrary goal state outside the lifecycle methods and flag gate, and later getGoal()/goal driving will treat that host metadata as the current goal. Apply the same reservation to create/fork metadata inputs.

Useful? React with 👍 / 👎.

Comment on lines +725 to +728
typeof state.status === 'string' &&
ALL_GOAL_STATUSES.has(state.status) &&
typeof state.turnsUsed === 'number' &&
typeof state.tokensUsed === 'number' &&
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject goal records missing wall-clock fields

normalizeMetadata() relies on this predicate before treating metadata.custom.goal as a SessionGoalState, but this accepts records that lack required fields such as wallClockMs, createdAt, and actor timestamps. For an imported/forked session with the checked subset present, the malformed record is kept and later snapshots compute elapsed time from undefined, producing NaN/invalid goal status output instead of dropping the corrupt goal. Require the full numeric/string fields used by toSnapshot() and budget math here.

Useful? React with 👍 / 👎.

Comment on lines +62 to +63
await store.setBudgetLimits({ budgetLimits: budget, actor: 'model' });
return { output: `Goal budget set: ${formatBudget(args.value, args.unit)}.` };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop immediately when SetGoalBudget is already exhausted

When the model records a user-stated budget after the goal has already spent at least that much (for example it has used one turn and calls SetGoalBudget({ value: 1, unit: 'turns' }) as instructed), this persists an over-budget goal but returns an ordinary tool result. Because the goal driver only checks budgets at the turn boundary, the current tool batch and even the next model step can continue before the goal is blocked; return a stop hint or block immediately when the new snapshot is over budget.

Useful? React with 👍 / 👎.

@chengluyu chengluyu changed the title Support pursuing a goal autonomously feat: pursue a goal autonomously Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant